ruby-dbus 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/NEWS CHANGED
@@ -5,6 +5,15 @@ Note about bug numbers:
5
5
  Issue#1 - http://github.com/mvidner/ruby-dbus/issues#issue/1
6
6
  bnc#1 - https://bugzilla.novell.com/show_bug.cgi?id=1
7
7
 
8
+ == Ruby D-Bus 0.6.0 - 2010-12-11
9
+
10
+ Features:
11
+ * Clients can access properties conveniently (Ticket#28).
12
+
13
+ Bug fixes:
14
+ * Service won't crash whan handling an unknown method or interface (Ticket#31).
15
+ * Don't send an invalid error name when it originates from a NameError.
16
+
8
17
  == Ruby D-Bus 0.5.0 - 2010-11-07
9
18
 
10
19
  Features:
data/README CHANGED
@@ -5,23 +5,11 @@ D-Bus system can be used in the Ruby programming language.
5
5
 
6
6
  == Requirements
7
7
 
8
- * Ruby 1.8 (>= 1.8.6?)
9
-
10
- Optionally, for generating the tutorial:
11
- * Webgen (>= 0.4)
8
+ * Ruby 1.8 (>= 1.8.6?) or 1.9
12
9
 
13
10
  == Installation
14
11
 
15
- 1. Decompress the Ruby D-Bus tarball (ruby-dbus-<version>.tar.gz).
16
- 2. Move to top-level directory and type:
17
-
18
- $ ruby setup.rb config
19
- $ ruby setup.rb setup
20
- ($ su)
21
- # ruby setup.rb install
22
-
23
- You can also install files in your favorite directory by
24
- supplying setup.rb some options. Try "ruby setup.rb --help".
12
+ * gem install ruby-dbus
25
13
 
26
14
  == Feature
27
15
 
@@ -42,8 +30,9 @@ Ruby D-Bus currently supports the following features:
42
30
  == Usage
43
31
 
44
32
  See some of the examples in the examples/ subdirectory of the tarball.
45
- Also, check out the included tutorial (in Webgen format) in doc/tutorial/
46
- or view it online on http://trac.luon.net/data/ruby-dbus/tutorial/.
33
+ Also, check out the included tutorial (in Markdown format) in doc/tutorial/
34
+ or view it online on
35
+ https://github.com/mvidner/ruby-dbus/blob/master/doc/tutorial/index.markdown .
47
36
 
48
37
  == License
49
38
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.6.0
@@ -164,6 +164,15 @@ access it with <code>bus.proxy</code> method. For example, you can retrieve an a
164
164
  exported service names of a bus like this:</p>
165
165
  <pre><code>bus.proxy.ListNames[0]
166
166
  </code></pre>
167
+ <h2>Properties</h2>
168
+ <p>Some D-Bus objects provide access to properties. They are accessed by
169
+ treating a proxy interface as a hash:</p>
170
+ <pre><code>nm_iface = network_manager_object["org.freedesktop.NetworkManager"]
171
+ enabled = nm_iface["WirelessEnabled"]
172
+ puts "Wireless is " + (enabled ? "enabled":"disabled")
173
+ puts "Toggling wireless"
174
+ nm_iface["WirelessEnabled"] = ! enabled
175
+ </code></pre>
167
176
  <h2>Calling a method asynchronously</h2>
168
177
  <p>D-Bus is <em>asynchronous</em>. This means that you do not have to wait for a
169
178
  reply when you send a message. When you call a remote method that takes a
@@ -229,6 +229,19 @@ exported service names of a bus like this:
229
229
 
230
230
  bus.proxy.ListNames[0]
231
231
 
232
+ Properties
233
+ ----------
234
+
235
+ Some D-Bus objects provide access to properties. They are accessed by
236
+ treating a proxy interface as a hash:
237
+
238
+ nm_iface = network_manager_object["org.freedesktop.NetworkManager"]
239
+ enabled = nm_iface["WirelessEnabled"]
240
+ puts "Wireless is " + (enabled ? "enabled":"disabled")
241
+ puts "Toggling wireless"
242
+ nm_iface["WirelessEnabled"] = ! enabled
243
+
244
+
232
245
  Calling a method asynchronously
233
246
  -------------------------------
234
247
 
File without changes
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # How to call overloaded methods.
4
+
5
+ require 'dbus'
6
+
7
+ bus = DBus::SessionmBus.instance
8
+
9
+ konsole_svc = bus["org.freedesktop.konsole"]
10
+ konsole_obj = konsole_svc["/Konsole"]
11
+ poi = DBus::ProxyObjectInterface.new(konsole_obj, "org.kde.konsole.Konsole")
12
+
13
+
14
+ begin
15
+ poi.define_method("getDevices", "") # NM 0.6
16
+ p poi.getDevices
17
+ rescue Exception
18
+ poi.define_method("GetDevices", "") # NM 0.7
19
+ p poi.GetDevices
20
+ end
21
+
22
+
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,19 @@
1
+ #! /usr/bin/env ruby
2
+ require 'dbus'
3
+
4
+ bus = DBus::SystemBus.instance
5
+ nm_service = bus["org.freedesktop.NetworkManager"]
6
+ network_manager_object = nm_service.object("/org/freedesktop/NetworkManager")
7
+ network_manager_object.introspect
8
+ nm_iface = network_manager_object["org.freedesktop.NetworkManager"]
9
+
10
+ # read a property
11
+ enabled = nm_iface["WirelessEnabled"]
12
+ if enabled
13
+ puts "Wireless is enabled"
14
+ else
15
+ puts "Wireless is disabled"
16
+ end
17
+ puts "Toggling wireless"
18
+ # write a property
19
+ nm_iface["WirelessEnabled"] = ! enabled
File without changes
File without changes
@@ -64,14 +64,6 @@ module DBus
64
64
  class IncompleteBufferException < Exception
65
65
  end
66
66
 
67
- # Exception raised when an interface is not implemented.
68
- class InterfaceNotImplemented < Exception
69
- end
70
-
71
- # Exception raised when an method is not found in the interface.
72
- class MethodNotInInterface < Exception
73
- end
74
-
75
67
  # Exception raised when a method has not been implemented (yet).
76
68
  class MethodNotImplemented < Exception
77
69
  end
@@ -427,8 +427,8 @@ module DBus
427
427
  pof = DBus::ProxyObjectFactory.new(data, self, dest, path)
428
428
  return pof.build
429
429
  else
430
- introspect_data(dest, path) do |data|
431
- yield(DBus::ProxyObjectFactory.new(data, self, dest, path).build)
430
+ introspect_data(dest, path) do |async_data|
431
+ yield(DBus::ProxyObjectFactory.new(async_data, self, dest, path).build)
432
432
  end
433
433
  end
434
434
  end
@@ -11,18 +11,6 @@
11
11
  require 'thread'
12
12
 
13
13
  module DBus
14
- # Exception raised when an interface cannot be found in an object.
15
- class InterfaceNotInObject < Exception
16
- end
17
-
18
- # Exception raised when a method cannot be found in an inferface.
19
- class MethodNotInInterface < Exception
20
- end
21
-
22
- # Method raised when a method returns an invalid return type.
23
- class InvalidReturnType < Exception
24
- end
25
-
26
14
  # Exported object type
27
15
  # = Exportable D-Bus object class
28
16
  #
@@ -55,14 +43,18 @@ module DBus
55
43
  def dispatch(msg)
56
44
  case msg.message_type
57
45
  when Message::METHOD_CALL
58
- if not self.intfs[msg.interface]
59
- raise InterfaceNotInObject, msg.interface
60
- end
61
- meth = self.intfs[msg.interface].methods[msg.member.to_sym]
62
- raise MethodNotInInterface if not meth
63
- methname = Object.make_method_name(msg.interface, msg.member)
64
46
  reply = nil
65
47
  begin
48
+ if not self.intfs[msg.interface]
49
+ raise DBus.error("org.freedesktop.DBus.Error.UnknownMethod"),
50
+ "Interface \"#{msg.interface}\" of object \"#{msg.path}\" doesn't exist"
51
+ end
52
+ meth = self.intfs[msg.interface].methods[msg.member.to_sym]
53
+ if not meth
54
+ raise DBus.error("org.freedesktop.DBus.Error.UnknownMethod"),
55
+ "Method \"#{msg.member}\" on interface \"#{msg.interface}\" of object \"#{msg.path}\" doesn't exist"
56
+ end
57
+ methname = Object.make_method_name(msg.interface, msg.member)
66
58
  retdata = method(methname).call(*msg.params)
67
59
  retdata = [*retdata]
68
60
 
@@ -422,6 +422,23 @@ module DBus
422
422
  bus.add_match(mr) { |msg| block.call(*msg.params) }
423
423
  end
424
424
  end
425
+
426
+ PROPERTY_INTERFACE = "org.freedesktop.DBus.Properties"
427
+
428
+ # Read a property.
429
+ def [](propname)
430
+ self.object[PROPERTY_INTERFACE].Get(self.name, propname)[0]
431
+ end
432
+
433
+ # Write a property.
434
+ def []=(propname, value)
435
+ self.object[PROPERTY_INTERFACE].Set(self.name, propname, value)
436
+ end
437
+
438
+ # Read all properties at once, as a hash.
439
+ def all_properties
440
+ self.object[PROPERTY_INTERFACE].GetAll(self.name)[0]
441
+ end
425
442
  end # class ProxyObjectInterface
426
443
 
427
444
  # D-Bus proxy object class
@@ -295,7 +295,7 @@ module DBus
295
295
  end
296
296
 
297
297
  def self.from_exception(ex)
298
- name = if ex.respond_to? :name
298
+ name = if ex.is_a? DBus::Error
299
299
  ex.name
300
300
  else
301
301
  "org.freedesktop.DBus.Error.Failed"
@@ -10,7 +10,7 @@ GEMSPEC = Gem::Specification.new do |s|
10
10
  s.version = File.read("VERSION").strip
11
11
  s.author = "Ruby DBus Team"
12
12
  s.email = "ruby-dbus-devel@lists.luon.net"
13
- s.homepage = "http://trac.luon.net/data/ruby-dbus/"
13
+ s.homepage = "https://trac.luon.net/ruby-dbus"
14
14
  s.files = FileList["{doc/tutorial,examples,lib,test}/**/*", "Rakefile", "ruby-dbus.gemspec", "VERSION"].to_a.sort
15
15
  s.require_path = "lib"
16
16
  s.has_rdoc = true
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+ require "test/unit"
3
+ require "dbus"
4
+
5
+ class PropertyTest < Test::Unit::TestCase
6
+ def setup
7
+ session_bus = DBus::SessionBus.instance
8
+ svc = session_bus.service("org.ruby.service")
9
+ @obj = svc.object("/org/ruby/MyInstance")
10
+ @obj.introspect
11
+ @iface = @obj["org.ruby.SampleInterface"]
12
+ end
13
+
14
+ def test_property_reading
15
+ assert_equal "READ ME", @iface["ReadMe"]
16
+ end
17
+
18
+ def test_property_nonreading
19
+ e = assert_raises DBus::Error do
20
+ @iface["WriteMe"]
21
+ end
22
+ assert_match(/not readable/, e.to_s)
23
+ end
24
+
25
+ def test_property_writing
26
+ @iface["ReadOrWriteMe"] = "VALUE"
27
+ assert_equal "VALUE", @iface["ReadOrWriteMe"]
28
+ end
29
+
30
+ def test_property_nonwriting
31
+ e = assert_raises DBus::Error do
32
+ @iface["ReadMe"] = "WROTE"
33
+ end
34
+ assert_match(/not writable/, e.to_s)
35
+ end
36
+
37
+ def test_get_all
38
+ all = @iface.all_properties
39
+ assert_equal ["ReadMe", "ReadOrWriteMe"], all.keys.sort
40
+ end
41
+
42
+ def test_unknown_property_reading
43
+ e = assert_raises DBus::Error do
44
+ @iface["Spoon"]
45
+ end
46
+ assert_match(/not found/, e.to_s)
47
+ end
48
+
49
+ def test_unknown_property_writing
50
+ e = assert_raises DBus::Error do
51
+ @iface["Spoon"] = "FORK"
52
+ end
53
+ assert_match(/not found/, e.to_s)
54
+ end
55
+ end
@@ -38,4 +38,35 @@ class ServerRobustnessTest < Test::Unit::TestCase
38
38
  rescue DBus::Error => e
39
39
  assert_no_match(/timeout/, e.to_s)
40
40
  end
41
+
42
+ def test_a_method_that_raises_name_error
43
+ obj = @svc.object "/org/ruby/MyInstance"
44
+ obj.introspect
45
+ obj.default_iface = "org.ruby.SampleInterface"
46
+ obj.will_raise_name_error
47
+ assert false, "should have raised"
48
+ rescue DBus::Error => e
49
+ assert_no_match(/timeout/, e.to_s)
50
+ end
51
+
52
+ # https://trac.luon.net/ruby-dbus/ticket/31#comment:3
53
+ def test_no_such_method_without_introspection
54
+ obj = @svc.object "/org/ruby/MyInstance"
55
+ ifc = DBus::ProxyObjectInterface.new(obj, "org.ruby.SampleInterface")
56
+ ifc.define_method("not_the_answer", "out n:i")
57
+ ifc.not_the_answer
58
+ assert false, "should have raised"
59
+ rescue DBus::Error => e
60
+ assert_no_match(/timeout/, e)
61
+ end
62
+
63
+ def test_no_such_interface_without_introspection
64
+ obj = @svc.object "/org/ruby/MyInstance"
65
+ ifc = DBus::ProxyObjectInterface.new(obj, "org.ruby.NoSuchInterface")
66
+ ifc.define_method("the_answer", "out n:i")
67
+ ifc.the_answer
68
+ assert false, "should have raised"
69
+ rescue DBus::Error => e
70
+ assert_no_match(/timeout/, e)
71
+ end
41
72
  end
@@ -9,9 +9,18 @@ def d(msg)
9
9
  puts "#{$$} #{msg}" if $DEBUG
10
10
  end
11
11
 
12
+ PROPERTY_INTERFACE = "org.freedesktop.DBus.Properties"
13
+
12
14
  class Test < DBus::Object
15
+ INTERFACE = "org.ruby.SampleInterface"
16
+ def initialize(path)
17
+ super path
18
+ @read_me = "READ ME"
19
+ @read_or_write_me = "READ OR WRITE ME"
20
+ end
21
+
13
22
  # Create an interface aggregating all upcoming dbus_method defines.
14
- dbus_interface "org.ruby.SampleInterface" do
23
+ dbus_interface INTERFACE do
15
24
  dbus_method :hello, "in name:s, in name2:s" do |name, name2|
16
25
  puts "hello(#{name}, #{name2})"
17
26
  end
@@ -40,6 +49,10 @@ class Test < DBus::Object
40
49
  raise DBus.error, "failed as designed"
41
50
  end
42
51
 
52
+ dbus_method :will_raise_name_error, "" do
53
+ "foo".frobnicate
54
+ end
55
+
43
56
  dbus_method :Error, "in name:s, in description:s" do |name, description|
44
57
  raise DBus.error(name), description
45
58
  end
@@ -81,6 +94,61 @@ class Test < DBus::Object
81
94
 
82
95
  dbus_signal :LongTaskEnd
83
96
  end
97
+
98
+ # Properties:
99
+ # ReadMe:string, returns "READ ME" at first, then what WriteMe received
100
+ # WriteMe:string
101
+ # ReadOrWriteMe:string, returns "READ OR WRITE ME" at first
102
+ dbus_interface PROPERTY_INTERFACE do
103
+ dbus_method :Get, "in interface:s, in propname:s, out value:v" do |interface, propname|
104
+ if interface == INTERFACE
105
+ if propname == "ReadMe"
106
+ [@read_me]
107
+ elsif propname == "ReadOrWriteMe"
108
+ [@read_or_write_me]
109
+ elsif propname == "WriteMe"
110
+ raise DBus.error("org.freedesktop.DBus.Error.InvalidArgs"), "Property '#{interface}.#{propname}' (on object '#{@path}') is not readable"
111
+ else
112
+ raise DBus.error("org.freedesktop.DBus.Error.InvalidArgs"), "Property '#{interface}.#{propname}' not found on object '#{@path}'"
113
+ end
114
+ else
115
+ raise DBus.error("org.freedesktop.DBus.Error.UnknownInterface"), "Interface '#{interface}' not found on object '#{@path}'"
116
+ end
117
+ # what should happen for unknown properties
118
+ # plasma: InvalidArgs (propname), UnknownInterface (interface)
119
+ end
120
+
121
+ dbus_method :Set, "in interface:s, in propname:s, in value:v" do |interface, propname, value|
122
+ if interface == INTERFACE
123
+ if propname == "ReadMe"
124
+ raise DBus.error("org.freedesktop.DBus.Error.InvalidArgs"), "Property '#{interface}.#{propname}' (on object '#{@path}') is not writable"
125
+ elsif propname == "ReadOrWriteMe"
126
+ @read_or_write_me = value
127
+ self.PropertiesChanged(interface, {propname => value}, [])
128
+ elsif propname == "WriteMe"
129
+ @read_me = value
130
+ self.PropertiesChanged(interface, {"ReadMe" => value}, [])
131
+ else
132
+ raise DBus.error("org.freedesktop.DBus.Error.InvalidArgs"), "Property '#{interface}.#{propname}' not found on object '#{@path}'"
133
+ end
134
+ else
135
+ raise DBus.error("org.freedesktop.DBus.Error.UnknownInterface"), "Interface '#{interface}' not found on object '#{@path}'"
136
+ end
137
+ end
138
+
139
+ dbus_method :GetAll, "in interface:s, out value:a{sv}" do |interface|
140
+ if interface == INTERFACE
141
+ [ {
142
+ "ReadMe" => @read_me,
143
+ "ReadOrWriteMe" =>@read_or_write_me,
144
+ } ]
145
+ else
146
+ raise DBus.error("org.freedesktop.DBus.Error.UnknownInterface"), "Interface '#{interface}' not found on object '#{@path}'"
147
+ end
148
+ end
149
+
150
+ dbus_signal :PropertiesChanged, "interface:s, changed_properties:a{sv}, invalidated_properties:as"
151
+ end
84
152
  end
85
153
 
86
154
  class Derived < Test
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-dbus
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 5
8
+ - 6
9
9
  - 0
10
- version: 0.5.0
10
+ version: 0.6.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ruby DBus Team
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-07 00:00:00 +01:00
18
+ date: 2010-12-10 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -37,12 +37,14 @@ files:
37
37
  - examples/gdbus/gdbus
38
38
  - examples/gdbus/gdbus.glade
39
39
  - examples/gdbus/launch.sh
40
+ - examples/no-introspect/call-overloaded.rb
40
41
  - examples/no-introspect/nm-test.rb
41
42
  - examples/no-introspect/tracker-test.rb
42
43
  - examples/rhythmbox/playpause.rb
43
44
  - examples/service/call_service.rb
44
45
  - examples/service/service_newapi.rb
45
46
  - examples/simple/call_introspect.rb
47
+ - examples/simple/properties.rb
46
48
  - examples/utils/listnames.rb
47
49
  - examples/utils/notify.rb
48
50
  - lib/dbus.rb
@@ -63,6 +65,7 @@ files:
63
65
  - test/bus_driver_test.rb
64
66
  - test/dbus-launch-simple
65
67
  - test/dbus-limited-session.conf
68
+ - test/property_test.rb
66
69
  - test/server_robustness_test.rb
67
70
  - test/server_test.rb
68
71
  - test/service_newapi.rb
@@ -80,7 +83,7 @@ files:
80
83
  - README
81
84
  - NEWS
82
85
  has_rdoc: true
83
- homepage: http://trac.luon.net/data/ruby-dbus/
86
+ homepage: https://trac.luon.net/ruby-dbus
84
87
  licenses: []
85
88
 
86
89
  post_install_message: