diff options
author | John (J5) Palmieri <johnp@redhat.com> | 2005-08-18 04:04:57 +0000 |
---|---|---|
committer | John (J5) Palmieri <johnp@redhat.com> | 2005-08-18 04:04:57 +0000 |
commit | 8d1e7dfeb9f68541225e7a990dd700d35bb8342c (patch) | |
tree | e2f6054b2d07bf7f4adf7d3ae60a893e8fd4e2db /python/_dbus.py | |
parent | e5268be6b33e98cd4da0090da7cb2e3ab534c57a (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/_dbus.py')
-rw-r--r-- | python/_dbus.py | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/python/_dbus.py b/python/_dbus.py index 6074be16..2a290bd6 100644 --- a/python/_dbus.py +++ b/python/_dbus.py @@ -41,9 +41,10 @@ dbus_object = dbus_service.get_object('/org/freedesktop/DBus', print(dbus_object.ListServices()) """ +import dbus + import dbus_bindings -import dbus from proxies import * from exceptions import * from matchrules import * @@ -104,25 +105,67 @@ class Bus: """Get a proxy object to call over the bus""" return self.ProxyObjectClass(self, named_service, object_path) - def add_signal_receiver(self, handler_function, signal_name=None, dbus_interface=None, named_service=None, path=None): + def _create_args_dict(self, keywords): + args_dict = None + for (key, value) in keywords.iteritems(): + if key.startswith('arg'): + try: + snum = key[3:] + num = int(snum) + + if not args_dict: + args_dict = {} + + args_dict[num] = value + except ValueError: + raise TypeError("Invalid arg index %s"%snum) + else: + raise TypeError("Unknown keyword %s"%(key)) + + return args_dict + + def add_signal_receiver(self, handler_function, + signal_name=None, + dbus_inteface=None, + named_service=None, + path=None, + **keywords): + + args_dict = self._create_args_dict(keywords) + if (named_service and named_service[0] != ':'): bus_object = self.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus') named_service = bus_object.GetNameOwner(named_service, dbus_interface='org.freedesktop.DBus') match_rule = SignalMatchRule(signal_name, dbus_interface, named_service, path) + + if args_dict: + match_rule.add_args_match(args_dict) + match_rule.add_handler(handler_function) self._match_rule_tree.add(match_rule) - dbus_bindings.bus_add_match(self._connection, str(match_rule)) + dbus_bindings.bus_add_match(self._connection, repr(match_rule)) - def remove_signal_receiver(self, handler_function, signal_name=None, dbus_interface=None, named_service=None, path=None): + def remove_signal_receiver(self, handler_function, + signal_name=None, + dbus_interface=None, + named_service=None, + path=None, + **keywords): + + args_dict = self._create_args_dict(keywords) + if (named_service and named_service[0] != ':'): bus_object = self.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus') named_service = bus_object.GetNameOwner(named_service, dbus_interface='org.freedesktop.DBus') match_rule = SignalMatchRule(signal_name, dbus_interface, named_service, path) + if (args_dict): + match_rule.add_args_match(args_dict) + if (handler_function): match_rule.add_handler(handler_function) @@ -139,8 +182,8 @@ class Bus: return dbus_bindings.HANDLER_RESULT_NOT_YET_HANDLED dbus_interface = message.get_interface() - named_service = message.get_sender() - path = message.get_path() + named_service = message.get_sender() + path = message.get_path() signal_name = message.get_member() match_rule = SignalMatchRule(signal_name, dbus_interface, named_service, path) |