Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorius/translator.py
diff options
context:
space:
mode:
Diffstat (limited to 'tutorius/translator.py')
-rw-r--r--tutorius/translator.py61
1 files changed, 37 insertions, 24 deletions
diff --git a/tutorius/translator.py b/tutorius/translator.py
index d0504be..bfa1746 100644
--- a/tutorius/translator.py
+++ b/tutorius/translator.py
@@ -22,6 +22,7 @@ logger = logging.getLogger("ResourceTranslator")
from .properties import *
from .vault import Vault
+from .dbustools import save_args
class ResourceTranslator(object):
"""
@@ -53,6 +54,8 @@ class ResourceTranslator(object):
self._tutorial_id = tutorial_id
self._translation_mapping = {}
+ self._action_installed_cbs = {}
+ self._install_error_cbs = {}
def translate_resource(self, res_value):
"""
@@ -133,10 +136,11 @@ class ResourceTranslator(object):
# Change the list contained in the addonlist property, since
# we got a copy of the list when requesting it
prop_container.replace_property(propname, prop_value)
-
- ### ProbeManager interface for decorator ###
-
- ## Unchanged functions ##
+
+ ###########################################################################
+ ### ProbeManager interface for decorator
+
+ # Unchanged functions
def setCurrentActivity(self, activity_id):
self._probe_manager.currentActivity = activity_id
@@ -150,8 +154,8 @@ class ResourceTranslator(object):
def detach(self, activity_id):
self._probe_manager.detach(activity_id)
- def subscribe(self, event, callback):
- return self._probe_manager.subscribe(event, callback)
+ 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)
@@ -165,8 +169,24 @@ class ResourceTranslator(object):
def get_registered_probes_list(self, process_name=None):
return self._probe_manager.get_registered_probes_list(process_name)
- ## Decorated functions ##
- def install(self, action, callback, block=False):
+ ###########################################################################
+
+ def action_installed(self, new_action, address):
+ # Update the internal mapping
+ self._translation_mapping[address] = new_action
+
+ # 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):
+ # Warn the upper layer that the installation failed
+ error_cb = self._install_error_cbs[new_action]
+ error_cb(old_action, exception)
+
+ # Decorated functions
+ def install(self, action, action_installed_cb, error_cb):
# Make a new copy of the action that we want to install,
# because translate() changes the action and we
# don't want to modify the caller's action representation
@@ -174,31 +194,24 @@ class ResourceTranslator(object):
# Execute the replacement
self.translate(new_action)
- # Send the new action to the probe manager
- action_address = self._probe_manager.install(new_action, callback, block)
-
- # Remember the address
- self._translation_mapping[action_address] = new_action
+ self._action_installed_cbs[new_action] = save_args(action_installed_cb, action)
+ self._install_error_cbs[new_action] = save_args(error_cb, action)
- return action_address
+ # 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))
- def update(self, action_address, newaction, block=False):
- # TODO : Repair this as it currently doesn't work.
- # Actions are being copied, then translated in install(), so they
- # won't be addressable via the same object that is in the Tutorial
- # Runner.
+ 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
- return self._probe_manager.update(action_address, translated_new_action, block)
-
- def uninstall(self, action_address, block=False):
- return_value = self._probe_manager.uninstall(action_address, block)
+ 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]
- return return_value
+ self._probe_manager.uninstall(action_address)