Class: DBus::Node

Inherits:
Hash
  • Object
show all
Defined in:
lib/dbus/node_tree.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.



54
55
56
57
58
# File 'lib/dbus/node_tree.rb', line 54

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 “/”



51
52
53
# File 'lib/dbus/node_tree.rb', line 51

def name
  @name
end

#objectDBus::Object, ...

Returns The D-Bus object contained by the node.

Returns:



47
48
49
# File 'lib/dbus/node_tree.rb', line 47

def object
  @object
end

Instance Method Details

#descendant_objectsArray<DBus::Object>

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

Returns:



98
99
100
101
102
103
# File 'lib/dbus/node_tree.rb', line 98

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.



79
80
81
82
# File 'lib/dbus/node_tree.rb', line 79

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

#sub_inspectObject

Return instance inspect information, used by Node#inspect.



85
86
87
88
89
90
91
92
93
94
# File 'lib/dbus/node_tree.rb', line 85

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)


63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/dbus/node_tree.rb', line 63

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