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, line 44 def initialize(name) validate_name(name) @name = name @methods = {} @signals = {} @properties = {} @emits_changed_signal = EmitsChangedSignal::DEFAULT_ECS end
Public Instance Methods
Add ifc_el as a known {Method}, {Signal} or {Property} @param ifc_el [InterfaceElement]
# File lib/dbus/introspect.rb, line 80 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
Defines a method with name id and a given prototype in the interface. Better name: #declare_method
# File lib/dbus/introspect.rb, line 98 def define_method(id, prototype) m = Method.new(id) m.from_prototype(prototype) define(m) end
Helper for {Object.emits_changed_signal=}. @api private
# File lib/dbus/introspect.rb, line 55 def emits_changed_signal=(ecs) raise TypeError unless ecs.is_a? EmitsChangedSignal # equal?: object identity unless @emits_changed_signal.equal?(EmitsChangedSignal::DEFAULT_ECS) || @emits_changed_signal.value == ecs.value raise "emits_change_signal was assigned more than once" end @emits_changed_signal = ecs end
Return introspection XML string representation of the property. @return [String]
# File lib/dbus/introspect.rb, line 107 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
Validates a service name.
# File lib/dbus/introspect.rb, line 67 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