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.



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

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

Instance Attribute Details

#busObject (readonly)

The bus the service is running on.



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

def bus
  @bus
end

#nameObject (readonly)

The service name.



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

def name
  @name
end

#rootObject (readonly)

The service root (FIXME).



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

def root
  @root
end

Instance Method Details

#exists?Boolean

Determine whether the serice name already exists.

Returns:

  • (Boolean)


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

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

#export(obj) ⇒ Object

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



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

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.



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

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

#introspectObject

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



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

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

#object(path) ⇒ Object

Retrieves an object at the given path.



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

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