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

Constructor Details

#initialize(name) ⇒ Node

Create a new node with a given name.



195
196
197
198
199
# File 'lib/dbus/bus.rb', line 195

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

Instance Attribute Details

#nameString (readonly)

The name of the node.

Returns:

  • (String)

    the last component of its object path, or “/”



192
193
194
# File 'lib/dbus/bus.rb', line 192

def name
  @name
end

#objectDBus::Object, ...

Returns The D-Bus object contained by the node.

Returns:



188
189
190
# File 'lib/dbus/bus.rb', line 188

def object
  @object
end

Instance Method Details

#descendant_objectsArray<DBus::Object>

All objects (not paths) under this path (except itself).

Returns:



239
240
241
242
243
244
# File 'lib/dbus/bus.rb', line 239

def descendant_objects
  children_objects = values.map(&:object).compact
  descendants = values.map(&:descendant_objects)
  flat_descendants = descendants.reduce([], &:+)
  children_objects + flat_descendants
end

#inspectObject

Return inspect information of the node.



220
221
222
223
# File 'lib/dbus/bus.rb', line 220

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

#sub_inspectObject

Return instance inspect information, used by Node#inspect.



226
227
228
229
230
231
232
233
234
235
# File 'lib/dbus/bus.rb', line 226

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

#to_xml(node_opath) ⇒ Object

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

Parameters:

  • node_opath (String)


204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/dbus/bus.rb', line 204

def to_xml(node_opath)
  xml = '<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
'
  xml += "<node name=\"#{node_opath}\">\n"
  each_key do |k|
    xml += "  <node name=\"#{k}\" />\n"
  end
  @object&.intfs&.each_value do |v|
    xml += v.to_xml
  end
  xml += "</node>"
  xml
end