Giter Site home page Giter Site logo

ruby-dbus's Introduction

Ruby D-Bus

D-Bus is an interprocess communication mechanism for Linux. Ruby D-Bus is a pure Ruby library for writing clients and services for D-Bus.

Gem Version Build Status Dependency Status Code Climate Coverage Status

Example

Check whether the system is on battery power via UPower

require "dbus"
sysbus = DBus.system_bus
upower_service   = sysbus["org.freedesktop.UPower"]
upower_object    = upower_service["/org/freedesktop/UPower"]
upower_interface = upower_object["org.freedesktop.UPower"]
on_battery       = upower_interface["OnBattery"]
if on_battery
  puts "The computer IS on battery power."
else
  puts "The computer IS NOT on battery power."
end

Requirements

  • Ruby 2.4 or newer.

Installation

  • gem install ruby-dbus

Features

Ruby D-Bus currently supports the following features:

  • Connecting to local buses.
  • Accessing remote services, objects and interfaces.
  • Invoking methods on remote objects synchronously and asynchronously.
  • Catch signals on remote objects and handle them via callbacks.
  • Remote object introspection.
  • Walking object trees.
  • Creating services and registering them on the bus.
  • Exporting objects with interfaces on a bus for remote use.
  • Rubyish D-Bus object and interface syntax support that automatically allows for introspection.
  • Emitting signals on exported objects.

Usage

See some of the examples in the examples/ subdirectory of the tarball. Also, check out the included tutorial (in Markdown format) in doc/Tutorial.md or view it online on https://github.com/mvidner/ruby-dbus/blob/master/doc/Tutorial.md .

License

Ruby D-Bus is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

ruby-dbus's People

Contributors

bernd avatar bkabrda avatar clery avatar da1l6 avatar derjanb avatar felixonmars avatar geoffyoungs avatar havenwood avatar jbro avatar jeremycole avatar johnnywalker avatar joseivanlopez avatar jreidinger avatar kkaempf avatar lslezak avatar miaoufkirsh avatar mvidner avatar myra avatar nmeyerhans avatar qnet-herwin avatar quark-zju avatar rpignolet avatar schorppda avatar sdague avatar toshia avatar valpackett avatar voxik avatar walterbrebels avatar ytaka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ruby-dbus's Issues

Not compatible with Ruby 1.9.2_p290

The gem is not compatible with Ruby 1.9.2_p290 (and probably earlier).

irb(main):001:0> require 'dbus'
/usr/lib/ruby/site_ruby/1.9.1/dbus/introspect.rb:94: warning: else without rescue is useless
SyntaxError: /usr/lib/ruby/site_ruby/1.9.1/dbus/introspect.rb:91: syntax error, unexpected ':', expecting keyword_then or ',' or ';' or '\n'
        when 0: name
               ^
/usr/lib/ruby/site_ruby/1.9.1/dbus/introspect.rb:552: syntax error, unexpected keyword_end, expecting $end
end # module DBus
   ^
    from <internal:lib/rubygems/custom_require>:29:in `require'
    from <internal:lib/rubygems/custom_require>:29:in `require'
    from /usr/lib/ruby/site_ruby/1.9.1/dbus.rb:12:in `<top (required)>'
    from <internal:lib/rubygems/custom_require>:29:in `require'
    from <internal:lib/rubygems/custom_require>:29:in `require'
    from (irb):1
    from /usr/bin/irb:12:in `<main>'

please leave README, NEWS and COPYING in the gem

Hi,

Could you please continue to ship the README, NEWS and COPYING files in the gem? COPYING is needed for legal reasons. README and NEWS are nice to have in the gem, so that it is not needed to find the repo to know what changed.

Thanks in advance.

Cédric

Values returned by object proxies are always arrays

A method proxy always returns an array of values. This is to accomodate the rare cases of a DBus method specifying more than one out parameter. For nearly all methods you should use proxy.Method[0] or proxy.Method.first.

We cannot simply change the behavior because users' code would break silently. A proposed solution is to keep the current API for ProxyObjects obtained by Service#object and to return a single value for proxies obtained differently, by currently nonexisting Service#[] or Connection#[path, optional_destination]

Close dbus connection?

Hello @mvidner,
I would like to ask you if there is any option to close DBus connection? I am iterating through Modem Manager modems and after gathering some information I would like to close dbus connection.

service side: interface must be optional for methods if unambiguous

If I create the service from the example, I get the following on the command line

╰─➤ qdbus org.ruby.service /org/ruby/MyInstance
signal void org.ruby.SampleInterface.SomethingJustHappened(QString toto, uint tutu)
method void org.ruby.SampleInterface.hello(QString name, QString name2)
method void org.ruby.SampleInterface.test_variant(QDBusVariant stuff)
method QString org.ruby.AnotherInterface.Reverse(QString instr)
method void org.ruby.AnotherInterface.ThatsALongMethodNameIThink()

Notice there is no introspect method. Also, I can't call any of the methods, I get the following error:

╰─➤ qdbus org.ruby.service /org/ruby/MyInstance Reverse "yay"
Error: org.freedesktop.DBus.Error.UnknownMethod
Interface "" of object "/org/ruby/MyInstance" doesn't exist

I have created multiple service, in different applications, but still keep getting this error. When the method genuinely doesn't exist, there is another different error saying it cannot be found.

Fails when used in a project that uses activesupport 5.2.0.rc1 callbacks

If ActiveSupport 5.2.0.rc1 is loaded alongside this gem, bad things happen:

/home/hayden/.gem/ruby/gems/activesupport-5.2.0.rc1/lib/active_support/callbacks.rb:841:in `set_callbacks': undefined method `merge' for nil:NilClass (NoMethodError)
	from /home/hayden/.gem/ruby/gems/activesupport-5.2.0.rc1/lib/active_support/callbacks.rb:812:in `block in define_callbacks'
	from /home/hayden/.gem/ruby/gems/activesupport-5.2.0.rc1/lib/active_support/callbacks.rb:809:in `each'
	from /home/hayden/.gem/ruby/gems/activesupport-5.2.0.rc1/lib/active_support/callbacks.rb:809:in `define_callbacks'
	from /home/hayden/.gem/ruby/gems/activesupport-5.2.0.rc1/lib/active_support/execution_wrapper.rb:13:in `<class:ExecutionWrapper>'
	from /home/hayden/.gem/ruby/gems/activesupport-5.2.0.rc1/lib/active_support/execution_wrapper.rb:6:in `<module:ActiveSupport>'
	from /home/hayden/.gem/ruby/gems/activesupport-5.2.0.rc1/lib/active_support/execution_wrapper.rb:5:in `<main>'

