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 Bus::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
-
#exists? ⇒ Boolean
Determine whether the service name already exists.
-
#export(obj) ⇒ Object
Export an object obj (an DBus::Object subclass instance).
-
#get_node(path, create = false) ⇒ Object
Get the object node corresponding to the given path.
-
#initialize(name, bus, threaded = false) ⇒ 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) ⇒ Object
Retrieves an object (ProxyObject) at the given path.
- #threaded=(threaded) ⇒ Object
- #threaded? ⇒ Boolean
-
#unexport(obj) ⇒ Object
Undo exporting an object obj.
Constructor Details
Instance Attribute Details
#bus ⇒ Object (readonly)
The bus the service is running on.
28 29 30 |
# File 'lib/dbus/bus.rb', line 28 def bus @bus end |
#name ⇒ Object (readonly)
The service name.
26 27 28 |
# File 'lib/dbus/bus.rb', line 26 def name @name end |
Instance Method Details
#exists? ⇒ Boolean
Determine whether the service name already exists.
48 49 50 |
# File 'lib/dbus/bus.rb', line 48 def exists? bus.proxy.ListNames[0].member?(@name) end |
#export(obj) ⇒ Object
Export an object obj (an DBus::Object subclass instance).
73 74 75 76 |
# File 'lib/dbus/bus.rb', line 73 def export(obj) obj.service = self get_node(obj.path, true).object = obj end |
#get_node(path, create = false) ⇒ Object
Get the object node corresponding to the given path. if create is true, the the nodes in the path are created if they do not already exist.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/dbus/bus.rb', line 96 def get_node(path, create = false) n = @root path.sub(/^\//, "").split("/").each do |elem| if not n[elem] if not create return nil else n[elem] = Node.new(elem) end end n = n[elem] end if n.nil? puts "Warning, unknown object #{path}" if $DEBUG end n end |
#introspect ⇒ Object
Perform an introspection on all the objects on the service (starting recursively from the root).
54 55 56 57 58 59 60 61 |
# File 'lib/dbus/bus.rb', line 54 def introspect if block_given? raise NotImplementedError else rec_introspect(@root, "/") end self end |
#object(path) ⇒ Object
Retrieves an object (ProxyObject) at the given path.
64 65 66 67 68 69 70 |
# File 'lib/dbus/bus.rb', line 64 def object(path) node = get_node(path, true) if node.object.nil? node.object = ProxyObject.new(@bus, @name, path) end node.object end |
#threaded=(threaded) ⇒ Object
43 44 45 |
# File 'lib/dbus/bus.rb', line 43 def threaded=(threaded) @threaded = threaded end |
#threaded? ⇒ Boolean
39 40 41 |
# File 'lib/dbus/bus.rb', line 39 def threaded? return @threaded 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.
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/dbus/bus.rb', line 81 def unexport(obj) raise ArgumentError.new("DBus::Service#unexport() expects a DBus::Object argument") unless obj.kind_of?(DBus::Object) return false unless obj.path pathSep = obj.path.rindex("/") #last path seperator parent_path = obj.path[1..pathSep-1] node_name = obj.path[pathSep+1..-1] parent_node = get_node(parent_path, false) return false unless parent_node obj.service = nil parent_node.delete(node_name) end |