ruby-dbus 0.16.0 → 0.25.0

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 (108) hide show
  1. checksums.yaml +4 -4
  2. data/NEWS.md +288 -3
  3. data/README.md +3 -5
  4. data/Rakefile +27 -12
  5. data/VERSION +1 -1
  6. data/doc/Reference.md +109 -10
  7. data/examples/doc/_extract_examples +7 -0
  8. data/examples/no-bus/pulseaudio.rb +50 -0
  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 +3 -3
  15. data/examples/simple/call_introspect.rb +1 -0
  16. data/examples/simple/get_id.rb +6 -3
  17. data/examples/simple/properties.rb +2 -0
  18. data/examples/utils/listnames.rb +10 -1
  19. data/examples/utils/notify.rb +1 -0
  20. data/lib/dbus/api_options.rb +9 -0
  21. data/lib/dbus/auth.rb +307 -217
  22. data/lib/dbus/bus.rb +155 -588
  23. data/lib/dbus/bus_name.rb +12 -8
  24. data/lib/dbus/connection.rb +363 -0
  25. data/lib/dbus/core_ext/class/attribute.rb +1 -1
  26. data/lib/dbus/data.rb +821 -0
  27. data/lib/dbus/emits_changed_signal.rb +83 -0
  28. data/lib/dbus/error.rb +4 -2
  29. data/lib/dbus/introspect.rb +133 -31
  30. data/lib/dbus/logger.rb +6 -3
  31. data/lib/dbus/main.rb +66 -0
  32. data/lib/dbus/marshall.rb +247 -296
  33. data/lib/dbus/matchrule.rb +16 -16
  34. data/lib/dbus/message.rb +66 -57
  35. data/lib/dbus/message_queue.rb +40 -25
  36. data/lib/dbus/node_tree.rb +105 -0
  37. data/lib/dbus/object.rb +442 -33
  38. data/lib/dbus/object_manager.rb +61 -0
  39. data/lib/dbus/object_path.rb +11 -6
  40. data/lib/dbus/object_server.rb +149 -0
  41. data/lib/dbus/org.freedesktop.DBus.xml +97 -0
  42. data/lib/dbus/platform.rb +26 -0
  43. data/lib/dbus/proxy_object.rb +30 -11
  44. data/lib/dbus/proxy_object_factory.rb +13 -7
  45. data/lib/dbus/proxy_object_interface.rb +63 -30
  46. data/lib/dbus/proxy_service.rb +107 -0
  47. data/lib/dbus/raw_message.rb +91 -0
  48. data/lib/dbus/type.rb +319 -86
  49. data/lib/dbus/xml.rb +40 -19
  50. data/lib/dbus.rb +28 -17
  51. data/ruby-dbus.gemspec +13 -6
  52. data/spec/async_spec.rb +2 -0
  53. data/spec/auth_spec.rb +225 -0
  54. data/spec/binding_spec.rb +2 -0
  55. data/spec/bus_and_xml_backend_spec.rb +5 -1
  56. data/spec/bus_connection_spec.rb +93 -0
  57. data/spec/bus_name_spec.rb +3 -1
  58. data/spec/bus_spec.rb +2 -0
  59. data/spec/byte_array_spec.rb +2 -0
  60. data/spec/client_robustness_spec.rb +4 -2
  61. data/spec/connection_spec.rb +37 -0
  62. data/spec/coverage_helper.rb +39 -0
  63. data/spec/data/marshall.yaml +1667 -0
  64. data/spec/data_spec.rb +673 -0
  65. data/spec/dbus_spec.rb +22 -0
  66. data/spec/emits_changed_signal_spec.rb +58 -0
  67. data/spec/err_msg_spec.rb +2 -0
  68. data/spec/introspect_xml_parser_spec.rb +2 -0
  69. data/spec/introspection_spec.rb +2 -0
  70. data/spec/main_loop_spec.rb +17 -1
  71. data/spec/message_spec.rb +21 -0
  72. data/spec/mock-service/cockpit-dbustests.rb +29 -0
  73. data/spec/mock-service/com.redhat.Cockpit.DBusTests.xml +180 -0
  74. data/spec/mock-service/org.ruby.service.service +4 -0
  75. data/spec/mock-service/org.rubygems.ruby_dbus.DBusTests.service +4 -0
  76. data/spec/{service_newapi.rb → mock-service/spaghetti-monster.rb} +122 -75
  77. data/spec/node_spec.rb +65 -0
  78. data/spec/object_manager_spec.rb +33 -0
  79. data/spec/object_path_spec.rb +3 -0
  80. data/spec/object_server_spec.rb +138 -0
  81. data/spec/object_spec.rb +194 -0
  82. data/spec/packet_marshaller_spec.rb +41 -0
  83. data/spec/packet_unmarshaller_spec.rb +248 -0
  84. data/spec/platform_spec.rb +14 -0
  85. data/spec/property_spec.rb +214 -12
  86. data/spec/proxy_object_interface_spec.rb +35 -0
  87. data/spec/proxy_object_spec.rb +2 -0
  88. data/spec/{bus_driver_spec.rb → proxy_service_spec.rb} +15 -8
  89. data/spec/raw_message_spec.rb +32 -0
  90. data/spec/server_robustness_spec.rb +20 -6
  91. data/spec/session_bus_spec.rb +36 -1
  92. data/spec/session_bus_spec_manual.rb +2 -0
  93. data/spec/signal_spec.rb +16 -3
  94. data/spec/spec_helper.rb +25 -33
  95. data/spec/thread_safety_spec.rb +55 -12
  96. data/spec/tools/dbus-launch-simple +9 -6
  97. data/spec/tools/dbus-limited-session.conf +32 -0
  98. data/spec/tools/test_env +26 -6
  99. data/spec/type_spec.rb +214 -6
  100. data/spec/value_spec.rb +16 -1
  101. data/spec/variant_spec.rb +4 -2
  102. data/spec/zzz_quit_spec.rb +16 -0
  103. metadata +92 -20
  104. data/examples/gdbus/gdbus +0 -257
  105. data/examples/gdbus/gdbus.glade +0 -98
  106. data/examples/gdbus/launch.sh +0 -4
  107. data/spec/server_spec.rb +0 -53
  108. data/spec/tools/test_server +0 -39
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8a530c6d561a17c6179bda15319036a806f1a42b427033e96caccfc738ebf7b
4
- data.tar.gz: 959143cab388b528354cc569c698a8c99dc79bbca1b21dbdcc064e212b8794a2
3
+ metadata.gz: 48184aac3dc75bb3407fb52dff9f10628b2dc5e38208270d756212b1ae026931
4
+ data.tar.gz: c345834e8cbc03a55b34f7b8bb63151d3770749213bf7afa73be73ee6038dca6
5
5
  SHA512:
6
- metadata.gz: 41d4ff1294958f67efac62ae0d1b326728617976ea944f3c3374f7156bf33632e9e072260f002c11ca44b099113d75e5ecc58f67c3d2c9d34666f6abe92bdbb3
7
- data.tar.gz: c93e54662d3cf01a9b0ac0a2e5c70d0efc78da1758349cfe6209cba37fa707b7334503518a7e0b4f53d754aff22d5ff53c2d7f8c2d8c32e6df9b097a1bf0f34b
6
+ metadata.gz: c376083a3b761223d5b8f37b9fbb2f1383a874ac0f26c6c5ae92d2385fc936e8145aa20dfe4b327e1551a70030c4a1ffacfd289884e06e9bec2bc5ba9e9fb56c
7
+ data.tar.gz: 460a6e5bc96b6a2b0d4b227de8b8b34595102c67c40f62cf520947b4a394d3dc101af98e6147e5ced15143a0fb5ddf9aeec0764c4a74f9e83ee8b4730a12d544
data/NEWS.md CHANGED
@@ -2,6 +2,291 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## Ruby D-Bus 0.25.0 - 2025-04-03
6
+
7
+ Bug fixes:
8
+ * Mention qualified property name in Get or Set errors ([#147][]).
9
+ * Fix declaring logger and ostruct gems for Ruby 3.5
10
+
11
+ [#147]: https://github.com/mvidner/ruby-dbus/pull/147
12
+
13
+ ## Ruby D-Bus 0.24.0 - 2025-01-02
14
+
15
+ Bug fixes:
16
+ * Adapted for Ruby 3.4, which uses a single quote instead of a backtick
17
+ in exceptions ([#145][], by Mamoru TASAKA).
18
+
19
+ [#145]: https://github.com/mvidner/ruby-dbus/pull/145
20
+
21
+ ## Ruby D-Bus 0.23.1 - 2023-10-03
22
+
23
+ API:
24
+ * Add DBus::Object.dbus_reader_attr_accessor to declare a common use case
25
+ with a single call ([#140][]).
26
+ * BusConnection#request_name defaults to the simple use case: single owner
27
+ without queuing, failing fast; documented the complex use cases.
28
+
29
+ [#140]: https://github.com/mvidner/ruby-dbus/pull/140
30
+
31
+ ## Ruby D-Bus 0.23.0.beta2 - 2023-06-23
32
+
33
+ License:
34
+ * clarified to be LGPL-2.1-or-later
35
+
36
+ API:
37
+ * DBus::Object#object_server replaces @service (which still works) and the short-lived
38
+ @connection
39
+ * ObjectServer#export will raise if the path is already taken by an object
40
+ * ObjectServer#unexport now also accepts an object path
41
+ * Connection#object_server can export objects even without requesting any
42
+ service name ([#49][], in beta1 already).
43
+ * Add PeerConnection for connections without a bus, useful for PulseAudio.
44
+ Fix listening for signals there ([#44][]).
45
+ * Moved from Connection to BusConnection: #unique_name, #proxy, #service.
46
+ Call send_hello in BusConnection#initialize already.
47
+
48
+ Bug fixes:
49
+ * Fixed a refactoring crasher bug in ProxyService#introspect (oops).
50
+ * Fix crash on #unexport of /child_of_root or even /
51
+
52
+ [#44]: https://github.com/mvidner/ruby-dbus/issues/44
53
+ [#49]: https://github.com/mvidner/ruby-dbus/issues/49
54
+
55
+ ## Ruby D-Bus 0.23.0.beta1 - 2023-06-05
56
+
57
+ Bug fixes:
58
+ * A service can now have more than one name ([#69][]).
59
+ Connection#request_service is deprecated in favor of Connection#object_server
60
+ and BusConnection#request_name
61
+
62
+ [#69]: https://github.com/mvidner/ruby-dbus/issues/69
63
+
64
+ API:
65
+ * Remove Service, splitting it into ProxyService and ObjectServer
66
+ * Split off BusConnection from Connection
67
+ * DBus::Object @service replaced by @connection
68
+
69
+ ## Ruby D-Bus 0.22.1 - 2023-05-17
70
+
71
+ Bug fixes:
72
+ * Fix OBS building by disabling IPv6 tests, [#134][].
73
+
74
+ [#134]: https://github.com/mvidner/ruby-dbus/pull/134
75
+
76
+ ## Ruby D-Bus 0.22.0 - 2023-05-08
77
+
78
+ Features:
79
+ * Enable using nokogiri without rexml (by Dominik Andreas Schorpp, [#132][])
80
+
81
+ Bug fixes:
82
+ * Respect DBUS_SYSTEM_BUS_ADDRESS environment variable.
83
+
84
+ Other:
85
+ * For NameRequestError, mention who is the other owner.
86
+ * Session bus autolaunch still does not work, but: don't try launchd except
87
+ on macOS, and improve the error message.
88
+ * examples/gdbus split off to its own repository,
89
+ https://github.com/mvidner/dbus-gui-gtk
90
+
91
+ [#132]: https://github.com/mvidner/ruby-dbus/pull/132
92
+
93
+ ## Ruby D-Bus 0.21.0 - 2023-04-08
94
+
95
+ Features:
96
+ * Respect env RUBY_DBUS_ENDIANNESS=B (or =l) for outgoing messages.
97
+
98
+ Bug fixes:
99
+ * Reduce socket buffer allocations ([#129][]).
100
+ * Message#marshall speedup: don't marshall the body twice.
101
+
102
+ [#129]: https://github.com/mvidner/ruby-dbus/pull/129
103
+
104
+ ## Ruby D-Bus 0.20.0 - 2023-03-21
105
+
106
+ Features:
107
+ * For EXTERNAL authentication, try also without the user id, to work with
108
+ containers ([#126][]).
109
+ * Thread safety, as long as the non-main threads only send signals.
110
+
111
+ [#126]: https://github.com/mvidner/ruby-dbus/issues/126
112
+
113
+ ## Ruby D-Bus 0.19.0 - 2023-01-18
114
+
115
+ API:
116
+ * Added a ObjectManager mix-in to implement the service-side
117
+ [ObjectManager][objmgr] interface.
118
+
119
+ Bug fixes:
120
+ * dbus_attr_accessor and friends validate the signature ([#120][]).
121
+ * Declare the Introspectable interface in exported objects([#99][]).
122
+ * Do reply with an error when calling a nonexisting object
123
+ with an existing path prefix([#121][]).
124
+
125
+ [#120]: https://github.com/mvidner/ruby-dbus/issues/120
126
+ [#99]: https://github.com/mvidner/ruby-dbus/issues/99
127
+ [#121]: https://github.com/mvidner/ruby-dbus/issues/121
128
+ [objmgr]: https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager
129
+
130
+ ## Ruby D-Bus 0.18.1 - 2022-07-13
131
+
132
+ No changes since 0.18.0.beta8.
133
+ Repeating the most important changes since 0.17.0:
134
+
135
+ API:
136
+ * Introduced DBus::Data classes, use them in Properties.Get,
137
+ Properties.GetAll to return correct types as declared ([#97][]).
138
+ * Introduced Object#dbus_properties_changed to send correctly typed property
139
+ values ([#115][]). Avoid calling PropertiesChanged directly as it will
140
+ guess the types.
141
+ * Service side `emits_changed_signal` to control emission of
142
+ PropertiesChanged: can be assigned within `dbus_interface` or as an option
143
+ when declaring properties ([#117][]).
144
+ * DBus.variant(type, value) is deprecated in favor of
145
+ Data::Variant.new(value, member_type:)
146
+ * Added type factories
147
+ * Type::Array[type]
148
+ * Type::Hash[key_type, value_type]
149
+ * Type::Struct[type1, type2...]
150
+
151
+ Bug fixes:
152
+ * Fix Object.dbus_reader to work with attr_accessor and automatically produce
153
+ dbus_properties_changed for properties that are read-write at
154
+ implementation side and read-only at D-Bus side ([#96][])
155
+ * Service-side properties: Fix Properties.Get, Properties.GetAll
156
+ to use the specific property signature, not the generic
157
+ Variant ([#97][], [#105][], [#109][]).
158
+ * Client-side properties: When calling Properties.Set in
159
+ ProxyObjectInterface#[]=, use the correct type ([#108][]).
160
+ * Added thorough tests (`spec/data/marshall.yaml`) to detect nearly all
161
+ invalid data at unmarshalling time.
162
+
163
+ Requirements:
164
+ * Require Ruby 2.4, because of RuboCop 1.0.
165
+
166
+ ## Ruby D-Bus 0.18.0.beta8 - 2022-06-21
167
+
168
+ Bug fixes:
169
+ * Introduced Object#dbus_properties_changed to send correctly typed property
170
+ values ([#115][]). Avoid calling PropertiesChanged directly as it will
171
+ guess the types.
172
+ * Fix Object.dbus_reader to work with attr_accessor and automatically produce
173
+ dbus_properties_changed for properties that are read-write at
174
+ implementation side and read-only at D-Bus side ([#96][])
175
+
176
+ [#96]: https://github.com/mvidner/ruby-dbus/issues/96
177
+
178
+ API:
179
+ * Service side `emits_changed_signal` to control emission of
180
+ PropertiesChanged: can be assigned within `dbus_interface` or as an option
181
+ when declaring properties ([#117][]).
182
+
183
+ [#115]: https://github.com/mvidner/ruby-dbus/issues/115
184
+ [#117]: https://github.com/mvidner/ruby-dbus/pull/117
185
+
186
+ ## Ruby D-Bus 0.18.0.beta7 - 2022-05-29
187
+
188
+ API:
189
+ * DBus.variant(type, value) is deprecated in favor of
190
+ Data::Variant.new(value, member_type:)
191
+
192
+ Bug fixes:
193
+ * Client-side properties: When calling Properties.Set in
194
+ ProxyObjectInterface#[]=, use the correct type ([#108][]).
195
+
196
+ [#108]: https://github.com/mvidner/ruby-dbus/issues/108
197
+
198
+ ## Ruby D-Bus 0.18.0.beta6 - 2022-05-25
199
+
200
+ API:
201
+ * Data::Base#value returns plain Ruby types;
202
+ Data::Container#exact_value contains Data::Base ([#114][]).
203
+ * Data::Base#initialize and .from_typed allow plain or exact values, validate
204
+ argument types.
205
+ * Implement #== (converting) and #eql? (strict) for Data::Base and DBus::Type.
206
+
207
+ [#114]: https://github.com/mvidner/ruby-dbus/pull/114
208
+
209
+ ## Ruby D-Bus 0.18.0.beta5 - 2022-04-27
210
+
211
+ API:
212
+ * DBus::Type instances are frozen.
213
+ * Data::Container classes (Array, Struct, DictEntry, but not Variant)
214
+ constructors (#initialize, .from_items, .from_typed) changed to have
215
+ a *type* argument instead of *member_type* or *member_types*.
216
+ * Added type factories
217
+ * Type::Array[type]
218
+ * Type::Hash[key_type, value_type]
219
+ * Type::Struct[type1, type2...]
220
+
221
+ Bug fixes:
222
+ * Properties containing Variants would return them doubly wrapped ([#111][]).
223
+
224
+ [#111]: https://github.com/mvidner/ruby-dbus/pull/111
225
+
226
+ ## Ruby D-Bus 0.18.0.beta4 - 2022-04-21
227
+
228
+ Bug fixes:
229
+ * Service-side properties: Fix Properties.Get, Properties.GetAll for
230
+ properties that contain arrays, on other than outermost level ([#109][]).
231
+ * Sending variants: fixed make_variant to correctly guess the signature
232
+ for UInt64 and number-keyed hashes/dictionaries.
233
+
234
+ [#109]: https://github.com/mvidner/ruby-dbus/pull/109
235
+
236
+ ## Ruby D-Bus 0.18.0.beta3 - 2022-04-10
237
+
238
+ Bug fixes:
239
+ * Service-side properties: Fix Properties.Get, Properties.GetAll for Array,
240
+ Dict, and Variant types ([#105][]).
241
+
242
+ [#105]: https://github.com/mvidner/ruby-dbus/pull/105
243
+
244
+ ## Ruby D-Bus 0.18.0.beta2 - 2022-04-04
245
+
246
+ API:
247
+ * Renamed the DBus::Type::Type class to DBus::Type
248
+ (which was previously a module).
249
+ * Introduced DBus::Data classes, use them in Properties.Get,
250
+ Properties.GetAll to return correct types as declared (still [#97][]).
251
+
252
+ Bug fixes:
253
+ * Signature validation: Ensure DBus.type produces a valid Type
254
+ * Detect more malformed messages: non-NUL padding bytes, variants with
255
+ multiple or no value.
256
+ * Added thorough tests (`spec/data/marshall.yaml`) to detect nearly all
257
+ invalid data at unmarshalling time.
258
+
259
+ ## Ruby D-Bus 0.18.0.beta1 - 2022-02-24
260
+
261
+ API:
262
+ * D-Bus structs have been passed as Ruby arrays. Now these arrays are frozen.
263
+ * Ruby structs can be used as D-Bus structs.
264
+
265
+ Bug fixes:
266
+ * Returning the value for o.fd.DBus.Properties.Get, use the specific property
267
+ signature, not the generic Variant ([#97][]).
268
+
269
+ Requirements:
270
+ * Require Ruby 2.4, because of RuboCop 1.0.
271
+
272
+ [#97]: https://github.com/mvidner/ruby-dbus/issues/97
273
+
274
+ ## Ruby D-Bus 0.17.0 - 2022-02-11
275
+
276
+ API:
277
+ * Export properties with `dbus_attr_accessor`, `dbus_reader` etc. ([#86][]).
278
+
279
+ Bug fixes:
280
+ * Depend on rexml which is separate since Ruby 3.0 ([#87][],
281
+ by Toshiaki Asai).
282
+ Nokogiri is faster but bigger so it remains optional.
283
+ * Fix connection in case ~/.dbus-keyrings has multiple cookies, showing
284
+ as "Oops: undefined method `zero?' for nil:NilClass".
285
+ * Add the missing name to the root introspection node.
286
+
287
+ [#86]: https://github.com/mvidner/ruby-dbus/pull/86
288
+ [#87]: https://github.com/mvidner/ruby-dbus/pull/87
289
+
5
290
  ## Ruby D-Bus 0.16.0 - 2019-10-15
6
291
 
7
292
  API:
@@ -264,7 +549,7 @@ Bug fixes:
264
549
  * Handle more ways which tell us that a bus connection has died.
265
550
 
266
551
  [#3]: https://github.com/mvidner/ruby-dbus/issue/3
267
- [bsc#617350]: https://bugzilla.novell.com/show_bug.cgi?id=617350
552
+ [bsc#617350]: https://bugzilla.suse.com/show_bug.cgi?id=617350
268
553
 
269
554
  ## Ruby D-Bus 0.3.0 - 2010-03-28
270
555
 
@@ -332,8 +617,8 @@ Bug fixes:
332
617
  * Fixed an endless sleep in DBus::Main.run ([bsc#537401][]).
333
618
  * Added details to PacketMarshaller exceptions ([bsc#538050][]).
334
619
 
335
- [bsc#537401]: https://bugzilla.novell.com/show_bug.cgi?id=537401
336
- [bsc#538050]: https://bugzilla.novell.com/show_bug.cgi?id=538050
620
+ [bsc#537401]: https://bugzilla.suse.com/show_bug.cgi?id=537401
621
+ [bsc#538050]: https://bugzilla.suse.com/show_bug.cgi?id=538050
337
622
 
338
623
  ## Ruby D-Bus "I'm not dead" 0.2.9 - 2009-08-26
339
624
 
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,14 +1,21 @@
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
- require "rspec/core/rake_task"
7
+ require "shellwords"
7
8
  begin
8
9
  require "rubocop/rake_task"
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|
@@ -27,23 +34,22 @@ desc "Default: run specs in the proper environment"
27
34
  task default: [:spec, :rubocop]
28
35
  task test: :spec
29
36
 
30
- RSpec::Core::RakeTask.new("bare:spec")
37
+ desc "Run RSpec code examples"
38
+ task "bare:spec", [:options] do |_t, args|
39
+ args.with_defaults(options: "")
40
+ sh "rspec #{args[:options]}"
41
+ end
31
42
 
32
43
  ["spec"].each do |tname|
33
44
  desc "Run bare:#{tname} in the proper environment"
34
- task tname do |_t|
45
+ task tname, [:options] do |_t, args|
46
+ args.with_defaults(options: "")
35
47
  cd "spec/tools" do
36
- sh "./test_env rake bare:#{tname}"
48
+ sh "./test_env rake bare:#{tname}[#{args[:options].shellescape}]"
37
49
  end
38
50
  end
39
51
  end
40
52
 
41
- if ENV["TRAVIS"]
42
- require "coveralls/rake/task"
43
- Coveralls::RakeTask.new
44
- task default: "coveralls:push"
45
- end
46
-
47
53
  # remove tarball implementation and create gem for this gemfile
48
54
  Rake::Task[:tarball].clear
49
55
 
@@ -68,4 +74,13 @@ namespace :doc do
68
74
  end
69
75
  end
70
76
 
71
- RuboCop::RakeTask.new if Object.const_defined? :RuboCop
77
+ if Object.const_defined? :RuboCop
78
+ RuboCop::RakeTask.new
79
+ else
80
+ desc "Run RuboCop (dummy)"
81
+ task :rubocop do
82
+ warn "RuboCop not installed"
83
+ end
84
+ end
85
+
86
+ YARD::Rake::YardocTask.new if Object.const_defined? :YARD
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.16.0
1
+ 0.25.0
data/doc/Reference.md CHANGED
@@ -23,8 +23,8 @@ is simply "dbus"
23
23
  #### Calling Methods
24
24
 
25
25
  1. {DBus.session_bus Connect to the session bus};
26
- 2. {DBus::Connection#[] get the screensaver service}
27
- 3. {DBus::Service#[] and its screensaver object}.
26
+ 2. {DBus::BusConnection#[] get the screensaver service}
27
+ 3. {DBus::ProxyService#[] and its screensaver object}.
28
28
  4. Call one of its methods in a loop, solving [xkcd#196](http://xkcd.com/196).
29
29
 
30
30
   
@@ -58,7 +58,7 @@ a method proxy always returned an array of values. This was to
58
58
  accomodate the rare cases of a DBus method specifying more than one
59
59
  *out* parameter. For compatibility, the behavior is preserved if you
60
60
  construct a {DBus::ProxyObject} with {DBus::ApiOptions::A0},
61
- which is what {DBus::Service#object} does.
61
+ which is what {DBus::ProxyService#object} does.
62
62
 
63
63
  For nearly all methods you used `Method[0]` or
64
64
  `Method.first`
@@ -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
+ bus.object_server.export(obj)
344
+ bus.request_name("net.vidner.Example")
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
@@ -0,0 +1,50 @@
1
+ #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # find the library without external help
5
+ $LOAD_PATH.unshift File.expand_path("../../lib", __dir__)
6
+
7
+ require "dbus"
8
+
9
+ def peer_address
10
+ bus = DBus::SessionBus.instance
11
+ svc = bus["org.PulseAudio1"]
12
+ obj = svc["/org/pulseaudio/server_lookup1"]
13
+ ifc = obj["org.PulseAudio.ServerLookup1"]
14
+ adr = ifc["Address"]
15
+ puts "PA address: #{adr}"
16
+ adr
17
+ end
18
+
19
+ address = peer_address
20
+ begin
21
+ conn = DBus::PeerConnection.new(address)
22
+ rescue Errno::ENOENT
23
+ puts "Address exists but could not connect; telling PA to load the protocol"
24
+ system "pactl load-module module-dbus-protocol"
25
+ conn = DBus::PeerConnection.new(address)
26
+ end
27
+ no_svc = conn.peer_service
28
+ obj = no_svc["/org/pulseaudio/core1"]
29
+ ifc = obj["org.PulseAudio.Core1"]
30
+ puts "PA version: #{ifc["Version"]}"
31
+
32
+ puts "Waiting for volume changes, try adjusting it. Ctrl-C to exit."
33
+
34
+ vol_ifc = "org.PulseAudio.Core1.Device"
35
+ vol_member = "VolumeUpdated"
36
+ # PA needs explicit enabling of signals
37
+ ifc.ListenForSignal("#{vol_ifc}.#{vol_member}", [])
38
+
39
+ match_rule = DBus::MatchRule.new
40
+ match_rule.interface = vol_ifc
41
+ match_rule.member = vol_member
42
+ conn.add_match(match_rule) do |msg|
43
+ # a single argument that is an array
44
+ volumes = msg.params[0]
45
+ puts "VolumeUpdated: #{volumes.join(", ")}"
46
+ end
47
+
48
+ loop = DBus::Main.new
49
+ loop << conn
50
+ loop.run