ruby-dbus 0.17.0 → 0.18.0.beta1

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 (66) hide show
  1. checksums.yaml +4 -4
  2. data/NEWS.md +15 -0
  3. data/README.md +1 -1
  4. data/Rakefile +3 -11
  5. data/VERSION +1 -1
  6. data/doc/Reference.md +9 -2
  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/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 +12 -7
  21. data/lib/dbus/bus.rb +114 -70
  22. data/lib/dbus/bus_name.rb +12 -8
  23. data/lib/dbus/error.rb +4 -2
  24. data/lib/dbus/introspect.rb +29 -18
  25. data/lib/dbus/logger.rb +3 -1
  26. data/lib/dbus/marshall.rb +118 -86
  27. data/lib/dbus/matchrule.rb +16 -16
  28. data/lib/dbus/message.rb +40 -27
  29. data/lib/dbus/message_queue.rb +10 -5
  30. data/lib/dbus/object.rb +34 -13
  31. data/lib/dbus/object_path.rb +9 -5
  32. data/lib/dbus/proxy_object.rb +18 -4
  33. data/lib/dbus/proxy_object_factory.rb +11 -7
  34. data/lib/dbus/proxy_object_interface.rb +26 -22
  35. data/lib/dbus/type.rb +41 -34
  36. data/lib/dbus/xml.rb +28 -17
  37. data/lib/dbus.rb +7 -7
  38. data/ruby-dbus.gemspec +4 -2
  39. data/spec/async_spec.rb +2 -0
  40. data/spec/binding_spec.rb +2 -0
  41. data/spec/bus_and_xml_backend_spec.rb +2 -0
  42. data/spec/bus_driver_spec.rb +2 -0
  43. data/spec/bus_name_spec.rb +3 -1
  44. data/spec/bus_spec.rb +2 -0
  45. data/spec/byte_array_spec.rb +2 -0
  46. data/spec/client_robustness_spec.rb +4 -2
  47. data/spec/err_msg_spec.rb +2 -0
  48. data/spec/introspect_xml_parser_spec.rb +2 -0
  49. data/spec/introspection_spec.rb +2 -0
  50. data/spec/main_loop_spec.rb +2 -0
  51. data/spec/node_spec.rb +23 -0
  52. data/spec/object_path_spec.rb +2 -0
  53. data/spec/property_spec.rb +11 -2
  54. data/spec/proxy_object_spec.rb +2 -0
  55. data/spec/server_robustness_spec.rb +2 -0
  56. data/spec/server_spec.rb +2 -0
  57. data/spec/service_newapi.rb +19 -4
  58. data/spec/session_bus_spec.rb +3 -1
  59. data/spec/session_bus_spec_manual.rb +2 -0
  60. data/spec/signal_spec.rb +2 -0
  61. data/spec/spec_helper.rb +5 -3
  62. data/spec/thread_safety_spec.rb +2 -0
  63. data/spec/type_spec.rb +2 -0
  64. data/spec/value_spec.rb +16 -1
  65. data/spec/variant_spec.rb +4 -2
  66. metadata +8 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee629ce8a78d7cd23f718103cfd622d2a5fd67c51dab6b2a88e453c512c608f3
4
- data.tar.gz: a8995a9526e3b957d32c503de7ad5ef781e5c464925fec8e2107eda4529aa447
3
+ metadata.gz: 491efa855b01f946194979c90d4bb4c1bb6bc4c33e342cd9d3dd76cbd53111cd
4
+ data.tar.gz: d2c1acaa46d04a7f4799b95722b71f4449c2d39fd87fd993c1c1140dbb5d0732
5
5
  SHA512:
6
- metadata.gz: 531e01c12aed4aeedaa5ce55fec2fee0c3da714211adc768c8990d2ce79509e6b925bc06d4308e9628cff109b9880dbea72878e7aeaf23c8e5fb19ddf8a249e2
7
- data.tar.gz: 6449aa2798ed78d29c430423a92d7c8a921fd4ea244eea11fb8a84ca2eb880a4e6860325dc6a05254dc432b971d4929fc4d3a5057e423939c0574a687e7680f7
6
+ metadata.gz: 340b53e7aa449c84705668db9b753ced7c9d24a3229b1d7bafcc95d29508f1b4418001cc5f2749566b9edb8c2068a8d99565c251054c413252ed68450490208b
7
+ data.tar.gz: 8c6dafbd226ae516dc8aef3ad5f01cabb9850455f3f3866cfe66548b7ece22ac1865272bb17fd9af138e52d69b647e4d8ef824ebd2999605e0de28e688710ff8
data/NEWS.md CHANGED
@@ -2,6 +2,21 @@
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
+
5
20
  ## Ruby D-Bus 0.17.0 - 2022-02-11
6
21
 
7
22
  API:
data/README.md CHANGED
@@ -41,7 +41,7 @@ via [UPower](http://upower.freedesktop.org/docs/UPower.html#UPower:OnBattery)
41
41
 
42
42
  ## Requirements
43
43
 
44
- - Ruby 2.1 or newer.
44
+ - Ruby 2.4 or newer.
45
45
 
46
46
 
47
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
@@ -69,16 +70,7 @@ namespace :doc do
69
70
  end
70
71
 
71
72
  if Object.const_defined? :RuboCop
72
- if RUBY_VERSION.start_with?("2.")
73
- RuboCop::RakeTask.new
74
- else
75
- desc "Run RuboCop (dummy)"
76
- task :rubocop do
77
- warn "The code is not adapted to recent RuboCop yet,\n" \
78
- "and the old one no longer works with Ruby 3.x.\n" \
79
- "Switch back to Ruby 2.x to run it."
80
- end
81
- end
73
+ RuboCop::RakeTask.new
82
74
  else
83
75
  desc "Run RuboCop (dummy)"
84
76
  task :rubocop do
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.17.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
 
@@ -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
 
@@ -1,4 +1,6 @@
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
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 += ")"
@@ -146,11 +149,12 @@ class DBusUI
146
149
  name = view.model.get_iter(path)[0]
147
150
  puts "Clicked on: #{name.inspect}"
148
151
  type = view.model.get_iter(path)[1]
149
- if type == "M"
152
+ case type
153
+ when "M"
150
154
  method = view.model.get_iter(path)[2]
151
155
  intf = view.model.get_iter(path)[3]
152
156
  MethodCallWindow.new(@window, intf, method).run
153
- elsif type == "S"
157
+ when "S"
154
158
  signal = view.model.get_iter(path)[2]
155
159
  intf = view.model.get_iter(path)[3]
156
160
  mr = DBus::MatchRule.new.from_signal(intf, signal)
@@ -205,6 +209,7 @@ class DBusUI
205
209
  end
206
210
 
207
211
  return unless ENABLE_SYSTEM
212
+
208
213
  DBus::SystemBus.instance.proxy.ListNames do |_msg, names|
209
214
  fill_treeview(DBus::SystemBus.instance, @systemtreeview, names)
210
215
  end
@@ -218,6 +223,7 @@ class DBusUI
218
223
  end
219
224
 
220
225
  return if node.object.nil?
226
+
221
227
  node.object.interfaces.sort.each do |ifname|
222
228
  subiter = model.append(iter)
223
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
 
@@ -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
  #
@@ -100,14 +102,15 @@ module DBus
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