Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorius/TProbe.py
diff options
context:
space:
mode:
Diffstat (limited to 'tutorius/TProbe.py')
-rw-r--r--tutorius/TProbe.py76
1 files changed, 63 insertions, 13 deletions
diff --git a/tutorius/TProbe.py b/tutorius/TProbe.py
index acba26f..2f99329 100644
--- a/tutorius/TProbe.py
+++ b/tutorius/TProbe.py
@@ -47,6 +47,10 @@ import copy
-------------------- ----------
"""
+
+#Prefix separator for action/event addresses
+PSEP=":"
+
#TODO Add stub error handling for remote calls in the classes so that it will
# be clearer how errors can be handled in the future.
@@ -429,6 +433,7 @@ class ProbeProxy:
bus = dbus.SessionBus()
self._object = bus.get_object(activityName, "/tutorius/Probe/"+str(unique_id))
self._probe = dbus.Interface(self._object, "org.tutorius.ProbeInterface")
+ self.prefix = str(unique_id)+PSEP
self._actions = {}
self._edition_callbacks = {}
@@ -480,7 +485,7 @@ class ProbeProxy:
if editing_cb:
self._edition_callbacks[address] = editing_cb
# Propagate the action installed callback upwards in the stack
- callback(address)
+ callback(self.prefix + address)
def __clear_action(self, address):
# Remove the action installed at this address
@@ -563,7 +568,7 @@ class ProbeProxy:
# our dictionary (python pass arguments by reference)
self._subscribedEvents[address] = copy.copy(event)
- event_subscribed_cb(address)
+ event_subscribed_cb(self.prefix + address)
return address
def __clear_event(self, address):
@@ -679,6 +684,12 @@ class ProbeManager(object):
currentActivity = property(fget=getCurrentActivity, fset=setCurrentActivity)
+ def get_source_activity(self, propc):
+ if hasattr(propc, "source"):
+ return propc.source
+ else:
+ return None
+
def install(self, action, action_installed_cb, error_cb, is_editing=False, editing_cb=None):
"""
Install an action on the current activity
@@ -691,8 +702,13 @@ class ProbeManager(object):
this action (only used when is_editing is true)
@return None
"""
- if self.currentActivity:
- return self._first_proxy(self.currentActivity).install(
+ activity = self.get_source_activity(action)
+ #Allow the creator to look for the current activity
+ if activity is None and is_editing:
+ activity = self.currentActivity
+
+ if activity:
+ return self._first_proxy(activity).install(
action=action,
is_editing=is_editing,
action_installed_cb=action_installed_cb,
@@ -710,8 +726,15 @@ class ProbeManager(object):
@param is_editing whether this action comes from the editor
@return None
"""
- if self.currentActivity:
- return self._first_proxy(self.currentActivity).update(action_address, newaction, is_editing)
+ probe_id, sep, address = action_address.rpartition(PSEP)
+ if probe_id:
+ probe = self._get_proxy_by_unique_id(probe_id)
+ if probe is None:
+ #TODO What happens if the Probe is gone??
+ raise RuntimeWarning("ProbeProxy containing action address is gone")
+ else:
+ return probe.update(address, newaction, is_editing)
+
else:
raise RuntimeWarning("No activity attached")
@@ -722,8 +745,16 @@ class ProbeManager(object):
@param block Force a synchroneous dbus call if True
@param is_editing whether this action comes from the editor
"""
- if self.currentActivity:
- return self._first_proxy(self.currentActivity).uninstall(action_address, is_editing)
+ probe_id, sep, address = action_address.rpartition(PSEP)
+ if probe_id:
+ probe = self._get_proxy_by_unique_id(probe_id)
+ if probe is None:
+ logging.warning(
+ "ProbeProxy for address %s is gone, assuming uninstall not necessary" % \
+ action_address)
+ else:
+ return probe.uninstall(address, is_editing)
+
else:
raise RuntimeWarning("No activity attached")
@@ -751,8 +782,10 @@ class ProbeManager(object):
installation
@return address identifier used for unsubscribing
"""
- if self.currentActivity:
- return self._first_proxy(self.currentActivity).subscribe(event, notification_cb,\
+ activity = self.get_source_activity(event)
+
+ if activity:
+ return self._first_proxy(activity).subscribe(event, notification_cb,\
event_subscribed_cb, error_cb)
else:
raise RuntimeWarning("No activity attached")
@@ -763,8 +796,15 @@ class ProbeManager(object):
@param address identifier given by subscribe()
@return None
"""
- if self.currentActivity:
- return self._first_proxy(self.currentActivity).unsubscribe(address)
+ probe_id, sep, address = address.rpartition(PSEP)
+ if probe_id:
+ probe = self._get_proxy_by_unique_id(probe_id)
+ if probe is None:
+ logging.warning(
+ "ProbeProxy for address %s is gone, assuming unsubscribe not necessary" % \
+ address)
+ else:
+ return probe.unsubscribe(address)
else:
raise RuntimeWarning("No activity attached")
@@ -825,4 +865,14 @@ class ProbeManager(object):
else:
raise RuntimeWarning("No activity attached under '%s'", process_name)
-
+ def _get_proxy_by_unique_id(self, unique_id):
+ """
+ Get a probe proxy by it's unique id.
+ @param unique_id The unique id of the probe
+ @return the probe proxy or None if not found
+ """
+ for probes in self._probes.values():
+ for id, probe in probes:
+ if id == unique_id:
+ return probe
+ return None