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 instanciates and configures this class for us.

It also is the local definition of interface exported by the program.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Interface

Creates a new interface with a given name.



43
44
45
46
47
# File 'lib/dbus/introspect.rb', line 43

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

Instance Attribute Details

#methodsObject (readonly)

The methods that are part of the interface.



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

def methods
  @methods
end

#nameObject (readonly)

The name of the interface.



36
37
38
# File 'lib/dbus/introspect.rb', line 36

def name
  @name
end

#signalsObject (readonly)

The signals that are part of the interface.



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

def signals
  @signals
end

Instance Method Details

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

Helper method for defining a method m.



61
62
63
64
65
66
67
# File 'lib/dbus/introspect.rb', line 61

def define(m)
  if m.kind_of?(Method)
    @methods[m.name.to_sym] = m
  elsif m.kind_of?(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.



72
73
74
75
76
# File 'lib/dbus/introspect.rb', line 72

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

#validate_name(name) ⇒ Object

Validates a service name.



50
51
52
53
54
55
56
57
58
# File 'lib/dbus/introspect.rb', line 50

def validate_name(name)
  raise InvalidIntrospectionData if name.size > 255
  raise InvalidIntrospectionData if name =~ /^\./ or name =~ /\.$/
  raise InvalidIntrospectionData if name =~ /\.\./
  raise InvalidIntrospectionData if not name =~ /\./
  name.split(".").each do |element|
    raise InvalidIntrospectionData if not element =~ InterfaceElementRE
  end
end