# class DBus::Service

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

### Attributes

bus[R]

The bus the service is running on.

name[R]

The service name.

root[R]

The service root (FIXME).

### Public Class Methods

new(name, bus) click to toggle source

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

    # File lib/dbus/bus.rb, line 30
    def initialize(name, bus)
      @name = name
      @bus = bus
      @root = Node.new("/")
    end

### Public Instance Methods

[](path) click to toggle source

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

    # File lib/dbus/bus.rb, line 52
    def [](path)
      object(path, api: ApiOptions::A1)
    end

exists?() click to toggle source

Determine whether the service name already exists.

    # File lib/dbus/bus.rb, line 37
    def exists?
      bus.proxy.ListNames[0].member?(@name)
    end

export(obj) click to toggle source

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

    # File lib/dbus/bus.rb, line 71
    def export(obj)
      obj.service = self
      get_node(obj.path, true).object = obj
    end

get_node(path, create = false) click to toggle source

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.

    # File lib/dbus/bus.rb, line 94
    def get_node(path, create = false)
      n = @root
      path.sub(%r{^/}, "").split("/").each do |elem|
        if !(n[elem])
          return nil if !create
          n[elem] = Node.new(elem)
        end
        n = n[elem]
      end
      if n.nil?
        DBus.logger.debug "Warning, unknown object #{path}"
      end
      n
    end

introspect() click to toggle source

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

    # File lib/dbus/bus.rb, line 43
    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. @return [ProxyObject]

    # File lib/dbus/bus.rb, line 59
    def object(path, api: ApiOptions::A0)
      node = get_node(path, _create = true)
      if node.object.nil? || node.object.api != api
        node.object = ProxyObject.new(
          @bus, @name, path,
          api: api
        )
      end
      node.object
    end

unexport(obj) click to toggle source

Undo exporting an object obj. Raises ArgumentError if it is not a DBus::Object. Returns the object, or false if obj was not exported.

    # File lib/dbus/bus.rb, line 79
    def unexport(obj)
      raise ArgumentError, "DBus::Service#unexport() expects a DBus::Object argument" unless obj.is_a?(DBus::Object)
      return false unless obj.path
      last_path_separator_idx = obj.path.rindex("/")
      parent_path = obj.path[1..last_path_separator_idx - 1]
      node_name = obj.path[last_path_separator_idx + 1..-1]

      parent_node = get_node(parent_path, false)
      return false unless parent_node
      obj.service = nil
      parent_node.delete(node_name).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/bus.rb, line 117
    def rec_introspect(node, path)
      xml = bus.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, @bus, @name, path).build
    end