From 6686a0f73d0eaa86221f40a7074e8f5b3aac7d63 Mon Sep 17 00:00:00 2001 From: mike Date: Fri, 27 Nov 2009 00:11:21 +0000 Subject: LP 448319 : Code review changes for Probe and ProbeMan --- diff --git a/tests/enginetests.py b/tests/enginetests.py index f24aedb..1723954 100644 --- a/tests/enginetests.py +++ b/tests/enginetests.py @@ -72,17 +72,17 @@ class MockProbeMgrMultiAddons(object): def uninstall(self, action_address): del self.action_dict[action_address] - def subscribe(self, event_name, event, notif_cb, subscribe_cb, error_cb): + def subscribe(self, event, notif_cb, subscribe_cb, error_cb): event_address = str(uuid1()) - self.event_dict[event_name] = event_address - self.event_cb_dict[event_name] = notif_cb + self.event_dict[event_address] = event + self.event_cb_dict[event_address] = notif_cb self._event_subscribed_cb_list.append(subscribe_cb) self._subscribe_error_cb_list.append(error_cb) def unsubscribe(self, address): - for (event_name, other_event) in self.event_dict.values(): - if event == othet_event: - del self.event_dict[event_name] + for (event_address, other_event) in self.event_dict.values(): + if event == other_event: + del self.event_dict[address] break class MockProbeMgr(object): @@ -110,7 +110,7 @@ class MockProbeMgr(object): def uninstall(self, action_address): self.action = None - def subscribe(self, event_name, event, notif_cb, event_sub_cb, error_cb): + def subscribe(self, event, notif_cb, event_sub_cb, error_cb): self.event = event self.cB = notif_cb self.event.install_handlers(notif_cb) diff --git a/tests/probetests.py b/tests/probetests.py index 8dbac29..37748d8 100644 --- a/tests/probetests.py +++ b/tests/probetests.py @@ -470,6 +470,7 @@ class ProbeProxyTest(unittest.TestCase): event_address = 'event1' event2 = MockAddon() event2.i, event2.s = 10, "event2" + event_address2 = 'event2' def callback(event): global message_box @@ -499,7 +500,7 @@ class ProbeProxyTest(unittest.TestCase): #ErrorCase: unsubcribe for non subscribed event #Test the unsubscribe - self.probeProxy.unsubscribe("otheraddress") + self.probeProxy.unsubscribe(event_address2) assert not "unsubscribe" in self.mockObj.MockCall, "Unsubscribe should not be called if event is not subscribeed" self.probeProxy.unsubscribe(event_address) diff --git a/tutorius/TProbe.py b/tutorius/TProbe.py index dd27762..4e458a0 100644 --- a/tutorius/TProbe.py +++ b/tutorius/TProbe.py @@ -29,7 +29,7 @@ from . import addon from .services import ObjectStore from .properties import TPropContainer -from .dbustools import remote_call, save_args +from .dbustools import save_args, ignore, logError import copy """ @@ -289,7 +289,6 @@ class ProbeProxy: self._subscribedEvents = {} self._registeredCallbacks = {} - self._object.connect_to_signal("eventOccured", self._handle_signal, dbus_interface="org.tutorius.ProbeInterface") def _handle_signal(self, pickled_event): @@ -313,11 +312,11 @@ class ProbeProxy: def __update_action(self, action, callback, address): LOGGER.debug("ProbeProxy :: Updating action %s with address %s", str(action), str(address)) - self._actions[action] = str(address) + self._actions[address] = action callback(address) - def __clear_action(self, action): - self._actions.pop(action, None) + def __clear_action(self, address): + self._actions.pop(address, None) def install(self, action, action_installed_cb, error_cb): """ @@ -341,10 +340,12 @@ class ProbeProxy: @return None """ #TODO review how to make this work well - if not action_address in self._actions.values(): + if not action_address in self._actions.keys(): raise RuntimeWarning("Action not installed") #TODO Check error handling - return remote_call(self._probe.update, (action_address, pickle.dumps(newaction._props)), block=False) + return self._probe.update(action_address, pickle.dumps(newaction._props), + reply_handler=ignore, + error_handler=logError) def uninstall(self, action_address): """ @@ -353,11 +354,9 @@ class ProbeProxy: on action installation @param block Force a synchroneous dbus call if True """ - for (this_action, this_address) in self._actions.items(): - if this_address == action_address: - remote_call(self._probe.uninstall,(action_address,)) - del self._actions[this_action] - break + if action_address in self._actions: + self._actions.pop(action_address, None) + self._probe.uninstall(action_address, reply_handler=ignore, error_handler=logError) def __update_event(self, event, callback, event_subscribed_cb, address): LOGGER.debug("ProbeProxy :: Registered event %s with address %s", str(hash(event)), str(address)) @@ -437,9 +436,10 @@ class ProbeProxy: """ LOGGER.debug("ProbeProxy :: Unregister adress %s issued", str(address)) if address in self._subscribedEvents.keys(): - remote_call(self._probe.unsubscribe, (address,), - return_cb=save_args(self.__clear_event, address), - block=block) + self.__clear_event(address) + self._probe.unsubscribe(address, + reply_handler=save_args(self.__clear_event, address), + error_handler=logError) else: LOGGER.debug("ProbeProxy :: unsubscribe address %s failed : not registered", address) diff --git a/tutorius/engine.py b/tutorius/engine.py index c882d91..198fa11 100644 --- a/tutorius/engine.py +++ b/tutorius/engine.py @@ -141,7 +141,7 @@ class TutorialRunner(object): # Send all the event registration for (event_name, (event, next_state)) in transitions.items(): - self._pM.subscribe(event_name, event, + self._pM.subscribe(event, save_args(self._handleEvent, next_state), save_args(self.event_subscribed, event_name), save_args(self.subscribe_error, event_name)) @@ -190,8 +190,8 @@ class TutorialRunner(object): def _remove_subscribed_events(self): #Clear the EventFilters - for (event_name, event) in self._subscribed_events.items(): - self._pM.unsubscribe(event) + for (event_name, event_address) in self._subscribed_events.items(): + self._pM.unsubscribe(event_address) self._subscribed_events.clear() self._subscription_errors.clear() -- cgit v0.9.1