I suspect the same may be true of slightly less bleeding edge versions of activesupport as well, given the version that's been copied into this them is now coming up on 4 years old.

I'm thinking it's clashing with the copy of the class_attribute monkeypatch defined here: https://github.com/mvidner/ruby-dbus/blob/master/lib/dbus/core_ext/class/attribute.rb

I'm going to put together a fork that depends on activesupport, rather than copying the required modules, and I'll open a PR assuming there are no significant issues.

login as root, su [-] user, tests fail (mismatched authentication)

On openSUSE Tumbleweed, with Ruby 2.2 (VM os-tw-2015-04-24b, dhcp139); or on oS 13.2 (Ruby 2.1)

ssh in as root
su tux (or even su - tux)
cd ~/ruby-dbus
./spec/bus_driver_spec.rb # the test that sets up service by itself; but others fail too

The bus disconnects the client because the client calls Etc.getlogin which returns "root" and then authentication somehow fails.

Deprecated use of Fixnum in Ruby 2.4

Since Ruby 2.4, Fixnum and Bignum are unified into Integer.

Using ruby-dbus in ruby 2.4 generates (at least) these warnings:

ruby-dbus-0.13.0/lib/dbus/marshall.rb:299: warning: constant ::Fixnum is deprecated
ruby-dbus-0.13.0/lib/dbus/message.rb:129: warning: constant ::Fixnum is deprecated

Running tests without rake

Hi, is it possible to run the test suite without rake? I am trying to run the precisely same line that rake does, but the test keep failing:

/usr/bin/ruby -I"lib:lib" -I"/usr/share/gems/gems/rake-0.9.2.2/lib" "/usr/share/gems/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb" "test/binding_test.rb" "test/thread_safety_test.rb" "test/property_test.rb" "test/server_robustness_test.rb" "test/signal_test.rb" "test/server_test.rb" "test/bus_driver_test.rb" "test/bus_test.rb" "test/variant_test.rb" "test/t5-report-dbus-interface.rb" "test/t3-ticket27.rb" "test/t6-loop.rb" "test/t2.rb"

Is there something that the rake task does behind the scene?

Thank you!

failed to register callback for PulseAudio signal

Hi,

I'm trying to register a callback for a pulseaudio source device on the pulseaudio bus.
see https://gist.github.com/r10r/5496667

I get the following error:

DBus::Error: Method "AddMatch" with signature "s" on interface "org.freedesktop.DBus" doesn't exist

    from /var/lib/soundmaster/.gem/ruby/2.0.0/gems/ruby-dbus-0.9.1/lib/dbus/bus.rb:407:in `block in send_sync_or_async'
    from /var/lib/soundmaster/.gem/ruby/2.0.0/gems/ruby-dbus-0.9.1/lib/dbus/bus.rb:633:in `call'
    from /var/lib/soundmaster/.gem/ruby/2.0.0/gems/ruby-dbus-0.9.1/lib/dbus/bus.rb:633:in `process'
    from /var/lib/soundmaster/.gem/ruby/2.0.0/gems/ruby-dbus-0.9.1/lib/dbus/bus.rb:580:in `send_sync'
    from /var/lib/soundmaster/.gem/ruby/2.0.0/gems/ruby-dbus-0.9.1/lib/dbus/bus.rb:405:in `send_sync_or_async'
    from /var/lib/soundmaster/.gem/ruby/2.0.0/gems/ruby-dbus-0.9.1/lib/dbus/introspect.rb:274:in `block (2 levels) in define_method_from_descriptor'
    from /var/lib/soundmaster/.gem/ruby/2.0.0/gems/ruby-dbus-0.9.1/lib/dbus/bus.rb:607:in `add_match'
    from /var/lib/soundmaster/.gem/ruby/2.0.0/gems/ruby-dbus-0.9.1/lib/dbus/introspect.rb:325:in `on_signal'
    from /var/lib/soundmaster/.gem/ruby/2.0.0/gems/ruby-dbus-0.9.1/lib/dbus/introspect.rb:455:in `on_signal'
    from (irb):145
    from /usr/bin/irb:12:in `'

Any idea what is going wrong here?

[soundmaster@blaubeere ~]$ dbus-daemon --version
D-Bus Message Bus Daemon 1.6.8
Copyright (C) 2002, 2003 Red Hat, Inc., CodeFactory AB, and others
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Rubinius::EncodingClass::Encoding::CompatibilityError in 1.9 mode:

ruby-dbus does not work with rbx-19mode (sample failure on Travis), raising this exception when trying to marshall a message:

undefined conversion for '"[...]"' from US-ASCII to ASCII-8BIT (Rubinius::EncodingClass::Encoding::CompatibilityError)

I have tracked it down to several bugs in Rubinius:

Cannot open system or session bus

irb(main):002:0> bus = DBus::SystemBus.instance
EOFError: end of file reached
    from /usr/local/lib/ruby/site_ruby/2.1/dbus/auth.rb:84:in `readline'
    from /usr/local/lib/ruby/site_ruby/2.1/dbus/auth.rb:84:in `next_msg'
    from /usr/local/lib/ruby/site_ruby/2.1/dbus/auth.rb:89:in `next_state'
    from /usr/local/lib/ruby/site_ruby/2.1/dbus/auth.rb:56:in `authenticate'
    from /usr/local/lib/ruby/site_ruby/2.1/dbus/bus.rb:602:in `init_connection'
    from /usr/local/lib/ruby/site_ruby/2.1/dbus/bus.rb:203:in `connect'
    from /usr/local/lib/ruby/site_ruby/2.1/dbus/bus.rb:635:in `initialize'
    from /usr/local/lib/ruby/2.1/singleton.rb:141:in `new'
    from /usr/local/lib/ruby/2.1/singleton.rb:141:in `block in instance'
    from /usr/local/lib/ruby/2.1/singleton.rb:139:in `synchronize'
    from /usr/local/lib/ruby/2.1/singleton.rb:139:in `instance'
    from (irb):2
    from /usr/local/bin/irb21:11:in `<main>'

