ruby-dbus 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/dbus/marshall.rb CHANGED
@@ -42,9 +42,7 @@ module DBus
42
42
  @uint16 = "v"
43
43
  @double = "E"
44
44
  else
45
- # FIXME: shouldn't a more special exception be raised here?
46
- # yes, idea for a good name ? :)
47
- raise Exception, "Incorrect endianness"
45
+ raise InvalidPacketException, "Incorrect endianness #{@endianness}"
48
46
  end
49
47
  @idx = 0
50
48
  end
@@ -53,7 +51,7 @@ module DBus
53
51
  # Return an array of unmarshalled objects
54
52
  def unmarshall(signature, len = nil)
55
53
  if len != nil
56
- if @buffy.size < @idx + len
54
+ if @buffy.bytesize < @idx + len
57
55
  raise IncompleteBufferException
58
56
  end
59
57
  end
@@ -73,7 +71,7 @@ module DBus
73
71
  when 2, 4, 8
74
72
  bits = a - 1
75
73
  @idx = @idx + bits & ~bits
76
- raise IncompleteBufferException if @idx > @buffy.size
74
+ raise IncompleteBufferException if @idx > @buffy.bytesize
77
75
  else
78
76
  raise "Unsupported alignment #{a}"
79
77
  end
@@ -86,7 +84,7 @@ module DBus
86
84
 
87
85
  # Retrieve the next _nbytes_ number of bytes from the buffer.
88
86
  def get(nbytes)
89
- raise IncompleteBufferException if @idx + nbytes > @buffy.size
87
+ raise IncompleteBufferException if @idx + nbytes > @buffy.bytesize
90
88
  ret = @buffy.slice(@idx, nbytes)
91
89
  @idx += nbytes
92
90
  ret
@@ -96,8 +94,8 @@ module DBus
96
94
  def get_nul_terminated
97
95
  raise IncompleteBufferException if not @buffy[@idx..-1] =~ /^([^\0]*)\0/
98
96
  str = $1
99
- raise IncompleteBufferException if @idx + str.size + 1 > @buffy.size
100
- @idx += str.size + 1
97
+ raise IncompleteBufferException if @idx + str.bytesize + 1 > @buffy.bytesize
98
+ @idx += str.bytesize + 1
101
99
  str
102
100
  end
103
101
 
@@ -107,7 +105,7 @@ module DBus
107
105
  align(4)
108
106
  str_sz = get(4).unpack(@uint32)[0]
109
107
  ret = @buffy.slice(@idx, str_sz)
110
- raise IncompleteBufferException if @idx + str_sz + 1 > @buffy.size
108
+ raise IncompleteBufferException if @idx + str_sz + 1 > @buffy.bytesize
111
109
  @idx += str_sz
112
110
  if @buffy[@idx].ord != 0
113
111
  raise InvalidPacketException, "String is not nul-terminated"
@@ -122,7 +120,7 @@ module DBus
122
120
  def get_signature
123
121
  str_sz = get(1).unpack('C')[0]
124
122
  ret = @buffy.slice(@idx, str_sz)
125
- raise IncompleteBufferException if @idx + str_sz + 1 >= @buffy.size
123
+ raise IncompleteBufferException if @idx + str_sz + 1 >= @buffy.bytesize
126
124
  @idx += str_sz
127
125
  if @buffy[@idx].ord != 0
128
126
  raise InvalidPacketException, "Type is not nul-terminated"
@@ -193,7 +191,7 @@ module DBus
193
191
  raise InvalidPacketException if array_sz > 67108864
194
192
 
195
193
  align(signature.child.alignment)
196
- raise IncompleteBufferException if @idx + array_sz > @buffy.size
194
+ raise IncompleteBufferException if @idx + array_sz > @buffy.bytesize
197
195
 
198
196
  packet = Array.new
199
197
  start_idx = @idx
@@ -223,6 +221,7 @@ module DBus
223
221
  packet = get_string
224
222
  when Type::STRING
225
223
  packet = get_string
224
+ packet.force_encoding('UTF-8') if RUBY_VERSION >= '1.9'
226
225
  when Type::SIGNATURE
227
226
  packet = get_signature
