diff options
author | mike <michael.jmontcalm@gmail.com> | 2009-11-04 15:20:30 (GMT) |
---|---|---|
committer | mike <michael.jmontcalm@gmail.com> | 2009-11-04 15:20:30 (GMT) |
commit | 0db118e6320d157748fad0b4d7a31beebcf5b301 (patch) | |
tree | 80fc57cfbb02a82cbcf58f0d0e4e2c41cfa190df /tutorius/TProbe.py | |
parent | 58a99dcf76cb1a9f85fa2873f9a2e7b46470ae8b (diff) | |
parent | d50c3cd98d6e99c7311286559136dc1a775a326d (diff) |
Merge branch 'master' of git://git.sugarlabs.org/tutorius/mainline
Diffstat (limited to 'tutorius/TProbe.py')
-rw-r--r-- | tutorius/TProbe.py | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/tutorius/TProbe.py b/tutorius/TProbe.py index 6d7b6e2..f55547c 100644 --- a/tutorius/TProbe.py +++ b/tutorius/TProbe.py @@ -8,12 +8,12 @@ import dbus import dbus.service import cPickle as pickle -import sugar.tutorius.addon as addon -from sugar.tutorius.services import ObjectStore -from sugar.tutorius.properties import TPropContainer +from . import addon +from .services import ObjectStore +from .properties import TPropContainer -from sugar.tutorius.dbustools import remote_call, save_args +from .dbustools import remote_call, save_args import copy """ @@ -195,7 +195,11 @@ class TProbe(dbus.service.Object): # The actual method we will call on the probe to send events def notify(self, event): LOGGER.debug("TProbe :: notify event %s", str(event)) - self.eventOccured(pickle.dumps(event)) + #Check that this event is even allowed + if event in self._subscribedEvents.values(): + self.eventOccured(pickle.dumps(event)) + else: + raise RuntimeWarning("Attempted to raise an unregistered event") # Return a unique name for this action def _generate_action_reference(self, action): @@ -388,8 +392,6 @@ class ProbeProxy: @return None """ LOGGER.debug("ProbeProxy :: Unregister adress %s issued", str(address)) - if not block: - raise RuntimeError("This function does not allow non-blocking mode yet") if address in self._subscribedEvents.keys(): remote_call(self._probe.unsubscribe, (address,), return_cb=save_args(self.__clear_event, address), @@ -402,8 +404,8 @@ class ProbeProxy: Detach the ProbeProxy from it's TProbe. All installed actions and subscribed events should be removed. """ - for action in self._actions.keys(): - self.uninstall(action, block) + for action_addr in self._actions.keys(): + self.uninstall(action_addr, block) for address in self._subscribedEvents.keys(): self.unsubscribe(address, block) @@ -416,7 +418,13 @@ class ProbeManager(object): For now, it only handles one at a time, though. Actually it doesn't do much at all. But it keeps your encapsulation happy """ - def __init__(self): + def __init__(self, proxy_class=ProbeProxy): + """Constructor + @param proxy_class Class to use for creating Proxies to activities. + The class should support the same interface as ProbeProxy. Exists + to make this class unit-testable by replacing the Proxy with a mock + """ + self._ProxyClass = proxy_class self._probes = {} self._current_activity = None @@ -433,7 +441,7 @@ class ProbeManager(object): if activity_id in self._probes: raise RuntimeWarning("Activity already attached") - self._probes[activity_id] = ProbeProxy(activity_id) + self._probes[activity_id] = self._ProxyClass(activity_id) #TODO what do we do with this? Raise something? if self._probes[activity_id].isAlive(): print "Alive!" @@ -444,6 +452,8 @@ class ProbeManager(object): if activity_id in self._probes: probe = self._probes.pop(activity_id) probe.detach() + if self._current_activity == activity_id: + self._current_activity = None def install(self, action, block=False): """ |