ruby-dbus 0.14.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 +5 -5
- data/NEWS.md +44 -0
- data/README.md +3 -5
- data/Rakefile +26 -8
- data/VERSION +1 -1
- data/doc/Reference.md +84 -1
- data/examples/doc/_extract_examples +5 -0
- data/examples/gdbus/gdbus +21 -20
- data/examples/service/call_service.rb +1 -1
- data/lib/dbus/auth.rb +8 -8
- data/lib/dbus/bus.rb +23 -11
- data/lib/dbus/bus_name.rb +27 -0
- data/lib/dbus/core_ext/class/attribute.rb +23 -41
- data/lib/dbus/core_ext/module/redefine_method.rb +51 -0
- data/lib/dbus/introspect.rb +71 -26
- data/lib/dbus/marshall.rb +2 -1
- data/lib/dbus/message_queue.rb +17 -14
- data/lib/dbus/object.rb +380 -0
- data/lib/dbus/object_path.rb +24 -0
- data/lib/dbus/proxy_object.rb +11 -2
- data/lib/dbus/proxy_object_interface.rb +1 -0
- data/lib/dbus/type.rb +18 -0
- data/lib/dbus/xml.rb +4 -8
- data/lib/dbus.rb +3 -2
- data/ruby-dbus.gemspec +11 -9
- data/spec/binding_spec.rb +6 -2
- data/spec/bus_name_spec.rb +25 -0
- data/spec/client_robustness_spec.rb +25 -0
- data/spec/introspect_xml_parser_spec.rb +13 -13
- data/spec/main_loop_spec.rb +1 -1
- data/spec/object_path_spec.rb +23 -0
- data/spec/property_spec.rb +53 -3
- data/spec/proxy_object_spec.rb +9 -0
- data/spec/service_newapi.rb +20 -66
- data/spec/session_bus_spec.rb +6 -6
- data/spec/signal_spec.rb +33 -18
- data/spec/spec_helper.rb +23 -11
- data/spec/tools/dbus-limited-session.conf +4 -0
- data/spec/type_spec.rb +2 -2
- metadata +32 -15
- data/lib/dbus/core_ext/array/extract_options.rb +0 -31
- data/lib/dbus/core_ext/kernel/singleton_class.rb +0 -8
- data/lib/dbus/core_ext/module/remove_method.rb +0 -14
- data/lib/dbus/export.rb +0 -130
data/lib/dbus/export.rb
DELETED
@@ -1,130 +0,0 @@
|
|
1
|
-
# dbus/introspection.rb - module containing a low-level D-Bus introspection implementation
|
2
|
-
#
|
3
|
-
# This file is part of the ruby-dbus project
|
4
|
-
# Copyright (C) 2007 Arnaud Cornet and Paul van Tilburg
|
5
|
-
#
|
6
|
-
# This library is free software; you can redistribute it and/or
|
7
|
-
# modify it under the terms of the GNU Lesser General Public
|
8
|
-
# License, version 2.1 as published by the Free Software Foundation.
|
9
|
-
# See the file "COPYING" for the exact licensing terms.
|
10
|
-
|
11
|
-
require "thread"
|
12
|
-
|
13
|
-
module DBus
|
14
|
-
# Exported object type
|
15
|
-
# = Exportable D-Bus object class
|
16
|
-
#
|
17
|
-
# Objects that are going to be exported by a D-Bus service
|
18
|
-
# should inherit from this class. At the client side, use ProxyObject.
|
19
|
-
class Object
|
20
|
-
# The path of the object.
|
21
|
-
attr_reader :path
|
22
|
-
# The interfaces that the object supports. Hash: String => Interface
|
23
|
-
class_attribute :intfs
|
24
|
-
self.intfs = {}
|
25
|
-
|
26
|
-
# The service that the object is exported by.
|
27
|
-
attr_writer :service
|
28
|
-
|
29
|
-
@@cur_intf = nil # Interface
|
30
|
-
@@intfs_mutex = Mutex.new
|
31
|
-
|
32
|
-
# Create a new object with a given _path_.
|
33
|
-
# Use Service#export to export it.
|
34
|
-
def initialize(path)
|
35
|
-
@path = path
|
36
|
-
@service = nil
|
37
|
-
end
|
38
|
-
|
39
|
-
# Dispatch a message _msg_ to call exported methods
|
40
|
-
def dispatch(msg)
|
41
|
-
case msg.message_type
|
42
|
-
when Message::METHOD_CALL
|
43
|
-
reply = nil
|
44
|
-
begin
|
45
|
-
if !intfs[msg.interface]
|
46
|
-
raise DBus.error("org.freedesktop.DBus.Error.UnknownMethod"),
|
47
|
-
"Interface \"#{msg.interface}\" of object \"#{msg.path}\" doesn't exist"
|
48
|
-
end
|
49
|
-
meth = intfs[msg.interface].methods[msg.member.to_sym]
|
50
|
-
if !meth
|
51
|
-
raise DBus.error("org.freedesktop.DBus.Error.UnknownMethod"),
|
52
|
-
"Method \"#{msg.member}\" on interface \"#{msg.interface}\" of object \"#{msg.path}\" doesn't exist"
|
53
|
-
end
|
54
|
-
methname = Object.make_method_name(msg.interface, msg.member)
|
55
|
-
retdata = method(methname).call(*msg.params)
|
56
|
-
retdata = [*retdata]
|
57
|
-
|
58
|
-
reply = Message.method_return(msg)
|
59
|
-
meth.rets.zip(retdata).each do |rsig, rdata|
|
60
|
-
reply.add_param(rsig.type, rdata)
|
61
|
-
end
|
62
|
-
rescue => ex
|
63
|
-
dbus_msg_exc = msg.annotate_exception(ex)
|
64
|
-
reply = ErrorMessage.from_exception(dbus_msg_exc).reply_to(msg)
|
65
|
-
end
|
66
|
-
@service.bus.message_queue.push(reply)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
# Select (and create) the interface that the following defined methods
|
71
|
-
# belong to.
|
72
|
-
def self.dbus_interface(s)
|
73
|
-
@@intfs_mutex.synchronize do
|
74
|
-
@@cur_intf = intfs[s]
|
75
|
-
if !@@cur_intf
|
76
|
-
@@cur_intf = Interface.new(s)
|
77
|
-
# As this is a mutable class_attr, we cannot use
|
78
|
-
# self.intfs[s] = @@cur_intf # Hash#[]=
|
79
|
-
# as that would modify parent class attr in place.
|
80
|
-
# Using the setter lets a subclass have the new value
|
81
|
-
# while the superclass keeps the old one.
|
82
|
-
self.intfs = intfs.merge(s => @@cur_intf)
|
83
|
-
end
|
84
|
-
yield
|
85
|
-
@@cur_intf = nil
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
# Dummy undefined interface class.
|
90
|
-
class UndefinedInterface < ScriptError
|
91
|
-
def initialize(sym)
|
92
|
-
super "No interface specified for #{sym}"
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
# Defines an exportable method on the object with the given name _sym_,
|
97
|
-
# _prototype_ and the code in a block.
|
98
|
-
def self.dbus_method(sym, protoype = "", &block)
|
99
|
-
raise UndefinedInterface, sym if @@cur_intf.nil?
|
100
|
-
@@cur_intf.define(Method.new(sym.to_s).from_prototype(protoype))
|
101
|
-
define_method(Object.make_method_name(@@cur_intf.name, sym.to_s), &block)
|
102
|
-
end
|
103
|
-
|
104
|
-
# Emits a signal from the object with the given _interface_, signal
|
105
|
-
# _sig_ and arguments _args_.
|
106
|
-
def emit(intf, sig, *args)
|
107
|
-
@service.bus.emit(@service, self, intf, sig, *args)
|
108
|
-
end
|
109
|
-
|
110
|
-
# Defines a signal for the object with a given name _sym_ and _prototype_.
|
111
|
-
def self.dbus_signal(sym, protoype = "")
|
112
|
-
raise UndefinedInterface, sym if @@cur_intf.nil?
|
113
|
-
cur_intf = @@cur_intf
|
114
|
-
signal = Signal.new(sym.to_s).from_prototype(protoype)
|
115
|
-
cur_intf.define(Signal.new(sym.to_s).from_prototype(protoype))
|
116
|
-
define_method(sym.to_s) do |*args|
|
117
|
-
emit(cur_intf, signal, *args)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
####################################################################
|
122
|
-
|
123
|
-
# Helper method that returns a method name generated from the interface
|
124
|
-
# name _intfname_ and method name _methname_.
|
125
|
-
# @api private
|
126
|
-
def self.make_method_name(intfname, methname)
|
127
|
-
"#{intfname}%%#{methname}"
|
128
|
-
end
|
129
|
-
end # class Object
|
130
|
-
end # module DBus
|