ruby-dbus-wrapper-process-watch
Allows to register nice callbacks when D-Bus processess appear or disappear from the bus.
Installation
Step 1: Add this gem to your Gemfile
Just add the following line to your Gemfile
:
gem 'ruby-dbus-wrapper-process-watch'
Step 2: Read ruby-dbus-wrapper docs
This gem relies on ruby-dbus-wrapper. It expects that you manually add ruby-dbus gem to your Gemfile, follow its docs.
Usage
Watching
# Initialize connection and wrapper
conn = DBus::SessionBus.instance
bus = DBus::Wrapper::Bus.new(conn)
# Initialize process watch
ps = DBus::Wrapper::ProcessWatch.new(bus, /\Amonitored\.dbus\.name\.wildcard.*/)
# Bind to events
ps.on(:registered) { |a| puts "Registered #{a}" }
ps.on(:unregistered) { |a| puts "Unregistered #{a}" }
ps.on(:resolved) { puts "Boot process finished, resolved IDs of all existing processes" };
# Start watching
ps.start!
# Start mainloop
main = DBus::Main.new
main << conn
main.run
Resolving names/IDs
Once process became watched, you can call following methods to make D-Bus ID/name resolution:
ps.resolve_name_to_id("my.process.name") # => :1:231
ps.resolve_id_to_name(":1:213") # => "my.process.name"
These methods can be useful if you try to convert D-Bus ID received as sender in signal callback.
If there's no match, these methods will return nil.
License
MIT
Author
(c) 2014 Marcin Lewandowski