Permalink
Browse files

Properties: documentation, example.

  • Loading branch information...
mvidner committed Dec 8, 2010
1 parent 2613a88 commit c65c6b92e0c494ee21c27a5a06f15c8595c7a588
Showing with 33 additions and 1 deletion.
  1. +13 −0 doc/tutorial/index.markdown
  2. +19 −0 examples/simple/properties.rb
  3. +1 −1 lib/dbus/introspect.rb
@@ -229,6 +229,19 @@ exported service names of a bus like this:
bus.proxy.ListNames[0]
+Properties
+----------
+
+Some D-Bus objects provide access to properties. They are accessed by
+treating a proxy interface as a hash:
+
+ nm_iface = network_manager_object["org.freedesktop.NetworkManager"]
+ enabled = nm_iface["WirelessEnabled"]
+ puts "Wireless is " + (enabled ? "enabled":"disabled")
+ puts "Toggling wireless"
+ nm_iface["WirelessEnabled"] = ! enabled
+
+
Calling a method asynchronously
-------------------------------
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby
+require 'dbus'
+
+bus = DBus::SystemBus.instance
+nm_service = bus["org.freedesktop.NetworkManager"]
+network_manager_object = nm_service.object("/org/freedesktop/NetworkManager")
+network_manager_object.introspect
+nm_iface = network_manager_object["org.freedesktop.NetworkManager"]
+
+# read a property
+enabled = nm_iface["WirelessEnabled"]
+if enabled
+ puts "Wireless is enabled"
+else
+ puts "Wireless is disabled"
+end
+puts "Toggling wireless"
+# write a property
+nm_iface["WirelessEnabled"] = ! enabled
View
@@ -435,7 +435,7 @@ def []=(propname, value)
self.object[PROPERTY_INTERFACE].Set(self.name, propname, value)
end
- # Read all properties at once.
+ # Read all properties at once, as a hash.
def all_properties
self.object[PROPERTY_INTERFACE].GetAll(self.name)[0]
end

0 comments on commit c65c6b9

Please sign in to comment.