summaryrefslogtreecommitdiffstats
path: root/python/matchrules.py
diff options
context:
space:
mode:
authorJohn (J5) Palmieri <johnp@redhat.com>2005-08-18 04:04:57 +0000
committerJohn (J5) Palmieri <johnp@redhat.com>2005-08-18 04:04:57 +0000
commit8d1e7dfeb9f68541225e7a990dd700d35bb8342c (patch)
treee2f6054b2d07bf7f4adf7d3ae60a893e8fd4e2db /python/matchrules.py
parente5268be6b33e98cd4da0090da7cb2e3ab534c57a (diff)
* ChangeLog: clean up my last entry a bit
* doc/introspect.xsl: New stylesheet for converting introspection data into browser renderable xhtml. Contributed by Lennart Poettering. * doc/introspect.dtd: Fixups in the introspect format from Lennart Poettering. * doc/dbus-tutorial.xml: - Add Colin Walter to the Authors section for authoring the GLib section - Add descriptions of the new signature and type functionality in the Python complex type mapping section - Add a sidenote on the new args matching functionality in the Python bindings - Fixed up some of the examples to use the gobject.MainLoop instead of gtk.main * python/_dbus.py: (Bus::_create_args_dict): New. Converts a hash of arg matches to a more useable format (Bus::add_signal_receiver): add a **keywords parameter for catching arg match parameters (Bus::remove_signal_receiver): add a **keywords parameter for catching arg match parameters * python/matchrules.py: (MatchTree::exec_matches): Check for arg matches (SignalMatchRule::add_args_match): New method (SignalMatchRule::execute): Added args_list parameter as an optimization so we don't have to marshal the args more than once (SignalMatchRule::match_args_from_list): New method that checks to see if the rule's arg matches match an argument list. Only arguments set in the rule are checked. (SignalMatchRule::match_args_from_rule): New method that checks to see if the rule's arg matches match another rule's. All args have to match in order for this method to return true. If either rule has more args then it is not a match. (SignalMatchRule::is_match): Add args match (SignalMatchRule::repr): Add args to the final output if they exist
Diffstat (limited to 'python/matchrules.py')
-rw-r--r--python/matchrules.py64
1 files changed, 58 insertions, 6 deletions
diff --git a/python/matchrules.py b/python/matchrules.py
index d65e3920..3a2fbedf 100644
--- a/python/matchrules.py
+++ b/python/matchrules.py
@@ -70,6 +70,8 @@ class SignalMatchTree:
path.add(rule.path, leaf=rule)
def exec_matches(self, match_rule, message):
+ args = message.get_args_list()
+
sender_matches = self._tree.get_matches(match_rule.sender)
for sender_node in sender_matches:
interface_matches = sender_node.get_matches(match_rule.dbus_interface)
@@ -80,7 +82,8 @@ class SignalMatchTree:
for path_node in path_matches:
if(path_node.rules):
for rule in path_node.rules:
- rule.execute(message)
+ if (rule.match_args_from_list(args)):
+ rule.execute(message, args)
def remove(self, rule):
try:
@@ -121,9 +124,16 @@ class SignalMatchRule:
self.dbus_interface = dbus_interface
self.sender = sender
self.path = path
+ self.args = None
- def execute(self, message):
- args = message.get_args_list()
+ def add_args_match(self, args):
+ self.args = args
+
+ def execute(self, message, args=None):
+ #optimization just in case we already extarcted the args
+ if not args:
+ args = message.get_args_list()
+
for handler in self.handler_functions:
if getattr(handler, "_dbus_pass_message", False):
keywords = {"dbus_message": message}
@@ -133,12 +143,48 @@ class SignalMatchRule:
def add_handler(self, handler):
self.handler_functions.append(handler)
-
+
+ #matches only those arguments listed by self
+ def match_args_from_list(self, args_list):
+ if not self.args:
+ return True
+
+ last_index = len(args_list) - 1
+ for (index, value) in self.args.iteritems():
+ if index > last_index:
+ return False
+
+ if not (args_list[index] == value):
+ return False
+
+ return True
+
+ #does exact matching
+ def match_args_from_rule(self, rule):
+ if self.args == rule.args:
+ return True
+
+ if self.args == None or rule.args == None:
+ return False
+
+ my_args_list = self.args.items()
+ match_args_list = rule.args.iterms()
+
+ if len(my_args_list) != len(match_args_list):
+ return False
+
+ for (key, value) in my_args_list:
+ if rule.args.get(key) != value:
+ return False
+
+ return True
+
def is_match(self, rule):
if (self.signal_name == rule.signal_name and
self.dbus_interface == rule.dbus_interface and
self.sender == rule.sender and
- self.path == rule.path):
+ self.path == rule.path and
+ self.match_args_from_rule(rule)):
if rule.handler_functions == []:
return True
@@ -167,5 +213,11 @@ class SignalMatchRule:
if (self.signal_name):
repr = repr + ",member='%s'" % (self.signal_name)
-
+
+ if (self.args):
+ my_args_list = self.args.items()
+ my_args_list.sort()
+ for (index, value) in my_args_list:
+ repr = repr + ",arg%i='%s'" % (index, value)
+
return repr