228
227
  when Type::DICT_ENTRY
@@ -240,7 +239,7 @@ module DBus
240
239
 
241
240
  # D-Bus packet marshaller class
242
241
  #
243
- # Class that handles the conversion (unmarshalling) of Ruby objects to
242
+ # Class that handles the conversion (marshalling) of Ruby objects to
244
243
  # (binary) payload data.
245
244
  class PacketMarshaller
246
245
  # The current or result packet.
@@ -267,18 +266,18 @@ module DBus
267
266
 
268
267
  # Align the buffer with NULL (\0) bytes on a byte length of _a_.
269
268
  def align(a)
270
- @packet = @packet.ljust(num_align(@offset + @packet.length, a) - @offset, 0.chr)
269
+ @packet = @packet.ljust(num_align(@offset + @packet.bytesize, a) - @offset, 0.chr)
271
270
  end
272
271
 
273
272
  # Append the the string _str_ itself to the packet.
274
273
  def append_string(str)
275
274
  align(4)
276
- @packet += [str.length].pack("L") + str + "\0"
275
+ @packet += [str.bytesize].pack("L") + [str].pack("Z*")
277
276
  end
278
277
 
279
278
  # Append the the signature _signature_ itself to the packet.
280
279
  def append_signature(str)
281
- @packet += str.length.chr + str + "\0"
280
+ @packet += str.bytesize.chr + str + "\0"
282
281
  end
283
282
 
284
283
  # Append the array type _type_ to the packet and allow for appending
@@ -286,12 +285,12 @@ module DBus
286
285
  def array(type)
287
286
  # Thanks to Peter Rullmann for this line
288
287
  align(4)
289
- sizeidx = @packet.size
288
+ sizeidx = @packet.bytesize
290
289
  @packet += "ABCD"
291
290
  align(type.alignment)
292
- contentidx = @packet.size
291
+ contentidx = @packet.bytesize
293
292
  yield
294
- sz = @packet.size - contentidx
293
+ sz = @packet.bytesize - contentidx
295
294
  raise InvalidPacketException if sz > 67108864
296
295
  @packet[sizeidx...sizeidx + 4] = [sz].pack("L")
297
296
  end
@@ -308,6 +307,8 @@ module DBus
308
307
  end
309
308
 
310
309
  # Append a value _val_ to the packet based on its _type_.
310
+ #
311
+ # Host native endianness is used, declared in Message#marshall
311
312
  def append(type, val)
312
313
  raise TypeException, "Cannot send nil" if val.nil?
313
314
 
@@ -372,7 +373,7 @@ module DBus
372
373
 
373
374
  append_signature(vartype.to_s)
374
375
  align(vartype.alignment)
375
- sub = PacketMarshaller.new(@offset + @packet.length)
376
+ sub = PacketMarshaller.new(@offset + @packet.bytesize)
376
377
  sub.append(vartype, vardata)
377
378
  @packet += sub.packet
378
379
  when Type::ARRAY
@@ -15,7 +15,7 @@ module DBus
15
15
  #
16
16
  # FIXME
17
17
  class MatchRule
18
- # The list of possible match filters.
18
+ # The list of possible match filters. TODO argN, argNpath
19
19
  FILTERS = [:sender, :interface, :member, :path, :destination, :type]
20
20
  # The sender filter.
21
21
  attr_accessor :sender
@@ -94,6 +94,7 @@ module DBus
94
94
  return false if @interface and @interface != msg.interface
95
95
  return false if @member and @member != msg.member
96
96
  return false if @path and @path != msg.path
97
+ # FIXME sender and destination are ignored
97
98
  true
98
99
  end
99
100
  end # class MatchRule
data/lib/dbus/message.rb CHANGED
@@ -152,7 +152,7 @@ module DBus
152
152
  @params.each do |param|
153
153
  params.append(param[0], param[1])
154
154
  end
155
- @body_length = params.packet.length
155
+ @body_length = params.packet.bytesize
156
156
 
157
157
  marshaller = PacketMarshaller.new
158
158
  marshaller.append(Type::BYTE, HOST_END)
data/ruby-dbus.gemspec CHANGED
@@ -8,6 +8,7 @@ GEMSPEC = Gem::Specification.new do |s|
8
8
  s.summary = "Ruby module for interaction with D-Bus"
