Merge lp:~zeitgeist/zeitgeist/bug673008 into lp:zeitgeist/0.1

Proposed by Siegfried Gevatter
Status: Merged
Merged at revision: 1667
Proposed branch: lp:~zeitgeist/zeitgeist/bug673008
Merge into: lp:zeitgeist/0.1
Diff against target: 109 lines (+30/-6)
1 file modified
zeitgeist/client.py (+30/-6)
To merge this branch: bzr merge lp:~zeitgeist/zeitgeist/bug673008
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen Approve
Review via email: mp+48914@code.launchpad.net

Commit message

ZeitgeistClient: reinstall monitors upon reconnection (LP: #673008)

Description of the change

This will re-install all monitors set by ZeitgeistClient if ZeitgeistInterface (or, actually, _DBusInterface) sees it has lost of the connection to Zeitgeist and reconnects to it.

To post a comment you must log in.
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Looks good to me

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'zeitgeist/client.py'
--- zeitgeist/client.py 2011-02-08 12:54:20 +0000
+++ zeitgeist/client.py 2011-02-08 13:36:25 +0000
@@ -2,7 +2,7 @@
22
3# Zeitgeist3# Zeitgeist
4#4#
5# Copyright © 2009-2010 Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com>5# Copyright © 2009-2011 Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com>
6# Copyright © 2009 Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com>6# Copyright © 2009 Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com>
7# Copyright © 2009 Markus Korn <thekorn@gmx.de>7# Copyright © 2009 Markus Korn <thekorn@gmx.de>
8#8#
@@ -41,6 +41,8 @@
41class _DBusInterface(object):41class _DBusInterface(object):
42 """Wrapper around dbus.Interface adding convenience methods."""42 """Wrapper around dbus.Interface adding convenience methods."""
4343
44 reconnect_callbacks = []
45
44 @staticmethod46 @staticmethod
45 def get_members(introspection_xml):47 def get_members(introspection_xml):
46 """Parses the XML context returned by Introspect() and returns48 """Parses the XML context returned by Introspect() and returns
@@ -58,6 +60,13 @@
58 pass60 pass
59 return methods, signals61 return methods, signals
6062
63 def reconnect(self):
64 self.__proxy = dbus.SessionBus().get_object(self.__iface.requested_bus_name,
65 self.__object_path)
66 self.__iface = dbus.Interface(self.__proxy, self.__interface_name)
67 for callback in self.reconnect_callbacks:
68 callback()
69
61 def _disconnection_safe(self, meth, *args, **kwargs):70 def _disconnection_safe(self, meth, *args, **kwargs):
62 """71 """
63 Executes the given method. If it fails because the D-Bus connection72 Executes the given method. If it fails because the D-Bus connection
@@ -70,10 +79,7 @@
70 def reconnecting_error_handler(e):79 def reconnecting_error_handler(e):
71 error = e.get_dbus_name()80 error = e.get_dbus_name()
72 if error == "org.freedesktop.DBus.Error.ServiceUnknown":81 if error == "org.freedesktop.DBus.Error.ServiceUnknown":
73 self.__proxy = dbus.SessionBus().get_object(82 self.reconnect()
74 self.__iface.requested_bus_name, self.__object_path)
75 self.__iface = dbus.Interface(self.__proxy,
76 self.__interface_name)
77 # We don't use the reconnecting_error_handler here since that'd83 # We don't use the reconnecting_error_handler here since that'd
78 # get us into an endless loop if Zeitgeist really isn't there.84 # get us into an endless loop if Zeitgeist really isn't there.
79 return meth(*args, **original_kwargs)85 return meth(*args, **original_kwargs)
@@ -171,7 +177,7 @@
171 dbus_interface.proxy.get_dbus_method("Get",177 dbus_interface.proxy.get_dbus_method("Get",
172 dbus_interface=dbus.PROPERTIES_IFACE),178 dbus_interface=dbus.PROPERTIES_IFACE),
173 self.INTERFACE_NAME, "extensions")179 self.INTERFACE_NAME, "extensions")
174 180
175 def get_extension(cls, name, path, busname=None):181 def get_extension(cls, name, path, busname=None):
176 """ Returns an interface to the given extension.182 """ Returns an interface to the given extension.
177 183
@@ -209,6 +215,8 @@
209 self.__shared_state["extension_interfaces"] = {}215 self.__shared_state["extension_interfaces"] = {}
210 self.__shared_state["dbus_interface"] = _DBusInterface(proxy,216 self.__shared_state["dbus_interface"] = _DBusInterface(proxy,
211 self.INTERFACE_NAME, self.OBJECT_PATH)217 self.INTERFACE_NAME, self.OBJECT_PATH)
218 self.reconnect_callbacks = \
219 self.__shared_state["dbus_interface"].reconnect_callbacks
212220
213class Monitor(dbus.service.Object):221class Monitor(dbus.service.Object):
214 """222 """
@@ -317,6 +325,8 @@
317 DBus calls use the raw DBus API found in the ZeitgeistDBusInterface class.325 DBus calls use the raw DBus API found in the ZeitgeistDBusInterface class.
318 """326 """
319 327
328 _installed_monitors = []
329
320 @staticmethod330 @staticmethod
321 def get_event_and_extra_arguments(arguments):331 def get_event_and_extra_arguments(arguments):
322 """ some methods of :class:`ZeitgeistClient` take a variable332 """ some methods of :class:`ZeitgeistClient` take a variable
@@ -335,6 +345,18 @@
335 self._iface = ZeitgeistDBusInterface()345 self._iface = ZeitgeistDBusInterface()
336 self._registry = self._iface.get_extension("DataSourceRegistry",346 self._registry = self._iface.get_extension("DataSourceRegistry",
337 "data_source_registry")347 "data_source_registry")
348
349 # Reconnect all active monitors if the connection is reset.
350 def reconnect_monitors():
351 log.info("Reconnected to Zeitgeist engine...")
352 for monitor in self._installed_monitors:
353 self._iface.InstallMonitor(monitor.path,
354 monitor.time_range,
355 monitor.templates,
356 reply_handler=self._void_reply_handler,
357 error_handler=lambda err: log.warn(
358 "Error reinstalling monitor: %s" % err))
359 self._iface.reconnect_callbacks.append(reconnect_monitors)
338 360
339 def _safe_error_handler(self, error_handler, *args):361 def _safe_error_handler(self, error_handler, *args):
340 if error_handler is not None:362 if error_handler is not None:
@@ -837,6 +859,7 @@
837 reply_handler=self._void_reply_handler,859 reply_handler=self._void_reply_handler,
838 error_handler=lambda err: log.warn(860 error_handler=lambda err: log.warn(
839 "Error installing monitor: %s" % err))861 "Error installing monitor: %s" % err))
862 self._installed_monitors.append(mon)
840 return mon863 return mon
841 864
842 def remove_monitor (self, monitor, monitor_removed_handler=None):865 def remove_monitor (self, monitor, monitor_removed_handler=None):
@@ -875,6 +898,7 @@
875 self._iface.RemoveMonitor(path,898 self._iface.RemoveMonitor(path,
876 reply_handler=reply_handler,899 reply_handler=reply_handler,
877 error_handler=error_handler)900 error_handler=error_handler)
901 self._installed_monitors.remove(monitor)
878 902
879 def register_data_source(self, unique_id, name, description, event_templates):903 def register_data_source(self, unique_id, name, description, event_templates):
880 """904 """