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

emits_changed_signal[R]

@return [EmitsChangedSignal]

methods[R]

@return [Hash{Symbol => DBus::Method}] The methods that are part of the interface.

name[R]

@return [String] The name of the interface.

properties[R]

@return [Hash{Symbol => Property}]

signals[R]

@return [Hash{Symbol => Signal}] The signals that are part of the interface.

Public Class Methods

new(name) click to toggle source

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

<<(ifc_el)
Alias for: define
declare(ifc_el)
Alias for: define
declare_method(id, prototype)
Alias for: define_method
define(ifc_el) click to toggle source

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
Also aliased as: declare, <<
define_method(id, prototype) click to toggle source

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
Also aliased as: declare_method
emits_changed_signal=(ecs) click to toggle source

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
to_xml() click to toggle source

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
validate_name(name) click to toggle source

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