ruby-dbus 0.16.0 → 0.18.0.beta2

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 (75) hide show
  1. checksums.yaml +4 -4
  2. data/NEWS.md +46 -0
  3. data/README.md +3 -5
  4. data/Rakefile +18 -8
  5. data/VERSION +1 -1
  6. data/doc/Reference.md +94 -4
  7. data/examples/doc/_extract_examples +7 -0
  8. data/examples/gdbus/gdbus +31 -24
  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 +2 -1
  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 +20 -15
  22. data/lib/dbus/bus.rb +126 -74
  23. data/lib/dbus/bus_name.rb +12 -8
  24. data/lib/dbus/core_ext/class/attribute.rb +1 -1
  25. data/lib/dbus/data.rb +725 -0
  26. data/lib/dbus/error.rb +4 -2
  27. data/lib/dbus/introspect.rb +91 -30
  28. data/lib/dbus/logger.rb +3 -1
  29. data/lib/dbus/marshall.rb +228 -294
  30. data/lib/dbus/matchrule.rb +16 -16
  31. data/lib/dbus/message.rb +44 -37
  32. data/lib/dbus/message_queue.rb +16 -10
  33. data/lib/dbus/object.rb +296 -24
  34. data/lib/dbus/object_path.rb +11 -6
  35. data/lib/dbus/proxy_object.rb +22 -1
  36. data/lib/dbus/proxy_object_factory.rb +11 -7
  37. data/lib/dbus/proxy_object_interface.rb +26 -21
  38. data/lib/dbus/raw_message.rb +91 -0
  39. data/lib/dbus/type.rb +182 -80
  40. data/lib/dbus/xml.rb +28 -17
  41. data/lib/dbus.rb +13 -7
  42. data/ruby-dbus.gemspec +7 -3
  43. data/spec/async_spec.rb +2 -0
  44. data/spec/binding_spec.rb +2 -0
  45. data/spec/bus_and_xml_backend_spec.rb +2 -0
  46. data/spec/bus_driver_spec.rb +2 -0
  47. data/spec/bus_name_spec.rb +3 -1
  48. data/spec/bus_spec.rb +2 -0
  49. data/spec/byte_array_spec.rb +2 -0
  50. data/spec/client_robustness_spec.rb +4 -2
  51. data/spec/data/marshall.yaml +1639 -0
  52. data/spec/data_spec.rb +298 -0
  53. data/spec/err_msg_spec.rb +2 -0
  54. data/spec/introspect_xml_parser_spec.rb +2 -0
  55. data/spec/introspection_spec.rb +2 -0
  56. data/spec/main_loop_spec.rb +3 -1
  57. data/spec/node_spec.rb +23 -0
  58. data/spec/object_path_spec.rb +3 -0
  59. data/spec/packet_marshaller_spec.rb +34 -0
  60. data/spec/packet_unmarshaller_spec.rb +262 -0
  61. data/spec/property_spec.rb +88 -5
  62. data/spec/proxy_object_spec.rb +2 -0
  63. data/spec/server_robustness_spec.rb +2 -0
  64. data/spec/server_spec.rb +2 -0
  65. data/spec/service_newapi.rb +39 -70
  66. data/spec/session_bus_spec.rb +3 -1
  67. data/spec/session_bus_spec_manual.rb +2 -0
  68. data/spec/signal_spec.rb +5 -3
  69. data/spec/spec_helper.rb +35 -9
  70. data/spec/thread_safety_spec.rb +2 -0
  71. data/spec/tools/dbus-limited-session.conf +4 -0
  72. data/spec/type_spec.rb +69 -6
  73. data/spec/value_spec.rb +16 -1
  74. data/spec/variant_spec.rb +4 -2
  75. metadata +32 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8a530c6d561a17c6179bda15319036a806f1a42b427033e96caccfc738ebf7b
4
- data.tar.gz: 959143cab388b528354cc569c698a8c99dc79bbca1b21dbdcc064e212b8794a2
3
+ metadata.gz: 0c89eebb575c67de57670fdc2e8b70b4c08dcaf7fc3c1bad858f1d23869571c1
4
+ data.tar.gz: 4a4793ed412ebd25a636bed4dafa5367800658eb5d52d853ef1b2c0df0e3e272
5
5
  SHA512:
