doc/Reference.md in ruby-dbus-0.12.0 vs doc/Reference.md in ruby-dbus-0.13.0
- old
+ new
@@ -21,39 +21,33 @@
require "dbus"
#### Calling Methods
1. {DBus.session_bus Connect to the session bus};
- {DBus::Connection#[] get the screensaver service}
- {DBus::Service#[] and its screensaver object}.
-2. Perform {DBus::ProxyObject#introspect explicit introspection}
- to define the interfaces and methods
- on the {DBus::ProxyObject object proxy}
-([I#28](https://github.com/mvidner/ruby-dbus/issues/28)).
-3. Call one of its methods in a loop, solving [xkcd#196](http://xkcd.com/196).
+2. {DBus::Connection#[] get the screensaver service}
+3. {DBus::Service#[] and its screensaver object}.
+4. Call one of its methods in a loop, solving [xkcd#196](http://xkcd.com/196).
mybus = DBus.session_bus
- service = mybus['org.freedesktop.ScreenSaver']
- object = service['/ScreenSaver']
- object.introspect
+ service = mybus["org.freedesktop.ScreenSaver"]
+ object = service["/ScreenSaver"]
loop do
- object.SimulateUserActivity
- sleep 5 * 60
+ object.SimulateUserActivity
+ sleep 5 * 60
end
##### Retrieving Return Values
A method proxy simply returns a value.
In this example SuspendAllowed returns a boolean:
mybus = DBus.session_bus
- pm_s = mybus['org.freedesktop.PowerManagement']
- pm_o = pm_s['/org/freedesktop/PowerManagement']
- pm_o.introspect
- pm_i = pm_o['org.freedesktop.PowerManagement']
+ pm_s = mybus["org.freedesktop.PowerManagement"]
+ pm_o = pm_s["/org/freedesktop/PowerManagement"]
+ pm_i = pm_o["org.freedesktop.PowerManagement"]
if pm_i.CanSuspend
pm_i.Suspend
end
@@ -67,17 +61,16 @@
which is what {DBus::Service#object} does.
For nearly all methods you used `Method[0]` or
`Method.first`
([I#30](https://github.com/mvidner/ruby-dbus/issues/30)).
-
+
mybus = DBus.session_bus
- pm_s = mybus['org.freedesktop.PowerManagement']
+ pm_s = mybus["org.freedesktop.PowerManagement"]
# use legacy compatibility API
- pm_o = pm_s.object['/org/freedesktop/PowerManagement']
- pm_o.introspect
- pm_i = pm_o['org.freedesktop.PowerManagement']
+ pm_o = pm_s.object["/org/freedesktop/PowerManagement"]
+ pm_i = pm_o["org.freedesktop.PowerManagement"]
# wrong
# if pm_i.CanSuspend
# pm_i.Suspend # [false] is true!
# end
@@ -93,16 +86,15 @@
{DBus::ProxyObjectInterface#[] hash} keyed by strings,
or use {DBus::ProxyObjectInterface#all_properties} to get
an actual Hash of them.
sysbus = DBus.system_bus
- upower_s = sysbus['org.freedesktop.UPower']
- upower_o = upower_s['/org/freedesktop/UPower']
- upower_o.introspect
- upower_i = upower_o['org.freedesktop.UPower']
+ upower_s = sysbus["org.freedesktop.UPower"]
+ upower_o = upower_s["/org/freedesktop/UPower"]
+ upower_i = upower_o["org.freedesktop.UPower"]
- on_battery = upower_i['OnBattery']
+ on_battery = upower_i["OnBattery"]
puts "Is the computer on battery now? #{on_battery}"
(TODO a writable property example)
@@ -133,26 +125,24 @@
To receive signals for a specific object and interface, use
{DBus::ProxyObjectInterface#on\_signal}(name, &block) or
{DBus::ProxyObject#on_signal}(name, &block), for the default interface.
sysbus = DBus.system_bus
- login_s = sysbus['org.freedesktop.login1'] # part of systemd
- login_o = login_s.object '/org/freedesktop/login1'
- login_o.introspect
- login_o.default_iface = 'org.freedesktop.login1.Manager'
+ login_s = sysbus["org.freedesktop.login1"] # part of systemd
+ login_o = login_s.object "/org/freedesktop/login1"
+ login_o.default_iface = "org.freedesktop.login1.Manager"
main = DBus::Main.new
main << sysbus
# to trigger this signal, login on the Linux console
login_o.on_signal("SessionNew") do |name, opath|
puts "New session: #{name}"
session_o = login_s.object(opath)
- session_o.introspect
- session_i = session_o['org.freedesktop.login1.Session']
- uid, user_opath = session_i['User']
+ session_i = session_o["org.freedesktop.login1.Session"]
+ uid, _user_opath = session_i["User"]
puts "Its UID: #{uid}"
main.quit
end
main.run
@@ -187,11 +177,11 @@
gives the same result as [{DBus.type}(signature), value].
ISSUE: using something else than cryptic signatures is even more painful
than remembering the signatures!
- foo_i['Bar'] = DBus.variant("au", [0, 1, 1, 2, 3, 5, 8])
+ foo_i["Bar"] = DBus.variant("au", [0, 1, 1, 2, 3, 5, 8])
2. Other values are tried to fit one of these:
Boolean, Double, Array of Variants, Hash of String keyed Variants,
String, Int32, Int64.
@@ -216,15 +206,14 @@
D-Bus calls can reply with an error instead of a return value. An error is
translated to a Ruby exception, an instance of {DBus::Error}.
nm_o = DBus.system_bus["org.freedesktop.NetworkManager"]["/org/freedesktop/NetworkManager"]
- nm_o.introspect
nm = nm_o["org.freedesktop.NetworkManager"]
begin
- nm.Sleep(false)
+ nm.Sleep(false)
rescue DBus::Error => e
- puts e unless e.name == "org.freedesktop.NetworkManager.AlreadyAsleepOrAwake"
+ puts e unless e.name == "org.freedesktop.NetworkManager.AlreadyAsleepOrAwake"
end
#### Interfaces
Methods, properties and signals of a D-Bus object always belong to one of its interfaces.