diff options
author | John (J5) Palmieri <johnp@redhat.com> | 2005-05-24 16:30:51 +0000 |
---|---|---|
committer | John (J5) Palmieri <johnp@redhat.com> | 2005-05-24 16:30:51 +0000 |
commit | 982e34a1ec594ae8ad8c27a651b6eba68dcae40e (patch) | |
tree | 0daec34abaa48b1d776497f4b4c72b8748ad39c3 | |
parent | e43a353d27f1b9643c21ccff53a7759fc3dcdffe (diff) |
* python/decorators.py: add explicitly_pass_message decorator
for passing in the dbus message as keyword for edge case signal
handling
* python/matchrules.py (SignalMatchRule.__repr__): fix output
to conform with what dbus expects for match rules
(SignalMatchRule.execute): add the dbus message as a keyword
if the signal handler has requested it
* python/examples/example/signal-recipient.py: added some more
examples on how to hook up to signals
* python/proxies.py: minor formatting changes
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | python/_dbus.py | 4 | ||||
-rw-r--r-- | python/decorators.py | 5 | ||||
-rw-r--r-- | python/examples/example-signal-recipient.py | 22 | ||||
-rw-r--r-- | python/matchrules.py | 21 |
5 files changed, 49 insertions, 17 deletions
@@ -1,3 +1,17 @@ +2005-05-24 John (J5) Palmieri <johnp@redhat.com> + + * python/decorators.py: add explicitly_pass_message decorator + for passing in the dbus message as keyword for edge case signal + handling + + * python/matchrules.py (SignalMatchRule.__repr__): fix output + to conform with what dbus expects for match rules + (SignalMatchRule.execute): add the dbus message as a keyword + if the signal handler has requested it + + * python/examples/example/signal-recipient.py: added some more + examples on how to hook up to signals + 2005-05-23 John (J5) Palmieri <johnp@redhat.com> * python/decorators.py: import dbus_bindings diff --git a/python/_dbus.py b/python/_dbus.py index d408704a..d559ce18 100644 --- a/python/_dbus.py +++ b/python/_dbus.py @@ -150,9 +150,7 @@ class Bus: match_rule = SignalMatchRule(signal_name, dbus_interface, named_service, path) - args = message.get_args_list() - - self._match_rule_tree.exec_matches(match_rule, *args) + self._match_rule_tree.exec_matches(match_rule, message) def start_service_by_name(self, named_service): return dbus_bindings.bus_start_service_by_name(self._connection, named_service) diff --git a/python/decorators.py b/python/decorators.py index 7847b3a2..2deec6d0 100644 --- a/python/decorators.py +++ b/python/decorators.py @@ -1,7 +1,7 @@ import _util import inspect import dbus_bindings - +import new def method(dbus_interface): _util._validate_interface_or_name(dbus_interface) @@ -37,3 +37,6 @@ def signal(dbus_interface): return decorator +def explicitly_pass_message(func): + func._dbus_pass_message = True + return func diff --git a/python/examples/example-signal-recipient.py b/python/examples/example-signal-recipient.py index 2f932a9b..681dd7c2 100644 --- a/python/examples/example-signal-recipient.py +++ b/python/examples/example-signal-recipient.py @@ -20,10 +20,30 @@ bus = dbus.SessionBus() object = bus.get_object("org.designfu.TestService","/org/designfu/TestService/object") def hello_signal_handler(hello_string): - print ("Received signal and it says: " + hello_string) + print ("Received signal and it says: " + hello_string) + +@dbus.explicitly_pass_message +def catchall_signal_handler(*args, **keywords): + #The dbus.handler directive passes in the special __dbus_message__ variable + dbus_message = keywords["dbus_message"] + print "Caught signal " + dbus_message.get_member() + for arg in args: + print " " + str(arg) + +def catchall_hello_signals_handler(hello_string): + print ("Received a hello signal and it says ") + hello_string + +@dbus.explicitly_pass_message +def catchall_testservice_interface_handler(hello_string, dbus_message): + print "org.designfu.TestService interface says " + hello_string + " when it sent signal " + dbus_message.get_member() object.connect_to_signal("HelloSignal", hello_signal_handler, dbus_interface="org.designfu.TestService") +#lets make a catchall +bus.add_signal_receiver(catchall_signal_handler) +bus.add_signal_receiver(catchall_hello_signals_handler, dbus_interface = "org.designfu.TestService", signal_name = "HelloSignal") +bus.add_signal_receiver(catchall_testservice_interface_handler, dbus_interface = "org.designfu.TestService") + gobject.timeout_add(2000, emit_signal) # Tell the remote object to emit the signal diff --git a/python/matchrules.py b/python/matchrules.py index e27c4c8f..6d5fcd86 100644 --- a/python/matchrules.py +++ b/python/matchrules.py @@ -69,7 +69,7 @@ class SignalMatchTree: path = signal.add(rule.signal_name) path.add(rule.path, leaf=rule) - def exec_matches(self, match_rule, *args): + def exec_matches(self, match_rule, message): 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 +80,7 @@ class SignalMatchTree: for path_node in path_matches: if(path_node.rules): for rule in path_node.rules: - rule.execute(*args) + rule.execute(message) def remove(self, rule): try: @@ -122,9 +122,14 @@ class SignalMatchRule: self.sender = sender self.path = path - def execute(self, *args): + def execute(self, message): + args = message.get_args_list() for handler in self.handler_functions: - handler(*args) + if getattr(handler, "_dbus_pass_message", False): + keywords = {"dbus_message": message} + handler(*args, **keywords) + else: + handler(*args) def add_handler(self, handler): self.handler_functions.append(handler) @@ -149,22 +154,14 @@ class SignalMatchRule: repr = "type='signal'" if (self.dbus_interface): repr = repr + ",interface='%s'" % (self.dbus_interface) - else: - repr = repr + ",interface='*'" if (self.sender): repr = repr + ",sender='%s'" % (self.sender) - else: - repr = repr + ",sender='*'" if (self.path): repr = repr + ",path='%s'" % (self.path) - else: - repr = repr + ",path='*'" if (self.signal_name): repr = repr + ",member='%s'" % (self.signal_name) - else: - repr = repr + ",member='*'" return repr |