Class: DBus::MatchRule
- Inherits:
-
Object
- Object
- DBus::MatchRule
- Defined in:
- lib/dbus/matchrule.rb
Overview
D-Bus match rule class
FIXME
Constant Summary collapse
- FILTERS =
The list of possible match filters.
[:sender, :interface, :member, :path, :destination, :type]
Instance Attribute Summary collapse
-
#destination ⇒ Object
The destination filter.
-
#interface ⇒ Object
The interface filter.
-
#member ⇒ Object
The member filter.
-
#path ⇒ Object
The path filter.
-
#sender ⇒ Object
The sender filter.
-
#type ⇒ Object
The type type that is matched.
Instance Method Summary collapse
-
#from_s(str) ⇒ Object
Parses a match rule string s and sets the filters on the object.
-
#from_signal(intf, signal) ⇒ Object
Sets the match rule to filter for the given signal and the given interface intf.
-
#initialize ⇒ MatchRule
constructor
Create a new match rule.
-
#match(msg) ⇒ Object
Determines whether a message msg matches the match rule.
-
#to_s ⇒ Object
Returns a match rule string version of the object.
Constructor Details
#initialize ⇒ MatchRule
Create a new match rule
34 35 36 |
# File 'lib/dbus/matchrule.rb', line 34 def initialize @sender = @interface = @member = @path = @destination = @type = nil end |
Instance Attribute Details
#destination ⇒ Object
The destination filter.
29 30 31 |
# File 'lib/dbus/matchrule.rb', line 29 def destination @destination end |
#interface ⇒ Object
The interface filter.
23 24 25 |
# File 'lib/dbus/matchrule.rb', line 23 def interface @interface end |
#member ⇒ Object
The member filter.
25 26 27 |
# File 'lib/dbus/matchrule.rb', line 25 def member @member end |
#sender ⇒ Object
The sender filter.
21 22 23 |
# File 'lib/dbus/matchrule.rb', line 21 def sender @sender end |
#type ⇒ Object
The type type that is matched.
31 32 33 |
# File 'lib/dbus/matchrule.rb', line 31 def type @type end |
Instance Method Details
#from_s(str) ⇒ Object
Parses a match rule string s and sets the filters on the object.
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/dbus/matchrule.rb', line 58 def from_s(str) s.split(",").each do |eq| if eq =~ /^(.*)='([^']*)'$/ name = $1 val = $1 if FILTERS.member?(name.to_sym) method(name + "=").call(val) else raise MatchRuleException end end end end |
#from_signal(intf, signal) ⇒ Object
Sets the match rule to filter for the given signal and the given interface intf.
74 75 76 77 78 79 80 81 |
# File 'lib/dbus/matchrule.rb', line 74 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 |
#match(msg) ⇒ Object
Determines whether a message msg matches the match rule.
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/dbus/matchrule.rb', line 84 def match(msg) if @type if {Message::SIGNAL => "signal", Message::METHOD_CALL => "method_call", Message::METHOD_RETURN => "method_return", Message::ERROR => "error"}[msg.] != @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 true end |
#to_s ⇒ Object
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’”
49 50 51 52 53 54 55 |
# 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 |