-
Notifications
You must be signed in to change notification settings - Fork 49
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
Properly convert types for properties #97
Comments
The current behavior is that the property returned by This is because the Ruby to D-Bus value conversion only looks at the method signature, and We should add a special case to look at the signature of the property being retrieved. |
(Which reminds me that the library could use more type checking both at client and service side. I need to make a separate Issue for that.) |
agreed. I can very easily return wrong types and even wrong signatures like |
Another side issue: The reported issue is at the service side, but when I want to write a test for it, the client side does not distinguish between arrays and structs either (representing them both as Ruby Arrays). Instead of writing a low-level test at the message+signature level, I will fix it by returning structs as frozen Ruby Arrays. |
The test fails, no property-signature hint for the variant-typed Property.Get yet. TODO: properly document: unserializing a struct makes a frozen array
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.
Thanks for the catch. (The |
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.
Status:
To fix For a property dbus_attr_accessor :my_property, "s" The service-side methods Introducing I am adding regression tests to |
Oops, "in order to fix this issue" was interpreted by the GitHub bot as "this issue is fixed". Not so, reopening. |
https://build.opensuse.org/request/show/963982 by user mvidner + dimstar_suse (Fix previous submissions by using the gem file from rubygems.org) - 0.18.0.beta1 API: * D-Bus structs have been passed as Ruby arrays. Now these arrays are frozen. * Ruby structs can be used as D-Bus structs. Bug fixes: * Returning the value for o.fd.DBus.Properties.Get, use the specific property signature, not the generic Variant (gh#mvidner/ruby-dbus#97). - 0.17.0 API: * Export properties with `dbus_attr_accessor`, `dbus_reader` etc. (gh#mvidner/ruby-dbus#86). Bug fixes: * Depend on rexml which is separate since Ruby 3.0 (gh#mvidner/ruby-dbus#87, by Toshiaki Asai). Nokogiri is faster but bigger so it remains optional. * Fix connection in case ~/.dbus-keyrings has multiple cookies, showing as "Oops: undefined method `zero?' for nil:NilClass". * Add the mis
I think I'm seeing a similar problem, adding to this issue. (Let me know you're prefer this as a separate ticket). Properties defined as adapter[ 'DiscoverableTimeout' ] = 0
... and on the
This is using the beta2 prerelease. |
... and almost immediately after writing that, I found the Variants stuff. adapter[ 'DiscoverableTimeout' ] = DBus.variant( 'u', 0 ) That'll do in a pinch. |
@mahlonsmith Thanks for the report! I can reproduce the problem with: #! /usr/bin/env ruby
# frozen_string_literal: true
require "dbus"
bus = DBus::SystemBus.instance
bz_service = bus["org.bluez"]
bz_object = bz_service["/org/bluez/hci0"]
bz_iface = bz_object["org.bluez.Adapter1"]
PROP_NAME = "DiscoverableTimeout"
# read a property
val = bz_iface[PROP_NAME]
puts "#{PROP_NAME} is #{val}"
# write a property
bz_iface[PROP_NAME] = 0 It is present also in earlier versions, not a regression in 0.18 beta. It seems the fix will be using the recently introduced |
With 0.18.1:
Unrelated problems discovered along the way, validation of
|
ruby-dbus represents data using plain Ruby types, which is natural and perfectly fine when the method and property types are simple.
If we export a property with a more complex type, like
(stttt)
in the following example (available asGist, inspired by dinstaller/dbus/manager.rb) then the result will have a similar but incorrect type.
Given a Properties.Get(Progress) call, implemented like this:
The EXPECTED result should be a variant of struct containing uint64's
At the time this issue was originally reported, it was:
PR #98 was a partial fix for
Get
but it is actually wrong since it doesn't respect the Variant return type:GetAll
is still mistyped:Original issue description by JReidinger
Hi,
basically issue is with properties. If property has signature, then ruby-dbus should convert result same as it does for methods. So something like
should work out of the box.
(mvidner: the original report had
a(ssa{sv})
as the signature, off by one level of nesting)The text was updated successfully, but these errors were encountered: