diff options
Diffstat (limited to 'tutorius/TProbe.py')
-rw-r--r-- | tutorius/TProbe.py | 78 |
1 files changed, 64 insertions, 14 deletions
diff --git a/tutorius/TProbe.py b/tutorius/TProbe.py index 2834f0c..7f4126e 100644 --- a/tutorius/TProbe.py +++ b/tutorius/TProbe.py @@ -46,6 +46,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. @@ -94,7 +98,7 @@ class TProbe(dbus.service.Object): self._installedActions = {} self._subscribedEvents = {} - LOGGER.debug("TProbe :: registering '%s' with unique_id '%s'", self._activity_name, activity.get_id()) + LOGGER.debug("TProbe :: registering '%s' with unique_id '%s'", self._activity_name, self._unique_id) self._service_proxy.register_probe(self._activity_name, self._unique_id) def start(self): @@ -324,6 +328,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 = {} @@ -375,7 +380,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 @@ -458,7 +463,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): @@ -574,6 +579,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 @@ -586,8 +597,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, @@ -605,8 +621,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") @@ -617,8 +640,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") @@ -646,8 +677,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") @@ -658,8 +691,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") @@ -720,4 +760,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 |