Class: DBus::IntrospectXMLParser

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

Overview

D-Bus introspect XML parser class

This class parses introspection XML of an object and constructs a tree of Node, Interface, Method, Signal instances.

Defined Under Namespace

Classes: AbstractXML, NokogiriParser, REXMLParser

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ IntrospectXMLParser

Creates a new parser for XML data in string xml.

Parameters:

  • xml (String)


32
33
34
# File 'lib/dbus/xml.rb', line 32

def initialize(xml)
  @xml = xml
end

Class Attribute Details

.backendObject

Returns the value of attribute backend.



28
29
30
# File 'lib/dbus/xml.rb', line 28

def backend
  @backend
end

Instance Method Details

#parseArray(Array<Interface>,Array<String>)

Returns a pair: [list of Interfaces, list of direct subnode names].

Returns:

  • (Array(Array<Interface>,Array<String>))

    a pair: [list of Interfaces, list of direct subnode names]



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/dbus/xml.rb', line 112

def parse
  # Using a Hash instead of a list helps merge split-up interfaces,
  # a quirk observed in ModemManager (I#41).
  interfaces = Hash.new do |hash, missing_key|
    hash[missing_key] = Interface.new(missing_key)
  end
  subnodes = []
  t = Time.now

  d = IntrospectXMLParser.backend.new(@xml)
  d.each("node/node") do |e|
    subnodes << e["name"]
  end
  d.each("node/interface") do |e|
    i = interfaces[e["name"]]
    e.each("method") do |me|
      m = Method.new(me["name"])
      parse_methsig(me, m)
      i << m
    end
    e.each("signal") do |se|
      s = Signal.new(se["name"])
      parse_methsig(se, s)
      i << s
    end
    e.each("property") do |pe|
      p = Property.from_xml(pe)
      i << p
    end
  end
  d = Time.now - t
  if d > 2
    DBus.logger.debug "Some XML took more that two secs to parse. Optimize me!"
  end
  [interfaces.values, subnodes]
end