9
9
  # s.description = FIXME
10
10
  s.version = File.read("VERSION").strip
11
+ s.license = "LGPL v2.1"
11
12
  s.author = "Ruby DBus Team"
12
13
  s.email = "ruby-dbus-devel@lists.luon.net"
13
14
  s.homepage = "https://trac.luon.net/ruby-dbus"
@@ -15,4 +16,5 @@ GEMSPEC = Gem::Specification.new do |s|
15
16
  s.require_path = "lib"
16
17
  s.has_rdoc = true
17
18
  s.extra_rdoc_files = ["COPYING", "README", "NEWS"]
19
+ s.required_ruby_version = ">= 1.8.7"
18
20
  end
data/test/binding_test.rb CHANGED
@@ -5,7 +5,7 @@ require "dbus"
5
5
 
6
6
  class BindingTest < Test::Unit::TestCase
7
7
  def setup
8
- @bus = DBus::SessionBus.instance
8
+ @bus = DBus::ASessionBus.new
9
9
  @svc = @bus.service("org.ruby.service")
10
10
  @base = @svc.object "/org/ruby/MyInstance"
11
11
  @base.introspect
@@ -9,7 +9,7 @@ end
9
9
 
10
10
  class BusDriverTest < Test::Unit::TestCase
11
11
  def setup
12
- @bus = DBus::SessionBus.instance
12
+ @bus = DBus::ASessionBus.new
13
13
  @svc = @bus.service("org.ruby.service")
14
14
  @svc.object("/").introspect
15
15
  end
data/test/bus_test.rb ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # Test the bus class
3
+ require "test/unit"
4
+ require "dbus"
5
+
6
+ class BusTest < Test::Unit::TestCase
7
+ def setup
8
+ @bus = DBus::ASessionBus.new
9
+ @svc = @bus.service("org.ruby.service")
10
+ @svc.object("/").introspect
11
+ end
12
+
13
+ def test_introspection_not_leaking
14
+ # peek inside the object to see if a cleanup step worked or not
15
+ some_hash = @bus.instance_eval { @method_call_replies || Hash.new }
16
+ assert_equal 0, some_hash.size, "there are leftover method handlers"
17
+ end
18
+ end
@@ -4,7 +4,7 @@ require "dbus"
4
4
 
5
5
  class PropertyTest < Test::Unit::TestCase
6
6
  def setup
7
- session_bus = DBus::SessionBus.instance
7
+ session_bus = DBus::ASessionBus.new
8
8
  svc = session_bus.service("org.ruby.service")
9
9
  @obj = svc.object("/org/ruby/MyInstance")
10
10
  @obj.introspect
@@ -5,7 +5,7 @@ require "dbus"
5
5
 
6
6
  class ServerRobustnessTest < Test::Unit::TestCase
7
7
  def setup
8
- @bus = DBus::SessionBus.instance
8
+ @bus = DBus::ASessionBus.new
9
9
  @svc = @bus.service("org.ruby.service")
10
10
  end
11
11
 
@@ -57,7 +57,7 @@ class ServerRobustnessTest < Test::Unit::TestCase
57
57
  ifc.not_the_answer
58
58
  assert false, "should have raised"
59
59
  rescue DBus::Error => e
60
- assert_no_match(/timeout/, e)
60
+ assert_no_match(/timeout/, e.to_s)
61
61
  end
62
62
 
63
63
  def test_no_such_interface_without_introspection
@@ -67,6 +67,6 @@ class ServerRobustnessTest < Test::Unit::TestCase
67
67
  ifc.the_answer
68
68
  assert false, "should have raised"
69
69
  rescue DBus::Error => e
70
- assert_no_match(/timeout/, e)
70
+ assert_no_match(/timeout/, e.to_s)
71
71
  end
72
72
  end
data/test/server_test.rb CHANGED
@@ -25,7 +25,7 @@ end
25
25
 
26
26
  class ServerTest < Test::Unit::TestCase
27
27
  def setup
28
- @bus = DBus::SessionBus.instance
28
+ @bus = DBus::ASessionBus.new
29
29
  @svc = @bus.request_service "org.ruby.server-test"