6
- metadata.gz: 41d4ff1294958f67efac62ae0d1b326728617976ea944f3c3374f7156bf33632e9e072260f002c11ca44b099113d75e5ecc58f67c3d2c9d34666f6abe92bdbb3
7
- data.tar.gz: c93e54662d3cf01a9b0ac0a2e5c70d0efc78da1758349cfe6209cba37fa707b7334503518a7e0b4f53d754aff22d5ff53c2d7f8c2d8c32e6df9b097a1bf0f34b
6
+ metadata.gz: c03aa469aebb197943266b9147fba6b55383a22248e0814b0c2f7799c2e95d43b555f80a919c236a437c90805cbd7647498c1f8b1cf901d4a298da0b2d81e50c
7
+ data.tar.gz: f7906b8c2308909cb8974240f3d8de3bc3e10a481fc15c91acd7af5526f405fd314df8b1a424683009a64dfc52ebfa9fa2c73497f8215cb403d80ab02866d56a
data/NEWS.md CHANGED
@@ -2,6 +2,52 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## Ruby D-Bus 0.18.0.beta2 - 2022-04-04
6
+
7
+ API:
8
+ * Renamed the DBus::Type::Type class to DBus::Type
9
+ (which was previously a module).
10
+ * Introduced DBus::Data classes, use them in Properties.Get,
11
+ Properties.GetAll to return correct types as declared (still [#97][]).
12
+
13
+ Bug fixes:
14
+ * Signature validation: Ensure DBus.type produces a valid Type
15
+ * Detect more malformed messages: non-NUL padding bytes, variants with
16
+ multiple or no value.
17
+ * Added thorough tests (`spec/data/marshall.yaml`) to detect nearly all
18
+ invalid data at unmarshalling time.
19
+
20
+ ## Ruby D-Bus 0.18.0.beta1 - 2022-02-24
21
+
22
+ API:
23
+ * D-Bus structs have been passed as Ruby arrays. Now these arrays are frozen.
24
+ * Ruby structs can be used as D-Bus structs.
25
+
26
+ Bug fixes:
27
+ * Returning the value for o.fd.DBus.Properties.Get, use the specific property
28
+ signature, not the generic Variant ([#97][]).
29
+
30
+ Requirements:
31
+ * Require Ruby 2.4, because of RuboCop 1.0.
32
+
33
+ [#97]: https://github.com/mvidner/ruby-dbus/issues/97
34
+
35
+ ## Ruby D-Bus 0.17.0 - 2022-02-11
36
+
37
+ API:
38
+ * Export properties with `dbus_attr_accessor`, `dbus_reader` etc. ([#86][]).
39
+
40
+ Bug fixes:
41
+ * Depend on rexml which is separate since Ruby 3.0 ([#87][],
42
+ by Toshiaki Asai).
43
+ Nokogiri is faster but bigger so it remains optional.
44
+ * Fix connection in case ~/.dbus-keyrings has multiple cookies, showing
45
+ as "Oops: undefined method `zero?' for nil:NilClass".
46
+ * Add the missing name to the root introspection node.
47
+
48
+ [#86]: https://github.com/mvidner/ruby-dbus/pull/86
49
+ [#87]: https://github.com/mvidner/ruby-dbus/pull/87
50
+
5
51
  ## Ruby D-Bus 0.16.0 - 2019-10-15
6
52
 
7
53
  API:
data/README.md CHANGED
@@ -11,14 +11,13 @@ Ruby D-Bus is a pure Ruby library for writing clients and services for D-Bus.
11
11
  [![Coverage Status][CS img]][Coverage Status]
12
12
 
13
13
  [Gem Version]: https://rubygems.org/gems/ruby-dbus
14
- [Build Status]: https://travis-ci.org/mvidner/ruby-dbus
15
- [travis pull requests]: https://travis-ci.org/mvidner/ruby-dbus/pull_requests
14
+ [Build Status]: https://github.com/mvidner/ruby-dbus/actions?query=branch%3Amaster
16
15
  [Dependency Status]: https://gemnasium.com/mvidner/ruby-dbus
17
16
  [Code Climate]: https://codeclimate.com/github/mvidner/ruby-dbus
18
17
  [Coverage Status]: https://coveralls.io/r/mvidner/ruby-dbus
19
18
 
20
19
  [GV img]: https://badge.fury.io/rb/ruby-dbus.png
21
- [BS img]: https://travis-ci.org/mvidner/ruby-dbus.png?branch=master
20
+ [BS img]: https://github.com/mvidner/ruby-dbus/workflows/CI/badge.svg?branch=master
22
21
  [DS img]: https://gemnasium.com/mvidner/ruby-dbus.png
23
22
  [CC img]: https://codeclimate.com/github/mvidner/ruby-dbus.png
24
23
  [CS img]: https://coveralls.io/repos/mvidner/ruby-dbus/badge.png?branch=master
@@ -32,7 +31,6 @@ via [UPower](http://upower.freedesktop.org/docs/UPower.html#UPower:OnBattery)
32
31
  sysbus = DBus.system_bus
33
32
  upower_service = sysbus["org.freedesktop.UPower"]
34
33
  upower_object = upower_service["/org/freedesktop/UPower"]
35
- upower_object.introspect
36
34
  upower_interface = upower_object["org.freedesktop.UPower"]
37
35
  on_battery = upower_interface["OnBattery"]
38
36
  if on_battery
@@ -43,7 +41,7 @@ via [UPower](http://upower.freedesktop.org/docs/UPower.html#UPower:OnBattery)
43
41
 
44
42
  ## Requirements
45
43
 
46
- - Ruby 2.0 or newer.
44
+ - Ruby 2.4 or newer.
47
45
 
48
46
 
49
47
  ## Installation
data/Rakefile CHANGED
@@ -1,7 +1,8 @@
1
1
  #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  require "rake"
3
5
  require "fileutils"
4
- include FileUtils
5
6
  require "tmpdir"
6
7
  require "rspec/core/rake_task"
7
8
  begin
@@ -9,6 +10,12 @@ begin
9
10
  rescue LoadError
10
11
  nil
11
12
  end
13
+ begin
14
+ require "yard"
15
+ rescue LoadError
16
+ nil
17
+ end
18
+
12
19
  require "packaging"
13
20
 
14
21
  Packaging.configuration do |conf|
@@ -38,12 +45,6 @@ RSpec::Core::RakeTask.new("bare:spec")
38
45
  end
39
46
  end
40
47
 
41
- if ENV["TRAVIS"]
42
- require "coveralls/rake/task"
43
- Coveralls::RakeTask.new
44
- task default: "coveralls:push"
45
- end
46
-
47
48
  # remove tarball implementation and create gem for this gemfile
48
49
  Rake::Task[:tarball].clear
49
50
 
@@ -68,4 +69,13 @@ namespace :doc do
68
69
  end
69
70
  end
70
71
 
71
- RuboCop::RakeTask.new if Object.const_defined? :RuboCop
72
+ if Object.const_defined? :RuboCop
73
+ RuboCop::RakeTask.new
74
+ else
75
+ desc "Run RuboCop (dummy)"
76
+ task :rubocop do
77
+ warn "RuboCop not installed"
78
+ end
79
+ end
80
+
81
+ YARD::Rake::YardocTask.new if Object.const_defined? :YARD
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.16.0
1
+ 0.18.0.beta2
data/doc/Reference.md CHANGED
@@ -153,7 +153,7 @@ To receive signals for a specific object and interface, use
153
153
 
154
154
  D-Bus booleans, numbers, strings, arrays and dictionaries become their straightforward Ruby counterparts.
155
155
 
156
- Structs become arrays.
156
+ Structs become frozen arrays.
157
157
 
158
158
  Object paths become strings.
159
159
 
@@ -171,7 +171,7 @@ by the D-Bus signature.
171
171
  If the signature expects a Variant
172
172
  (which is the case for all Properties!) then an explicit mechanism is needed.
173
173
 
174
- 1. A pair [{DBus::Type::Type}, value] specifies to marshall *value* as
174
+ 1. A pair [{DBus::Type}, value] specifies to marshall *value* as
175
175
  that specified type.
176
176
  The pair can be produced by {DBus.variant}(signature, value) which
177
177
  gives the same result as [{DBus.type}(signature), value].
@@ -179,7 +179,7 @@ If the signature expects a Variant
179
179
  ISSUE: using something else than cryptic signatures is even more painful
180
180
  than remembering the signatures!
181
181
 
182
- foo_i["Bar"] = DBus.variant("au", [0, 1, 1, 2, 3, 5, 8])
182
+ `foo_i["Bar"] = DBus.variant("au", [0, 1, 1, 2, 3, 5, 8])`
183
183
 
184
184
  2. Other values are tried to fit one of these:
185
185
  Boolean, Double, Array of Variants, Hash of String keyed Variants,
@@ -190,11 +190,18 @@ If the signature expects a Variant
190
190
  type. This will hit you when you rely on method (2) but happen to have
191
191
  a particular string value in an array.
192
192
 
193
+ ##### Structs
194
+
195
+ If a **STRUCT** `(...)` is expected you may pass
196
+
197
+ - an [Array](https://ruby-doc.org/core/Array.html) (frozen is fine)
198
+ - a [Struct](https://ruby-doc.org/core/Struct.html)
199
+
193
200
  ##### Byte Arrays
194
201
 
195
202
  If a byte array (`ay`) is expected you can pass a String too.
196
203
  The bytes sent are according to the string's
197
- [encoding](http://ruby-doc.org/core-2.0.0/Encoding.html).
204
+ [encoding](http://ruby-doc.org/core/Encoding.html).
198
205
 
199
206
  ##### nil
200
207
 
@@ -244,14 +251,97 @@ When you want to provide a DBus API.
244
251
  (check that client and service side have their counterparts)
245
252
 
246
253
  ### Basic
254
+
247
255
  #### Exporting a Method
256
+
248
257
  ##### Interfaces
258
+
249
259
  ##### Methods
260
+
250
261
  ##### Bus Names
262
+
251
263
  ##### Errors
264
+
252
265
  #### Exporting Properties
266
+
267
+ Similar to plain Ruby attributes, declared with
268
+
269
+ - {https://docs.ruby-lang.org/en/3.1/Module.html#method-i-attr_accessor attr_accessor}
270
+ - {https://docs.ruby-lang.org/en/3.1/Module.html#method-i-attr_reader attr_reader}
271
+ - {https://docs.ruby-lang.org/en/3.1/Module.html#method-i-attr_writer attr_writer}
272
+
273
+ These methods declare the attributes and export them as properties:
274
+
275
+ - {DBus::Object.dbus_attr_accessor}
276
+ - {DBus::Object.dbus_attr_reader}
277
+ - {DBus::Object.dbus_attr_writer}
278
+
279
+ For making properties out of Ruby methods (which are not attributes), use:
280
+
281
+ - {DBus::Object.dbus_accessor}
282
+ - {DBus::Object.dbus_reader}
283
+ - {DBus::Object.dbus_writer}
284
+
285
+ Note that the properties are declared in the Ruby naming convention with
286
+ `snake_case` and D-Bus sees them `CamelCased`. Use the `dbus_name` argument
287
+ for overriding this.
288
+
289
+  
290
+
291
+ class Note < DBus::Object
292
+ dbus_interface "net.vidner.Example.Properties" do
293
+ # A read-write property "Title",
294
+ # with `title` and `title=` accessing @title.
295
+ dbus_attr_accessor :title, DBus::Type::STRING
296
+
297
+ # A read-only property "Author"
298
+ # (type specified via DBus signature)
299
+ # with `author` reading `@author`
300
+ dbus_attr_reader :author, "s"
301
+
302
+ # A read-only property `Clock`
303
+ def clock
304
+ Time.now.to_s
305
+ end
306
+ dbus_reader :clock, "s"
307
+
308
+ # Name mapping: `CreationTime`
309
+ def creation_time
310
+ "1993-01-01 00:00:00 +0100"
311
+ end
312
+ dbus_reader :creation_time, "s"
313
+
314
+ dbus_attr_accessor :book_volume, DBus::Type::VARIANT, dbus_name: "Volume"
315
+ end
316
+
317
+ dbus_interface "net.vidner.Example.Audio" do
318
+ dbus_attr_accessor :speaker_volume, DBus::Type::BYTE, dbus_name: "Volume"
319
+ end
320
+
321
+ # Must assign values because `nil` would crash our connection
322
+ def initialize(opath)
323
+ super
324
+ @title = "Ahem"
325
+ @author = "Martin"
326
+ @book_volume = 1
327
+ @speaker_volume = 11
328
+ end
329
+ end
330
+
331
+ obj = Note.new("/net/vidner/Example/Properties")
332
+
333
+ bus = DBus::SessionBus.instance
334
+ service = bus.request_service("net.vidner.Example")
335
+ service.export(obj)
336
+
337
+ main = DBus::Main.new
338
+ main << bus
339
+ main.run
340
+
253
341
  ### Advanced
342
+
254
343
  #### Inheritance
344
+
255
345
  #### Names
256
346
 
257
347
  Specification Conformance
@@ -1,9 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  if ARGV[0].nil?
3
5
  puts "Usage: #{$PROGRAM_NAME} file.md"
4
6
  exit
5
7
  end
6
8
 
9
+ base_url = "https://github.com/mvidner/ruby-dbus/blob/master/"
10
+ base_url += ARGV[0].gsub("../", "")
11
+
7
12
  File.open(ARGV[0]) do |f|
8
13
  title = nil
9
14
  setup = ""
@@ -20,7 +25,9 @@ File.open(ARGV[0]) do |f|
20
25
  setup = example
21
26
  else
22
27
  File.open("#{basename}.rb", "w") do |e|
28
+ anchor = title.downcase.gsub(/ +/, "-")
23
29
  e.write setup
30
+ e.write "# #{base_url}##{anchor}\n"
24
31
  e.write example
25
32
  e.chmod(0o755)
26
33
  end
data/examples/gdbus/gdbus CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
5
  # This is a quite complex example using internal lower level API.
4
6
  # Not a good starting point, but might be usefull if you want to do tricky
@@ -103,11 +105,12 @@ class DBusUI
103
105
 
104
106
  def beautify_method(meth)
105
107
  # Damn, this need to be rewritten :p
106
- s = meth.name + "("
107
- if meth.is_a?(DBus::Method)
108
+ s = "#{meth.name}("
109
+ case meth
110
+ when DBus::Method
108
111
  s += (meth.params.collect { |a| "in #{a[0]}:#{a[1]}" } +
109
112
  meth.rets.collect { |a| "out #{a[0]}:#{a[1]}" }).join(", ")
110
- elsif meth.is_a?(DBus::Signal)
113
+ when DBus::Signal
111
114
  s += (meth.params.collect { |a| "in #{a[0]}:#{a[1]}" }).join(", ")
112
115
  end
113
116
  s += ")"
@@ -119,25 +122,26 @@ class DBusUI
119
122
  model = Gtk::ListStore.new(String, String, DBus::Method,
120
123
  DBus::ProxyObjectInterface)
121
124
  @methsigtreeview.model = model
122
- if selected
123
- if (intf = selected[1])
124
- intf.methods.keys.sort.each do |mi|
125
- m = intf.methods[mi]
126
- subiter = model.append
127
- subiter[0] = beautify_method(m)
128
- subiter[1] = "M"
129
- subiter[2] = m
130
- subiter[3] = intf
131
- end
132
- intf.signals.keys.sort.each do |mi|
133
- m = intf.signals[mi]
134
- subiter = model.append
135
- subiter[0] = beautify_method(m)
136
- subiter[1] = "S"
137
- subiter[2] = m
138
- subiter[3] = intf
139
- end
140
- end
125
+ return unless selected
126
+
127
+ intf = selected[1]
128
+ return unless intf
129
+
130
+ intf.methods.keys.sort.each do |mi|
131
+ m = intf.methods[mi]
132
+ subiter = model.append
133
+ subiter[0] = beautify_method(m)
134
+ subiter[1] = "M"
135
+ subiter[2] = m
136
+ subiter[3] = intf
137
+ end
138
+ intf.signals.keys.sort.each do |mi|
139
+ m = intf.signals[mi]
140
+ subiter = model.append
141
+ subiter[0] = beautify_method(m)
142
+ subiter[1] = "S"
143
+ subiter[2] = m
144
+ subiter[3] = intf
141
145
  end
142
146
  end
143
147
 
@@ -145,11 +149,12 @@ class DBusUI
145
149
  name = view.model.get_iter(path)[0]
146
150
  puts "Clicked on: #{name.inspect}"
147
151
  type = view.model.get_iter(path)[1]
148
- if type == "M"
152
+ case type
153
+ when "M"
149
154
  method = view.model.get_iter(path)[2]
150
155
  intf = view.model.get_iter(path)[3]
151
156
  MethodCallWindow.new(@window, intf, method).run
152
- elsif type == "S"
157
+ when "S"
153
158
  signal = view.model.get_iter(path)[2]
154
159
  intf = view.model.get_iter(path)[3]
155
160
  mr = DBus::MatchRule.new.from_signal(intf, signal)
@@ -204,6 +209,7 @@ class DBusUI
204
209
  end
205
210
 
206
211
  return unless ENABLE_SYSTEM
212
+
207
213
  DBus::SystemBus.instance.proxy.ListNames do |_msg, names|
208
214
  fill_treeview(DBus::SystemBus.instance, @systemtreeview, names)
209
215
  end
@@ -217,6 +223,7 @@ class DBusUI
217
223
  end
218
224
 
219
225
  return if node.object.nil?
226
+
220
227
  node.object.interfaces.sort.each do |ifname|
221
228
  subiter = model.append(iter)
222
229
  subiter[0] = ifname
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
5
  # Trivial network interface lister using NetworkManager.
4
6
  # NetworkManager does not support introspection, so the api is not that sexy.
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
5
  # Trivial network interface lister using NetworkManager.
4
6
  # NetworkManager does not support introspection, so the api is not that sexy.
@@ -11,4 +13,4 @@ tracker_service = bus.service("org.freedesktop.Tracker")
11
13
  tracker_manager = tracker_service.object("/org/freedesktop/tracker")
12
14
  poi = DBus::ProxyObjectInterface.new(tracker_manager, "org.freedesktop.Tracker.Files")
13
15
  poi.define_method("GetMetadataForFilesInFolder", "in live_query_id:i, in uri:s, in fields:as, out values:aas")
14
- p poi.GetMetadataForFilesInFolder(-1, ENV["HOME"] + "/Desktop", ["File:Name", "File:Size"])
16
+ p poi.GetMetadataForFilesInFolder(-1, "#{ENV["HOME"]}/Desktop", ["File:Name", "File:Size"])
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "dbus"
4
5
  bus = DBus::SessionBus.instance
@@ -13,7 +14,7 @@ mr.type = "signal"
13
14
  mr.interface = "org.gnome.Rhythmbox.Player"
14
15
  mr.path = "/org/gnome/Rhythmbox/Player"
15
16
  bus.add_match(mr) do |msg, first_param|
16
- print msg.member + " "
17
+ print "#{msg.member} "
17
18
  puts first_param
18
19
  end
19
20
 
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "dbus"
4
5
 
@@ -14,7 +15,7 @@ player.test_variant(["s", "coucou"])
14
15
  player.on_signal("SomethingJustHappened") do |u, v|
15
16
  puts "SomethingJustHappened: #{u} #{v}"
16
17
  end
17
- player.hello("8=======D", "(_._)")
18
+ player.hello("Hey", "there!")
18
19
  p player["org.ruby.AnotherInterface"].Reverse("Hello world!")
19
20
 
20
21
  main = DBus::Main.new
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "dbus"
5
+
6
+ # Complex property
7
+ class Test < DBus::Object
8
+ dbus_interface "net.vidner.Scratch" do
9
+ dbus_attr_reader :progress, "(stttt)"
10
+ end
11
+
12
+ def initialize(opath)
13
+ @progress = ["working", 1, 0, 100, 42].freeze
14
+ super(opath)
15
+ end
16
+ end
17
+
18
+ bus = DBus::SessionBus.instance
19
+ svc = bus.request_service("net.vidner.Scratch")
20
+ svc.export(Test.new("/net/vidner/Scratch"))
21
+ DBus::Main.new.tap { |m| m << bus }.run
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "dbus"
4
- require "thread"
5
5
  Thread.abort_on_exception = true
6
6
 
7
7
  class Test < DBus::Object
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "dbus"
4
5
 
@@ -1,7 +1,8 @@
1
1
  #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  # find the library without external help
4
- $LOAD_PATH.unshift File.expand_path("../../../lib", __FILE__)
5
+ $LOAD_PATH.unshift File.expand_path("../../lib", __dir__)
5
6
 
6
7
  require "dbus"
7
8
 
@@ -1,4 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  require "dbus"
3
5
 
4
6
  bus = DBus::SystemBus.instance
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "dbus"
4
5
 
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "dbus"
4
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is part of the ruby-dbus project
2
4
  # Copyright (C) 2016 Martin Vidner
3
5
  #
@@ -9,6 +11,13 @@
9
11
  module DBus
10
12
  class ApiOptions
11
13
  # https://github.com/mvidner/ruby-dbus/issues/30
14
+ # @return [Boolean]
15
+ # - true: a proxy (client-side) method will return an array
16
+ # even for the most common case where the method is declared
17
+ # to have only one 'out parameter'
18
+ # - false: a proxy (client-side) method will return
19
+ # - one value for the only 'out parameter'
20
+ # - an array with more 'out parameters'
12
21
  attr_accessor :proxy_method_returns_array
13
22
 
14
23
  A0 = ApiOptions.new
data/lib/dbus/auth.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is part of the ruby-dbus project
2
4
  # Copyright (C) 2007 Arnaud Cornet and Paul van Tilburg
3
5
  #
@@ -73,7 +75,7 @@ module DBus
73
75
  path = File.join(ENV["HOME"], ".dbus-keyrings", context)
74
76
  DBus.logger.debug "path: #{path.inspect}"
75
77
  File.foreach(path) do |line|
76
- if line.index(id).zero?
78
+ if line.start_with?(id)
77
79
  # Right line of file, read cookie
78
80
  cookie = line.split(" ")[2].chomp
79
81
  DBus.logger.debug "cookie: #{cookie.inspect}"
@@ -87,27 +89,28 @@ module DBus
87
89
  return response
88
90
  end
89
91
  end
92
+ return if @retries <= 0
93
+
90
94
  # a little rescue magic
91
- unless @retries <= 0
92
- puts "ERROR: Could not auth, will now exit."
93
- puts "ERROR: Unable to locate cookie, retry in 1 second."
94
- @retries -= 1
95
- sleep 1
96
- data(hexdata)
97
- end
95
+ puts "ERROR: Could not auth, will now exit."
96
+ puts "ERROR: Unable to locate cookie, retry in 1 second."
97
+ @retries -= 1
98
+ sleep 1
99
+ data(hexdata)
98
100
  end
99
101
 
100
102
  # encode plain to hex
101
103
  def hex_encode(plain)
102
104
  return nil if plain.nil?
103
- plain.to_s.unpack("H*")[0]
105
+
106
+ plain.to_s.unpack1("H*")
104
107
  end
105
108
 
106
109
  # decode hex to plain
107
110
  def hex_decode(encoded)
108
111
  encoded.scan(/[[:xdigit:]]{2}/).map { |h| h.hex.chr }.join
109
112
  end
110
- end # DBusCookieSHA1 class ends here
113
+ end
111
114
 
112
115
  # Note: this following stuff is tested with External authenticator only!
113
116
 
@@ -148,12 +151,13 @@ module DBus
148
151
  # server.
149
152
  def send(meth, *args)
150
153
  o = ([meth] + args).join(" ")
151
- @socket.write(o + "\r\n")
154
+ @socket.write("#{o}\r\n")
152
155
  end
153
156
 
154
157
  # Try authentication using the next authenticator.
155
158
  def next_authenticator
156
159
  raise AuthenticationFailed if @auth_list.empty?
160
+
157
161
  @authenticator = @auth_list.shift.new
158
162
  auth_msg = ["AUTH", @authenticator.name, @authenticator.authenticate]
159
163
  DBus.logger.debug "auth_msg: #{auth_msg.inspect}"
@@ -169,9 +173,10 @@ module DBus
169
173
  data = ""
170
174
  crlf = "\r\n"
171
175
  left = 1024 # 1024 byte, no idea if it's ever getting bigger
172
- while left > 0
176
+ while left.positive?
173
177
  buf = @socket.read(left > 1 ? 1 : left)
174
178
  break if buf.nil?
179
+
175
180
  left -= buf.bytesize
176
181
  data += buf
177
182
  break if data.include? crlf # crlf means line finished, the TCP socket keeps on listening, so we break
@@ -262,6 +267,6 @@ module DBus
262
267
  end
263
268
  end
264
269
  true
265
- end # def next_state
266
- end # class Client
267
- end # module D-Bus
270
+ end
271
+ end
272
+ end