ruby-dbus 0.15.0 → 0.18.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +5 -5
  2. data/NEWS.md +41 -1
  3. data/README.md +3 -5
  4. data/Rakefile +18 -8
  5. data/VERSION +1 -1
  6. data/doc/Reference.md +93 -3
  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/service_newapi.rb +1 -1
  14. data/examples/simple/call_introspect.rb +1 -0
  15. data/examples/simple/get_id.rb +2 -1
  16. data/examples/simple/properties.rb +2 -0
  17. data/examples/utils/listnames.rb +1 -0
  18. data/examples/utils/notify.rb +1 -0
  19. data/lib/dbus/api_options.rb +9 -0
  20. data/lib/dbus/auth.rb +20 -15
  21. data/lib/dbus/bus.rb +129 -74
  22. data/lib/dbus/bus_name.rb +31 -0
  23. data/lib/dbus/core_ext/class/attribute.rb +1 -1
  24. data/lib/dbus/error.rb +4 -2
  25. data/lib/dbus/introspect.rb +90 -34
  26. data/lib/dbus/logger.rb +3 -1
  27. data/lib/dbus/marshall.rb +119 -87
  28. data/lib/dbus/matchrule.rb +16 -16
  29. data/lib/dbus/message.rb +40 -27
  30. data/lib/dbus/message_queue.rb +26 -18
  31. data/lib/dbus/object.rb +401 -0
  32. data/lib/dbus/object_path.rb +28 -0
  33. data/lib/dbus/proxy_object.rb +23 -2
  34. data/lib/dbus/proxy_object_factory.rb +11 -7
  35. data/lib/dbus/proxy_object_interface.rb +26 -21
  36. data/lib/dbus/type.rb +59 -34
  37. data/lib/dbus/xml.rb +28 -17
  38. data/lib/dbus.rb +10 -8
  39. data/ruby-dbus.gemspec +8 -4
  40. data/spec/async_spec.rb +2 -0
  41. data/spec/binding_spec.rb +2 -0
  42. data/spec/bus_and_xml_backend_spec.rb +2 -0
  43. data/spec/bus_driver_spec.rb +2 -0
  44. data/spec/bus_name_spec.rb +27 -0
  45. data/spec/bus_spec.rb +2 -0
  46. data/spec/byte_array_spec.rb +2 -0
  47. data/spec/client_robustness_spec.rb +27 -0
  48. data/spec/err_msg_spec.rb +2 -0
  49. data/spec/introspect_xml_parser_spec.rb +2 -0
  50. data/spec/introspection_spec.rb +2 -0
  51. data/spec/main_loop_spec.rb +3 -1
  52. data/spec/node_spec.rb +23 -0
  53. data/spec/object_path_spec.rb +25 -0
  54. data/spec/property_spec.rb +64 -5
  55. data/spec/proxy_object_spec.rb +2 -0
  56. data/spec/server_robustness_spec.rb +2 -0
  57. data/spec/server_spec.rb +2 -0
  58. data/spec/service_newapi.rb +39 -70
  59. data/spec/session_bus_spec.rb +3 -1
  60. data/spec/session_bus_spec_manual.rb +2 -0
  61. data/spec/signal_spec.rb +5 -3
  62. data/spec/spec_helper.rb +23 -9
  63. data/spec/thread_safety_spec.rb +2 -0
  64. data/spec/tools/dbus-limited-session.conf +4 -0
  65. data/spec/type_spec.rb +2 -0
  66. data/spec/value_spec.rb +16 -1
  67. data/spec/variant_spec.rb +4 -2
  68. metadata +32 -12
  69. data/lib/dbus/export.rb +0 -131
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 06e7540fb8468a14731fd8d988828dfe349e687a
4
- data.tar.gz: 86dbf9d6e8c1947bb87ef4f1ef1a4aefa337f1f6
2
+ SHA256:
3
+ metadata.gz: 491efa855b01f946194979c90d4bb4c1bb6bc4c33e342cd9d3dd76cbd53111cd
4
+ data.tar.gz: d2c1acaa46d04a7f4799b95722b71f4449c2d39fd87fd993c1c1140dbb5d0732
5
5
  SHA512:
6
- metadata.gz: 9347931528a1e83c9b4747b232c3f6e9f8da3968efa7f5fe4a473d6333783a0643823973e91efb35f1c7676a6da0ee6a16eade4176842de6fb4e7aa58c6d5304
7
- data.tar.gz: c814265c6472dc3b715a0f99ca5c6ea920d26a08dcde3eff573a889779320dc00292d637f976067ba3f6e5ae86cbccc099e56430adf8109147e910169f59e44a
6
+ metadata.gz: 340b53e7aa449c84705668db9b753ced7c9d24a3229b1d7bafcc95d29508f1b4418001cc5f2749566b9edb8c2068a8d99565c251054c413252ed68450490208b
7
+ data.tar.gz: 8c6dafbd226ae516dc8aef3ad5f01cabb9850455f3f3866cfe66548b7ece22ac1865272bb17fd9af138e52d69b647e4d8ef824ebd2999605e0de28e688710ff8
data/NEWS.md CHANGED
@@ -2,10 +2,50 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## Ruby D-Bus 0.18.0.beta1 - 2022-02-24
6
+
7
+ API:
8
+ * D-Bus structs have been passed as Ruby arrays. Now these arrays are frozen.
9
+ * Ruby structs can be used as D-Bus structs.
10
+
11
+ Bug fixes:
12
+ * Returning the value for o.fd.DBus.Properties.Get, use the specific property
13
+ signature, not the generic Variant ([#97][]).
14
+
15
+ Requirements:
16
+ * Require Ruby 2.4, because of RuboCop 1.0.
17
+
18
+ [#97]: https://github.com/mvidner/ruby-dbus/issues/97
19
+
20
+ ## Ruby D-Bus 0.17.0 - 2022-02-11
21
+
22
+ API:
23
+ * Export properties with `dbus_attr_accessor`, `dbus_reader` etc. ([#86][]).
24
+
25
+ Bug fixes:
26
+ * Depend on rexml which is separate since Ruby 3.0 ([#87][],
27
+ by Toshiaki Asai).
28
+ Nokogiri is faster but bigger so it remains optional.
29
+ * Fix connection in case ~/.dbus-keyrings has multiple cookies, showing
30
+ as "Oops: undefined method `zero?' for nil:NilClass".
31
+ * Add the missing name to the root introspection node.
32
+
33
+ [#86]: https://github.com/mvidner/ruby-dbus/pull/86
34
+ [#87]: https://github.com/mvidner/ruby-dbus/pull/87
35
+
36
+ ## Ruby D-Bus 0.16.0 - 2019-10-15
37
+
38
+ API:
39
+ * An invalid service name or an invalid object path will raise
40
+ instead of being sent to the bus. The bus would then drop the connection,
41
+ producing EOFError here ([#80][]).
42
+
43
+ [#80]: https://github.com/mvidner/ruby-dbus/issues/80
44
+
5
45
  ## Ruby D-Bus 0.15.0 - 2018-04-30
6
46
 
7
47
  API:
8
- * Accessing an unknown interface will raise instead of returning nil ([#74]).
48
+ * Accessing an unknown interface will raise instead of returning nil ([#74][]).
9
49
 
10
50
  Bug fixes:
11
51
  * Fixed a conflict with activesupport 5.2 ([#71])
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.15.0
1
+ 0.18.0.beta1
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
 
@@ -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
@@ -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