and for the session bus:

irb(main):005:0> bus = DBus::SessionBus.instance
NoMethodError: undefined method `split' for nil:NilClass
    from /usr/local/lib/ruby/site_ruby/2.1/dbus/bus.rb:581:in `parse_session_string'
    from /usr/local/lib/ruby/site_ruby/2.1/dbus/bus.rb:192:in `connect'
    from /usr/local/lib/ruby/site_ruby/2.1/dbus/bus.rb:621:in `initialize'
    from /usr/local/lib/ruby/2.1/singleton.rb:141:in `new'
    from /usr/local/lib/ruby/2.1/singleton.rb:141:in `block in instance'
    from /usr/local/lib/ruby/2.1/singleton.rb:139:in `synchronize'
    from /usr/local/lib/ruby/2.1/singleton.rb:139:in `instance'
    from (irb):5
    from /usr/local/bin/irb21:11:in `<main>'

Is there a way I can debug this further to see what's going on and why it fails?

[Question] Problem for using variant in ApplyMonitorsConfig

Hi,
I'm trying to write a simple ruby script using ruby-dbus for changing my display resolution. Usually, I use the following command:

gdbus call --session \
--dest=org.gnome.Mutter.DisplayConfig \
--object-path /org/gnome/Mutter/DisplayConfig \
--method org.gnome.Mutter.DisplayConfig.ApplyMonitorsConfig 3 1 "[(0, 0, 1, 0, true, [('HDMI-1', '[email protected]', [] )] )]" "[]"

I know that the above command was created based on the following method [1]:

    <method name="ApplyMonitorsConfig">
      <arg name="serial" direction="in" type="u" />
      <arg name="method" direction="in" type="u" />
      <arg name="logical_monitors" direction="in" type="a(iiduba(ssa{sv}))" />
      <arg name="properties" direction="in" type="a{sv}" />
    </method>

Based on that I wrote a simple script that tries to reproduce part of the command described in the begging. My script looks like this:

require "dbus"

bus = DBus::SessionBus.instance
service = bus.service("org.gnome.Mutter.DisplayConfig")
obj_conf = service.object("/org/gnome/Mutter/DisplayConfig")
obj_conf.introspect
interface = obj_conf["org.gnome.Mutter.DisplayConfig"]
serial, crtcs, outputs, modes, max_screen_width, max_screen_height = interface.GetResources

variant = DBus.variant("a{sv}", {})
logical_monitors = [0, 0, 1, 0, true, ['HDMI-1', '[email protected]', variant]]

interface.ApplyMonitorsConfig(serial, 1, logical_monitors, variant)

However, after running the above script I got the following error:

marshall.rb:384:in `append': Struct/DE expects an Array (DBus::TypeException)

I also tried to remove the DBus.variant("a{sv}", {}) and pass {} directly, but I got the same error.

Any ideas?

Thanks

  1. https://gitlab.gnome.org/GNOME/mutter/-/blob/master/src/org.gnome.Mutter.DisplayConfig.xml#L446

Can't initialize ASessionBus

I've installed dbus on OSX Lion via Homebrew.

The LaunchAgent sets the unix_domain_listener location to the launchctl env variable DBUS_LAUNCHD_SESSION_BUS_SOCKET

I have added eval $(launchctl export) to my ~/.bash_profile to make this variable available to the ruby-dbus gem.

However, the ruby-dbus gem looks for ENV[DBUS_SESSION_BUS_ADDRESS] when intializing ASessionBus.

I have updated the gem locally to look for ENV[DBUS_LAUNCHD_SESSION_BUS_SOCKET]instead.

However, I'm getting a undefined method split for nil on lib/dbus/bus.rb:216. This appears to be because ENV[DBUS_LAUNCHD_SESSION_BUS_SOCKET] returns "/tmp/launch-LR1q3u/unix_domain_listener".

I'm not really sure where the issue lies here. Is dbus not running correctly? Is this gem not meant for use on OSX?

Any help would be greatly appreciated.

ProxyObjectInterface#on_signal does not mimic ProxyObject#on_signal

ProxyObject#on_signal(name, &block) uses default_interface. When I want to use a non-default one, via ProxyObjectInterface#on_signal(bus,name, &block) I stupidly need to specify the bus too.

The API of PO and POI should reflect the fact that an object is almost entirely an aggregation of its interfaces, so their methods should have the same Ruby signatures; in this case #on_signal(name, &block)

Problem with reading Properties

