ruby-dbus 0.12.0 → 0.13.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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/NEWS.md +344 -0
  3. data/Rakefile +21 -15
  4. data/VERSION +1 -1
  5. data/doc/Reference.md +26 -37
  6. data/examples/doc/_extract_examples +4 -4
  7. data/examples/gdbus/gdbus +40 -39
  8. data/examples/no-introspect/nm-test.rb +1 -3
  9. data/examples/no-introspect/tracker-test.rb +2 -4
  10. data/examples/rhythmbox/playpause.rb +1 -2
  11. data/examples/service/call_service.rb +0 -3
  12. data/examples/service/service_newapi.rb +3 -4
  13. data/examples/simple/call_introspect.rb +0 -3
  14. data/examples/simple/get_id.rb +1 -3
  15. data/examples/simple/properties.rb +3 -4
  16. data/examples/utils/listnames.rb +6 -7
  17. data/examples/utils/notify.rb +3 -5
  18. data/lib/dbus.rb +8 -20
  19. data/lib/dbus/auth.rb +59 -61
  20. data/lib/dbus/bus.rb +86 -97
  21. data/lib/dbus/error.rb +1 -1
  22. data/lib/dbus/export.rb +20 -18
  23. data/lib/dbus/introspect.rb +26 -28
  24. data/lib/dbus/logger.rb +1 -1
  25. data/lib/dbus/marshall.rb +72 -74
  26. data/lib/dbus/matchrule.rb +22 -26
  27. data/lib/dbus/message.rb +24 -33
  28. data/lib/dbus/message_queue.rb +30 -30
  29. data/lib/dbus/proxy_object.rb +34 -30
  30. data/lib/dbus/proxy_object_factory.rb +5 -2
  31. data/lib/dbus/proxy_object_interface.rb +10 -8
  32. data/lib/dbus/type.rb +154 -156
  33. data/lib/dbus/xml.rb +22 -16
  34. data/ruby-dbus.gemspec +15 -3
  35. data/spec/async_spec.rb +2 -4
  36. data/spec/binding_spec.rb +1 -5
  37. data/spec/bus_and_xml_backend_spec.rb +6 -9
  38. data/spec/bus_spec.rb +1 -1
  39. data/spec/byte_array_spec.rb +0 -2
  40. data/spec/err_msg_spec.rb +13 -10
  41. data/spec/introspect_xml_parser_spec.rb +2 -2
  42. data/spec/introspection_spec.rb +1 -1
  43. data/spec/main_loop_spec.rb +4 -5
  44. data/spec/property_spec.rb +0 -3
  45. data/spec/proxy_object_spec.rb +42 -0
  46. data/spec/server_robustness_spec.rb +0 -2
  47. data/spec/service_newapi.rb +51 -41
  48. data/spec/session_bus_spec.rb +6 -7
  49. data/spec/signal_spec.rb +2 -3
  50. data/spec/spec_helper.rb +28 -24
  51. data/spec/thread_safety_spec.rb +1 -2
  52. data/spec/type_spec.rb +2 -2
  53. data/spec/value_spec.rb +7 -10
  54. data/spec/variant_spec.rb +15 -16
  55. metadata +60 -3
  56. data/NEWS +0 -279
@@ -30,7 +30,7 @@ module DBus
30
30
  @name = name
31
31
  super(msg)
32
32
  end
33
- # TODO validate error name
33
+ # TODO: validate error name
34
34
  end
35
35
  end # class Error
36
36
 
@@ -8,7 +8,7 @@
8
8
  # License, version 2.1 as published by the Free Software Foundation.
9
9
  # See the file "COPYING" for the exact licensing terms.
10
10
 
11
- require 'thread'
11
+ require "thread"
12
12
 
13
13
  module DBus
14
14
  # Exported object type
@@ -21,10 +21,12 @@ module DBus
21
21
  attr_reader :path
22
22
  # The interfaces that the object supports. Hash: String => Interface
23
23
  class_attribute :intfs
24
+ self.intfs = {}
25
+
24
26
  # The service that the object is exported by.
25
27
  attr_writer :service
26
28
 
27
- @@cur_intf = nil # Interface
29
+ @@cur_intf = nil # Interface
28
30
  @@intfs_mutex = Mutex.new
29
31
 
30
32
  # Create a new object with a given _path_.
@@ -34,30 +36,24 @@ module DBus
34
36
  @service = nil
35
37
  end
36
38
 
37
- # State that the object implements the given _intf_.
38
- def implements(intf)
39
- # use a setter
40
- self.intfs = (self.intfs || {}).merge({intf.name => intf})
41
- end
42
-
43
39
  # Dispatch a message _msg_ to call exported methods
44
40
  def dispatch(msg)
45
41
  case msg.message_type
46
42
  when Message::METHOD_CALL
47
43
  reply = nil
48
44
  begin
49
- if not self.intfs[msg.interface]
45
+ if !intfs[msg.interface]
50
46
  raise DBus.error("org.freedesktop.DBus.Error.UnknownMethod"),
51
- "Interface \"#{msg.interface}\" of object \"#{msg.path}\" doesn't exist"
47
+ "Interface \"#{msg.interface}\" of object \"#{msg.path}\" doesn't exist"
52
48
  end
53
- meth = self.intfs[msg.interface].methods[msg.member.to_sym]
54
- if not meth
49
+ meth = intfs[msg.interface].methods[msg.member.to_sym]
50
+ if !meth
55
51
  raise DBus.error("org.freedesktop.DBus.Error.UnknownMethod"),
56
- "Method \"#{msg.member}\" on interface \"#{msg.interface}\" of object \"#{msg.path}\" doesn't exist"
52
+ "Method \"#{msg.member}\" on interface \"#{msg.interface}\" of object \"#{msg.path}\" doesn't exist"
57
53
  end
58
54
  methname = Object.make_method_name(msg.interface, msg.member)
59
55
  retdata = method(methname).call(*msg.params)
60
- retdata = [*retdata]
56
+ retdata = [*retdata]
61
57
 
62
58
  reply = Message.method_return(msg)
63
59
  meth.rets.zip(retdata).each do |rsig, rdata|
@@ -75,9 +71,15 @@ module DBus
75
71
  # belong to.
76
72
  def self.dbus_interface(s)
77
73
  @@intfs_mutex.synchronize do
78
- unless @@cur_intf = (self.intfs && self.intfs[s])
74
+ @@cur_intf = intfs[s]
75
+ if !@@cur_intf
79
76
  @@cur_intf = Interface.new(s)
80
- self.intfs = (self.intfs || {}).merge({s => @@cur_intf})
77
+ # As this is a mutable class_attr, we cannot use
78
+ # self.intfs[s] = @@cur_intf # Hash#[]=
79
+ # as that would modify parent class attr in place.
80
+ # Using the setter lets a subclass have the new value
81
+ # while the superclass keeps the old one.
82
+ self.intfs = intfs.merge(s => @@cur_intf)
81
83
  end
82
84
  yield
83
85
  @@cur_intf = nil
@@ -96,7 +98,7 @@ module DBus
96
98
  def self.dbus_method(sym, protoype = "", &block)
97
99
  raise UndefinedInterface, sym if @@cur_intf.nil?
98
100
  @@cur_intf.define(Method.new(sym.to_s).from_prototype(protoype))
99
- define_method(Object.make_method_name(@@cur_intf.name, sym.to_s), &block)
101
+ define_method(Object.make_method_name(@@cur_intf.name, sym.to_s), &block)
100
102
  end
101
103
 
102
104
  # Emits a signal from the object with the given _interface_, signal
@@ -117,10 +119,10 @@ module DBus
117
119
  end
118
120
 
119
121
  ####################################################################
120
- private
121
122
 
122
123
  # Helper method that returns a method name generated from the interface
123
124
  # name _intfname_ and method name _methname_.
125
+ # @api private
124
126
  def self.make_method_name(intfname, methname)
125
127
  "#{intfname}%%#{methname}"
126
128
  end
@@ -10,9 +10,9 @@
10
10
 
11
11
  module DBus
12
12
  # Regular expressions that should match all method names.
13
- MethodSignalRE = /^[A-Za-z][A-Za-z0-9_]*$/
13
+ METHOD_SIGNAL_RE = /^[A-Za-z][A-Za-z0-9_]*$/
14
14
  # Regular expressions that should match all interface names.
15
- InterfaceElementRE = /^[A-Za-z][A-Za-z0-9_]*$/
15
+ INTERFACE_ELEMENT_RE = /^[A-Za-z][A-Za-z0-9_]*$/
16
16
 
17
17
  # Exception raised when an unknown signal is used.
18
18
  class UnknownSignal < Exception
@@ -41,29 +41,30 @@ module DBus
41
41
  def initialize(name)
42
42
  validate_name(name)
43
43
  @name = name
44
- @methods, @signals = Hash.new, Hash.new
44
+ @methods = {}
45
+ @signals = {}
45
46
  end
46
47
 
47
48
  # Validates a service _name_.
48
49
  def validate_name(name)
49
50
  raise InvalidIntrospectionData if name.bytesize > 255
50
- raise InvalidIntrospectionData if name =~ /^\./ or name =~ /\.$/
51
+ raise InvalidIntrospectionData if name =~ /^\./ || name =~ /\.$/
51
52
  raise InvalidIntrospectionData if name =~ /\.\./
52
- raise InvalidIntrospectionData if not name =~ /\./
53
+ raise InvalidIntrospectionData if !(name =~ /\./)
53
54
  name.split(".").each do |element|
54
- raise InvalidIntrospectionData if not element =~ InterfaceElementRE
55
+ raise InvalidIntrospectionData if !(element =~ INTERFACE_ELEMENT_RE)
55
56
  end
56
57
  end
57
58
 
58
59
  # Helper method for defining a method _m_.
59
60
  def define(m)
60
- if m.kind_of?(Method)
61
+ if m.is_a?(Method)
61
62
  @methods[m.name.to_sym] = m
62
- elsif m.kind_of?(Signal)
63
+ elsif m.is_a?(Signal)
63
64
  @signals[m.name.to_sym] = m
64
65
  end
65
66
  end
66
- alias :<< :define
67
+ alias << define
67
68
 
68
69
  # Defines a method with name _id_ and a given _prototype_ in the
69
70
  # interface.
@@ -87,9 +88,8 @@ module DBus
87
88
  # backward compatibility, deprecated
88
89
  def [](index)
89
90
  case index
90
- when 0 then name
91
- when 1 then type
92
- else nil
91
+ when 0 then name
92
+ when 1 then type
93
93
  end
94
94
  end
95
95
  end
@@ -106,16 +106,15 @@ module DBus
106
106
 
107
107
  # Validates element _name_.
108
108
  def validate_name(name)
109
- if (not name =~ MethodSignalRE) or (name.bytesize > 255)
110
- raise InvalidMethodName, name
111
- end
109
+ return if (name =~ METHOD_SIGNAL_RE) && (name.bytesize <= 255)
110
+ raise InvalidMethodName, name
112
111
  end
113
112
 
114
113
  # Creates a new element with the given _name_.
115
114
  def initialize(name)
116
115
  validate_name(name.to_s)
117
116
  @name = name
118
- @params = Array.new
117
+ @params = []
119
118
  end
120
119
 
121
120
  # Adds a formal parameter with _name_ and _signature_
@@ -140,7 +139,7 @@ module DBus
140
139
  # Creates a new method interface element with the given _name_.
141
140
  def initialize(name)
142
141
  super(name)
143
- @rets = Array.new
142
+ @rets = []
144
143
  end
145
144
 
146
145
  # Add a return value _name_ and _signature_.
@@ -172,16 +171,16 @@ module DBus
172
171
 
173
172
  # Return an XML string representation of the method interface elment.
174
173
  def to_xml
175
- xml = %{<method name="#{@name}">\n}
174
+ xml = %(<method name="#{@name}">\n)
176
175
  @params.each do |param|
177
- name = param.name ? %{name="#{param.name}" } : ""
178
- xml += %{<arg #{name}direction="in" type="#{param.type}"/>\n}
176
+ name = param.name ? %(name="#{param.name}" ) : ""
177
+ xml += %(<arg #{name}direction="in" type="#{param.type}"/>\n)
179
178
  end
180
179
  @rets.each do |param|
181
- name = param.name ? %{name="#{param.name}" } : ""
182
- xml += %{<arg #{name}direction="out" type="#{param.type}"/>\n}
180
+ name = param.name ? %(name="#{param.name}" ) : ""
181
+ xml += %(<arg #{name}direction="out" type="#{param.type}"/>\n)
183
182
  end
184
- xml += %{</method>\n}
183
+ xml += %(</method>\n)
185
184
  xml
186
185
  end
187
186
  end # class Method
@@ -206,14 +205,13 @@ module DBus
206
205
 
207
206
  # Return an XML string representation of the signal interface elment.
208
207
  def to_xml
209
- xml = %{<signal name="#{@name}">\n}
208
+ xml = %(<signal name="#{@name}">\n)
210
209
  @params.each do |param|
211
- name = param.name ? %{name="#{param.name}" } : ""
212
- xml += %{<arg #{name}type="#{param.type}"/>\n}
210
+ name = param.name ? %(name="#{param.name}" ) : ""
211
+ xml += %(<arg #{name}type="#{param.type}"/>\n)
213
212
  end
214
- xml += %{</signal>\n}
213
+ xml += %(</signal>\n)
215
214
  xml
216
215
  end
217
216
  end # class Signal
218
217
  end # module DBus
219
-
@@ -8,7 +8,7 @@
8
8
  # License, version 2.1 as published by the Free Software Foundation.
9
9
  # See the file "COPYING" for the exact licensing terms.
10
10
 
11
- require 'logger'
11
+ require "logger"
12
12
 
13
13
  module DBus
14
14
  # Get the logger for the DBus module.
@@ -8,7 +8,7 @@
8
8
  # License, version 2.1 as published by the Free Software Foundation.
9
9
  # See the file "COPYING" for the exact licensing terms.
10
10
 
11
- require 'socket'
11
+ require "socket"
12
12
 
13
13
  # = D-Bus main module
14
14
  #
@@ -23,7 +23,7 @@ module DBus
23
23
  # Class that handles the conversion (unmarshalling) of payload data
24
24
  # to Array.
25
25
  class PacketUnmarshaller
26
- # Index pointer that points to the byte in the data that is
26
+ # Index pointer that points to the byte in the data that is
27
27
  # currently being processed.
28
28
  #
29
29
  # Used to kown what part of the buffer has been consumed by unmarshalling.
@@ -32,7 +32,8 @@ module DBus
32
32
 
33
33
  # Create a new unmarshaller for the given data _buffer_ and _endianness_.
34
34
  def initialize(buffer, endianness)
35
- @buffy, @endianness = buffer.dup, endianness
35
+ @buffy = buffer.dup
36
+ @endianness = endianness
36
37
  if @endianness == BIG_END
37
38
  @uint32 = "N"
38
39
  @uint16 = "n"
@@ -50,13 +51,13 @@ module DBus
50
51
  # Unmarshall the buffer for a given _signature_ and length _len_.
51
52
  # Return an array of unmarshalled objects
52
53
  def unmarshall(signature, len = nil)
53
- if len != nil
54
+ if !len.nil?
54
55
  if @buffy.bytesize < @idx + len
55
56
  raise IncompleteBufferException
56
57
  end
57
58
  end
58
59
  sigtree = Type::Parser.new(signature).parse
59
- ret = Array.new
60
+ ret = []
60
61
  sigtree.each do |elem|
61
62
  ret << do_parse(elem)
62
63
  end
@@ -83,18 +84,18 @@ module DBus
83
84
  private
84
85
 
85
86
  # Retrieve the next _nbytes_ number of bytes from the buffer.
86
- def get(nbytes)
87
+ def read(nbytes)
87
88
  raise IncompleteBufferException if @idx + nbytes > @buffy.bytesize
88
89
  ret = @buffy.slice(@idx, nbytes)
89
90
  @idx += nbytes
90
91
  ret
91
92
  end
92
93
 
93
- # Get the string length and string itself from the buffer.
94
+ # Read the string length and string itself from the buffer.
94
95
  # Return the string.
95
- def get_string
96
+ def read_string
96
97
  align(4)
97
- str_sz = get(4).unpack(@uint32)[0]
98
+ str_sz = read(4).unpack(@uint32)[0]
98
99
  ret = @buffy.slice(@idx, str_sz)
99
100
  raise IncompleteBufferException if @idx + str_sz + 1 > @buffy.bytesize
100
101
  @idx += str_sz
@@ -106,10 +107,10 @@ module DBus
106
107
  ret
107
108
  end
108
109
 
109
- # Get the signature length and signature itself from the buffer.
110
+ # Read the signature length and signature itself from the buffer.
110
111
  # Return the signature.
111
- def get_signature
112
- str_sz = get(1).unpack('C')[0]
112
+ def read_signature
113
+ str_sz = read(1).unpack("C")[0]
113
114
  ret = @buffy.slice(@idx, str_sz)
114
115
  raise IncompleteBufferException if @idx + str_sz + 1 >= @buffy.bytesize
115
116
  @idx += str_sz
@@ -127,94 +128,91 @@ module DBus
127
128
  packet = nil
128
129
  case signature.sigtype
129
130
  when Type::BYTE
130
- packet = get(1).unpack("C")[0]
131
+ packet = read(1).unpack("C")[0]
131
132
  when Type::UINT16
132
133
  align(2)
133
- packet = get(2).unpack(@uint16)[0]
134
+ packet = read(2).unpack(@uint16)[0]
134
135
  when Type::INT16
135
136
  align(4)
136
- packet = get(4).unpack(@uint16)[0]
137
+ packet = read(4).unpack(@uint16)[0]
137
138
  if (packet & 0x8000) != 0
138
139
  packet -= 0x10000
139
140
  end
140
141
  when Type::UINT32, Type::UNIX_FD
141
142
  align(4)
142
- packet = get(4).unpack(@uint32)[0]
143
+ packet = read(4).unpack(@uint32)[0]
143
144
  when Type::INT32
144
145
  align(4)
145
- packet = get(4).unpack(@uint32)[0]
146
+ packet = read(4).unpack(@uint32)[0]
146
147
  if (packet & 0x80000000) != 0
147
148
  packet -= 0x100000000
148
149
  end
149
150
  when Type::UINT64
150
151
  align(8)
151
- packet_l = get(4).unpack(@uint32)[0]
152
- packet_h = get(4).unpack(@uint32)[0]
153
- if @endianness == LIL_END
154
- packet = packet_l + packet_h * 2**32
155
- else
156
- packet = packet_l * 2**32 + packet_h
157
- end
152
+ packet_l = read(4).unpack(@uint32)[0]
153
+ packet_h = read(4).unpack(@uint32)[0]
154
+ packet = if @endianness == LIL_END
155
+ packet_l + packet_h * 2**32
156
+ else
157
+ packet_l * 2**32 + packet_h
158
+ end
158
159
  when Type::INT64
159
160
  align(8)
160
- packet_l = get(4).unpack(@uint32)[0]
161
- packet_h = get(4).unpack(@uint32)[0]
162
- if @endianness == LIL_END
163
- packet = packet_l + packet_h * 2**32
164
- else
165
- packet = packet_l * 2**32 + packet_h
166
- end
161
+ packet_l = read(4).unpack(@uint32)[0]
162
+ packet_h = read(4).unpack(@uint32)[0]
163
+ packet = if @endianness == LIL_END
164
+ packet_l + packet_h * 2**32
165
+ else
166
+ packet_l * 2**32 + packet_h
167
+ end
167
168
  if (packet & 0x8000000000000000) != 0
168
169
  packet -= 0x10000000000000000
169
170
  end
170
171
  when Type::DOUBLE
171
172
  align(8)
172
- packet = get(8).unpack(@double)[0]
173
+ packet = read(8).unpack(@double)[0]
173
174
  when Type::BOOLEAN
174
175
  align(4)
175
- v = get(4).unpack(@uint32)[0]
176
- raise InvalidPacketException if not [0, 1].member?(v)
176
+ v = read(4).unpack(@uint32)[0]
177
+ raise InvalidPacketException if ![0, 1].member?(v)
177
178
  packet = (v == 1)
178
179
  when Type::ARRAY
179
180
  align(4)
180
181
  # checks please
181
- array_sz = get(4).unpack(@uint32)[0]
182
- raise InvalidPacketException if array_sz > 67108864
182
+ array_sz = read(4).unpack(@uint32)[0]
183
+ raise InvalidPacketException if array_sz > 67_108_864
183
184
 
184
185
  align(signature.child.alignment)
185
186
  raise IncompleteBufferException if @idx + array_sz > @buffy.bytesize
186
187
 
187
- packet = Array.new
188
+ packet = []
188
189
  start_idx = @idx
189
190
  while @idx - start_idx < array_sz
190
191
  packet << do_parse(signature.child)
191
192
  end
192
193
 
193
- if signature.child.sigtype == Type::DICT_ENTRY then
194
- packet = packet.inject(Hash.new) do |hash, pair|
195
- hash[pair[0]] = pair[1]
196
- hash
197
- end
194
+ if signature.child.sigtype == Type::DICT_ENTRY
195
+ packet = Hash[packet]
198
196
  end
199
197
  when Type::STRUCT
200
198
  align(8)
201
- packet = Array.new
199
+ packet = []
202
200
  signature.members.each do |elem|
203
201
  packet << do_parse(elem)
204
202
  end
205
203
  when Type::VARIANT
206
- string = get_signature
204
+ string = read_signature
207
205
  # error checking please
208
206
  sig = Type::Parser.new(string).parse[0]
209
207
  align(sig.alignment)
210
208
  packet = do_parse(sig)
211
209
  when Type::OBJECT_PATH
212
- packet = get_string
210
+ packet = read_string
213
211
  when Type::STRING
214
- packet = get_string
215
- packet.force_encoding('UTF-8')
212
+ packet = read_string
213
+ packet.force_encoding("UTF-8")
216
214
  when Type::SIGNATURE
217
- packet = get_signature
215
+ packet = read_signature
218
216
  when Type::DICT_ENTRY
219
217
  align(8)
220
218
  key = do_parse(signature.members[0])
@@ -222,7 +220,7 @@ module DBus
222
220
  packet = [key, value]
223
221
  else
224
222
  raise NotImplementedError,
225
- "sigtype: #{signature.sigtype} (#{signature.sigtype.chr})"
223
+ "sigtype: #{signature.sigtype} (#{signature.sigtype.chr})"
226
224
  end
227
225
  packet
228
226
  end # def do_parse
@@ -241,7 +239,7 @@ module DBus
241
239
  # empty packet.
242
240
  def initialize(offset = 0)
243
241
  @packet = ""
244
- @offset = offset # for correct alignment of nested marshallers
242
+ @offset = offset # for correct alignment of nested marshallers
245
243
  end
246
244
 
247
245
  # Round _n_ up to the specified power of two, _a_
@@ -282,7 +280,7 @@ module DBus
282
280
  contentidx = @packet.bytesize
283
281
  yield
284
282
  sz = @packet.bytesize - contentidx
285
- raise InvalidPacketException if sz > 67108864
283
+ raise InvalidPacketException if sz > 67_108_864
286
284
  @packet[sizeidx...sizeidx + 4] = [sz].pack("L")
287
285
  end
288
286
 
@@ -298,8 +296,8 @@ module DBus
298
296
  def append(type, val)
299
297
  raise TypeException, "Cannot send nil" if val.nil?
300
298
 
301
- type = type.chr if type.kind_of?(Fixnum)
302
- type = Type::Parser.new(type).parse[0] if type.kind_of?(String)
299
+ type = type.chr if type.is_a?(Fixnum)
300
+ type = Type::Parser.new(type).parse[0] if type.is_a?(String)
303
301
  case type.sigtype
304
302
  when Type::BYTE
305
303
  @packet += val.chr
@@ -307,11 +305,11 @@ module DBus
307
305
  align(4)
308
306
  @packet += [val].pack("L")
309
307
  when Type::UINT64
310
- align(8)
311
- @packet += [val].pack("Q")
308
+ align(8)
309
+ @packet += [val].pack("Q")
312
310
  when Type::INT64
313
- align(8)
314
- @packet += [val].pack("q")
311
+ align(8)
312
+ @packet += [val].pack("q")
315
313
  when Type::INT32
316
314
  align(4)
317
315
  @packet += [val].pack("l")
@@ -323,14 +321,14 @@ module DBus
323
321
  @packet += [val].pack("s")
324
322
  when Type::DOUBLE
325
323
  align(8)
326
- @packet += [val].pack("d")
324
+ @packet += [val].pack("d")
327
325
  when Type::BOOLEAN
328
326
  align(4)
329
- if val
330
- @packet += [1].pack("L")
331
- else
332
- @packet += [0].pack("L")
333
- end
327
+ @packet += if val
328
+ [1].pack("L")
329
+ else
330
+ [0].pack("L")
331
+ end
334
332
  when Type::OBJECT_PATH
335
333
  append_string(val)
336
334
  when Type::STRING
@@ -339,7 +337,7 @@ module DBus
339
337
  append_signature(val)
340
338
  when Type::VARIANT
341
339
  vartype = nil
342
- if val.is_a?(Array) and val.size == 2
340
+ if val.is_a?(Array) && val.size == 2
343
341
  if val[0].is_a?(DBus::Type::Type)
344
342
  vartype, vardata = val
345
343
  elsif val[0].is_a?(String)
@@ -363,16 +361,16 @@ module DBus
363
361
  sub.append(vartype, vardata)
364
362
  @packet += sub.packet
365
363
  when Type::ARRAY
366
- if val.kind_of?(Hash)
364
+ if val.is_a?(Hash)
367
365
  raise TypeException, "Expected an Array but got a Hash" if type.child.sigtype != Type::DICT_ENTRY
368
366
  # Damn ruby rocks here
369
367
  val = val.to_a
370
368
  end
371
369
  # If string is recieved and ay is expected, explode the string
372
- if val.kind_of?(String) && type.child.sigtype == Type::BYTE
370
+ if val.is_a?(String) && type.child.sigtype == Type::BYTE
373
371
  val = val.bytes
374
372
  end
375
- if not val.kind_of?(Enumerable)
373
+ if !val.is_a?(Enumerable)
376
374
  raise TypeException, "Expected an Enumerable of #{type.child.inspect} but got a #{val.class}"
377
375
  end
378
376
  array(type.child) do
@@ -381,9 +379,9 @@ module DBus
381
379
  end
382
380
  end
383
381
  when Type::STRUCT, Type::DICT_ENTRY
384
- # TODO use duck typing, val.respond_to?
385
- raise TypeException, "Struct/DE expects an Array" if not val.kind_of?(Array)
386
- if type.sigtype == Type::DICT_ENTRY and val.size != 2
382
+ # TODO: use duck typing, val.respond_to?
383
+ raise TypeException, "Struct/DE expects an Array" if !val.is_a?(Array)
384
+ if type.sigtype == Type::DICT_ENTRY && val.size != 2
387
385
  raise TypeException, "Dict entry expects a pair"
388
386
  end
389
387
  if type.members.size != val.size
@@ -396,7 +394,7 @@ module DBus
396
394
  end
397
395
  else
398
396
  raise NotImplementedError,
399
- "sigtype: #{type.sigtype} (#{type.sigtype.chr})"
397
+ "sigtype: #{type.sigtype} (#{type.sigtype.chr})"
400
398
  end
401
399
  end # def append
402
400
 
@@ -414,10 +412,10 @@ module DBus
414
412
  elsif value.is_a? Symbol
415
413
  ["s", value.to_s]
416
414
  elsif value.is_a? Array
417
- ["av", value.map {|i| make_variant(i) }]
415
+ ["av", value.map { |i| make_variant(i) }]
418
416
  elsif value.is_a? Hash
419
417
  h = {}
420
- value.each_key {|k| h[k] = make_variant(value[k]) }
418
+ value.each_key { |k| h[k] = make_variant(value[k]) }
421
419
  ["a{sv}", h]
422
420
  elsif value.respond_to? :to_str
423
421
  ["s", value.to_str]
@@ -429,6 +427,6 @@ module DBus
429
427
  ["x", i]
430
428
  end
431
429
  end
432
- end
430
+ end
433
431
  end # class PacketMarshaller
434
432
  end # module DBus