Class: DBus::IntrospectXMLParser

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

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ IntrospectXMLParser

Creates a new parser for XML data in string xml.



228
229
230
# File 'lib/dbus/introspect.rb', line 228

def initialize(xml)
  @xml = xml
end

Instance Method Details

#parseObject

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



243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/dbus/introspect.rb', line 243

def parse
  interfaces = Array.new
  subnodes = Array.new
  t = Time.now
  d = REXML::Document.new(@xml)
  d.elements.each("node/node") do |e|
    subnodes << e.attributes["name"]
  end
  d.elements.each("node/interface") do |e|
    i = Interface.new(e.attributes["name"])
    e.elements.each("method") do |me|
      m = Method.new(me.attributes["name"])
      parse_methsig(me, m)
      i << m
    end
    e.elements.each("signal") do |se|
      s = Signal.new(se.attributes["name"])
      parse_methsig(se, s)
      i << s
    end
    interfaces << i
  end
  d = Time.now - t
  if d > 2
    puts "Some XML took more that two secs to parse. Optimize me!" if $DEBUG
  end
  [interfaces, subnodes]
end

#parse_subnodesObject

return the names of direct subnodes



233
234
235
236
237
238
239
240
# File 'lib/dbus/introspect.rb', line 233

def parse_subnodes
  subnodes = Array.new
  d = REXML::Document.new(@xml)
  d.elements.each("node/node") do |e|
    subnodes << e.attributes["name"]
  end
  subnodes
end