Hello,
First of all I would like to say thanks you for great library :), I am trying to read properties for NetworkManager ( http://projects.gnome.org/NetworkManager/developers/mm-spec-04.html ) using following code:

    @bus        = DBus::SystemBus.instance
    @mm_service = @bus['org.freedesktop.ModemManager'
    @proxy = @mm_service.object('/org/freedesktop/ModemManager/Modems/0')
    @proxy.introspect
[85] pry(main)> @proxy['org.freedesktop.ModemManager.Modem']['Enabled']
NoMethodError: undefined method `Get' for #<DBus::ProxyObjectInterface:0x0000000304d190>
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p392/bundler/gems/ruby-dbus-f25a6953df05/lib/dbus/introspect.rb:333:in `[]'

Could you @mvidner please point me where I am making mistake? Thanks in advantage.

I would like to fix this odd method https://github.com/swistaczek/ruby-network-manager/blob/master/lib/network_manager/modem.rb#L27

macOS: No such file or directory - connect(2) for /var/run/dbus/system_bus_socket

I'm trying to load the gem ble which depends on the gem dbus. I get this error:

> $ pry
[1] pry(main)> require 'ble'
Errno::ENOENT: No such file or directory - connect(2) for /var/run/dbus/system_bus_socket
from /Users/wilson/.asdf/installs/ruby/3.0.0/lib/ruby/gems/3.0.0/gems/ruby-dbus-0.16.0/lib/dbus/message_queue.rb:116:in `connect'
Caused by LoadError: cannot load such file -- ble
from <internal:/Users/wilson/.asdf/installs/ruby/3.0.0/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
[2] pry(main)>

Same if I load dbus directly:

[1] pry(main)> require 'dbus'
=> true
[2] pry(main)> bus = DBus::SystemBus.instance
Errno::ENOENT: No such file or directory - connect(2) for /var/run/dbus/system_bus_socket
from /Users/wilson/.asdf/installs/ruby/3.0.0/lib/ruby/gems/3.0.0/gems/ruby-dbus-0.16.0/lib/dbus/message_queue.rb:116:in `connect'
[3] pry(main)>

The dbus daemon is running correctly:

> $ brew services
Name          Status  User   Plist
dbus          started wilson /Users/wilson/Library/LaunchAgents/org.freedesktop.dbus-session.plist
postgresql    started wilson /Users/wilson/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
postgresql@12 stopped
redis         started wilson /Users/wilson/Library/LaunchAgents/homebrew.mxcl.redis.plist

I verified that file /var/run/dbus/system_bus_socket does not exist.

Getting this problem on macOS BigSur 1.0.1 (20B29)

Question: can I export multiple services from a single process - dbus restriction?

I'm not sure if I got your question right but I will repurpose this report for my current problem:

A connection can have more than one well-known name (the letter-dotted one), ruby-dbus doesn't support it.

For example on my desktop I have one connection using 3 well-known names:

$ busctl --user | grep Thunar
NAME                          PID PROCESS USER   CONNECTION UNIT            SESSION DESCRIPTION
:1.18                        2448 Thunar  martin :1.18      session-1.scope 1       -
org.freedesktop.FileManager1 2448 Thunar  martin :1.18      session-1.scope 1       -
org.xfce.FileManager         2448 Thunar  martin :1.18      session-1.scope 1       -
org.xfce.Thunar              2448 Thunar  martin :1.18      session-1.scope 1       -
$ busctl --user tree org.xfce.Thunar
└─/org
  ├─/org/freedesktop
  │ └─/org/freedesktop/FileManager1
  └─/org/xfce
    ├─/org/xfce/FileManager
    └─/org/xfce/Thunar

This is persumably to offer a custom Thunar interface as well as a common FileManager interface.

Another use case is to implement multiple loosely related services in the same
process to save on memory overhead (like Agama Manager+Users).

Currently ruby-dbus cannot do this,
it assumes that your service has exactly one well-known name and you call:

service = bus.request_service("org.example.Widget1")
service.export(Widget.new("/org/example/Widget1"))
some_main_loop.run

Even if you try to trick the library requesting 2 "services" and exporting the
objects on the latter one which gets remembered internally:

s1 = bus.request_service("org.example.Widget1")
s2 = bus.request_service("org.example.Gadget1")
s2.export(Widget.new("/org/example/Widget1"))
s2.export(Gadget.new("/org/example/Widget1"))

It will kind of work, eventually producing the object tree what you want, but
importantly for autostarted services, the second request_service call will
already start processing method calls for the objects that haven't been
exported yet. So the first method call will fail.

Original report:

Dear Developer:

Can I export more than one service (assuming differing names of course) from a single process? I noticed that you use class variables instead of instance variables for the interface.

Thanks,

G.

Introspection fails when called multiple times in threads

I am trying to build a Rails application that regularly checks network status, Systemd service status etc. showing them on the UI. I need to use Puma which works with threads. When the application makes calls to DBus we start getting DBus::InvalidPacketException over and over during introspection. I am not sure if it is because of using threads, or if threads just makes it easier to reproduce (ex. calling DBus too fast).

I see it happen on OpenSUSE 42.3 and Ubuntu 16.04. Happens with Ruby 2.4.3 and 2.3.6, did not try other Ruby versions. This is reproducable with 2 threads too. Systemd is just an example, issue happens when calling NetworkManager too.

require 'dbus'

PARALLEL = 5
UNIT_NAME = 'ruby_dbus_test.service'

def local_service_unit_is_active(k)
  puts "current thread #{Thread.current[:num]}\n"
  sys_bus = DBus.system_bus
  core_service = sys_bus.service('org.freedesktop.systemd1')
  obj = core_service.object('/org/freedesktop/systemd1')
  obj.default_iface = 'org.freedesktop.systemd1'

  puts "before obj.introspect #{Thread.current[:num]}\n"
  obj.introspect
  puts "after obj.introspect #{Thread.current[:num]}\n"
  obj
end

def build_thread(k)
  Thread.new do
    Thread.current.abort_on_exception = true
    Thread.current[:num] = k

    resp = local_service_unit_is_active(UNIT_NAME)
    puts "\nFINISHED: result for #{k} active: #{resp.bus.inspect}\n"
  end
end

threads = []

PARALLEL.times do |k|
  puts "building thread #{k + 1} out of #{PARALLEL}"
  threads << build_thread(k)
end

threads.each(&:join)

and the errors I get changes time to time but they all look like introspection data is not correct so it is not parsed properly

/home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/marshall.rb:183:in `do_parse': DBus::InvalidPacketException (DBus::InvalidPacketException)
        from /home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/marshall.rb:62:in `block in unmarshall'
        from /home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/marshall.rb:61:in `each'
        from /home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/marshall.rb:61:in `unmarshall'
        from /home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/message.rb:201:in `unmarshall_buffer'
        from /home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/message_queue.rb:139:in `message_from_buffer_nonblock'
        from /home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/message_queue.rb:38:in `pop'
        from /home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/bus.rb:441:in `wait_for_message'
        from /home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/bus.rb:458:in `send_sync'
        from /home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/bus.rb:339:in `send_sync_or_async'
        from /home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/bus.rb:365:in `introspect_data'
        from /home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/proxy_object.rb:73:in `introspect'
        from ./multiple_dbus_calls.rb:18:in `local_service_unit_is_active'
        from ./multiple_dbus_calls.rb:28:in `block in build_thread'
/home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/marshall.rb:103:in `read_string': String is not nul-terminated (DBus::InvalidPacketException)
        from /home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/marshall.rb:212:in `do_parse'
        from /home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/marshall.rb:62:in `block in unmarshall'
        from /home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/marshall.rb:61:in `each'
        from /home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/marshall.rb:61:in `unmarshall'
        from /home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/message.rb:227:in `unmarshall_buffer'
        from /home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/message_queue.rb:139:in `message_from_buffer_nonblock'
        from /home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/message_queue.rb:38:in `pop'
        from /home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/bus.rb:441:in `wait_for_message'
        from /home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/bus.rb:453:in `send_sync'
        from /home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/bus.rb:339:in `send_sync_or_async'
        from /home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/bus.rb:365:in `introspect_data'
        from /home/zaburt/.rvm/gems/ruby-2.4.3@dbus_test/gems/ruby-dbus-0.14.1/lib/dbus/proxy_object.rb:73:in `introspect'
        from ./multiple_dbus_calls.rb:18:in `local_service_unit_is_active'
        from ./multiple_dbus_calls.rb:28:in `block in build_thread'

You can find the sample script to reproduce the issue (no Rails, just Ruby) and some info here too https://github.com/zaburt/ruby-dbus-test . I can try out any test code or suggestions.

Multithread in ruby-dbus

Hi,

We quite need for our project to use ruby-dbus multhreaded. This feature is not supported as reported in 20 - 21 -22. We are thinking about an implementation and we want to have an enlightened opinion before coding it.

The problem seems to be due to update_buffer function and IO.select. Update_buffer function doesn’t know from which does come the previous request and the first thread that take IO.select income takes the request. A way to solve it may be to dedicate a thread that wait IO.select and return the buffer to the according thread:

if message-type is METHOD_CALL or SIGNAL, return to main thread.
if MESSAGE_RETURN, return to concerned thread. To do so, we need when sending a message to log in a hash (for example) the thread it cames from.

The thread will wait a Thread.stop and will be restarted from the dedicated one with a Thread.run

Do you agree with this implementation, do you see limitations from that ?

Objects must be introspected explicitly

ProxyObject#introspect must be called explicitly, otherwise the proxy will not know what methods etc. it should handle.

Introspection should be automatic, with a way to opt out.

Bytestrings (ay)

Hi,

I'm the creator of pydbus, DBus bindings for Python. I've stumbled upon the case of bytestrings - ay - which are commonly used to send non-Unicode data over DBus.

Because of the GDBus's API, apps commonly require these strings to be '\0'-terminated. And that's completely unintuitive for high-level languages, and something that requires the user to read API docs.

I'm thinking about solving the problem automatically, and I see two solutions:

  1. Auto-append and auto-strip the last character of "ay"s; [EDIT: impossible, some APIs use not-terminated strings]
  2. Decree (how?) that GDBus API is wrong, and strings sent over the wire should not be \0-terminated.
  3. [EDIT:] Create a new DBus annotation meaning "All "ay"s in the arguments of this method/signal are \0-terminated bytestrings" - and auto-append/auto-strip \0 if it's present.

Whatever we choose, the solution should be agreed upon by authors of bindings for all languages. That's why I'm here.

Do you have any experience with "ay"-encoded bytestrings?

Relevant discussion: LEW21/pydbus#27 (please reply there, I've opened similar issues in 8 different projects to get attention of bindings authors)

Can not work with multibyte UTF-8 strings

String#length and String#size of Ruby 1.9 does not equal to
byte size of multibyte strings.
So, when we use multibyte strings of utf-8,
ruby-dbus can not work properly in ruby 1.9.

I created the following patch for ruby 1.9 and 1.8.7.
Since ruby 1.8.6 does not support String#bytesize,
it can not work for ruby 1.8.6.

I wonder if, verifying that this modification does not have bugs,
it is merged.

diff --git a/lib/dbus/auth.rb b/lib/dbus/auth.rb
index d14cc5c..bce9742 100644
--- a/lib/dbus/auth.rb
+++ b/lib/dbus/auth.rb
@@ -62,7 +62,7 @@ module DBus
       # name of cookie file, id of cookie in file, servers random challenge  
       context, id, s_challenge = data.split(' ')
       # Random client challenge        
-      c_challenge = Array.new(s_challenge.length/2).map{|obj|obj=rand(255).to_s}.join
+      c_challenge = Array.new(s_challenge.bytesize/2).map{|obj|obj=rand(255).to_s}.join
       # Search cookie file for id
       path = File.join(ENV['HOME'], '.dbus-keyrings', context)
       puts "DEBUG: path: #{path.inspect}" if $debug
@@ -161,7 +161,7 @@ module DBus
       while left > 0
         buf = @socket.read( left > 1 ? 1 : left )
         break if buf.nil?
-        left -= buf.size
+        left -= buf.bytesize
         data += buf
         break if data.include? crlf #crlf means line finished, the TCP socket keeps on listening, so we break 
       end
diff --git a/lib/dbus/introspect.rb b/lib/dbus/introspect.rb
index 9320a73..653da11 100644
--- a/lib/dbus/introspect.rb
+++ b/lib/dbus/introspect.rb
@@ -47,7 +47,7 @@ module DBus
 
     # Validates a service _name_.
     def validate_name(name)
-      raise InvalidIntrospectionData if name.size > 255
+      raise InvalidIntrospectionData if name.bytesize > 255
       raise InvalidIntrospectionData if name =~ /^\./ or name =~ /\.$/
       raise InvalidIntrospectionData if name =~ /\.\./
       raise InvalidIntrospectionData if not name =~ /\./
@@ -107,7 +107,7 @@ module DBus
 
     # Validates element _name_.
     def validate_name(name)
-      if (not name =~ MethodSignalRE) or (name.size > 255)
+      if (not name =~ MethodSignalRE) or (name.bytesize > 255)
         raise InvalidMethodName, name
       end
     end
diff --git a/lib/dbus/marshall.rb b/lib/dbus/marshall.rb
index 6f0c01c..532d29b 100644
--- a/lib/dbus/marshall.rb
+++ b/lib/dbus/marshall.rb
@@ -53,7 +53,7 @@ module DBus
     # Return an array of unmarshalled objects
     def unmarshall(signature, len = nil)
       if len != nil
-        if @buffy.size < @idx + len
+        if @buffy.bytesize < @idx + len
           raise IncompleteBufferException
         end
       end
@@ -73,7 +73,7 @@ module DBus
       when 2, 4, 8
         bits = a - 1
         @idx = @idx + bits & ~bits
-        raise IncompleteBufferException if @idx > @buffy.size
+        raise IncompleteBufferException if @idx > @buffy.bytesize
       else
         raise "Unsupported alignment #{a}"
       end
@@ -86,7 +86,7 @@ module DBus
 
     # Retrieve the next _nbytes_ number of bytes from the buffer.
     def get(nbytes)
-      raise IncompleteBufferException if @idx + nbytes > @buffy.size
+      raise IncompleteBufferException if @idx + nbytes > @buffy.bytesize
       ret = @buffy.slice(@idx, nbytes)
       @idx += nbytes
       ret
@@ -96,8 +96,8 @@ module DBus
     def get_nul_terminated
       raise IncompleteBufferException if not @buffy[@idx..-1] =~ /^([^\0]*)\0/
       str = $1
-      raise IncompleteBufferException if @idx + str.size + 1 > @buffy.size
-      @idx += str.size + 1
+      raise IncompleteBufferException if @idx + str.bytesize + 1 > @buffy.bytesize
+      @idx += str.bytesize + 1
       str
     end
 
@@ -107,7 +107,7 @@ module DBus
       align(4)
       str_sz = get(4).unpack(@uint32)[0]
       ret = @buffy.slice(@idx, str_sz)
-      raise IncompleteBufferException if @idx + str_sz + 1 > @buffy.size
+      raise IncompleteBufferException if @idx + str_sz + 1 > @buffy.bytesize
       @idx += str_sz
       if @buffy[@idx].ord != 0
         raise InvalidPacketException, "String is not nul-terminated"
@@ -122,7 +122,7 @@ module DBus
     def get_signature
       str_sz = get(1).unpack('C')[0]
       ret = @buffy.slice(@idx, str_sz)
-      raise IncompleteBufferException if @idx + str_sz + 1 >= @buffy.size
+      raise IncompleteBufferException if @idx + str_sz + 1 >= @buffy.bytesize
       @idx += str_sz
       if @buffy[@idx].ord != 0
         raise InvalidPacketException, "Type is not nul-terminated"
@@ -193,7 +193,7 @@ module DBus
         raise InvalidPacketException if array_sz > 67108864
 
         align(signature.child.alignment)
-        raise IncompleteBufferException if @idx + array_sz > @buffy.size
+        raise IncompleteBufferException if @idx + array_sz > @buffy.bytesize
 
         packet = Array.new
         start_idx = @idx
@@ -267,18 +267,18 @@ module DBus
 
     # Align the buffer with NULL (\0) bytes on a byte length of _a_.
     def align(a)
-      @packet = @packet.ljust(num_align(@offset + @packet.length, a) - @offset, 0.chr)
+      @packet = @packet.ljust(num_align(@offset + @packet.bytesize, a) - @offset, 0.chr)
     end
 
     # Append the the string _str_ itself to the packet.
     def append_string(str)
       align(4)
-      @packet += [str.length].pack("L") + str + "\0"
+      @packet += [str.bytesize].pack("L") + str + "\0"
     end
 
     # Append the the signature _signature_ itself to the packet.
     def append_signature(str)
-      @packet += str.length.chr + str + "\0"
+      @packet += str.bytesize.chr + str + "\0"
     end
 
     # Append the array type _type_ to the packet and allow for appending
@@ -286,12 +286,12 @@ module DBus
     def array(type)
       # Thanks to Peter Rullmann for this line
       align(4)
-      sizeidx = @packet.size
+      sizeidx = @packet.bytesize
       @packet += "ABCD"
       align(type.alignment)
-      contentidx = @packet.size
+      contentidx = @packet.bytesize
       yield
-      sz = @packet.size - contentidx
+      sz = @packet.bytesize - contentidx
       raise InvalidPacketException if sz > 67108864
       @packet[sizeidx...sizeidx + 4] = [sz].pack("L")
     end
@@ -372,7 +372,7 @@ module DBus
 
         append_signature(vartype.to_s)
         align(vartype.alignment)
-        sub = PacketMarshaller.new(@offset + @packet.length)
+        sub = PacketMarshaller.new(@offset + @packet.bytesize)
         sub.append(vartype, vardata)
         @packet += sub.packet
       when Type::ARRAY
diff --git a/lib/dbus/message.rb b/lib/dbus/message.rb
index 7affa22..378e0d5 100644
--- a/lib/dbus/message.rb
+++ b/lib/dbus/message.rb
@@ -152,7 +152,7 @@ module DBus
       @params.each do |param|
         params.append(param[0], param[1])
       end
-      @body_length = params.packet.length
+      @body_length = params.packet.bytesize
 
       marshaller = PacketMarshaller.new
       marshaller.append(Type::BYTE, HOST_END)

manjaro: Errno::ENOENT: No such file or directory - launchctl

$ uname -a                                                                                                                                                                                                                                                               39.7s
Linux apollo 4.15.18-3-MANJARO #1 SMP PREEMPT Fri Jun 8 06:18:41 UTC 2018 x86_64 GNU/Linux
$ ruby -v
ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]
[1] pry(main)> require 'dbus'
=> true
[2] pry(main)> d=DBus::SessionBus.instance
Errno::ENOENT: No such file or directory - launchctl
from [...]/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/ruby-dbus-0.15.0/lib/dbus/message_queue.rb:121:in ``'

  

NoMethodError: undefined method `get_node' for nil:NilClass

This is the code from the tutorial at http://trac.luon.net/data/ruby-dbus/tutorial/service.html

$ irb

require 'dbus'

=> true

bus = DBus.session_bus

=> #<DBus::SessionBus:0x7f45a9ed88c0

@Guid="d4acff2a02b667fa9dc5af2a4aef3e3c", @Proxy=nil, @unique_name=":1.62", @unix_abstract="/tmp/dbus-AI13XiS6cV", @signal_matchrules=[], @type="abstract", @method_call_msgs={}, @buffer="l\004\001\001\n\000\000\000\002\000\000\000\215\000\000\000\001\001o\000\025\000\000\000/org/freedesktop/DBus\000\000\000\002\001s\000\024\000\000\000org.freedesktop.DBus\000\000\000\000\003\001s\000\f\000\000\000NameAcquired\000\000\000\000\006\001s\000\005\000\000\000:1.62\000\000\000\b\001g\000\001s\000\000\a\001s\000\024\000\000\000org.freedesktop.DBus\000\000\000\000\005\000\000\000:1.62\000", @client=#<DBus::Client:0x7f45a9ed4fb8 @Authenticator=#DBus::External:0x7f45a9ed4c70, auth_list[], state:Authenticated, socket#<Socket:0x7f45a9ed7e70, @object_root=<DBus::Node {}>, socket#<Socket:0x7f45a9ed7e70, @path="unix:abstract=/tmp/dbus-AI13XiS6cV,guid=d4acff2a02b667fa9dc5af2a4aef3e3c", @transport="unix", @method_call_replies={}>
service = bus.request_service("org.ruby.service")
NoMethodError: undefined method 'get_node' for nil:NilClass
from /usr/local/lib/site_ruby/1.8/dbus/bus.rb:527:in 'process'
from /usr/local/lib/site_ruby/1.8/dbus/bus.rb:468:in 'send_sync'
from (eval):24:in 'RequestName'
from /usr/local/lib/site_ruby/1.8/dbus/bus.rb:382:in 'request_service'
from (irb):3

The version installed is 0.2.10 from the tarballs on github.
The OS is Ubuntu 9.04.
Ruby is ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux].
Rubygem is 1.3.5.

Remove luon.net links/mentions

Hi,

While Ruby D-Bus started out on our Luon infrastructure, it has long be standing on it's own here on GitHub. As we are reorganizing our Luon infrastructure, we are going to drop a lot of services. Because of that, I would like to ask you to remove all links to luon.net (mainly the trac.luon.net website and [email protected] mailing list) from the documentation/pages, as they will become broken links in the near future!

Thanks (again :)) for continuing this project!

