Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve D-Bus struct handling: as properties #98

Merged
merged 6 commits into from
Feb 23, 2022
Merged

Conversation

mvidner
Copy link
Owner

@mvidner mvidner commented Feb 17, 2022

Responding to #97.

  • properly document: unserializing a struct makes a frozen array

Before

Before this PR, the return signature for getting a property was a Variant:

org.freedesktop.DBus.Properties.Get(..., ..., out VARIANT value)

With no type hint for the Ruby -> D-Bus data conversion, a property with a nontrivial type, such as STRUCT, would get returned incorrectly:

$ busctl --user --list introspect org.ruby.service /org/ruby/MyInstance | grep -E NAME\|MyStruct
NAME                            TYPE      SIGNATURE RESULT/VALUE                            FLAGS
.MyStruct                       property  (sss)     3 s "three" s "strings" s "in a struct" emits-change # not visible here
$ dbus-send --session --print-reply --dest=org.ruby.service /org/ruby/MyInstance org.freedesktop.DBus.Properties.Get string:org.ruby.SampleInterface string:MyStruct
method return time=[...] sender=:1.985 -> destination=:1.987 serial=24 reply_serial=2
   variant       array [
         variant             string "three"
         variant             string "strings"
         variant             string "in a struct"
      ]

After

Now, Property.Get has a special case to look at the signature declared for the property itself.
So a STRUCT, ieven though mplemented at the service side as an Array, gets returned as a STRUCT.

$  dbus-send --session --print-reply --dest=org.ruby.service /org/ruby/MyInstance org.freedesktop.DBus.Properties.Get string:org.ruby.SampleInterface string:MyStruct
method return time=[...] sender=:1.990 -> destination=:1.991 serial=12 reply_serial=2
   struct {
      string "three"
      string "strings"
      string "in a struct"
   }

@coveralls
Copy link

coveralls commented Feb 23, 2022

Coverage Status

Coverage decreased (-0.3%) to 84.389% when pulling 6addc2e on struct-properties into bf4b868 on master.

The test fails, no property-signature hint for the variant-typed Property.Get
yet.
This is at the service side.
This fixes Get, but not GetAll or Set.
General type checks for properties or methods are still missing.
The implementation should be factorerd out.
@mvidner mvidner marked this pull request as ready for review February 23, 2022 18:15
if iface.name == PROPERTY_INTERFACE && member_sym == :Get
# Use the specific property type instead of the generic variant
# returned by Get.
# GetAll and Set still missing
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ruby dbus does not use common TODO: or FIXME: comments?

@mvidner mvidner merged commit 74c1f6d into master Feb 23, 2022
@mvidner mvidner deleted the struct-properties branch February 23, 2022 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants