ruby-dbus 0.17.0 → 0.18.0.beta3

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 (74) hide show
  1. checksums.yaml +4 -4
  2. data/NEWS.md +38 -0
  3. data/README.md +1 -1
  4. data/Rakefile +3 -11
  5. data/VERSION +1 -1
  6. data/doc/Reference.md +10 -3
  7. data/examples/doc/_extract_examples +2 -0
  8. data/examples/gdbus/gdbus +11 -5
  9. data/examples/no-introspect/nm-test.rb +2 -0
  10. data/examples/no-introspect/tracker-test.rb +3 -1
  11. data/examples/rhythmbox/playpause.rb +2 -1
  12. data/examples/service/call_service.rb +1 -0
  13. data/examples/service/complex-property.rb +21 -0
  14. data/examples/service/service_newapi.rb +1 -1
  15. data/examples/simple/call_introspect.rb +1 -0
  16. data/examples/simple/get_id.rb +2 -1
  17. data/examples/simple/properties.rb +2 -0
  18. data/examples/utils/listnames.rb +1 -0
  19. data/examples/utils/notify.rb +1 -0
  20. data/lib/dbus/api_options.rb +9 -0
  21. data/lib/dbus/auth.rb +12 -7
  22. data/lib/dbus/bus.rb +114 -70
  23. data/lib/dbus/bus_name.rb +12 -8
  24. data/lib/dbus/data.rb +744 -0
  25. data/lib/dbus/error.rb +4 -2
  26. data/lib/dbus/introspect.rb +30 -18
  27. data/lib/dbus/logger.rb +3 -1
  28. data/lib/dbus/marshall.rb +229 -293
  29. data/lib/dbus/matchrule.rb +16 -16
  30. data/lib/dbus/message.rb +44 -37
  31. data/lib/dbus/message_queue.rb +10 -5
  32. data/lib/dbus/object.rb +36 -15
  33. data/lib/dbus/object_path.rb +11 -6
  34. data/lib/dbus/proxy_object.rb +18 -4
  35. data/lib/dbus/proxy_object_factory.rb +11 -7
  36. data/lib/dbus/proxy_object_interface.rb +26 -22
  37. data/lib/dbus/raw_message.rb +91 -0
  38. data/lib/dbus/type.rb +164 -80
  39. data/lib/dbus/xml.rb +28 -17
  40. data/lib/dbus.rb +13 -7
  41. data/ruby-dbus.gemspec +4 -2
  42. data/spec/async_spec.rb +2 -0
  43. data/spec/binding_spec.rb +2 -0
  44. data/spec/bus_and_xml_backend_spec.rb +2 -0
  45. data/spec/bus_driver_spec.rb +2 -0
  46. data/spec/bus_name_spec.rb +3 -1
  47. data/spec/bus_spec.rb +2 -0
  48. data/spec/byte_array_spec.rb +2 -0
  49. data/spec/client_robustness_spec.rb +4 -2
  50. data/spec/data/marshall.yaml +1639 -0
  51. data/spec/data_spec.rb +353 -0
  52. data/spec/err_msg_spec.rb +2 -0
  53. data/spec/introspect_xml_parser_spec.rb +2 -0
  54. data/spec/introspection_spec.rb +2 -0
  55. data/spec/main_loop_spec.rb +2 -0
  56. data/spec/node_spec.rb +23 -0
  57. data/spec/object_path_spec.rb +3 -0
  58. data/spec/packet_marshaller_spec.rb +34 -0
  59. data/spec/packet_unmarshaller_spec.rb +262 -0
  60. data/spec/property_spec.rb +60 -2
  61. data/spec/proxy_object_spec.rb +2 -0
  62. data/spec/server_robustness_spec.rb +2 -0
  63. data/spec/server_spec.rb +2 -0
  64. data/spec/service_newapi.rb +37 -4
  65. data/spec/session_bus_spec.rb +3 -1
  66. data/spec/session_bus_spec_manual.rb +2 -0
  67. data/spec/signal_spec.rb +2 -0
  68. data/spec/spec_helper.rb +19 -3
  69. data/spec/thread_safety_spec.rb +2 -0
  70. data/spec/type_spec.rb +69 -6
  71. data/spec/value_spec.rb +16 -1
  72. data/spec/variant_spec.rb +4 -2
  73. data/spec/zzz_quit_spec.rb +16 -0
  74. metadata +16 -7
data/lib/dbus/error.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # error.rb
2
4
  #
3
5
  # This file is part of the ruby-dbus project
@@ -32,7 +34,7 @@ module DBus
32
34
  end
33
35
  # TODO: validate error name
34
36
  end
35
- end # class Error
37
+ end
36
38
 
37
39
  # @example raise a generic error
38
40
  # raise DBus.error, "message"
@@ -43,4 +45,4 @@ module DBus
43
45
  DBus::Error.new(nil, name)
44
46
  end
45
47
  module_function :error
46
- end # module DBus
48
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # dbus/introspection.rb - module containing a low-level D-Bus introspection implementation
2
4
  #
3
5
  # This file is part of the ruby-dbus project
@@ -10,9 +12,9 @@
10
12
 
11
13
  module DBus
12
14
  # Regular expressions that should match all method names.
13
- METHOD_SIGNAL_RE = /^[A-Za-z][A-Za-z0-9_]*$/
15
+ METHOD_SIGNAL_RE = /^[A-Za-z][A-Za-z0-9_]*$/.freeze
14
16
  # Regular expressions that should match all interface names.
15
- INTERFACE_ELEMENT_RE = /^[A-Za-z][A-Za-z0-9_]*$/
17
+ INTERFACE_ELEMENT_RE = /^[A-Za-z][A-Za-z0-9_]*$/.freeze
16
18
 
17
19
  # Exception raised when an invalid class definition is encountered.
18
20
  class InvalidClassDefinition < Exception
@@ -51,23 +53,25 @@ module DBus
51
53
  raise InvalidIntrospectionData if name =~ /^\./ || name =~ /\.$/
52
54
  raise InvalidIntrospectionData if name =~ /\.\./
53
55
  raise InvalidIntrospectionData if name !~ /\./
56
+
54
57
  name.split(".").each do |element|
55
58
  raise InvalidIntrospectionData if element !~ INTERFACE_ELEMENT_RE
56
59
  end
57
60
  end
58
61
 
59
- # Add _ie_ as a known {Method}, {Signal} or {Property}
60
- # @param ie [InterfaceElement]
61
- def define(ie)
62
- name = ie.name.to_sym
63
- category = if ie.is_a?(Method)
62
+ # Add _ifc_el_ as a known {Method}, {Signal} or {Property}
63
+ # @param ifc_el [InterfaceElement]
64
+ def define(ifc_el)
65
+ name = ifc_el.name.to_sym
66
+ category = case ifc_el
67
+ when Method
64
68
  @methods
65
- elsif ie.is_a?(Signal)
69
+ when Signal
66
70
  @signals
67
- elsif ie.is_a?(Property)
71
+ when Property
68
72
  @properties
69
73
  end
70
- category[name] = ie
74
+ category[name] = ifc_el
71
75
  end
72
76
  alias declare define
73
77
  alias << define
@@ -81,11 +85,13 @@ module DBus
81
85
  define(m)
82
86
  end
83
87
  alias declare_method define_method
84
- end # class Interface
88
+ end
85
89
 
86
90
  # = A formal parameter has a name and a type
87
91
  class FormalParameter
92
+ # @return [#to_s]
88
93
  attr_reader :name
94
+ # @return [SingleCompleteType]
89
95
  attr_reader :type
90
96
 
91
97
  def initialize(name, type)
@@ -107,14 +113,16 @@ module DBus
107
113
  # This is a generic class for entities that are part of the interface
108
114
  # such as methods and signals.
109
115
  class InterfaceElement
110
- # The name of the interface element. Symbol
116
+ # @return [Symbol] The name of the interface element
111
117
  attr_reader :name
112
- # The parameters of the interface element. Array: FormalParameter
118
+
119
+ # @return [Array<FormalParameter>] The parameters of the interface element
113
120
  attr_reader :params
114
121
 
115
122
  # Validates element _name_.
116
123
  def validate_name(name)
117
124
  return if (name =~ METHOD_SIGNAL_RE) && (name.bytesize <= 255)
125
+
118
126
  raise InvalidMethodName, name
119
127
  end
120
128
 
@@ -135,13 +143,13 @@ module DBus
135
143
  def add_param(name_signature_pair)
136
144
  add_fparam(*name_signature_pair)
137
145
  end
138
- end # class InterfaceElement
146
+ end
139
147
 
140
148
  # = D-Bus interface method class
141
149
  #
142
150
  # This is a class representing methods that are part of an interface.
143
151
  class Method < InterfaceElement
144
- # The list of return values for the method. Array: FormalParameter
152
+ # @return [Array<FormalParameter>] The list of return values for the method
145
153
  attr_reader :rets
146
154
 
147
155
  # Creates a new method interface element with the given _name_.
@@ -151,6 +159,8 @@ module DBus
151
159
  end
152
160
 
153
161
  # Add a return value _name_ and _signature_.
162
+ # @param name [#to_s]
163
+ # @param signature [SingleCompleteType]
154
164
  def add_return(name, signature)
155
165
  @rets << FormalParameter.new(name, signature)
156
166
  end
@@ -161,6 +171,7 @@ module DBus
161
171
  prototype.split(/, */).each do |arg|
162
172
  arg = arg.split(" ")
163
173
  raise InvalidClassDefinition if arg.size != 2
174
+
164
175
  dir, arg = arg
165
176
  if arg =~ /:/
166
177
  arg = arg.split(":")
@@ -192,7 +203,7 @@ module DBus
192
203
  xml += " </method>\n"
193
204
  xml
194
205
  end
195
- end # class Method
206
+ end
196
207
 
197
208
  # = D-Bus interface signal class
198
209
  #
@@ -222,13 +233,14 @@ module DBus
222
233
  xml += " </signal>\n"
223
234
  xml
224
235
  end
225
- end # class Signal
236
+ end
226
237
 
227
238
  # An (exported) property
228
239
  # https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties
229
240
  class Property
230
241
  # @return [String] The name of the property, for example FooBar.
231
242
  attr_reader :name
243
+ # @return [SingleCompleteType]
232
244
  attr_reader :type
233
245
  # @return [Symbol] :read :write or :readwrite
234
246
  attr_reader :access
@@ -259,4 +271,4 @@ module DBus
259
271
  " <property type=\"#{@type}\" name=\"#{@name}\" access=\"#{@access}\"/>\n"
260
272
  end
261
273
  end
262
- end # module DBus
274
+ end
data/lib/dbus/logger.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # dbus/logger.rb - debug logging
2
4
  #
3
5
  # This file is part of the ruby-dbus project
@@ -16,7 +18,7 @@ module DBus
16
18
  # with DEBUG if $DEBUG is set, otherwise INFO.
17
19
  def logger
18
20
  unless defined? @logger
19
- @logger = Logger.new(STDERR)
21
+ @logger = Logger.new($stderr)
20
22
  @logger.level = $DEBUG ? Logger::DEBUG : Logger::INFO
21
23
  end
22
24
  @logger