class DBus::IntrospectXMLParser

D-Bus introspect XML parser class

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

Attributes

backend[RW]

Public Class Methods

new(xml) click to toggle source

Creates a new parser for XML data in string xml.

   # File lib/dbus/xml.rb
29 def initialize(xml)
30   @xml = xml
31 end

Public Instance Methods

parse() click to toggle source

@return [Array(Array<Interface>,Array<String>)]

a pair: [list of Interfaces, list of direct subnode names]
    # File lib/dbus/xml.rb
103 def parse
104   # Using a Hash instead of a list helps merge split-up interfaces,
105   # a quirk observed in ModemManager (I#41).
106   interfaces = Hash.new do |hash, missing_key|
107     hash[missing_key] = Interface.new(missing_key)
108   end
109   subnodes = []
110   t = Time.now
111 
112   d = IntrospectXMLParser.backend.new(@xml)
113   d.each("node/node") do |e|
114     subnodes << e["name"]
115   end
116   d.each("node/interface") do |e|
117     i = interfaces[e["name"]]
118     e.each("method") do |me|
119       m = Method.new(me["name"])
120       parse_methsig(me, m)
121       i << m
122     end
123     e.each("signal") do |se|
124       s = Signal.new(se["name"])
125       parse_methsig(se, s)
126       i << s
127     end
128   end
129   d = Time.now - t
130   if d > 2
131     DBus.logger.debug "Some XML took more that two secs to parse. Optimize me!"
132   end
133   [interfaces.values, subnodes]
134 end

Private Instance Methods

parse_methsig(e, m) click to toggle source

Parses a method signature XML element e and initialises method/signal m.

    # File lib/dbus/xml.rb
141 def parse_methsig(e, m)
142   e.each("arg") do |ae|
143     name = ae["name"]
144     dir = ae["direction"]
145     sig = ae["type"]
146     if m.is_a?(DBus::Signal)
147       # Direction can only be "out", ignore it
148       m.add_fparam(name, sig)
149     elsif m.is_a?(DBus::Method)
150       case dir
151       # This is a method, so dir defaults to "in"
152       when "in", nil
153         m.add_fparam(name, sig)
154       when "out"
155         m.add_return(name, sig)
156       end
157     else
158       raise NotImplementedError, dir
159     end
160   end
161 end