sendmsg fails with 'Invalid argument' in OpenBSD

The following special handling of *BSD in authenticate.rb fails on OpenBSD with error 'Invalid argument'. We solved the problem by commenting out the special code and just calling @socket.write as on other systems.

if (RbConfig::CONFIG["target_os"] =~ /bsd/)
    @socket.sendmsg(0.chr, 0, nil, [:SOCKET, :SCM_CREDS, ""])

EOFError in introspect (when using an invalid object path)

Since a while I cannot connect any longer to my own Qt app, probably with new Qt in openSUSE 15.0, just reproduced also in 15.1.

#!/usr/bin/env ruby    
require 'dbus'

@dbus = DBus::SessionBus.instance

# Try out running applications, originally vym, also with konsole. Found via qdbusviewer:
#name = 'org.insilmaril.vym-10982'
name = 'org.kde.konsole-2393'

vym_service = @dbus[name]
vym_obj = vym_service[name]

vym_obj.introspect

Results in

Traceback (most recent call last):
        9: from ./dbus-test.rb:18:in `<main>'
        8: from /usr/lib64/ruby/gems/2.5.0/gems/ruby-dbus-0.14.0/lib/dbus/proxy_object.rb:73:in `introspect'
        7: from /usr/lib64/ruby/gems/2.5.0/gems/ruby-dbus-0.14.0/lib/dbus/bus.rb:365:in `introspect_data'
        6: from /usr/lib64/ruby/gems/2.5.0/gems/ruby-dbus-0.14.0/lib/dbus/bus.rb:339:in `send_sync_or_async'
        5: from /usr/lib64/ruby/gems/2.5.0/gems/ruby-dbus-0.14.0/lib/dbus/bus.rb:453:in `send_sync'
        4: from /usr/lib64/ruby/gems/2.5.0/gems/ruby-dbus-0.14.0/lib/dbus/bus.rb:441:in `wait_for_message'
        3: from /usr/lib64/ruby/gems/2.5.0/gems/ruby-dbus-0.14.0/lib/dbus/message_queue.rb:30:in `pop'
        2: from /usr/lib64/ruby/gems/2.5.0/gems/ruby-dbus-0.14.0/lib/dbus/message_queue.rb:154:in `buffer_from_socket_nonblock'
        1: from /usr/lib64/ruby/2.5.0/socket.rb:452:in `read_nonblock'
/usr/lib64/ruby/2.5.0/socket.rb:452:in `__read_nonblock': end of file reached (EOFError)