30
30
  end
31
31
 
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  # find the library without external help
4
5
  $:.unshift File.expand_path("../../lib", __FILE__)
@@ -56,6 +57,13 @@ class Test < DBus::Object
56
57
  dbus_method :Error, "in name:s, in description:s" do |name, description|
57
58
  raise DBus.error(name), description
58
59
  end
60
+ end
61
+
62
+ # closing and reopening the same interface
63
+ dbus_interface INTERFACE do
64
+ dbus_method :multibyte_string, "out string:s" do
65
+ "あいうえお"
66
+ end
59
67
 
60
68
  dbus_signal :SomethingJustHappened, "toto:s, tutu:u"
61
69
  end
@@ -186,7 +194,7 @@ bus.add_match(mr) do |msg|
186
194
  end
187
195
  end
188
196
 
189
- puts "listening"
197
+ puts "listening, with ruby-#{RUBY_VERSION}"
190
198
  main = DBus::Main.new
191
199
  main << bus
192
200
  begin
@@ -10,7 +10,7 @@ class SessionBusAddressTest < Test::Unit::TestCase
10
10
  def setup
11
11
  # test getting the session bus address even if unset in ENV (Issue#4)
12
12
  ENV.delete "DBUS_SESSION_BUS_ADDRESS"
13
- @bus = DBus::SessionBus.instance
13
+ @bus = DBus::ASessionBus.new
14
14
  @svc = @bus.service("org.freedesktop.DBus")
15
15
  end
16
16
 
data/test/signal_test.rb CHANGED
@@ -9,7 +9,7 @@ end
9
9
 
10
10
  class SignalHandlerTest < Test::Unit::TestCase
11
11
  def setup
12
- @session_bus = DBus::SessionBus.instance
12
+ @session_bus = DBus::ASessionBus.new
13
13
  svc = @session_bus.service("org.ruby.service")
14
14
  @obj = svc.object("/org/ruby/MyInstance")
15
15
  @obj.introspect # necessary
data/test/t2.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
2
3
  require "test/unit"
3
4
  require "dbus"
4
5
 
5
6
  class ValueTest < Test::Unit::TestCase
6
7
  def setup
7
- session_bus = DBus::SessionBus.instance
8
+ session_bus = DBus::ASessionBus.new
8
9
  svc = session_bus.service("org.ruby.service")
9
10
  @obj = svc.object("/org/ruby/MyInstance")
10
11
  @obj.introspect # necessary
@@ -63,4 +64,9 @@ class ValueTest < Test::Unit::TestCase
63
64
  # "warning: default `to_a' will be obsolete"
64
65
  @obj.the_answer
65
66
  end
67
+
68
+ def test_multibyte_string
69
+ str = @obj.multibyte_string[0]
70
+ assert_equal "あいうえお", str
71
+ end
66
72
  end
data/test/t3-ticket27.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # Test passing a particular struct array through a variant
3
3
  # https://trac.luon.net/ruby-dbus/ticket/27
4
4
  require "dbus"
5
- session_bus = DBus::SessionBus.instance
5
+ session_bus = DBus::ASessionBus.new
6
6
  svc = session_bus.service("org.ruby.service")
7
7
  obj = svc.object("/org/ruby/MyInstance")
8
8
  obj.introspect # necessary
@@ -6,7 +6,7 @@ require "dbus"
6
6
 
7
7
  class ErrMsgTest < Test::Unit::TestCase
8
8
  def setup
9
- session_bus = DBus::SessionBus.instance
9
+ session_bus = DBus::ASessionBus.new
10
10
  svc = session_bus.service("org.ruby.service")
11
11
  @obj = svc.object("/org/ruby/MyInstance")
12
12
  @obj.introspect # necessary
data/test/t6-loop.rb CHANGED
@@ -9,7 +9,7 @@ end
9
9
 
10
10
  class MainLoopTest < Test::Unit::TestCase
11
11
  def setup
12
- @session_bus = DBus::SessionBus.instance
12
+ @session_bus = DBus::ASessionBus.new
13
13
  svc = @session_bus.service("org.ruby.service")
14
14
  @obj = svc.object("/org/ruby/MyInstance")
