Class: DBus::Interface

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

Overview

D-Bus interface class

This class is the interface descriptor. In most cases, the Introspect() method call instantiates and configures this class for us.

It also is the local definition of interface exported by the program. At the client side, see ProxyObjectInterface

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Interface

Creates a new interface with a given name.



37
38
39
40
41
42
# File 'lib/dbus/introspect.rb', line 37

def initialize(name)
  validate_name(name)
  @name = name
  @methods = {}
  @signals = {}
end

Instance Attribute Details

#methodsObject (readonly)

The methods that are part of the interface. Hash: Symbol => DBus::Method



32
33
34
# File 'lib/dbus/introspect.rb', line 32

def methods
  @methods
end

#nameObject (readonly)

The name of the interface. String



30
31
32
# File 'lib/dbus/introspect.rb', line 30

def name
  @name
end

#signalsObject (readonly)

The signals that are part of the interface. Hash: Symbol => Signal



34
35
36
# File 'lib/dbus/introspect.rb', line 34

def signals
  @signals
end

Instance Method Details

#define(m) ⇒ Object Also known as: <<

Helper method for defining a method m.



56
57
58
59
60
61
62
# File 'lib/dbus/introspect.rb', line 56

def define(m)
  if m.is_a?(Method)
    @methods[m.name.to_sym] = m
  elsif m.is_a?(Signal)
    @signals[m.name.to_sym] = m
  end
end

#define_method(id, prototype) ⇒ Object

Defines a method with name id and a given prototype in the interface.



67
68
69
70
71
# File 'lib/dbus/introspect.rb', line 67

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

#validate_name(name) ⇒ Object

Validates a service name.



45
46
47
48
49
50
51
52
53
# File 'lib/dbus/introspect.rb', line 45

def validate_name(name)
  raise InvalidIntrospectionData if name.bytesize > 255
  raise InvalidIntrospectionData if name =~ /^\./ || name =~ /\.$/
  raise InvalidIntrospectionData if name =~ /\.\./
  raise InvalidIntrospectionData if name !~ /\./
  name.split(".").each do |element|
    raise InvalidIntrospectionData if element !~ INTERFACE_ELEMENT_RE
  end
end