From 53f7cc1f343e9f54bd61f92d434a9e700e7aa160 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Tue, 12 Sep 2006 13:21:18 +0200 Subject: [PATCH] Cleanup browser model service on destroy. Remove the activity service even if the owner is gone. --- activities/browser/BrowserActivity.py | 5 +++++ shell/PresenceService/PresenceService.py | 7 ++++--- shell/home/MeshGroup.py | 3 +-- sugar/p2p/model/LocalModel.py | 11 +++++++---- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/activities/browser/BrowserActivity.py b/activities/browser/BrowserActivity.py index a8c795a2..6d452c5f 100644 --- a/activities/browser/BrowserActivity.py +++ b/activities/browser/BrowserActivity.py @@ -25,6 +25,7 @@ class BrowserActivity(Activity): self._model = None self.set_title("Web Page") + self.connect('destroy', self._destroy_cb) vbox = gtk.VBox() @@ -123,3 +124,7 @@ class BrowserActivity(Activity): self._notif_bar.set_action('goto_shared_location', 'Go There') self._notif_bar.set_icon('stock_right') self._notif_bar.show() + + def _destroy_cb(self, window): + if self._model: + self._model.shutdown() diff --git a/shell/PresenceService/PresenceService.py b/shell/PresenceService/PresenceService.py index 56b54a32..ae7f7e05 100644 --- a/shell/PresenceService/PresenceService.py +++ b/shell/PresenceService/PresenceService.py @@ -536,6 +536,9 @@ class PresenceService(object): if not service: return False + self._dbus_helper.ServiceDisappeared(service.object_path()) + self._handle_remove_activity_service(service) + # Decompose service name if we can (actid, buddy_name) = Service.decompose_service_name(full_name) @@ -545,10 +548,8 @@ class PresenceService(object): except KeyError: pass else: - buddy.remove_service(service) - self._dbus_helper.ServiceDisappeared(service.object_path()) - self._handle_remove_activity_service(service) if not buddy.is_valid(): + buddy.remove_service(service) self._dbus_helper.BuddyDisappeared(buddy.object_path()) del self._buddies[buddy_name] key = (service.get_full_name(), service.get_type()) diff --git a/shell/home/MeshGroup.py b/shell/home/MeshGroup.py index bae483e6..f7bc1c99 100644 --- a/shell/home/MeshGroup.py +++ b/shell/home/MeshGroup.py @@ -68,8 +68,7 @@ class MeshGroup(goocanvas.Group): self._activities[item.get_id()] = item - def _activity_disappeared_cb(self, activity): - print 'remove' + def _activity_disappeared_cb(self, pservice, activity): if self._activities.has_key(activity.get_id()): self.remove_child(self._activities[activity.get_id()]) del self._activities[activity.get_id()] diff --git a/sugar/p2p/model/LocalModel.py b/sugar/p2p/model/LocalModel.py index b19e07e4..0053aeef 100644 --- a/sugar/p2p/model/LocalModel.py +++ b/sugar/p2p/model/LocalModel.py @@ -37,13 +37,16 @@ class LocalModel(AbstractModel): self._notifier.notify(key) def _setup_service(self): - service = self._pservice.share_activity(self._activity, - stype = LocalModel.SERVICE_TYPE) - self._setup_server(service) - + self._service = self._pservice.share_activity( + self._activity, stype = LocalModel.SERVICE_TYPE) + self._setup_server(self._service) + # FIXME this is duplicated with StreamReader def _setup_server(self, service): port = service.get_port() logging.debug('Start model server on port %d' % (port)) p2p_server = network.GlibXMLRPCServer(("", port)) p2p_server.register_instance(ModelRequestHandler(self)) + + def shutdown(self): + self._pservice.unregister_service(self._service)