Any hints?
Thx

Exporting object on unnamed service

I'm working with the BlueZ Bluetooth API which, for some operations, requires a callback object that is exported by the client connection. If I understand correctly, the only way to export an object in ruby-dbus is through a named service, which can only be retrieved from DBus::Connection#request_service. Unfortunately, since I'm working with an unprivileged connection to the system bus, my process does not have permission to request_service.

I noticed that SystemBus has a usable Service in @service, and if I call DBus::SystemBus.instance.instance_variable_get(:@service).export(my_object) my object is exported and receives method invocations as expected. However, I'm a little bit 😬 about relying on instance variables like that.

Is there a recommended way of doing this?

(For reference, line 152 of this file contains the Python equivalent of the code I need.)

DBUS_SESSION_BUS_ADDRESS not set

Using version 0.2.12, instantiating the SessionBus class assumes DBUS_SESSION_BUS_ADDRESS is defined in the environment. In my case this is not true and resulting in an exception when it attempts to parse the nil string.

I attempted to patch this by using a lookup in the file ~/.dbus/session-bus/(string) to fetch the address however this resulted in a connection refused, even when using sudo on a simple test script. Not sure of the issue here.

edit: using ruby 1.9.1p378

redefininition of methods of DBus objects

I have many warnings like this
/usr/lib/ruby/vendor_ruby/dbus/proxy_object.rb:94: warning: method redefined; discarding old Get

