Class: DBus::Node

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

Overview

Object path node class

Class representing a node on an object path.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Hash

#extractable_options?

Constructor Details

#initialize(name) ⇒ Node

Create a new node with a given name.



147
148
149
150
# File 'lib/dbus/bus.rb', line 147

def initialize(name)
  @name = name
  @object = nil
end

Instance Attribute Details

#nameObject (readonly)

The name of the node.



144
145
146
# File 'lib/dbus/bus.rb', line 144

def name
  @name
end

#objectObject

The D-Bus object contained by the node.



142
143
144
# File 'lib/dbus/bus.rb', line 142

def object
  @object
end

Instance Method Details

#inspectObject

Return inspect information of the node.



175
176
177
178
# File 'lib/dbus/bus.rb', line 175

def inspect
  # Need something here
  "<DBus::Node #{sub_inspect}>"
end

#sub_inspectObject

Return instance inspect information, used by Node#inspect.



181
182
183
184
185
186
187
# File 'lib/dbus/bus.rb', line 181

def sub_inspect
  s = ""
  if not @object.nil?
    s += "%x " % @object.object_id
  end
  s + "{" + keys.collect { |k| "#{k} => #{self[k].sub_inspect}" }.join(",") + "}"
end

#to_xmlObject

Return an XML string representation of the node. It is shallow, not recursing into subnodes



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/dbus/bus.rb', line 154

def to_xml
  xml = '<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
'
  self.each_pair do |k, v|
    xml += "<node name=\"#{k}\" />"
  end
  if @object
    @object.intfs.each_pair do |k, v|
      xml += %{<interface name="#{v.name}">\n}
      v.methods.each_value { |m| xml += m.to_xml }
      v.signals.each_value { |m| xml += m.to_xml }
      xml +="</interface>\n"
    end
  end
  xml += '</node>'
  xml
end