Class: DBus::ProxyService

Inherits:
NodeTree show all
Defined in:
lib/dbus/proxy_service.rb

Overview

Used by clients to represent a named service on the other side of the bus.

Formerly this class was intermixed with ObjectServer as Service.

Examples:

Usage

svc = DBus.system_bus["org.freedesktop.machine1"]
manager = svc["/org/freedesktop/machine1"]
p manager.ListImages

Direct Known Subclasses

ProxyPeerService

Instance Attribute Summary collapse

Attributes inherited from NodeTree

#root

Instance Method Summary collapse

Methods inherited from NodeTree

#get_node

Constructor Details

#initialize(name, connection) ⇒ ProxyService

Returns a new instance of ProxyService.

Parameters:

  • connection (Connection)

    The connection we’re using.



31
32
33
34
35
# File 'lib/dbus/proxy_service.rb', line 31

def initialize(name, connection)
  @name = BusName.new(name)
  @connection = connection
  super()
end

Instance Attribute Details

#connectionConnection (readonly)

Returns The connection we’re using.

Returns:



28
29
30
# File 'lib/dbus/proxy_service.rb', line 28

def connection
  @connection
end

#nameBusName? (readonly)

Will be nil for a DBus::PeerConnection

Returns:

  • (BusName, nil)

    The service name.



26
27
28
# File 'lib/dbus/proxy_service.rb', line 26

def name
  @name
end

Instance Method Details

#[](path) ⇒ ProxyObject

Retrieves an object at the given path.

Parameters:

Returns:



55
56
57
# File 'lib/dbus/proxy_service.rb', line 55

def [](path)
  object(path, api: ApiOptions::A1)
end

#exists?Boolean

Determine whether the service name already exists.

Returns:

  • (Boolean)


38
39
40
41
# 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

#introspectObject

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

Raises:

  • (NotImplementedError)


45
46
47
48
49
50
# 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) ⇒ ProxyObject

Retrieves an object at the given path whose methods always return an array.

Parameters:

Returns:



64
65
66
67
68
69
70
71
72
73
# 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