It is raised when dbus object is introspected more than one time.

I have solved by following patch, but I'm unsure if it is correct.

      univocal_meths.each do |name, intf|
        # creates a shortcut function that forwards each call to the method on
        # the appropriate intf
        singleton_class.class_eval do
+++          undef_method(name) if method_defined? name
          define_method name do |*args, &reply_handler|
            intf.method(name).call(*args, &reply_handler)
          end
        end
      end

Shouldn't be the method redefinition skipped instead?

Returning Variants in dbus_method

Hello, and thanks for the work you've done on this library, it's very useful.

I am writing a dbus service for rygel, following the MediaServer2 spec. Some of the method calls required (e.g. GetAll on org.freedesktop.DBus.Properties) need to return sets of variants in an array e.g. a{sv}, so I have code like this in my org.freedesktop.DBus.Properties interface:

    dbus_method :GetAll, "in iface:s, out values:a{sv}" do |iface|

        rvalues = Hash.new
        case iface
        when OBJECT_IFACE
            rvalues = @propertyValuesObject2
        when CONTAINER_IFACE
            rvalues = @propertyValues
        when ""
            rvalues = @propertyValuesObject2.merge(@propertyValues)
        else
            raise DBus.error, "Could not find interface #{iface} when getting all properties"
        end
        puts rvalues.to_s
        [rvalues]
    end

