Class DBus::MatchRule
In: lib/dbus/matchrule.rb
Parent: Object

D-Bus match rule class

FIXME

Methods

from_s   from_signal   match   new   to_s   type=  

Constants

FILTERS = [:sender, :interface, :member, :path, :destination, :type]   The list of possible match filters. TODO argN, argNpath

Attributes

destination  [RW]  The destination filter.
interface  [RW]  The interface filter.
member  [RW]  The member filter.
path  [RW]  The path filter.
sender  [RW]  The sender filter.
type  [R]  The type type that is matched.

Public Class methods

Create a new match rule

[Source]

# File lib/dbus/matchrule.rb, line 34
    def initialize
      @sender = @interface = @member = @path = @destination = @type = nil
    end

Public Instance methods

Parses a match rule string s and sets the filters on the object.

[Source]

# File lib/dbus/matchrule.rb, line 58
    def from_s(str)
      str.split(",").each do |eq|
        if eq =~ /^(.*)='([^']*)'$/
# "
          name = $1
          val = $2
          if FILTERS.member?(name.to_sym)
            method(name + "=").call(val)
          else
            raise MatchRuleException, name
          end
        end
      end
      self
    end

Sets the match rule to filter for the given signal and the given interface intf.

[Source]

# File lib/dbus/matchrule.rb, line 76
    def from_signal(intf, signal)
      signal = signal.name unless signal.is_a?(String)
      self.type = "signal"
      self.interface = intf.name
      self.member = signal
      self.path = intf.object.path
      self
    end

Determines whether a message msg matches the match rule.

[Source]

# File lib/dbus/matchrule.rb, line 86
    def match(msg)
      if @type
        if {Message::SIGNAL => "signal", Message::METHOD_CALL => "method_call",
          Message::METHOD_RETURN => "method_return",
          Message::ERROR => "error"}[msg.message_type] != @type
          return false
        end
      end
      return false if @interface and @interface != msg.interface
      return false if @member and @member != msg.member
      return false if @path and @path != msg.path
      # FIXME sender and destination are ignored
      true
    end

Returns a match rule string version of the object. E.g.: "type=‘signal’,sender=‘org.freedesktop.DBus’,interface=‘org.freedesktop.DBus’,member=‘Foo’,path=’/bar/foo’,destination=’:452345.34’,arg2=‘bar’"

[Source]

# File lib/dbus/matchrule.rb, line 49
    def to_s
      FILTERS.select do |sym|
        not method(sym).call.nil?
      end.collect do |sym|
        "#{sym.to_s}='#{method(sym).call}'"
      end.join(",")
    end

Set the message types to filter to type t. Possible message types are: signal, method_call, method_return, and error.

[Source]

# File lib/dbus/matchrule.rb, line 40
    def type=(t)
      if not ['signal', 'method_call', 'method_return', 'error'].member?(t)
        raise MatchRuleException, t
      end
      @type = t
    end

[Validate]