Class: DBus::Interface
- Inherits:
-
Object
- Object
- DBus::Interface
- 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
- #emits_changed_signal ⇒ EmitsChangedSignal
-
#methods ⇒ Hash{Symbol => DBus::Method}
readonly
The methods that are part of the interface.
-
#name ⇒ String
readonly
The name of the interface.
- #properties ⇒ Hash{Symbol => Property} readonly
-
#signals ⇒ Hash{Symbol => Signal}
readonly
The signals that are part of the interface.
Instance Method Summary collapse
- #define(ifc_el) ⇒ Object (also: #declare, #<<)
-
#define_method(id, prototype) ⇒ Object
(also: #declare_method)
Defines a method with name id and a given prototype in the interface.
-
#initialize(name) ⇒ Interface
constructor
Creates a new interface with a given name.
-
#to_xml ⇒ String
Return introspection XML string representation of the property.
-
#validate_name(name) ⇒ Object
Validates a service name.
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_signal ⇒ EmitsChangedSignal
42 43 44 |
# File 'lib/dbus/introspect.rb', line 42 def emits_changed_signal @emits_changed_signal end |
#methods ⇒ Hash{Symbol => DBus::Method} (readonly)
Returns The methods that are part of the interface.
34 35 36 |
# File 'lib/dbus/introspect.rb', line 34 def methods @methods end |
#name ⇒ String (readonly)
Returns The name of the interface.
32 33 34 |
# File 'lib/dbus/introspect.rb', line 32 def name @name end |
#properties ⇒ Hash{Symbol => Property} (readonly)
39 40 41 |
# File 'lib/dbus/introspect.rb', line 39 def properties @properties end |
#signals ⇒ Hash{Symbol => Signal} (readonly)
Returns 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, <<
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_xml ⇒ String
Return introspection XML string representation of the property.
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 |