diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2008-07-14 18:44:15 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2008-07-14 18:44:15 +0100 |
commit | 565d2e88c54d3f2e6dab4ae0ed3202d3a26bfd2c (patch) | |
tree | 35117296b38b3c2ec811f1ea00410d065b039789 /dbus | |
parent | a7e29e3dbab9651761fc9a7c3ec7fbc27c711286 (diff) | |
download | dbus-python-565d2e88c54d3f2e6dab4ae0ed3202d3a26bfd2c.tar.gz |
Add Connection.call_on_disconnection
Diffstat (limited to 'dbus')
-rw-r--r-- | dbus/connection.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/dbus/connection.py b/dbus/connection.py index 3a551ea..e2ec3b2 100644 --- a/dbus/connection.py +++ b/dbus/connection.py @@ -246,6 +246,8 @@ class Connection(_Connection): if not hasattr(self, '_dbus_Connection_initialized'): self._dbus_Connection_initialized = 1 + self.__call_on_disconnection = [] + self._signal_recipients_by_object_path = {} """Map from object path to dict mapping dbus_interface to dict mapping member to list of SignalMatch objects.""" @@ -508,6 +510,19 @@ class Connection(_Connection): for match in self._iter_easy_matches(path, dbus_interface, signal_name): match.maybe_handle_message(message) + + if (dbus_interface == LOCAL_IFACE and + path == LOCAL_PATH and + signal_name == 'Disconnected'): + for cb in self.__call_on_disconnection: + try: + cb(self) + except Exception, e: + # basicConfig is a no-op if logging is already configured + logging.basicConfig() + _logger.error('Exception in handler for Disconnected ' + 'signal:', exc_info=1) + return HANDLER_RESULT_NOT_YET_HANDLED def call_async(self, bus_name, object_path, dbus_interface, method, @@ -612,3 +627,12 @@ class Connection(_Connection): return args_list[0] else: return tuple(args_list) + + def call_on_disconnection(self, callable): + """Arrange for `callable` to be called with one argument (this + Connection object) when the Connection becomes + disconnected. + + :Since: 0.83.0 + """ + self.__call_on_disconnection.append(callable) |