[systemd-devel] sd-bus delayed reply
Lennart Poettering
lennart at poettering.net
Mon Feb 4 13:55:22 UTC 2019
On Mo, 04.02.19 13:25, Giacinto Cifelli (gciofono at gmail.com) wrote:
> > Or in other words: if you have some piece of data that is expensive to
> > get, that needs time, that might fail, then you should add an explicit
> > GetXYZ() method for it, and properties are not the right concept.
> >
> > It's a pity this is nowhere documented more explicitly. We should work
> > on that.
> >
> > (To clarify: this is not an sd-bus specific limitation, but pretty
> > much a general D-Bus fact)
>
> thank you for your insight, however I am faced with an existing dbus
> API, for ofono.
I am sorry, but that API isn't carefully designed then...
> I have to say that the API does use GetProperies/SetProperty, and
> signals for PropertyChanged, and not the properties above, but I
> think it is really a design issue:
> to power on a module (that can take several seconds) there should be a
> SetPower(true) method, and not a SetProperty(Powered, true).
What I wrote above is about read-access, not about write
access. if we are talking about Setting props, rather than Getting
them, then things are a bit different:
Write access is permitted to fail, and it's less important the
operation is cheaply implemented. Now, sd-bus still doesn't allow you
to handle them "slowly", but it's relatively simple to work around
that: you can install a filter callback (for example with
sd_bus_add_object() or sd_bus_add_match(), that matches against the
SetProperty() method call. In that callback you check if it's about
the property you care about then. If it is, you return > 0 (thus
indicating that you are handling it). Otherwise you return 0 (thus
allowing the usual vtable property handling of sd-bus handle it).
Still though, properties aren't made for this, they are supposed to be
quick, and cheap, and slow operations should be methods really.
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list