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

connection[R]

@return [Connection] The connection we’re using.

name[R]

@return [BusName,nil] The service name. Will be nil for a {PeerConnection}

Public Class Methods

new(name, connection) click to toggle source

@param connection [Connection] The connection we’re using.

Calls superclass method DBus::NodeTree::new
# File lib/dbus/proxy_service.rb, line 31
def initialize(name, connection)
  @name = BusName.new(name)
  @connection = connection
  super()
end

Public Instance Methods

[](path) click to toggle source

Retrieves an object at the given path. @param path [ObjectPath] @return [ProxyObject]

# File lib/dbus/proxy_service.rb, line 55
def [](path)
  object(path, api: ApiOptions::A1)
end
exists?() click to toggle source

Determine whether the service name already exists.

# File lib/dbus/proxy_service.rb, line 38
def exists?
  bus = connection # TODO: raise a better error if this is a peer connection
  bus.proxy.ListNames[0].member?(@name)
end
introspect() click to toggle source

Perform an introspection on all the objects on the service (starting recursively from the root).

# File lib/dbus/proxy_service.rb, line 45
def introspect
  raise NotImplementedError if block_given?

  rec_introspect(@root, "/")
  self
end
object(path, api: ApiOptions::A0) click to toggle source

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, line 64
def object(path, api: ApiOptions::A0)
  node = get_node(path, create: true)
  if node.object.nil? || node.object.api != api
    node.object = ProxyObject.new(
      @connection, @name, path,
      api: api
    )
  end
  node.object
end

Private Instance Methods

rec_introspect(node, path) click to toggle source

Perform a recursive retrospection on the given current node on the given path.

# File lib/dbus/proxy_service.rb, line 79
def rec_introspect(node, path)
  xml = connection.introspect_data(@name, path)
  intfs, subnodes = IntrospectXMLParser.new(xml).parse
  subnodes.each do |nodename|
    subnode = node[nodename] = Node.new(nodename)
    subpath = if path == "/"
                "/#{nodename}"
              else
                "#{path}/#{nodename}"
              end
    rec_introspect(subnode, subpath)
  end
  return if intfs.empty?

  node.object = ProxyObjectFactory.new(xml, @connection, @name, path).build
end