# class DBus::MatchRule

# D-Bus match rule class¶ ↑

FIXME

### Constants

FILTERS

  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

new() click to toggle source

Create a new match rule

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

### Public Instance Methods

from_s(str) click to toggle source

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

       # File lib/dbus/matchrule.rb
    58 def from_s(str)
    59   str.split(",").each do |eq|
    60     next unless eq =~ /^(.*)='([^']*)'$/
    61     # "
    62     name = Regexp.last_match(1)
    63     val = Regexp.last_match(2)
    64     raise MatchRuleException, name unless FILTERS.member?(name.to_sym)
    65     method(name + "=").call(val)
    66   end
    67   self
    68 end

from_signal(intf, signal) click to toggle source

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

       # File lib/dbus/matchrule.rb
    72 def from_signal(intf, signal)
    73   signal = signal.name unless signal.is_a?(String)
    74   self.type = "signal"
    75   self.interface = intf.name
    76   self.member = signal
    77   self.path = intf.object.path
    78   self
    79 end

match(msg) click to toggle source

Determines whether a message msg matches the match rule.

       # File lib/dbus/matchrule.rb
    82 def match(msg)
    83   if @type
    84     if { Message::SIGNAL => "signal", Message::METHOD_CALL => "method_call",
    85          Message::METHOD_RETURN => "method_return",
    86          Message::ERROR => "error" }[msg.message_type] != @type
    87       return false
    88     end
    89   end
    90   return false if @interface && @interface != msg.interface
    91   return false if @member && @member != msg.member
    92   return false if @path && @path != msg.path
    93   # FIXME: sender and destination are ignored
    94   true
    95 end

to_s() click to toggle source

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'”

       # File lib/dbus/matchrule.rb
    51 def to_s
    52   present_rules = FILTERS.select { |sym| method(sym).call }
    53   present_rules.map! { |sym| "#{sym}='#{method(sym).call}'" }
    54   present_rules.join(",")
    55 end

type=(t) click to toggle source

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

       # File lib/dbus/matchrule.rb
    40 def type=(t)
    41   if !["signal", "method_call", "method_return", "error"].member?(t)
    42     raise MatchRuleException, t
    43   end
    44   @type = t
    45 end