-1

Given libdbus-1 which is non-negotiable, I'd like to implement Get and GetAll for DBus properties.

I don't really see any examples for this.

Do I just have to match the method with dbus_message_is_method_call() and respond accordingly?

Or is there a built in way of doing this where I have some code to do the heavy lifting.

Once again, switching libraries is not an option so please don't say use Qt, glib, libnih, libsystemd, or anything else. Please be specific to libdbus-1 or don't answer.

1 Answers1

0

Look at the libdbus-1 source code: git://anongit.freedesktop.org/dbus/dbus

There's an example here in bus/driver.c called bus_driver_handle_get_all(). This function implements a reply to "GetAll".

Of course, we need to have GetAll implemented in our xml file for introspection as well.

<interface name='org.freedesktop.DBus.Properties'>
    <method name='Get'>
         <arg name='interface' type='s' direction='in' />
         <arg name='property'  type='s' direction='in' />
         <arg name='value'     type='s' direction='out' />
     </method>

     <method name='GetAll'>
         <arg name='interface'  type='s'     direction='in'/>
         <arg name='properties' type='a{sv}' direction='out'/>
     </method>
</interface>

So to reply to this, we need to iterate through all of our properties and load them up in a DBusMessageIter then send this reply to the sender.

Clearly the "Get" response is much easier, we merely have to return a string in this case which is obviously matched for our property. Again, this is in the same file, bus/driver.c in the function: bus_driver_handle_get().