From b290d0384ea13319026ddcaeca5d567a2556f0e3 Mon Sep 17 00:00:00 2001 From: mike Date: Thu, 26 Nov 2009 23:03:38 +0000 Subject: LP 448319 : Code review changes 2 --- (limited to 'tutorius') diff --git a/tutorius/TProbe.py b/tutorius/TProbe.py index e408fe9..dd27762 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, ignore, logError +from .dbustools import remote_call, save_args import copy """ @@ -359,7 +359,7 @@ class ProbeProxy: del self._actions[this_action] break - def __update_event(self, event_name, event, callback, event_subscribed_cb, address): + def __update_event(self, event, callback, event_subscribed_cb, address): LOGGER.debug("ProbeProxy :: Registered event %s with address %s", str(hash(event)), str(address)) # Since multiple callbacks could be associated to the same # event signature, we will store multiple callbacks @@ -408,7 +408,7 @@ class ProbeProxy: else: LOGGER.debug("ProbeProxy :: unsubsribe address %s inconsistency : not registered", address) - def subscribe(self, event_name, event, notification_cb, event_subscribed_cb, error_cb): + def subscribe(self, event, notification_cb, event_subscribed_cb, error_cb): """ Register an event listener @param event Event to listen for @@ -425,7 +425,7 @@ class ProbeProxy: # for event types and sources, we will need to revise the lookup # mecanism for which callback function to call self._probe.subscribe(pickle.dumps(event), - reply_handler=save_args(self.__update_event, event_name, event, notification_cb, event_subscribed_cb), + reply_handler=save_args(self.__update_event, event, notification_cb, event_subscribed_cb), error_handler=save_args(error_cb, event)) def unsubscribe(self, address, block=True): @@ -526,7 +526,7 @@ class ProbeManager(object): else: raise RuntimeWarning("No activity attached") - def subscribe(self, event_name, event, notification_cb, event_subscribed_cb, error_cb): + def subscribe(self, event, notification_cb, event_subscribed_cb, error_cb): """ Register an event listener @param event Event to listen for @@ -538,7 +538,7 @@ class ProbeManager(object): @return address identifier used for unsubscribing """ if self.currentActivity: - return self._first_proxy(self.currentActivity).subscribe(event_name, event, notification_cb,\ + return self._first_proxy(self.currentActivity).subscribe(event, notification_cb,\ event_subscribed_cb, error_cb) else: raise RuntimeWarning("No activity attached") diff --git a/tutorius/engine.py b/tutorius/engine.py index 46e1152..c882d91 100644 --- a/tutorius/engine.py +++ b/tutorius/engine.py @@ -91,7 +91,7 @@ class TutorialRunner(object): if self._runner_state == RUNNER_STATE_SETUP_ACTIONS or \ self._runner_state == RUNNER_STATE_SETUP_EVENTS: heappush(self._message_queue, (STOP_MSG_PRIORITY, None)) - else: + elif self._runner_state != RUNNER_STATE_IDLE: self._execute_stop() def action_installed(self, action_name, address): diff --git a/tutorius/translator.py b/tutorius/translator.py index 13b3c61..4f29078 100644 --- a/tutorius/translator.py +++ b/tutorius/translator.py @@ -53,10 +53,6 @@ class ResourceTranslator(object): self._probe_manager = probe_manager self._tutorial_id = tutorial_id - self._translation_mapping = {} - self._action_installed_cbs = {} - self._install_error_cbs = {} - def translate_resource(self, res_value): """ Replace the TResourceProperty in the container by their @@ -154,8 +150,8 @@ class ResourceTranslator(object): def detach(self, activity_id): self._probe_manager.detach(activity_id) - def subscribe(self, event_name, event, notification_cb, event_subscribed_cb, error_cb): - return self._probe_manager.subscribe(event_name, event, notification_cb, event_subscribed_cb, error_cb) + def subscribe(self, event, notification_cb, event_subscribed_cb, error_cb): + return self._probe_manager.subscribe(event, notification_cb, event_subscribed_cb, error_cb) def unsubscribe(self, address): return self._probe_manager.unsubscribe(address) @@ -171,19 +167,14 @@ class ResourceTranslator(object): ########################################################################### - def action_installed(self, new_action, address): - # Update the internal mapping - self._translation_mapping[address] = new_action - + def action_installed(self, action_installed_cb, address): # Callback to the upper layers to inform them that the action # was installed - action_installed_cb = self._action_installed_cbs[new_action] action_installed_cb(address) - def action_install_error(self, new_action, exception): + def action_install_error(self, install_error_cb, old_action, exception): # Warn the upper layer that the installation failed - error_cb = self._install_error_cbs[new_action] - error_cb(old_action, exception) + install_error_cb(old_action, exception) # Decorated functions def install(self, action, action_installed_cb, error_cb): @@ -194,24 +185,16 @@ class ResourceTranslator(object): # Execute the replacement self.translate(new_action) - self._action_installed_cbs[new_action] = action_installed_cb - self._install_error_cbs[new_action] = error_cb - # Send the new action to the probe manager - self._probe_manager.install(new_action, save_args(self.action_installed, new_action), - save_args(self.action_install_error, new_action)) + self._probe_manager.install(new_action, save_args(self.action_installed, action_installed_cb), + save_args(self.action_install_error, error_cb, new_action)) def update(self, action_address, newaction): translated_new_action = copy_module.deepcopy(newaction) self.translate(translated_new_action) - self._translation_mapping[action_address] = translated_new_action - self._probe_manager.update(action_address, translated_new_action, block) def uninstall(self, action_address): - if self._translation_mapping.has_key(action_address): - del self._translation_mapping[action_address] - self._probe_manager.uninstall(action_address) -- cgit v0.9.1