Class: DBus::Method
- Inherits:
-
InterfaceElement
- Object
- InterfaceElement
- DBus::Method
- Defined in:
- lib/dbus/introspect.rb
Overview
D-Bus interface method class
This is a class representing methods that are part of an interface.
Instance Attribute Summary collapse
-
#rets ⇒ Object
readonly
The list of return values for the method.
Attributes inherited from InterfaceElement
Instance Method Summary collapse
-
#add_return(name, signature) ⇒ Object
Add a return value name and signature.
-
#from_prototype(prototype) ⇒ Object
Add parameter types by parsing the given prototype.
-
#initialize(name) ⇒ Method
constructor
Creates a new method interface element with the given name.
-
#to_xml ⇒ Object
Return an XML string representation of the method interface elment.
Methods inherited from InterfaceElement
#add_fparam, #add_param, #validate_name
Constructor Details
Instance Attribute Details
#rets ⇒ Object (readonly)
The list of return values for the method. Array: FormalParameter
138 139 140 |
# File 'lib/dbus/introspect.rb', line 138 def rets @rets end |
Instance Method Details
#add_return(name, signature) ⇒ Object
Add a return value name and signature.
147 148 149 |
# File 'lib/dbus/introspect.rb', line 147 def add_return(name, signature) @rets << FormalParameter.new(name, signature) end |
#from_prototype(prototype) ⇒ Object
Add parameter types by parsing the given prototype.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/dbus/introspect.rb', line 152 def from_prototype(prototype) prototype.split(/, */).each do |arg| arg = arg.split(" ") raise InvalidClassDefinition if arg.size != 2 dir, arg = arg if arg =~ /:/ arg = arg.split(":") name, sig = arg else sig = arg end case dir when "in" add_fparam(name, sig) when "out" add_return(name, sig) end end self end |
#to_xml ⇒ Object
Return an XML string representation of the method interface elment.
174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/dbus/introspect.rb', line 174 def to_xml xml = %{<method name="#{@name}">\n} @params.each do |param| name = param.name ? %{name="#{param.name}" } : "" xml += %{<arg #{name}direction="in" type="#{param.type}"/>\n} end @rets.each do |param| name = param.name ? %{name="#{param.name}" } : "" xml += %{<arg #{name}direction="out" type="#{param.type}"/>\n} end xml += %{</method>\n} xml end |