@propertyValues and @propertyValuesObject2 are hashes of property name => desired value. Elsewhere in my code the values are set either as Strings or Integers, and at the moment that's how my processing returns the message over DBus. However I want some of the strings to be sent back over DBus as objects (signature "o" instead of "s") and some of the integers to be sent back as unsigned (signature "u" instead of "i").
Because the message has to return an array of string / variant pairs I can't explicitly set the desired signature in the prototype. It appears ruby-dbus is inferring the "correct" message signature to use when marshaling its reply from the object type that it marshals (String or Fixnum/Integer). How can I get it to marshal the contents of a String as an Object, and Integer as Unsigned?

My full code is at https://github.com/jameswyper/avice by the way, but it's not anywhere near working yet (although some communication over Dbus between rygel and my server is happening)

Thanks,
James

Connection#update_buffer blocking sometimes

I currently have the following in my code:

@dbus.update_buffer
@dbus.messages.each do |msg|
  # Pass messages through DBus
  @dbus.process(msg)

  # [snip] Do additional processing on msg
end

I'm specifically doing it this way so that I can process DBus messages without blocking, however occasionally I get the following message in the console and #update_buffer blocks:

Resource temporarily unavailable - read would block
WARNING: read_nonblock failed, falling back to .recv

This usually happens when there is no data to be read, which would coincide nicely with the message given. #glibize seems to watch the socket manually to avoid this situation. My question is, as a client to the library how can I avoid this behavior if I specifically don't want to block at all?

AltLinux: Connection refused - connect(2)

I have the following trouble in the connection to Session bus:

/usr/local/home/majioa/git/ntp/lib/ntp/server/control.rb:53:in `get_connection'/usr/local/home/majioa/git/ntp/.bundle/gems/ruby-dbus-0.11.0/lib/dbus/message_queue.rb:115:in `connect': Connection refused - connect(2) for UNIX:00:2f:76:61:72:2f:72:75:6e:2f:64:62:75:73:2f:75:73:65:72:73:2f:64:62:75:73:2d:54:67:4c:79:6f:51:4b:67:71:37 (Errno::ECONNREFUSED)
from /usr/local/home/majioa/git/ntp/.bundle/gems/ruby-dbus-0.11.0/lib/dbus/message_queue.rb:115:in `connect_to_unix'

code:

bus = DBus::SessionBus.instance

how to fix it?

Creating signal catchers (on_signal) cannot be changed

This is highly confusing and probably breaks code with two D-Bus connections.

Imagine a D-Bus system service "Foo" emitting a signal "Hello"
Imagine a second D-Bus system service "Bar" emitting a signal "Hello"

-> two different services, running on the same bus, emitting an identical signal

One can set up a FooProxy and FooProxy.on_signal("Hello") do something end
And a BarProxy and BarProxy.on_signal("Hello") do something ELSE end

However, since signals are catched per-bus, all "Hello" signals will go to FooProxy

Still using rdoc for doc generation?

Hi @mvidner,

Thanks for your work on ruby-dbus so far.
However, whilst maintaining this in Debian, I stumbled upon this:
rdoc --all --line-numbers -o doc/rdoc lib --> which means that we're relying on rdoc for docs generation. The previous maintainer of the Debian package left the following comment:

Title: Documentation of the Ruby bindings for D-Bus
Author: Chris Lalancette et al.
Abstract: This API documentation is generated with RDoc from the source of
 Ruby/Dbus, providing Ruby bindings for D-Bus.

However, whilst working on the Reproducible Build front, I noticed that the generation of docs using rdoc makes this gem build un-reproducibly. So I am inclined to remove the rdoc generation part altogether.

Before I do, I wanted to know where that is the correct thing to do? Or are you really using RDoc for some part of documentation generation?

A round problem when retrieving a double value

Hi,

I was playing around with the below script (let's call it my_script.rb):

require "dbus"

bus = DBus::SessionBus.instance
service = bus.service("org.gnome.Mutter.DisplayConfig")
obj_conf = service.object("/org/gnome/Mutter/DisplayConfig")
obj_conf.introspect
interface = obj_conf["org.gnome.Mutter.DisplayConfig"]
serial, crtcs, outputs, modes, max_screen_width, max_screen_height = interface.GetResources

pp modes
#my_script.rb

If we want to change the resolution based on the information retrieved from GetResources, we need something like this:

target_mode = modes[5] #e.g.: [1, 1, 1280, 800, 59.810825347900391, 5] see [1]
width = target_mode[2]
height = target_mode[3]
refresh = target_mode[4]
id = "#{width}x#{height}@#{refresh}"
logical_monitors = [0, 0, 1, 0, true, [['HDMI-1', id, []]]]
interface.ApplyMonitorsConfig(serial, 1, [logical_monitors], [])

However, after tried the above approach and constantly get failures, I noticed that the refresh rate retrieved in the line [..] modes [..] = interface.GetResources was rounded. For example:

If I try:

ruby ~/my_script.rb | grep 59.8108253479003

I got:

 [37, 37, 1280, 800, 59.81082534790039, 6],
 [62, 62, 800, 1280, 59.81082534790039, 9]

However, if I use another tool named gnome-monitor-config[2]:

./gnome-monitor-config list | grep 59.8108253479003

I got

Notice that using ruby-dbus I got 59.81082534790039 and with a C code I got 59.810825347900391. This little round make the id wrong, which means that I cannot set the correct resolution.

Do you have any idea how I can get the correct refresh rate value?

  1. https://gitlab.gnome.org/GNOME/mutter/-/blob/master/src/org.gnome.Mutter.DisplayConfig.xml#L137
  2. https://github.com/jadahl/gnome-monitor-config

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.