ruby-dbus 0.16.0 → 0.18.1

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 (79) hide show
  1. checksums.yaml +4 -4
  2. data/NEWS.md +160 -0
  3. data/README.md +3 -5
  4. data/Rakefile +18 -8
  5. data/VERSION +1 -1
  6. data/doc/Reference.md +106 -7
  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 +123 -75
  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 +821 -0
  26. data/lib/dbus/emits_changed_signal.rb +83 -0
  27. data/lib/dbus/error.rb +4 -2
  28. data/lib/dbus/introspect.rb +132 -31
  29. data/lib/dbus/logger.rb +3 -1
  30. data/lib/dbus/marshall.rb +247 -296
  31. data/lib/dbus/matchrule.rb +16 -16
  32. data/lib/dbus/message.rb +44 -37
  33. data/lib/dbus/message_queue.rb +16 -10
  34. data/lib/dbus/object.rb +358 -24
  35. data/lib/dbus/object_path.rb +11 -6
  36. data/lib/dbus/proxy_object.rb +22 -1
  37. data/lib/dbus/proxy_object_factory.rb +13 -7
  38. data/lib/dbus/proxy_object_interface.rb +63 -30
  39. data/lib/dbus/raw_message.rb +91 -0
  40. data/lib/dbus/type.rb +318 -86
  41. data/lib/dbus/xml.rb +32 -17
  42. data/lib/dbus.rb +14 -7
  43. data/ruby-dbus.gemspec +7 -3
  44. data/spec/async_spec.rb +2 -0
  45. data/spec/binding_spec.rb +2 -0
  46. data/spec/bus_and_xml_backend_spec.rb +2 -0
  47. data/spec/bus_driver_spec.rb +2 -0
  48. data/spec/bus_name_spec.rb +3 -1
  49. data/spec/bus_spec.rb +2 -0
  50. data/spec/byte_array_spec.rb +2 -0
  51. data/spec/client_robustness_spec.rb +4 -2
  52. data/spec/data/marshall.yaml +1667 -0
  53. data/spec/data_spec.rb +673 -0
  54. data/spec/emits_changed_signal_spec.rb +58 -0
  55. data/spec/err_msg_spec.rb +2 -0
  56. data/spec/introspect_xml_parser_spec.rb +2 -0
  57. data/spec/introspection_spec.rb +2 -0
  58. data/spec/main_loop_spec.rb +3 -1
  59. data/spec/node_spec.rb +23 -0
  60. data/spec/object_path_spec.rb +3 -0
  61. data/spec/object_spec.rb +138 -0
  62. data/spec/packet_marshaller_spec.rb +41 -0
  63. data/spec/packet_unmarshaller_spec.rb +248 -0
  64. data/spec/property_spec.rb +192 -5
  65. data/spec/proxy_object_spec.rb +2 -0
  66. data/spec/server_robustness_spec.rb +2 -0
  67. data/spec/server_spec.rb +2 -0
  68. data/spec/service_newapi.rb +70 -70
  69. data/spec/session_bus_spec.rb +3 -1
  70. data/spec/session_bus_spec_manual.rb +2 -0
  71. data/spec/signal_spec.rb +5 -3
  72. data/spec/spec_helper.rb +37 -9
  73. data/spec/thread_safety_spec.rb +2 -0
  74. data/spec/tools/dbus-limited-session.conf +4 -0
  75. data/spec/type_spec.rb +214 -6
  76. data/spec/value_spec.rb +16 -1
  77. data/spec/variant_spec.rb +4 -2
  78. data/spec/zzz_quit_spec.rb +16 -0
  79. metadata +34 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8a530c6d561a17c6179bda15319036a806f1a42b427033e96caccfc738ebf7b
