Class: DBus::ProxyObjectInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/dbus/introspect.rb

Overview

D-Bus proxy object interface class

A class similar to the normal Interface used as a proxy for remote object interfaces.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, name) ⇒ ProxyObjectInterface

Creates a new proxy interface for the given proxy object and the given name.



287
288
289
290
# File 'lib/dbus/introspect.rb', line 287

def initialize(object, name)
  @object, @name = object, name
  @methods, @signals = Hash.new, Hash.new
end

Instance Attribute Details

#methodsObject

The proxied methods contained in the interface.



277
278
279
# File 'lib/dbus/introspect.rb', line 277

def methods
  @methods
end

#nameObject (readonly)

The name of the interface.



283
284
285
# File 'lib/dbus/introspect.rb', line 283

def name
  @name
end

#objectObject (readonly)

The proxy object to which this interface belongs.



281
282
283
# File 'lib/dbus/introspect.rb', line 281

def object
  @object
end

#signalsObject

The proxied signals contained in the interface.



279
280
281
# File 'lib/dbus/introspect.rb', line 279

def signals
  @signals
end

Instance Method Details

#check_for_eval(s) ⇒ Object

FIXME

Raises:

  • (RuntimeException)


303
304
305
# File 'lib/dbus/introspect.rb', line 303

def check_for_eval(s)
  raise RuntimeException, "invalid internal data" if not s.to_s =~ /^[A-Za-z0-9_]*$/
end

#check_for_quoted_eval(s) ⇒ Object

FIXME

Raises:

  • (RuntimeException)


308
309
310
# File 'lib/dbus/introspect.rb', line 308

def check_for_quoted_eval(s)
  raise RuntimeException, "invalid internal data" if not s.to_s =~ /^[^"]+$/
end

#define(m) ⇒ Object

Defines a signal or method based on the descriptor m.



374
375
376
377
378
379
380
# File 'lib/dbus/introspect.rb', line 374

def define(m)
  if m.kind_of?(Method)
    define_method_from_descriptor(m)
  elsif m.kind_of?(Signal)
    define_signal_from_descriptor(m)
  end
end

#define_method(methodname, prototype) ⇒ Object

Defines a proxied method on the interface.



383
384
385
386
387
# File 'lib/dbus/introspect.rb', line 383

def define_method(methodname, prototype)
  m = Method.new(methodname)
  m.from_prototype(prototype)
  define(m)
end

#define_method_from_descriptor(m) ⇒ Object

Defines a method on the interface from the descriptor m.



313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'lib/dbus/introspect.rb', line 313

def define_method_from_descriptor(m)
  check_for_eval(m.name)
  check_for_quoted_eval(@name)
  methdef = "def #{m.name}("
  methdef += (0..(m.params.size - 1)).to_a.collect { |n|
    "arg#{n}"
  }.join(", ")
  methdef += %{)
          msg = Message.new(Message::METHOD_CALL)
          msg.path = @object.path
          msg.interface = "#{@name}"
          msg.destination = @object.destination
          msg.member = "#{m.name}"
          msg.sender = @object.bus.unique_name
        }
  idx = 0
  m.params.each do |npar|
    paramname, par = npar
    check_for_quoted_eval(par)

    # This is the signature validity check
    Type::Parser.new(par).parse

    methdef += %{
      msg.add_param("#{par}", arg#{idx})
    }
    idx += 1
  end
  methdef += "
    ret = nil
    if block_given?
      @object.bus.on_return(msg) do |rmsg|
        if rmsg.is_a?(Error)
          yield(rmsg)
        else
          yield(rmsg, *rmsg.params)
        end
      end
      @object.bus.send(msg.marshall)
    else
      @object.bus.send_sync(msg) do |rmsg|
        if rmsg.is_a?(Error)
          raise rmsg
        else
          ret = rmsg.params
        end
      end
    end
    ret
  end
  "
  singleton_class.class_eval(methdef)
  @methods[m.name] = m
end

#define_signal_from_descriptor(s) ⇒ Object

Defines a signal from the descriptor s.



369
370
371
# File 'lib/dbus/introspect.rb', line 369

def define_signal_from_descriptor(s)
  @signals[s.name] = s
end

#on_signal(bus, name, &block) ⇒ Object

Registers a handler (code block) for a signal with name arriving over the given bus.



391
392
393
394
# File 'lib/dbus/introspect.rb', line 391

def on_signal(bus, name, &block)
  mr = DBus::MatchRule.new.from_signal(self, name)
  bus.add_match(mr) { |msg| block.call(*msg.params) }
end

#singleton_classObject

Returns the singleton class of the interface.



298
299
300
# File 'lib/dbus/introspect.rb', line 298

def singleton_class
  (class << self ; self ; end)
end

#to_strObject

Returns the string representation of the interface (the name).



293
294
295
# File 'lib/dbus/introspect.rb', line 293

def to_str
  @name
end