Class: DBus::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/dbus/bus.rb

Overview

This represents a remote service. It should not be instancied directly Use Bus::service()

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, bus) ⇒ Service

Create a new service with a given name on a given bus.



29
30
31
32
# File 'lib/dbus/bus.rb', line 29

def initialize(name, bus)
  @name, @bus = name, bus
  @root = Node.new("/")
end

Instance Attribute Details

#busObject (readonly)

The bus the service is running on.



24
25
26
# File 'lib/dbus/bus.rb', line 24

def bus
  @bus
end

#nameObject (readonly)

The service name.



22
23
24
# File 'lib/dbus/bus.rb', line 22

def name
  @name
end

#rootObject (readonly)

The service root (FIXME).



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

def root
  @root
end

Instance Method Details

#exists?Boolean

Determine whether the serice name already exists.

Returns:

  • (Boolean)


35
36
37
# File 'lib/dbus/bus.rb', line 35

def exists?
  bus.proxy.ListName.member?(@name)
end

#export(obj) ⇒ Object

Export an object obj (an DBus::Object subclass instance).



60
61
62
63
# File 'lib/dbus/bus.rb', line 60

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.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/dbus/bus.rb', line 67

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?
    wlog "Unknown object #{path.inspect}"
  end
  n
end

#introspectObject

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



41
42
43
44
45
46
47
48
# File 'lib/dbus/bus.rb', line 41

def introspect
  if block_given?
    raise NotImplementedError
  else
    rec_introspect(@root, "/")
  end
  self
end

#object(path) ⇒ Object

Retrieves an object at the given path.



51
52
53
54
55
56
57
# File 'lib/dbus/bus.rb', line 51

def object(path)
  node = get_node(path, true)
  if node.object.nil?
    node.object = ProxyObject.new(@bus, @name, path)
  end
  node.object
end