Class: DBus::Method

Inherits:
InterfaceElement show all
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

Attributes inherited from InterfaceElement

#name, #params

Instance Method Summary collapse

Methods inherited from InterfaceElement

#add_fparam, #add_param, #validate_name

Constructor Details

#initialize(name) ⇒ Method

Creates a new method interface element with the given name.



185
186
187
188
# File 'lib/dbus/introspect.rb', line 185

def initialize(name)
  super(name)
  @rets = []
end

Instance Attribute Details

#retsArray<FormalParameter> (readonly)

Returns The list of return values for the method.

Returns:



182
183
184
# File 'lib/dbus/introspect.rb', line 182

def rets
  @rets
end

Instance Method Details

#add_return(name, signature) ⇒ Object

Add a return value name and signature.

Parameters:



193
194
195
# File 'lib/dbus/introspect.rb', line 193

def add_return(name, signature)
  @rets << FormalParameter.new(name, signature)
end

#from_prototype(prototype) ⇒ Object

Add parameter types by parsing the given prototype.

Parameters:



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/dbus/introspect.rb', line 199

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_xmlString

Return an XML string representation of the method interface elment.

Returns:

  • (String)


223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/dbus/introspect.rb', line 223

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