15
15
  @obj.introspect # necessary
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+ # Test thread safety
3
+ require "test/unit"
4
+ require "dbus"
5
+
6
+ def d(msg)
7
+ puts "#{$$} #{msg}" if $DEBUG
8
+ end
9
+
10
+ class ThreadSafetyTest < Test::Unit::TestCase
11
+ def test_thread_competition
12
+ print "Thread competition: "
13
+ jobs = []
14
+ 5.times do
15
+ jobs << Thread.new do
16
+ Thread.current.abort_on_exception = true
17
+
18
+ # use separate connections to avoid races
19
+ bus = DBus::ASessionBus.new
20
+ svc = bus.service("org.ruby.service")
21
+ obj = svc.object("/org/ruby/MyInstance")
22
+ obj.introspect
23
+ obj.default_iface = "org.ruby.SampleInterface"
24
+
25
+ 10.times do |i|
26
+ print "#{i} "
27
+ $stdout.flush
28
+ assert_equal 42, obj.the_answer[0]
29
+ sleep 0.1 * rand
30
+ end
31
+ end
32
+ end
33
+ jobs.each do |thread| thread.join end
34
+ end
35
+ end
data/test/variant_test.rb CHANGED
@@ -5,7 +5,7 @@ require "dbus"
5
5
 
6
6
  class VariantTest < Test::Unit::TestCase
7
7
  def setup
8
- @bus = DBus::SessionBus.instance
8
+ @bus = DBus::ASessionBus.new
9
9
  @svc = @bus.service("org.ruby.service")
10
10
  end
11
11
 
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: 7
5
- prerelease: false
4
+ hash: 3
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 6
8
+ - 7
9
9
  - 0
10
- version: 0.6.0
10
+ version: 0.7.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-12-10 00:00:00 +01:00
18
+ date: 2011-07-26 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -32,12 +32,10 @@ extra_rdoc_files:
32
32
  files:
33
33
  - Rakefile
34
34
  - VERSION
35
- - doc/tutorial/index.html
36
35
  - doc/tutorial/index.markdown
37
36
  - examples/gdbus/gdbus
38
37
  - examples/gdbus/gdbus.glade
39
38
  - examples/gdbus/launch.sh
40
- - examples/no-introspect/call-overloaded.rb
41
39
  - examples/no-introspect/nm-test.rb
42
40
  - examples/no-introspect/tracker-test.rb
43
41
  - examples/rhythmbox/playpause.rb
@@ -63,6 +61,7 @@ files:
63
61
  - ruby-dbus.gemspec
64
62
  - test/binding_test.rb
65
63
  - test/bus_driver_test.rb
64
+ - test/bus_test.rb
66
65
  - test/dbus-launch-simple
67
66
  - test/dbus-limited-session.conf
68
67
  - test/property_test.rb
@@ -78,14 +77,15 @@ files:
78
77
  - test/t6-loop.rb
79
78
  - test/test_env
80
79
  - test/test_server
80
+ - test/thread_safety_test.rb
81
81
  - test/variant_test.rb
82
82
  - COPYING
83
83
  - README
84
84
  - NEWS
85
85
  has_rdoc: true
86
86
  homepage: https://trac.luon.net/ruby-dbus
87
- licenses: []
88
-
87
+ licenses:
88
+ - LGPL v2.1
89
89
  post_install_message:
90
90
  rdoc_options: []
91
91
 
@@ -96,10 +96,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
96
  requirements:
97
97
  - - ">="
98
98
  - !ruby/object:Gem::Version
99
- hash: 3
99
+ hash: 57
100
100
  segments:
101
- - 0
102
- version: "0"
101
+ - 1
102
+ - 8
103
+ - 7
104
+ version: 1.8.7
103
105
  required_rubygems_version: !ruby/object:Gem::Requirement
104
106
  none: false
105
107
  requirements:
@@ -112,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
114
  requirements: []
113
115
 
114
116
  rubyforge_project:
115
- rubygems_version: 1.3.7
117
+ rubygems_version: 1.5.2
116
118
  signing_key:
117
119
  specification_version: 3
118
120
  summary: Ruby module for interaction with D-Bus