Class: DBus::Service
- Inherits:
-
Object
- Object
- DBus::Service
- Defined in:
- lib/dbus/bus.rb
Overview
This represents a remote service. It should not be instantiated directly Use Connection#service
Instance Attribute Summary collapse
-
#bus ⇒ Object
readonly
The bus the service is running on.
-
#name ⇒ Object
readonly
The service name.
-
#root ⇒ Object
readonly
The service root (FIXME).
Instance Method Summary collapse
-
#[](path) ⇒ ProxyObject
Retrieves an object at the given path.
-
#exists? ⇒ Boolean
Determine whether the service name already exists.
-
#export(obj) ⇒ Object
Export an object.
-
#get_node(path, create: false) ⇒ Node?
Get the object node corresponding to the given path.
-
#initialize(name, bus) ⇒ Service
constructor
Create a new service with a given name on a given bus.
-
#introspect ⇒ Object
Perform an introspection on all the objects on the service (starting recursively from the root).
-
#object(path, api: ApiOptions::A0) ⇒ ProxyObject
Retrieves an object at the given path whose methods always return an array.
-
#unexport(obj) ⇒ Object
Undo exporting an object obj.
Constructor Details
Instance Attribute Details
#bus ⇒ Object (readonly)
The bus the service is running on.
26 27 28 |
# File 'lib/dbus/bus.rb', line 26 def bus @bus end |
#name ⇒ Object (readonly)
The service name.
24 25 26 |
# File 'lib/dbus/bus.rb', line 24 def name @name end |
Instance Method Details
#[](path) ⇒ ProxyObject
Retrieves an object at the given path.
54 55 56 |
# File 'lib/dbus/bus.rb', line 54 def [](path) object(path, api: ApiOptions::A1) end |
#exists? ⇒ Boolean
Determine whether the service name already exists.
38 39 40 |
# File 'lib/dbus/bus.rb', line 38 def exists? bus.proxy.ListNames[0].member?(@name) end |
#export(obj) ⇒ Object
Export an object
76 77 78 79 |
# File 'lib/dbus/bus.rb', line 76 def export(obj) obj.service = self get_node(obj.path, create: true).object = obj end |
#get_node(path, create: false) ⇒ Node?
Get the object node corresponding to the given path.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/dbus/bus.rb', line 105 def get_node(path, create: false) n = @root path.sub(%r{^/}, "").split("/").each do |elem| if !(n[elem]) return nil if !create n[elem] = Node.new(elem) end n = n[elem] end if n.nil? DBus.logger.debug "Warning, unknown object #{path}" end n end |
#introspect ⇒ Object
Perform an introspection on all the objects on the service (starting recursively from the root).
44 45 46 47 48 49 |
# File 'lib/dbus/bus.rb', line 44 def introspect raise NotImplementedError if block_given? rec_introspect(@root, "/") self end |
#object(path, api: ApiOptions::A0) ⇒ ProxyObject
Retrieves an object at the given path whose methods always return an array.
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/dbus/bus.rb', line 63 def object(path, api: ApiOptions::A0) node = get_node(path, create: true) if node.object.nil? || node.object.api != api node.object = ProxyObject.new( @bus, @name, path, api: api ) end node.object end |
#unexport(obj) ⇒ Object
Undo exporting an object obj. Raises ArgumentError if it is not a DBus::Object. Returns the object, or false if obj was not exported.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/dbus/bus.rb', line 85 def unexport(obj) raise ArgumentError, "DBus::Service#unexport() expects a DBus::Object argument" unless obj.is_a?(DBus::Object) return false unless obj.path last_path_separator_idx = obj.path.rindex("/") parent_path = obj.path[1..last_path_separator_idx - 1] node_name = obj.path[last_path_separator_idx + 1..-1] parent_node = get_node(parent_path, create: false) return false unless parent_node obj.service = nil parent_node.delete(node_name).object end |