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