[systemd-devel] sd-bus object manager question
David Härdeman
david at hardeman.nu
Sat Jun 27 00:22:45 PDT 2015
On Thu, Jun 25, 2015 at 04:25:29PM +0200, David Herrmann wrote:
>On Tue, Jun 23, 2015 at 2:41 PM, David Härdeman <david at hardeman.nu> wrote:
...
>> Now, a question...how is an object manager supposed to be implemented in
>> sd-bus?
>>
>> I've seen that there's a sd_bus_add_object_manager() function in sd-bus.h,
>> but how would I notify the object manager when objects are added and
>> removed?
>>
>> Two likely candidates seemed to be:
>> sd_bus_emit_object_added()
>> sd_bus_emit_object_removed()
>>
>> But calling them did not seem to do the right thing. And there seems to be
>> zero usage of sd_bus_add_object_manager() in the systemd tree itself (though
>> plenty of calls to sd_bus_add_node_enumerator() which might be related?).
>
>Not sure where the confusion is. Those calls generate the
>InterfacesAdded/Removed signals that the objectmanager API specifies.
>They collect the interfaces based on the vtables you registered on a
>given path. have a look at test-bus-objects.c which uses these
>interfaces.
I've done some more experimentation and I think I've got a better idea
of what's going on. Sorry if my first email was a bit confusing.
My problem is that I couldn't get the sd-bus object manager to properly
notify clients when objects are added or removed.
I'm testing my sd-bus server with a gdbus client. The
GDBusObjectManagerClient should normally generate signals (gobject
signals, that is) when objects are added or removed.
Anyway, I tried implementing an object manager server with gdbus as
well, and when talking to the gdbus server, the client is notified of
object additions/removals, so I used used busctl to monitor the signals
that were generated. I think I've found the problem.
Assume there's an object manager at "/org/example/mgr" and that a new
object is created at "/org/example/mgr/object1".
With sd-bus, I'd call:
sd_bus_emit_object_added(bus, "/org/example/mgr/object1");
The generated signal would be:
‣ Type=signal Endian=l Flags=1 Version=1 Priority=0 Cookie=11
Sender=:1.297 Path=/org/example/mgr/object1
Interface=org.freedesktop.DBus.ObjectManager Member=InterfacesAdded
UniqueName=:1.297
MESSAGE "oa{sa{sv}}" {
OBJECT_PATH "/org/example/mgr/object1";
With gdbus, the generated signal is instead:
The generated signal would be:
‣ Type=signal Endian=l Flags=1 Version=1 Priority=0 Cookie=21
Sender=:1.297 Path=/org/example/mgr
Interface=org.freedesktop.DBus.ObjectManager Member=InterfacesAdded
UniqueName=:1.297
MESSAGE "oa{sa{sv}}" {
OBJECT_PATH "/org/example/mgr/object1";
Note the difference in the sender path.
The GDBusObjectManagerClient seems to ignore the signal sd-bus generates
because of the different path.
I think that means that sd_bus_emit_object_added() would need to take
both the object manager path and the object path as arguments instead of
a single path?
Regards,
David
More information about the systemd-devel
mailing list