4
- data.tar.gz: 959143cab388b528354cc569c698a8c99dc79bbca1b21dbdcc064e212b8794a2
3
+ metadata.gz: 07f1f2fd26d13923b2601c9c3f29ccf57afd42c0348b937bceea0804eece6d66
4
+ data.tar.gz: 5ad80792234951e7ed422b6eba16e7f6e55b41f24a116ef40afaa7f32cdeef74
5
5
  SHA512:
6
- metadata.gz: 41d4ff1294958f67efac62ae0d1b326728617976ea944f3c3374f7156bf33632e9e072260f002c11ca44b099113d75e5ecc58f67c3d2c9d34666f6abe92bdbb3
7
- data.tar.gz: c93e54662d3cf01a9b0ac0a2e5c70d0efc78da1758349cfe6209cba37fa707b7334503518a7e0b4f53d754aff22d5ff53c2d7f8c2d8c32e6df9b097a1bf0f34b
6
+ metadata.gz: acbe18b2d9695f8959ef6d51a3871e989600291076d6eef870a9215768ed6c7afd599d3af2741e13a733fe2f5cc9f75fdf075a130cafd0a9144b4ca00bd80dc9
7
+ data.tar.gz: 0363375dd8c4465aa2650649d0bd62a4f95431b78178edb624a84f5326e395476e0c54e4755b27fedc86caf94b7c059abbdc15af28832417ec1d3e4770ea9ae0
data/NEWS.md CHANGED
@@ -2,6 +2,166 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## Ruby D-Bus 0.18.1 - 2022-07-13
6
+
7
+ No changes since 0.18.0.beta8.
8
+ Repeating the most important changes since 0.17.0:
9
+
10
+ API:
11
+ * Introduced DBus::Data classes, use them in Properties.Get,
12
+ Properties.GetAll to return correct types as declared ([#97][]).
13
+ * Introduced Object#dbus_properties_changed to send correctly typed property
14
+ values ([#115][]). Avoid calling PropertiesChanged directly as it will
15
+ guess the types.
16
+ * Service side `emits_changed_signal` to control emission of
17
+ PropertiesChanged: can be assigned within `dbus_interface` or as an option
18
+ when declaring properties ([#117][]).
19
+ * DBus.variant(type, value) is deprecated in favor of
20
+ Data::Variant.new(value, member_type:)
21
+ * Added type factories
22
+ * Type::Array[type]
23
+ * Type::Hash[key_type, value_type]
24
+ * Type::Struct[type1, type2...]
25
+
26
+ Bug fixes:
27
+ * Fix Object.dbus_reader to work with attr_accessor and automatically produce
28
+ dbus_properties_changed for properties that are read-write at
29
+ implementation side and read-only at D-Bus side ([#96][])
30
+ * Service-side properties: Fix Properties.Get, Properties.GetAll
31
+ to use the specific property signature, not the generic
32
+ Variant ([#97][], [#105][], [#109][]).
33
+ * Client-side properties: When calling Properties.Set in
34
+ ProxyObjectInterface#[]=, use the correct type ([#108][]).
35
+ * Added thorough tests (`spec/data/marshall.yaml`) to detect nearly all
36
+ invalid data at unmarshalling time.
37
+
38
+ Requirements:
39
+ * Require Ruby 2.4, because of RuboCop 1.0.
40
+
41
+ ## Ruby D-Bus 0.18.0.beta8 - 2022-06-21
42
+
43
+ Bug fixes:
44
+ * Introduced Object#dbus_properties_changed to send correctly typed property
45
+ values ([#115][]). Avoid calling PropertiesChanged directly as it will
46
+ guess the types.
47
+ * Fix Object.dbus_reader to work with attr_accessor and automatically produce
48
+ dbus_properties_changed for properties that are read-write at
49
+ implementation side and read-only at D-Bus side ([#96][])
50
+
51
+ [#96]: https://github.com/mvidner/ruby-dbus/issues/96
52
+
53
+ API:
54
+ * Service side `emits_changed_signal` to control emission of
55
+ PropertiesChanged: can be assigned within `dbus_interface` or as an option
56
+ when declaring properties ([#117][]).
57
+
58
+ [#115]: https://github.com/mvidner/ruby-dbus/issues/115
59
+ [#117]: https://github.com/mvidner/ruby-dbus/pulls/117
60
+
61
+ ## Ruby D-Bus 0.18.0.beta7 - 2022-05-29
62
+
63
+ API:
64
+ * DBus.variant(type, value) is deprecated in favor of
65
+ Data::Variant.new(value, member_type:)
66
+
67
+ Bug fixes:
68
+ * Client-side properties: When calling Properties.Set in
69
+ ProxyObjectInterface#[]=, use the correct type ([#108][]).
70
+
71
+ [#108]: https://github.com/mvidner/ruby-dbus/issues/108
72
+
73
+ ## Ruby D-Bus 0.18.0.beta6 - 2022-05-25
74
+
75
+ API:
76
+ * Data::Base#value returns plain Ruby types;
77
+ Data::Container#exact_value contains Data::Base ([#114][]).
78
+ * Data::Base#initialize and .from_typed allow plain or exact values, validate
79
+ argument types.
80
+ * Implement #== (converting) and #eql? (strict) for Data::Base and DBus::Type.
81
+
82
+ [#114]: https://github.com/mvidner/ruby-dbus/pull/114
83
+
84
+ ## Ruby D-Bus 0.18.0.beta5 - 2022-04-27
85
+
86
+ API:
87
+ * DBus::Type instances are frozen.
88
+ * Data::Container classes (Array, Struct, DictEntry, but not Variant)
89
+ constructors (#initialize, .from_items, .from_typed) changed to have
90
+ a *type* argument instead of *member_type* or *member_types*.
91
+ * Added type factories
92
+ * Type::Array[type]
93
+ * Type::Hash[key_type, value_type]
94
+ * Type::Struct[type1, type2...]
95
+
96
+ Bug fixes:
97
+ * Properties containing Variants would return them doubly wrapped ([#111][]).
98
+
99
+ [#111]: https://github.com/mvidner/ruby-dbus/pull/111
100
+
101
+ ## Ruby D-Bus 0.18.0.beta4 - 2022-04-21
102
+
103
+ Bug fixes:
104
+ * Service-side properties: Fix Properties.Get, Properties.GetAll for
105
+ properties that contain arrays, on other than outermost level ([#109][]).
106
+ * Sending variants: fixed make_variant to correctly guess the signature
107
+ for UInt64 and number-keyed hashes/dictionaries.
108
+
109
+ [#109]: https://github.com/mvidner/ruby-dbus/pull/109
110
+
111
+ ## Ruby D-Bus 0.18.0.beta3 - 2022-04-10
112
+
113
+ Bug fixes:
114
+ * Service-side properties: Fix Properties.Get, Properties.GetAll for Array,
115
+ Dict, and Variant types ([#105][]).
116
+
117
+ [#105]: https://github.com/mvidner/ruby-dbus/pull/105
118
+
119
+ ## Ruby D-Bus 0.18.0.beta2 - 2022-04-04
120
+
121
+ API:
122
+ * Renamed the DBus::Type::Type class to DBus::Type
123
+ (which was previously a module).
124
+ * Introduced DBus::Data classes, use them in Properties.Get,
125
+ Properties.GetAll to return correct types as declared (still [#97][]).
126
+
127
+ Bug fixes:
128
+ * Signature validation: Ensure DBus.type produces a valid Type
129
+ * Detect more malformed messages: non-NUL padding bytes, variants with
130
+ multiple or no value.
131
+ * Added thorough tests (`spec/data/marshall.yaml`) to detect nearly all
132
+ invalid data at unmarshalling time.
133
+
134
+ ## Ruby D-Bus 0.18.0.beta1 - 2022-02-24
135
+
136
+ API:
137
+ * D-Bus structs have been passed as Ruby arrays. Now these arrays are frozen.
138
+ * Ruby structs can be used as D-Bus structs.
139
+
140
+ Bug fixes:
141
+ * Returning the value for o.fd.DBus.Properties.Get, use the specific property
142
+ signature, not the generic Variant ([#97][]).
143
+
144
+ Requirements:
145
+ * Require Ruby 2.4, because of RuboCop 1.0.
146
+
147
+ [#97]: https://github.com/mvidner/ruby-dbus/issues/97
148
+
149
+ ## Ruby D-Bus 0.17.0 - 2022-02-11
150
+
151
+ API:
152
+ * Export properties with `dbus_attr_accessor`, `dbus_reader` etc. ([#86][]).
153
+
154
+ Bug fixes:
155
+ * Depend on rexml which is separate since Ruby 3.0 ([#87][],
156
+ by Toshiaki Asai).
157
+ Nokogiri is faster but bigger so it remains optional.
158
+ * Fix connection in case ~/.dbus-keyrings has multiple cookies, showing
159
+ as "Oops: undefined method `zero?' for nil:NilClass".
160
+ * Add the missing name to the root introspection node.
161
+
162
+ [#86]: https://github.com/mvidner/ruby-dbus/pull/86
163
+ [#87]: https://github.com/mvidner/ruby-dbus/pull/87
164
+
5
165
  ## Ruby D-Bus 0.16.0 - 2019-10-15
6
166
 
7
167
  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.1
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
 
@@ -166,12 +166,21 @@ D-Bus has stricter typing than Ruby, so the library must decide
166
166
  which D-Bus type to choose. Most of the time the choice is dictated
167
167
  by the D-Bus signature.
168
168
 
169
+ For exact representation of D-Bus data types, use subclasses
170
+ of {DBus::Data::Base}, such as {DBus::Data::Int16} or {DBus::Data::UInt64}.
171
+
169
172
  ##### Variants
170
173
 
171
174
  If the signature expects a Variant
172
175
  (which is the case for all Properties!) then an explicit mechanism is needed.
173
176
 
174
- 1. A pair [{DBus::Type::Type}, value] specifies to marshall *value* as
177
+ 1. Any {DBus::Data::Base}.
178
+
179
+ 2. A {DBus::Data::Variant} made by {DBus.variant}(signature, value).
180
+ (Formerly this produced the type+value pair below, now it is just an alias
181
+ to the Variant constructor.)
182
+
183
+ 3. A pair [{DBus::Type}, value] specifies to marshall *value* as
175
184
  that specified type.
176
185
  The pair can be produced by {DBus.variant}(signature, value) which
177
186
  gives the same result as [{DBus.type}(signature), value].
@@ -179,22 +188,29 @@ If the signature expects a Variant
179
188
  ISSUE: using something else than cryptic signatures is even more painful
180
189
  than remembering the signatures!
181
190
 
182
- foo_i["Bar"] = DBus.variant("au", [0, 1, 1, 2, 3, 5, 8])
191
+ `foo_i["Bar"] = DBus.variant("au", [0, 1, 1, 2, 3, 5, 8])`
183
192
 
184
- 2. Other values are tried to fit one of these:
193
+ 4. Other values are tried to fit one of these:
185
194
  Boolean, Double, Array of Variants, Hash of String keyed Variants,
186
195
  String, Int32, Int64.
187
196
 
188
- 3. **Deprecated:** A pair [String, value], where String is a valid
197
+ 5. **Deprecated:** A pair [String, value], where String is a valid
189
198
  signature of a single complete type, marshalls value as that
190
- type. This will hit you when you rely on method (2) but happen to have
199
+ type. This will hit you when you rely on method (4) but happen to have
191
200
  a particular string value in an array.
192
201
 
202
+ ##### Structs
203
+
204
+ If a **STRUCT** `(...)` is expected you may pass
205
+
206
+ - an [Array](https://ruby-doc.org/core/Array.html) (frozen is fine)
207
+ - a [Struct](https://ruby-doc.org/core/Struct.html)
208
+
193
209
  ##### Byte Arrays
194
210
 
195
211
  If a byte array (`ay`) is expected you can pass a String too.
196
212
  The bytes sent are according to the string's
197
- [encoding](http://ruby-doc.org/core-2.0.0/Encoding.html).
213
+ [encoding](http://ruby-doc.org/core/Encoding.html).
198
214
 
199
215
  ##### nil
200
216
 
@@ -244,14 +260,97 @@ When you want to provide a DBus API.
244
260
  (check that client and service side have their counterparts)
245
261
 
246
262
  ### Basic
263
+
247
264
  #### Exporting a Method
265
+
248
266
  ##### Interfaces
267
+
249
268
  ##### Methods
269
+
250
270
  ##### Bus Names
271
+
251
272
  ##### Errors
273
+
252
274
  #### Exporting Properties
275
+
276
+ Similar to plain Ruby attributes, declared with
277
+
278
+ - {https://docs.ruby-lang.org/en/3.1/Module.html#method-i-attr_accessor attr_accessor}
279
+ - {https://docs.ruby-lang.org/en/3.1/Module.html#method-i-attr_reader attr_reader}
280
+ - {https://docs.ruby-lang.org/en/3.1/Module.html#method-i-attr_writer attr_writer}
281
+
282
+ These methods declare the attributes and export them as properties:
283
+
284
+ - {DBus::Object.dbus_attr_accessor}
285
+ - {DBus::Object.dbus_attr_reader}
286
+ - {DBus::Object.dbus_attr_writer}
287
+
288
+ For making properties out of Ruby methods (which are not attributes), use:
289
+
290
+ - {DBus::Object.dbus_accessor}
291
+ - {DBus::Object.dbus_reader}
292
+ - {DBus::Object.dbus_writer}
293
+
294
+ Note that the properties are declared in the Ruby naming convention with
295
+ `snake_case` and D-Bus sees them `CamelCased`. Use the `dbus_name` argument
296
+ for overriding this.
297
+
298
+  
299
+
300
+ class Note < DBus::Object
301
+ dbus_interface "net.vidner.Example.Properties" do
302
+ # A read-write property "Title",
303
+ # with `title` and `title=` accessing @title.
304
+ dbus_attr_accessor :title, DBus::Type::STRING
305
+
306
+ # A read-only property "Author"
307
+ # (type specified via DBus signature)
308
+ # with `author` reading `@author`
309
+ dbus_attr_reader :author, "s"
310
+
311
+ # A read-only property `Clock`
312
+ def clock
313
+ Time.now.to_s
314
+ end
315
+ dbus_reader :clock, "s"
316
+
317
+ # Name mapping: `CreationTime`
318
+ def creation_time
319
+ "1993-01-01 00:00:00 +0100"
320
+ end
321
+ dbus_reader :creation_time, "s"
322
+
323
+ dbus_attr_accessor :book_volume, DBus::Type::VARIANT, dbus_name: "Volume"
324
+ end
325
+
326
+ dbus_interface "net.vidner.Example.Audio" do
327
+ dbus_attr_accessor :speaker_volume, DBus::Type::BYTE, dbus_name: "Volume"
328
+ end
329
+
330
+ # Must assign values because `nil` would crash our connection
331
+ def initialize(opath)
332
+ super
333
+ @title = "Ahem"
334
+ @author = "Martin"
335
+ @book_volume = 1
336
+ @speaker_volume = 11
337
+ end
338
+ end
339
+
340
+ obj = Note.new("/net/vidner/Example/Properties")
341
+
342
+ bus = DBus::SessionBus.instance
343
+ service = bus.request_service("net.vidner.Example")
344
+ service.export(obj)
345
+
346
+ main = DBus::Main.new
347
+ main << bus
348
+ main.run
349
+
253
350
  ### Advanced
351
+
254
352
  #### Inheritance
353
+
255
354
  #### Names
256
355
 
257
356
  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