Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Array method parameters type "aay" (array of array of bytes) #367

Closed
crussell42 opened this issue Sep 29, 2023 · 5 comments
Closed

Comments

@crussell42
Copy link

Unable to invoke method that requires a dbus parameter type='aay' or any nested arrays for that matter.

From avahi source:
[(https://github.com/lathiat/avahi/blob/e5b0badfc725b7fa9e6069b6a3d5f278d1b96113/avahi-daemon/org.freedesktop.Avahi.EntryGroup.xml)]

I am trying to call method AddService but am unable to create an nested DBusArray.
dart-dbus program seem to get it wrong as well.

Here is the pertinent xml definition of the object in a temp file named test.xml

<node>
  <interface name="org.freedesktop.Avahi.EntryGroup">

    <method name="AddService">
      <arg name="interface" type="i" direction="in"/>
      <arg name="protocol" type="i" direction="in"/>
      <arg name="flags" type="u" direction="in"/>
      <arg name="name" type="s" direction="in"/>
      <arg name="type" type="s" direction="in"/>
      <arg name="domain" type="s" direction="in"/>
      <arg name="host" type="s" direction="in"/>
      <arg name="port" type="q" direction="in"/>
      <arg name="txt" type="aay" direction="in"/>
    </method>

  </interface>
</node>

$ ~/.pub-cache/bin/dart-dbus generate-remote-object test.xml -o test.dart

Note that method parameter for txt is "aay" and the code generated is

DBusArray(DBusSignature('ay'), txt.map((child) => DBusArray.byte(child)))

This does not work with the DBusSignature checking as DBusSignature('ay') is invalid.
Hopefully I am not missing something simple but it seems like nested arrays are not supported.

@crussell42
Copy link
Author

Ive added a pull request with the changes necessary to allow this.
Pull Request Name: allow DBus data type='aay'
#368

@robert-ancell
Copy link
Contributor

I can't see any issues here. I took the example in https://gist.github.com/lemenkov/7515376 and implemented it using Dart using the generated code and it seems to work. Are you seeing any errors with this?

import 'dart:convert';
import 'package:dbus/dbus.dart';

class OrgFreedesktopAvahiEntryGroup extends DBusRemoteObject {
  OrgFreedesktopAvahiEntryGroup(
      DBusClient client, String destination, DBusObjectPath path)
      : super(client, name: destination, path: path);

  /// Invokes org.freedesktop.Avahi.EntryGroup.AddService()
  Future<void> callAddService(
      int interface,
      int protocol,
      int flags,
      String name,
      String type,
      String domain,
      String host,
      int port,
      List<List<int>> txt,
      {bool noAutoStart = false,
      bool allowInteractiveAuthorization = false}) async {
    await callMethod(
        'org.freedesktop.Avahi.EntryGroup',
        'AddService',
        [
          DBusInt32(interface),
          DBusInt32(protocol),
          DBusUint32(flags),
          DBusString(name),
          DBusString(type),
          DBusString(domain),
          DBusString(host),
          DBusUint16(port),
          DBusArray(
              DBusSignature('ay'), txt.map((child) => DBusArray.byte(child)))
        ],
        replySignature: DBusSignature(''),
        noAutoStart: noAutoStart,
        allowInteractiveAuthorization: allowInteractiveAuthorization);
  }
}

Future<int> main(List<String> args) async {
  var client = DBusClient.system();

  var result = await client.callMethod(
      destination: 'org.freedesktop.Avahi',
      path: DBusObjectPath('/'),
      interface: 'org.freedesktop.Avahi.Server',
      name: 'EntryGroupNew',
      replySignature: DBusSignature('o'));
  var path = result.returnValues[0].asObjectPath();
  print(path);
  var o = OrgFreedesktopAvahiEntryGroup(client, 'org.freedesktop.Avahi', path);
  await o.callAddService(
      -1, -1, 0, 'test@Hostname', '_epmd._tcp', 'local', 'work.local', 4369, [
    utf8.encode('[email protected]'),
    utf8.encode('[email protected]'),
    utf8.encode('status=avail')
  ]);

  await client.close();

  return 0;
}

@crussell42
Copy link
Author

I swear I was....but now you have me thinking I just did a useless exercise.
Let me dig back up my original test using the pub.dev package, and the original main I cloned.
I will dig into it and get back.
Thank you very much for the response, hope I didnt waste your time on a simple screw up on my part.

@crussell42
Copy link
Author

Well, its a long story but it all started trying to call AddService with an improper EntryGroup path.
The error messages I was getting back from the Avahi daemon:
org.freedesktop.DBus.Error.UnknownMethod: Method "AddService" with signature "iiussssqaay" on interface "org.freedesktop.Avahi.EntryGroup" doesn't exist
Lead me to believe that somehow my structuring of the DBusValue's was wrong and this led me off on the tangent.
Like a Dope, I let my tests change as I was working toward allowing an DBusArray with a single 'a' signature.
Hubris I know.
In my defense, this was my first attempt at anything 'Dart'.
If I may suggest, adding the example of creating the service and the Array of Array of bytes might be helpful to others as well.

@robert-ancell
Copy link
Contributor

No problem, thanks for the feedback and good luck with your project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants