dbus-native icon indicating copy to clipboard operation
dbus-native copied to clipboard

Fixed problems with introspection, the path names and structure were not

Open dashxdr opened this issue 8 years ago • 4 comments

correct and didn't allow for proper recursion. Now the path names for all child nodes have names relative to the path specified in the query, and are provided with a null node placeholder entry so they appear in the xml, and the caller can then recursively scan as desired.

The code could probably be made more efficient with fewer checks for exceptions.

dashxdr avatar Feb 27 '17 21:02 dashxdr

Hi @dashxdr ! I think I understand the issue, but could you provide step-by-step example where old code would fail?

sidorares avatar Feb 27 '17 23:02 sidorares

Here is an example, it mimics the ofono dbus interface (just a little). It can be placed in the node-dbus/test directory.

// ****************** START
#!/usr/bin/env node
"use strict";

var dbus = require('../../node-dbus');
var bus = dbus.systemBus();


var ManagerIface = {
	name: 'org.ofono.Manager',
	methods: {
		GetModems: ['', 'a(oa{sv})', [], ['modems']], 
	},
	signals: {
		ModemAdded: ['oa{sv}', ['path'], ['properties']],
		ModemRemoved: ['o', ['path']],
	},
};

var Manager = {
	GetModems: function()
	{
		console.log('Manager.GetModems');

		return [[
			'/sim5320_0',
			[
				['Online', ['b', true]],
			]
		]];
	},
};

bus.requestName('org.ofono', 0x4, function(e, retCode) {
	if(e) console.log('error with requestName');
	else {
		console.log('requestName worked, retCode = ' + retCode);
		bus.exportInterface(Manager, '/', ManagerIface);

	}
});
//********************* END

When you run it you can test functionality with this: dbus-send --system --dest=org.ofono --print-reply / org.ofono.Manager.GetModems And it should output this:

   array [
      struct {
         object path "/sim5320_0"
         array [
            dict entry(
               string "Online"
               variant                   boolean true
            )
         ]
      }
   ]

To verify some instrospection functionality do this first: gdbus introspect --system --dest org.ofono --object-path / The output should be this:

node / {
  node  {
  };
};

NOW to cause the failure, add the --recurse onto the query: gdbus introspect --system --dest org.ofono --object-path / --recurse and voila:

node / {
  node / {
    node / {
      node / {
        node / {
          node / {
            node / {
              node / {
                node / {
                  node / {
                    node / {
                      node / {

... etc

With my version we get this for both queries, which is what we want:

node / {
  interface org.ofono.Manager {
    methods:
      GetModems(out a(oa{sv}) modems);
    signals:
      ModemAdded(o path,
                 a{sv} properties);
      ModemRemoved(o path);
    properties:
  };
  interface org.freedesktop.DBus.Properties {
    methods:
      Get(in  s interface_name,
          in  s property_name,
          out v value);
      GetAll(in  s interface_name,
             out a{sv} properties);
      Set(in  s interface_name,
          in  s property_name,
          in  v value);
    signals:
      PropertiesChanged(s interface_name,
                        a{sv} changed_properties,
                        as invalidated_properties);
    properties:
  };
  interface org.freedesktop.DBus.Introspectable {
    methods:
      Introspect(out s xml_data);
    signals:
    properties:
  };
  interface org.freedesktop.DBus.Peer {
    methods:
      Ping();
      GetMachineId(out s machine_uuid);
    signals:
    properties:
  };
};

dashxdr avatar Feb 27 '17 23:02 dashxdr

One other note, you need to make sure your permissions are set to allow queries on the system dbus, I'm a little hazy on the details. Here is my /etc/dbus-1/system.d/ofono.conf file if it helps...

<!-- This configuration file specifies the required security policies
     for oFono core daemon to work. -->

<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
 "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>

  <!-- ../system.conf have denied everything, so we just punch some holes -->

  <policy user="root">
    <allow own="org.ofono"/>
    <allow send_destination="org.ofono"/>
    <allow send_interface="org.ofono.SimToolkitAgent"/>
    <allow send_interface="org.ofono.PushNotificationAgent"/>
    <allow send_interface="org.ofono.SmartMessagingAgent"/>
    <allow send_interface="org.ofono.PositioningRequestAgent"/>
    <allow send_interface="org.ofono.HandsfreeAudioAgent"/>
  </policy>

  <policy at_console="true">
    <allow send_destination="org.ofono"/>
  </policy>

  <policy context="default">
    <deny send_destination="org.ofono"/>
  </policy>

</busconfig>

dashxdr avatar Feb 27 '17 23:02 dashxdr

thanks! I'll try to have a look soon ( there is a huge backlog on this project I never had enough time to action )

sidorares avatar Feb 27 '17 23:02 sidorares