the GetAll method and invalid properties

Simon McVittie simon.mcvittie at collabora.co.uk
Tue Apr 10 01:49:04 PDT 2012


On 09/04/12 18:04, Shah, Nirav J2 wrote:
> Subject: dbus Digest, Vol 81, Issue 3

(You'd probably be better off subscribing to the non-digest version of
the list: it's not high-traffic, and gives you a more useful subject
line in replies.)

> Although you are right that a readable property has to be valid always.
[...]
> In my case it's an object-path type. On initialization it's not valid.
> I am thinking of returning a specific value (indicating invalid property)
> to make getall work.

Yes, you have to do this, one way or another.

If the current definitions of your properties don't always give them any
valid value, you need to redefine them so they do always have a value
(not necessarily a *meaningful* value, but that's OK, as long as there's
a simple way to tell whether it's meaningful or not).

For instance, if you had a property documented as "the last message
received" (not always valid) you could change it to "the last message
received, or '' if no message has been received yet" (always valid, but
sometimes empty/meaningless).

In Telepathy we often have a pattern like this:

    property Error : readable 's'
        If the Status is Disconnected, the error that caused
        disconnection, or the empty string if the status
        has always been Disconnected. Otherwise, the empty string.

> 1) Changing the type of the property to a container type like array of
> object-path (ao). I think from observation this can be NULL.

An 'ao' can't be NULL (there is no NULL in D-Bus), but it can be empty.
So, yes, you can have something like this:

    property MaybeThing : readable 'ao'
        If the thing is available, an array with one element containing
        its object path. If not, an empty array.

There is a proposal[1] to add 'm' (maybe) types, which are like 'a'
(array) types but can only have 0 or 1 elements in the array: so you
either have an object path (or whatever the element's type is), or
"nothing". These are not yet supported, though, and nobody's actively
working on them, so they're unlikely to be in D-Bus 1.6 at this stage.

[1] https://bugs.freedesktop.org/show_bug.cgi?id=27857

> 2) Using an invalid object path like "/"

We typically do this in Telepathy; for instance the Account.Connection
property is '/' if the Account does not currently have a Connection.
There are good reasons to avoid using '/' for anything else anyway[2],
so not being able to use a "real object" at '/' is not a problem.

[2] http://0pointer.de/blog/projects/versioning-dbus.html

> 3) Return an object initialized with an empty string. I think I tried
> this and it blew up because there is a valid type check somewhere in
> dbus library

No, this won't work: "" is not a syntactically valid object path, and
'o' properties require a valid object path.

    S


More information about the dbus mailing list