# 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. @param xml [String]

       # File lib/dbus/xml.rb
    38 def initialize(xml)
    39   @xml = xml
    40 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
    118 def parse
    119   # Using a Hash instead of a list helps merge split-up interfaces,
    120   # a quirk observed in ModemManager (I#41).
    121   interfaces = Hash.new do |hash, missing_key|
    122     hash[missing_key] = Interface.new(missing_key)
    123   end
    124   subnodes = []
    125   t = Time.now
    126
    127   d = IntrospectXMLParser.backend.new(@xml)
    128   d.each("node/node") do |e|
    129     subnodes << e["name"]
    130   end
    131   d.each("node/interface") do |e|
    132     i = interfaces[e["name"]]
    133     e.each("method") do |me|
    134       m = Method.new(me["name"])
    135       parse_methsig(me, m)
    136       i << m
    137     end
    138     e.each("signal") do |se|
    139       s = Signal.new(se["name"])
    140       parse_methsig(se, s)
    141       i << s
    142     end
    143     e.each("property") do |pe|
    144       p = Property.from_xml(pe)
    145       i << p
    146     end
    147   end
    148   d = Time.now - t
    149   if d > 2
    150     DBus.logger.debug "Some XML took more that two secs to parse. Optimize me!"
    151   end
    152   [interfaces.values, subnodes]
    153 end

### Private Instance Methods

parse_methsig(elem, methsig) click to toggle source

Parses a method signature XML element elem and initialises method/signal methsig. @param elem [AbstractXML::Node]

        # File lib/dbus/xml.rb
    161 def parse_methsig(elem, methsig)
    162   elem.each("arg") do |ae|
    163     name = ae["name"]
    164     dir = ae["direction"]
    165     sig = ae["type"]
    166     case methsig
    167     when DBus::Signal
    168       # Direction can only be "out", ignore it
    169       methsig.add_fparam(name, sig)
    170     when DBus::Method
    171       case dir
    172       # This is a method, so dir defaults to "in"
    173       when "in", nil
    174         methsig.add_fparam(name, sig)
    175       when "out"
    176         methsig.add_return(name, sig)
    177       end
    178     else
    179       raise NotImplementedError, dir
    180     end
    181   end
    182 end