class DBus::Interface
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}.
Attributes
@return [EmitsChangedSignal]
@return [Hash{Symbol => DBus::Method}] The methods that are part of the interface.
@return [String] The name of the interface.
@return [Hash{Symbol => Property}]
@return [Hash{Symbol => Signal}] The signals that are part of the interface.
Public Class Methods
Creates a new interface with a given name.
# File lib/dbus/introspect.rb 45 def initialize(name) 46 validate_name(name) 47 @name = name 48 @methods = {} 49 @signals = {} 50 @properties = {} 51 @emits_changed_signal = EmitsChangedSignal::DEFAULT_ECS 52 end
Public Instance Methods
Add ifc_el as a known {Method}, {Signal} or {Property} @param ifc_el [InterfaceElement]
# File lib/dbus/introspect.rb 81 def define(ifc_el) 82 name = ifc_el.name.to_sym 83 category = case ifc_el 84 when Method 85 @methods 86 when Signal 87 @signals 88 when Property 89 @properties 90 end 91 category[name] = ifc_el 92 end
Defines a method with name id and a given prototype in the interface. Better name: declare_method
# File lib/dbus/introspect.rb 99 def define_method(id, prototype) 100 m = Method.new(id) 101 m.from_prototype(prototype) 102 define(m) 103 end
Helper for {Object.emits_changed_signal=}. @api private
# File lib/dbus/introspect.rb 56 def emits_changed_signal=(ecs) 57 raise TypeError unless ecs.is_a? EmitsChangedSignal 58 # equal?: object identity 59 unless @emits_changed_signal.equal?(EmitsChangedSignal::DEFAULT_ECS) || 60 @emits_changed_signal.value == ecs.value 61 raise "emits_change_signal was assigned more than once" 62 end 63 64 @emits_changed_signal = ecs 65 end
Return introspection XML string representation of the property. @return [String]
# File lib/dbus/introspect.rb 108 def to_xml 109 xml = " <interface name=\"#{name}\">\n" 110 xml += emits_changed_signal.to_xml 111 methods.each_value { |m| xml += m.to_xml } 112 signals.each_value { |m| xml += m.to_xml } 113 properties.each_value { |m| xml += m.to_xml } 114 xml += " </interface>\n" 115 xml 116 end
Validates a service name.
# File lib/dbus/introspect.rb 68 def validate_name(name) 69 raise InvalidIntrospectionData if name.bytesize > 255 70 raise InvalidIntrospectionData if name =~ /^\./ || name =~ /\.$/ 71 raise InvalidIntrospectionData if name =~ /\.\./ 72 raise InvalidIntrospectionData if name !~ /\./ 73 74 name.split(".").each do |element| 75 raise InvalidIntrospectionData if element !~ INTERFACE_ELEMENT_RE 76 end 77 end