class DBus::ProxyService
Used by clients to represent a named service on the other side of the bus.
Formerly this class was intermixed with {ObjectServer} as Service.
@example Usage
svc = DBus.system_bus["org.freedesktop.machine1"] manager = svc["/org/freedesktop/machine1"] p manager.ListImages
Attributes
@return [Connection] The connection we’re using.
@return [BusName,nil] The service name. Will be nil for a {PeerConnection}
Public Class Methods
@param connection [Connection] The connection we’re using.
DBus::NodeTree::new
# File lib/dbus/proxy_service.rb 31 def initialize(name, connection) 32 @name = BusName.new(name) 33 @connection = connection 34 super() 35 end
Public Instance Methods
Retrieves an object at the given path. @param path [ObjectPath] @return [ProxyObject]
# File lib/dbus/proxy_service.rb 55 def [](path) 56 object(path, api: ApiOptions::A1) 57 end
Determine whether the service name already exists.
# File lib/dbus/proxy_service.rb 38 def exists? 39 bus = connection # TODO: raise a better error if this is a peer connection 40 bus.proxy.ListNames[0].member?(@name) 41 end
Perform an introspection on all the objects on the service (starting recursively from the root).
# File lib/dbus/proxy_service.rb 45 def introspect 46 raise NotImplementedError if block_given? 47 48 rec_introspect(@root, "/") 49 self 50 end
Retrieves an object at the given path whose methods always return an array. @param path [ObjectPath] @param api [ApiOptions] @return [ProxyObject]
# File lib/dbus/proxy_service.rb 64 def object(path, api: ApiOptions::A0) 65 node = get_node(path, create: true) 66 if node.object.nil? || node.object.api != api 67 node.object = ProxyObject.new( 68 @connection, @name, path, 69 api: api 70 ) 71 end 72 node.object 73 end
Private Instance Methods
Perform a recursive retrospection on the given current node on the given path.
# File lib/dbus/proxy_service.rb 79 def rec_introspect(node, path) 80 xml = connection.introspect_data(@name, path) 81 intfs, subnodes = IntrospectXMLParser.new(xml).parse 82 subnodes.each do |nodename| 83 subnode = node[nodename] = Node.new(nodename) 84 subpath = if path == "/" 85 "/#{nodename}" 86 else 87 "#{path}/#{nodename}" 88 end 89 rec_introspect(subnode, subpath) 90 end 91 return if intfs.empty? 92 93 node.object = ProxyObjectFactory.new(xml, @connection, @name, path).build 94 end