class DBus::Service
This represents a remote service. It should not be instantiated directly Use Bus::service()
Attributes
The bus the service is running on.
The service name.
The service root (FIXME).
Public Class Methods
Create a new service with a given name on a given bus.
# File lib/dbus/bus.rb, line 33 def initialize(name, bus,threaded = false) @name, @bus = name, bus @threaded = threaded @root = Node.new("/") end
Public Instance Methods
Determine whether the service name already exists.
# File lib/dbus/bus.rb, line 48 def exists? bus.proxy.ListNames[0].member?(@name) end
Export an object obj (an DBus::Object
subclass instance).
# File lib/dbus/bus.rb, line 73 def export(obj) obj.service = self get_node(obj.path, true).object = obj end
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.
# 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
Perform an introspection on all the objects on the service (starting recursively from the root).
# File lib/dbus/bus.rb, line 54 def introspect if block_given? raise NotImplementedError else rec_introspect(@root, "/") end self end
Retrieves an object (ProxyObject
) at the given path.
# 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
# File lib/dbus/bus.rb, line 43 def threaded=(threaded) @threaded = threaded end
# File lib/dbus/bus.rb, line 39 def threaded? return @threaded end
Undo exporting an object obj. Raises ArgumentError if it is not a DBus::Object
. Returns the object, or false if obj was not exported.
# 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
Private Instance Methods
Perform a recursive retrospection on the given current node on the given path.
# File lib/dbus/bus.rb, line 120 def rec_introspect(node, path) xml = bus.introspect_data(@name, path) intfs, subnodes = IntrospectXMLParser.new(xml).parse subnodes.each do |nodename| subnode = node[nodename] = Node.new(nodename) if path == "/" subpath = "/" + nodename else subpath = path + "/" + nodename end rec_introspect(subnode, subpath) end if intfs.size > 0 node.object = ProxyObjectFactory.new(xml, @bus, @name, path).build end end