Class: DBus::MatchRule

Inherits:
Object
  • Object
show all
Defined in:
lib/dbus/matchrule.rb

Overview

D-Bus match rule class

FIXME

Constant Summary collapse

FILTERS =

The list of possible match filters. TODO argN, argNpath

[:sender, :interface, :member, :path, :destination, :type].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMatchRule

Create a new match rule



36
37
38
# File 'lib/dbus/matchrule.rb', line 36

def initialize
  @sender = @interface = @member = @path = @destination = @type = nil
end

Instance Attribute Details

#destinationObject

The destination filter.



31
32
33
# File 'lib/dbus/matchrule.rb', line 31

def destination
  @destination
end

#interfaceObject

The interface filter.



25
26
27
# File 'lib/dbus/matchrule.rb', line 25

def interface
  @interface
end

#memberObject

The member filter.



27
28
29
# File 'lib/dbus/matchrule.rb', line 27

def member
  @member
end

#pathObject

The path filter.



29
30
31
# File 'lib/dbus/matchrule.rb', line 29

def path
  @path
end

#senderObject

The sender filter.



23
24
25
# File 'lib/dbus/matchrule.rb', line 23

def sender
  @sender
end

#typeString

Returns The type type that is matched.

Returns:

  • (String)

    The type type that is matched.



33
34
35
# File 'lib/dbus/matchrule.rb', line 33

def type
  @type
end

Instance Method Details

#from_s(str) ⇒ Object

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



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/dbus/matchrule.rb', line 61

def from_s(str)
  str.split(",").each do |eq|
    next unless eq =~ /^(.*)='([^']*)'$/

    # "
    name = Regexp.last_match(1)
    val = Regexp.last_match(2)
    raise MatchRuleException, name unless FILTERS.member?(name.to_sym)

    method("#{name}=").call(val)
  end
  self
end

#from_signal(intf, signal) ⇒ Object

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



77
78
79
80
81
82
83
84
# File 'lib/dbus/matchrule.rb', line 77

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.



87
88
89
90
91
92
93
94
95
# File 'lib/dbus/matchrule.rb', line 87

def match(msg)
  return false if @type && @type != msg.message_type_s
  return false if @interface && @interface != msg.interface
  return false if @member && @member != msg.member
  return false if @path && @path != msg.path

  # FIXME: sender and destination are ignored
  true
end

#to_sObject

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



54
55
56
57
58
# File 'lib/dbus/matchrule.rb', line 54

def to_s
  present_rules = FILTERS.select { |sym| method(sym).call }
  present_rules.map! { |sym| "#{sym}='#{method(sym).call}'" }
  present_rules.join(",")
end