ruby-dbus 0.16.0 → 0.17.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.
- checksums.yaml +4 -4
- data/NEWS.md +16 -0
- data/README.md +3 -5
- data/Rakefile +25 -7
- data/VERSION +1 -1
- data/doc/Reference.md +84 -1
- data/examples/doc/_extract_examples +5 -0
- data/examples/gdbus/gdbus +20 -19
- data/examples/service/call_service.rb +1 -1
- data/lib/dbus/auth.rb +8 -8
- data/lib/dbus/bus.rb +16 -8
- data/lib/dbus/core_ext/class/attribute.rb +1 -1
- data/lib/dbus/introspect.rb +69 -20
- data/lib/dbus/marshall.rb +1 -1
- data/lib/dbus/message_queue.rb +6 -5
- data/lib/dbus/object.rb +264 -13
- data/lib/dbus/proxy_object.rb +7 -0
- data/lib/dbus/proxy_object_interface.rb +1 -0
- data/lib/dbus/type.rb +18 -0
- data/ruby-dbus.gemspec +5 -3
- data/spec/main_loop_spec.rb +1 -1
- data/spec/property_spec.rb +53 -3
- data/spec/service_newapi.rb +20 -66
- data/spec/signal_spec.rb +3 -3
- data/spec/spec_helper.rb +18 -6
- data/spec/tools/dbus-limited-session.conf +4 -0
- metadata +22 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee629ce8a78d7cd23f718103cfd622d2a5fd67c51dab6b2a88e453c512c608f3
|
4
|
+
data.tar.gz: a8995a9526e3b957d32c503de7ad5ef781e5c464925fec8e2107eda4529aa447
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 531e01c12aed4aeedaa5ce55fec2fee0c3da714211adc768c8990d2ce79509e6b925bc06d4308e9628cff109b9880dbea72878e7aeaf23c8e5fb19ddf8a249e2
|
7
|
+
data.tar.gz: 6449aa2798ed78d29c430423a92d7c8a921fd4ea244eea11fb8a84ca2eb880a4e6860325dc6a05254dc432b971d4929fc4d3a5057e423939c0574a687e7680f7
|
data/NEWS.md
CHANGED
@@ -2,6 +2,22 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## Ruby D-Bus 0.17.0 - 2022-02-11
|
6
|
+
|
7
|
+
API:
|
8
|
+
* Export properties with `dbus_attr_accessor`, `dbus_reader` etc. ([#86][]).
|
9
|
+
|
10
|
+
Bug fixes:
|
11
|
+
* Depend on rexml which is separate since Ruby 3.0 ([#87][],
|
12
|
+
by Toshiaki Asai).
|
13
|
+
Nokogiri is faster but bigger so it remains optional.
|
14
|
+
* Fix connection in case ~/.dbus-keyrings has multiple cookies, showing
|
15
|
+
as "Oops: undefined method `zero?' for nil:NilClass".
|
16
|
+
* Add the missing name to the root introspection node.
|
17
|
+
|
18
|
+
[#86]: https://github.com/mvidner/ruby-dbus/pull/86
|
19
|
+
[#87]: https://github.com/mvidner/ruby-dbus/pull/87
|
20
|
+
|
5
21
|
## Ruby D-Bus 0.16.0 - 2019-10-15
|
6
22
|
|
7
23
|
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://
|
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://
|
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.
|
44
|
+
- Ruby 2.1 or newer.
|
47
45
|
|
48
46
|
|
49
47
|
## Installation
|
data/Rakefile
CHANGED
@@ -9,6 +9,12 @@ begin
|
|
9
9
|
rescue LoadError
|
10
10
|
nil
|
11
11
|
end
|
12
|
+
begin
|
13
|
+
require "yard"
|
14
|
+
rescue LoadError
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
|
12
18
|
require "packaging"
|
13
19
|
|
14
20
|
Packaging.configuration do |conf|
|
@@ -38,12 +44,6 @@ RSpec::Core::RakeTask.new("bare:spec")
|
|
38
44
|
end
|
39
45
|
end
|
40
46
|
|
41
|
-
if ENV["TRAVIS"]
|
42
|
-
require "coveralls/rake/task"
|
43
|
-
Coveralls::RakeTask.new
|
44
|
-
task default: "coveralls:push"
|
45
|
-
end
|
46
|
-
|
47
47
|
# remove tarball implementation and create gem for this gemfile
|
48
48
|
Rake::Task[:tarball].clear
|
49
49
|
|
@@ -68,4 +68,22 @@ namespace :doc do
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
|
71
|
+
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
|
82
|
+
else
|
83
|
+
desc "Run RuboCop (dummy)"
|
84
|
+
task :rubocop do
|
85
|
+
warn "RuboCop not installed"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
YARD::Rake::YardocTask.new if Object.const_defined? :YARD
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.17.0
|
data/doc/Reference.md
CHANGED
@@ -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
|
-
|
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,
|
@@ -244,14 +244,97 @@ When you want to provide a DBus API.
|
|
244
244
|
(check that client and service side have their counterparts)
|
245
245
|
|
246
246
|
### Basic
|
247
|
+
|
247
248
|
#### Exporting a Method
|
249
|
+
|
248
250
|
##### Interfaces
|
251
|
+
|
249
252
|
##### Methods
|
253
|
+
|
250
254
|
##### Bus Names
|
255
|
+
|
251
256
|
##### Errors
|
257
|
+
|
252
258
|
#### Exporting Properties
|
259
|
+
|
260
|
+
Similar to plain Ruby attributes, declared with
|
261
|
+
|
262
|
+
- {https://docs.ruby-lang.org/en/3.1/Module.html#method-i-attr_accessor attr_accessor}
|
263
|
+
- {https://docs.ruby-lang.org/en/3.1/Module.html#method-i-attr_reader attr_reader}
|
264
|
+
- {https://docs.ruby-lang.org/en/3.1/Module.html#method-i-attr_writer attr_writer}
|
265
|
+
|
266
|
+
These methods declare the attributes and export them as properties:
|
267
|
+
|
268
|
+
- {DBus::Object.dbus_attr_accessor}
|
269
|
+
- {DBus::Object.dbus_attr_reader}
|
270
|
+
- {DBus::Object.dbus_attr_writer}
|
271
|
+
|
272
|
+
For making properties out of Ruby methods (which are not attributes), use:
|
273
|
+
|
274
|
+
- {DBus::Object.dbus_accessor}
|
275
|
+
- {DBus::Object.dbus_reader}
|
276
|
+
- {DBus::Object.dbus_writer}
|
277
|
+
|
278
|
+
Note that the properties are declared in the Ruby naming convention with
|
279
|
+
`snake_case` and D-Bus sees them `CamelCased`. Use the `dbus_name` argument
|
280
|
+
for overriding this.
|
281
|
+
|
282
|
+
|
283
|
+
|
284
|
+
class Note < DBus::Object
|
285
|
+
dbus_interface "net.vidner.Example.Properties" do
|
286
|
+
# A read-write property "Title",
|
287
|
+
# with `title` and `title=` accessing @title.
|
288
|
+
dbus_attr_accessor :title, DBus::Type::STRING
|
289
|
+
|
290
|
+
# A read-only property "Author"
|
291
|
+
# (type specified via DBus signature)
|
292
|
+
# with `author` reading `@author`
|
293
|
+
dbus_attr_reader :author, "s"
|
294
|
+
|
295
|
+
# A read-only property `Clock`
|
296
|
+
def clock
|
297
|
+
Time.now.to_s
|
298
|
+
end
|
299
|
+
dbus_reader :clock, "s"
|
300
|
+
|
301
|
+
# Name mapping: `CreationTime`
|
302
|
+
def creation_time
|
303
|
+
"1993-01-01 00:00:00 +0100"
|
304
|
+
end
|
305
|
+
dbus_reader :creation_time, "s"
|
306
|
+
|
307
|
+
dbus_attr_accessor :book_volume, DBus::Type::VARIANT, dbus_name: "Volume"
|
308
|
+
end
|
309
|
+
|
310
|
+
dbus_interface "net.vidner.Example.Audio" do
|
311
|
+
dbus_attr_accessor :speaker_volume, DBus::Type::BYTE, dbus_name: "Volume"
|
312
|
+
end
|
313
|
+
|
314
|
+
# Must assign values because `nil` would crash our connection
|
315
|
+
def initialize(opath)
|
316
|
+
super
|
317
|
+
@title = "Ahem"
|
318
|
+
@author = "Martin"
|
319
|
+
@book_volume = 1
|
320
|
+
@speaker_volume = 11
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
obj = Note.new("/net/vidner/Example/Properties")
|
325
|
+
|
326
|
+
bus = DBus::SessionBus.instance
|
327
|
+
service = bus.request_service("net.vidner.Example")
|
328
|
+
service.export(obj)
|
329
|
+
|
330
|
+
main = DBus::Main.new
|
331
|
+
main << bus
|
332
|
+
main.run
|
333
|
+
|
253
334
|
### Advanced
|
335
|
+
|
254
336
|
#### Inheritance
|
337
|
+
|
255
338
|
#### Names
|
256
339
|
|
257
340
|
Specification Conformance
|
@@ -4,6 +4,9 @@ if ARGV[0].nil?
|
|
4
4
|
exit
|
5
5
|
end
|
6
6
|
|
7
|
+
base_url = "https://github.com/mvidner/ruby-dbus/blob/master/"
|
8
|
+
base_url += ARGV[0].gsub("../", "")
|
9
|
+
|
7
10
|
File.open(ARGV[0]) do |f|
|
8
11
|
title = nil
|
9
12
|
setup = ""
|
@@ -20,7 +23,9 @@ File.open(ARGV[0]) do |f|
|
|
20
23
|
setup = example
|
21
24
|
else
|
22
25
|
File.open("#{basename}.rb", "w") do |e|
|
26
|
+
anchor = title.downcase.gsub(/ +/, "-")
|
23
27
|
e.write setup
|
28
|
+
e.write "# #{base_url}##{anchor}\n"
|
24
29
|
e.write example
|
25
30
|
e.chmod(0o755)
|
26
31
|
end
|
data/examples/gdbus/gdbus
CHANGED
@@ -119,25 +119,26 @@ class DBusUI
|
|
119
119
|
model = Gtk::ListStore.new(String, String, DBus::Method,
|
120
120
|
DBus::ProxyObjectInterface)
|
121
121
|
@methsigtreeview.model = model
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
122
|
+
return unless selected
|
123
|
+
|
124
|
+
intf = selected[1]
|
125
|
+
return unless intf
|
126
|
+
|
127
|
+
intf.methods.keys.sort.each do |mi|
|
128
|
+
m = intf.methods[mi]
|
129
|
+
subiter = model.append
|
130
|
+
subiter[0] = beautify_method(m)
|
131
|
+
subiter[1] = "M"
|
132
|
+
subiter[2] = m
|
133
|
+
subiter[3] = intf
|
134
|
+
end
|
135
|
+
intf.signals.keys.sort.each do |mi|
|
136
|
+
m = intf.signals[mi]
|
137
|
+
subiter = model.append
|
138
|
+
subiter[0] = beautify_method(m)
|
139
|
+
subiter[1] = "S"
|
140
|
+
subiter[2] = m
|
141
|
+
subiter[3] = intf
|
141
142
|
end
|
142
143
|
end
|
143
144
|
|
@@ -14,7 +14,7 @@ player.test_variant(["s", "coucou"])
|
|
14
14
|
player.on_signal("SomethingJustHappened") do |u, v|
|
15
15
|
puts "SomethingJustHappened: #{u} #{v}"
|
16
16
|
end
|
17
|
-
player.hello("
|
17
|
+
player.hello("Hey", "there!")
|
18
18
|
p player["org.ruby.AnotherInterface"].Reverse("Hello world!")
|
19
19
|
|
20
20
|
main = DBus::Main.new
|
data/lib/dbus/auth.rb
CHANGED
@@ -73,7 +73,7 @@ module DBus
|
|
73
73
|
path = File.join(ENV["HOME"], ".dbus-keyrings", context)
|
74
74
|
DBus.logger.debug "path: #{path.inspect}"
|
75
75
|
File.foreach(path) do |line|
|
76
|
-
if line.
|
76
|
+
if line.start_with?(id)
|
77
77
|
# Right line of file, read cookie
|
78
78
|
cookie = line.split(" ")[2].chomp
|
79
79
|
DBus.logger.debug "cookie: #{cookie.inspect}"
|
@@ -87,14 +87,14 @@ module DBus
|
|
87
87
|
return response
|
88
88
|
end
|
89
89
|
end
|
90
|
+
return if @retries <= 0
|
91
|
+
|
90
92
|
# a little rescue magic
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
data(hexdata)
|
97
|
-
end
|
93
|
+
puts "ERROR: Could not auth, will now exit."
|
94
|
+
puts "ERROR: Unable to locate cookie, retry in 1 second."
|
95
|
+
@retries -= 1
|
96
|
+
sleep 1
|
97
|
+
data(hexdata)
|
98
98
|
end
|
99
99
|
|
100
100
|
# encode plain to hex
|
data/lib/dbus/bus.rb
CHANGED
@@ -17,7 +17,7 @@ require "singleton"
|
|
17
17
|
# Module containing all the D-Bus modules and classes.
|
18
18
|
module DBus
|
19
19
|
# This represents a remote service. It should not be instantiated directly
|
20
|
-
# Use {
|
20
|
+
# Use {Connection#service}
|
21
21
|
class Service
|
22
22
|
# The service name.
|
23
23
|
attr_reader :name
|
@@ -148,20 +148,22 @@ module DBus
|
|
148
148
|
|
149
149
|
# Return an XML string representation of the node.
|
150
150
|
# It is shallow, not recursing into subnodes
|
151
|
-
|
151
|
+
# @param node_opath [String]
|
152
|
+
def to_xml(node_opath)
|
152
153
|
xml = '<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
|
153
154
|
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
154
|
-
<node>
|
155
155
|
'
|
156
|
+
xml += "<node name=\"#{node_opath}\">\n"
|
156
157
|
each_pair do |k, _v|
|
157
|
-
xml += "<node name=\"#{k}\"
|
158
|
+
xml += " <node name=\"#{k}\" />\n"
|
158
159
|
end
|
159
160
|
if @object
|
160
161
|
@object.intfs.each_pair do |_k, v|
|
161
|
-
xml +=
|
162
|
+
xml += " <interface name=\"#{v.name}\">\n"
|
162
163
|
v.methods.each_value { |m| xml += m.to_xml }
|
163
164
|
v.signals.each_value { |m| xml += m.to_xml }
|
164
|
-
xml +=
|
165
|
+
v.properties.each_value { |m| xml += m.to_xml }
|
166
|
+
xml += " </interface>\n"
|
165
167
|
end
|
166
168
|
end
|
167
169
|
xml += "</node>"
|
@@ -532,7 +534,8 @@ module DBus
|
|
532
534
|
m.member == "Introspect"
|
533
535
|
reply = Message.new(Message::METHOD_RETURN).reply_to(m)
|
534
536
|
reply.sender = @unique_name
|
535
|
-
|
537
|
+
xml = node.to_xml(m.path)
|
538
|
+
reply.add_param(Type::STRING, xml)
|
536
539
|
@message_queue.push(reply)
|
537
540
|
else
|
538
541
|
obj = node.object
|
@@ -566,6 +569,11 @@ module DBus
|
|
566
569
|
# @api private
|
567
570
|
# Emit a signal event for the given _service_, object _obj_, interface
|
568
571
|
# _intf_ and signal _sig_ with arguments _args_.
|
572
|
+
# @param service [Service]
|
573
|
+
# @param obj [DBus::Object]
|
574
|
+
# @param intf [Interface]
|
575
|
+
# @param sig [Signal]
|
576
|
+
# @param args arguments for the signal
|
569
577
|
def emit(service, obj, intf, sig, *args)
|
570
578
|
m = Message.new(DBus::Message::SIGNAL)
|
571
579
|
m.path = obj.path
|
@@ -668,7 +676,7 @@ module DBus
|
|
668
676
|
# (for Unix-socket) unix:path=/tmp/my_funky_bus_socket
|
669
677
|
#
|
670
678
|
# you'll need to take care about authentification then, more info here:
|
671
|
-
#
|
679
|
+
# https://gitlab.com/pangdudu/ruby-dbus/-/blob/master/README.rdoc
|
672
680
|
class RemoteBus < Connection
|
673
681
|
# Get the remote bus.
|
674
682
|
def initialize(socket_name)
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# copied from activesupport/core_ext from Rails, MIT license
|
3
3
|
# https://github.com/rails/rails/tree/9794e85351243cac6d4e78adaba634b8e4ecad0a/activesupport/lib/active_support/core_ext
|
4
4
|
|
5
|
-
|
5
|
+
require_relative "../module/redefine_method"
|
6
6
|
|
7
7
|
class Class
|
8
8
|
# Declare a class-level attribute whose value is inheritable by subclasses.
|
data/lib/dbus/introspect.rb
CHANGED
@@ -26,19 +26,23 @@ module DBus
|
|
26
26
|
# It also is the local definition of interface exported by the program.
|
27
27
|
# At the client side, see ProxyObjectInterface
|
28
28
|
class Interface
|
29
|
-
# The name of the interface.
|
29
|
+
# @return [String] The name of the interface.
|
30
30
|
attr_reader :name
|
31
|
-
# The methods that are part of the interface.
|
31
|
+
# @return [Hash{Symbol => DBus::Method}] The methods that are part of the interface.
|
32
32
|
attr_reader :methods
|
33
|
-
# The signals that are part of the interface.
|
33
|
+
# @return [Hash{Symbol => Signal}] The signals that are part of the interface.
|
34
34
|
attr_reader :signals
|
35
35
|
|
36
|
+
# @return [Hash{Symbol => Property}]
|
37
|
+
attr_reader :properties
|
38
|
+
|
36
39
|
# Creates a new interface with a given _name_.
|
37
40
|
def initialize(name)
|
38
41
|
validate_name(name)
|
39
42
|
@name = name
|
40
43
|
@methods = {}
|
41
44
|
@signals = {}
|
45
|
+
@properties = {}
|
42
46
|
end
|
43
47
|
|
44
48
|
# Validates a service _name_.
|
@@ -52,23 +56,31 @@ module DBus
|
|
52
56
|
end
|
53
57
|
end
|
54
58
|
|
55
|
-
#
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
59
|
+
# Add _ie_ as a known {Method}, {Signal} or {Property}
|
60
|
+
# @param ie [InterfaceElement]
|
61
|
+
def define(ie)
|
62
|
+
name = ie.name.to_sym
|
63
|
+
category = if ie.is_a?(Method)
|
64
|
+
@methods
|
65
|
+
elsif ie.is_a?(Signal)
|
66
|
+
@signals
|
67
|
+
elsif ie.is_a?(Property)
|
68
|
+
@properties
|
69
|
+
end
|
70
|
+
category[name] = ie
|
62
71
|
end
|
72
|
+
alias declare define
|
63
73
|
alias << define
|
64
74
|
|
65
75
|
# Defines a method with name _id_ and a given _prototype_ in the
|
66
76
|
# interface.
|
77
|
+
# Better name: declare_method
|
67
78
|
def define_method(id, prototype)
|
68
79
|
m = Method.new(id)
|
69
80
|
m.from_prototype(prototype)
|
70
81
|
define(m)
|
71
82
|
end
|
83
|
+
alias declare_method define_method
|
72
84
|
end # class Interface
|
73
85
|
|
74
86
|
# = A formal parameter has a name and a type
|
@@ -144,6 +156,7 @@ module DBus
|
|
144
156
|
end
|
145
157
|
|
146
158
|
# Add parameter types by parsing the given _prototype_.
|
159
|
+
# @param prototype [Prototype]
|
147
160
|
def from_prototype(prototype)
|
148
161
|
prototype.split(/, */).each do |arg|
|
149
162
|
arg = arg.split(" ")
|
@@ -167,16 +180,16 @@ module DBus
|
|
167
180
|
|
168
181
|
# Return an XML string representation of the method interface elment.
|
169
182
|
def to_xml
|
170
|
-
xml =
|
183
|
+
xml = " <method name=\"#{@name}\">\n"
|
171
184
|
@params.each do |param|
|
172
|
-
name = param.name ?
|
173
|
-
xml +=
|
185
|
+
name = param.name ? "name=\"#{param.name}\" " : ""
|
186
|
+
xml += " <arg #{name}direction=\"in\" type=\"#{param.type}\"/>\n"
|
174
187
|
end
|
175
188
|
@rets.each do |param|
|
176
|
-
name = param.name ?
|
177
|
-
xml +=
|
189
|
+
name = param.name ? "name=\"#{param.name}\" " : ""
|
190
|
+
xml += " <arg #{name}direction=\"out\" type=\"#{param.type}\"/>\n"
|
178
191
|
end
|
179
|
-
xml +=
|
192
|
+
xml += " </method>\n"
|
180
193
|
xml
|
181
194
|
end
|
182
195
|
end # class Method
|
@@ -201,13 +214,49 @@ module DBus
|
|
201
214
|
|
202
215
|
# Return an XML string representation of the signal interface elment.
|
203
216
|
def to_xml
|
204
|
-
xml =
|
217
|
+
xml = " <signal name=\"#{@name}\">\n"
|
205
218
|
@params.each do |param|
|
206
|
-
name = param.name ?
|
207
|
-
xml +=
|
219
|
+
name = param.name ? "name=\"#{param.name}\" " : ""
|
220
|
+
xml += " <arg #{name}type=\"#{param.type}\"/>\n"
|
208
221
|
end
|
209
|
-
xml +=
|
222
|
+
xml += " </signal>\n"
|
210
223
|
xml
|
211
224
|
end
|
212
225
|
end # class Signal
|
226
|
+
|
227
|
+
# An (exported) property
|
228
|
+
# https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties
|
229
|
+
class Property
|
230
|
+
# @return [String] The name of the property, for example FooBar.
|
231
|
+
attr_reader :name
|
232
|
+
attr_reader :type
|
233
|
+
# @return [Symbol] :read :write or :readwrite
|
234
|
+
attr_reader :access
|
235
|
+
|
236
|
+
# @return [Symbol] What to call at Ruby side.
|
237
|
+
# (Always without the trailing `=`)
|
238
|
+
attr_reader :ruby_name
|
239
|
+
|
240
|
+
def initialize(name, type, access, ruby_name:)
|
241
|
+
@name = name
|
242
|
+
@type = type
|
243
|
+
@access = access
|
244
|
+
@ruby_name = ruby_name
|
245
|
+
end
|
246
|
+
|
247
|
+
# @return [Boolean]
|
248
|
+
def readable?
|
249
|
+
access == :read || access == :readwrite
|
250
|
+
end
|
251
|
+
|
252
|
+
# @return [Boolean]
|
253
|
+
def writable?
|
254
|
+
access == :write || access == :readwrite
|
255
|
+
end
|
256
|
+
|
257
|
+
# Return introspection XML string representation of the property.
|
258
|
+
def to_xml
|
259
|
+
" <property type=\"#{@type}\" name=\"#{@name}\" access=\"#{@access}\"/>\n"
|
260
|
+
end
|
261
|
+
end
|
213
262
|
end # module DBus
|
data/lib/dbus/marshall.rb
CHANGED
data/lib/dbus/message_queue.rb
CHANGED
@@ -81,22 +81,23 @@ module DBus
|
|
81
81
|
|
82
82
|
# Connect to a bus over tcp and initialize the connection.
|
83
83
|
def connect_to_tcp(params)
|
84
|
-
|
85
|
-
|
84
|
+
host = params["host"]
|
85
|
+
port = params["port"]
|
86
|
+
if host && port
|
86
87
|
begin
|
87
88
|
# initialize the tcp socket
|
88
|
-
@socket = TCPSocket.new(
|
89
|
+
@socket = TCPSocket.new(host, port.to_i)
|
89
90
|
@socket.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
|
90
91
|
init_connection
|
91
92
|
@is_tcp = true
|
92
93
|
rescue Exception => e
|
93
94
|
puts "Oops:", e
|
94
|
-
puts "Error: Could not establish connection to: #{
|
95
|
+
puts "Error: Could not establish connection to: #{host}:#{port}, will now exit."
|
95
96
|
exit(1) # a little harsh
|
96
97
|
end
|
97
98
|
else
|
98
99
|
# Danger, Will Robinson: the specified "path" is not usable
|
99
|
-
puts "Error: supplied
|
100
|
+
puts "Error: supplied params: #{@params}, unusable! sorry."
|
100
101
|
end
|
101
102
|
end
|
102
103
|
|