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.



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

def initialize(name)
  validate_name(name)
  @name = name
  @methods = {}
  @signals = {}
  @properties = {}
  @emits_changed_signal = EmitsChangedSignal::DEFAULT_ECS
end

Instance Attribute Details

#emits_changed_signalEmitsChangedSignal

Returns:



42
43
44
# File 'lib/dbus/introspect.rb', line 42

def emits_changed_signal
  @emits_changed_signal
end

#methodsHash{Symbol => DBus::Method} (readonly)

Returns The methods that are part of the interface.

Returns:

  • (Hash{Symbol => DBus::Method})

    The methods that are part of the interface.



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

def methods
  @methods
end

#nameString (readonly)

Returns The name of the interface.

Returns:

  • (String)

    The name of the interface.



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

def name
  @name
end

#propertiesHash{Symbol => Property} (readonly)

Returns:



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

def properties
  @properties
end

#signalsHash{Symbol => Signal} (readonly)

Returns The signals that are part of the interface.

Returns:

  • (Hash{Symbol => Signal})

    The signals that are part of the interface.



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

def signals
  @signals
end

Instance Method Details

#define(ifc_el) ⇒ Object Also known as: declare, <<

Add ifc_el as a known Method, Signal or Property

Parameters:



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/dbus/introspect.rb', line 81

def define(ifc_el)
  name = ifc_el.name.to_sym
  category = case ifc_el
             when Method
               @methods
             when Signal
               @signals
             when Property
               @properties
             end
  category[name] = ifc_el
end

#define_method(id, prototype) ⇒ Object Also known as: declare_method

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



99
100
101
102
103
# File 'lib/dbus/introspect.rb', line 99

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

#to_xmlString

Return introspection XML string representation of the property.

Returns:

  • (String)


108
109
110
111
112
113
114
115
116
# File 'lib/dbus/introspect.rb', line 108

def to_xml
  xml = "  <interface name=\"#{name}\">\n"
  xml += emits_changed_signal.to_xml
  methods.each_value { |m| xml += m.to_xml }
  signals.each_value { |m| xml += m.to_xml }
  properties.each_value { |m| xml += m.to_xml }
  xml += "  </interface>\n"
  xml
end

#validate_name(name) ⇒ Object

Validates a service name.



68
69
70
71
72
73
74
75
76
77
# File 'lib/dbus/introspect.rb', line 68

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