1
# This file is part of the ruby-dbus project
2
# Copyright (C) 2007 Arnaud Cornet and Paul van Tilburg
4
# This library is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU Lesser General Public
6
# License, version 2.1 as published by the Free Software Foundation.
7
# See the file "COPYING" for the exact licensing terms.
10
# Exception raised when an erroneous match rule type is encountered.
11
class MatchRuleException < Exception
14
# = D-Bus match rule class
18
# The list of possible match filters.
19
FILTERS = [:sender, :interface, :member, :path, :destination, :type]
22
# The interface filter.
23
attr_accessor :interface
28
# The destination filter.
29
attr_accessor :destination
30
# The type type that is matched.
33
# Set the message types to filter to type _t_.
34
# Possible message types are: signal, method_call, method_return, and error.
36
if not ['signal', 'method_call', 'method_return', 'error'].member?(t)
37
raise MatchRuleException
42
# Returns a match rule string version of the object.
43
# E.g.: "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='Foo',path='/bar/foo',destination=':452345.34',arg2='bar'"
45
FILTERS.select do |sym|
46
not method(sym).call.nil?
48
"#{sym.to_s}='#{method(sym).call}'"
52
# Parses a match rule string _s_ and sets the filters on the object.
54
s.split(",").each do |eq|
55
if eq =~ /^(.*)='([^']*)'$/
58
if FILTERS.member?(name.to_sym)
59
method(name + "=").call(val)
61
raise MatchRuleException
67
# Sets the match rule to filter for the given _signal_ and the
68
# given interface _intf_.
69
def from_signal(intf, signal)
70
signal = signal.name unless signal.is_a?(String)
72
self.interface = intf.name
74
self.path = intf.object.path
78
# Determines whether a message _msg_ matches the match rule.
81
if {Message::SIGNAL => "signal", Message::METHOD_CALL => "method_call",
82
Message::METHOD_RETURN => "method_return",
83
Message::ERROR => "error"}[msg.message_type] != @type
87
return false if @interface and @interface != msg.interface
88
return false if @member and @member != msg.member
89
return false if @path and @path != msg.path