diff options
Diffstat (limited to 'tutorius/TProbe.py')
-rw-r--r-- | tutorius/TProbe.py | 70 |
1 files changed, 59 insertions, 11 deletions
diff --git a/tutorius/TProbe.py b/tutorius/TProbe.py index cfa734b..1bfa5e8 100644 --- a/tutorius/TProbe.py +++ b/tutorius/TProbe.py @@ -1,3 +1,18 @@ +# Copyright (C) 2009, Tutorius.org +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import logging LOGGER = logging.getLogger("sugar.tutorius.TProbe") import os @@ -8,12 +23,11 @@ import dbus import dbus.service import cPickle as pickle - from . import addon from .services import ObjectStore from .properties import TPropContainer -from .dbustools import remote_call, save_args +from .dbustools import remote_call, save_args, Future, logError import copy """ @@ -125,6 +139,8 @@ class TProbe(dbus.service.Object): address = self._generate_action_reference(action) + LOGGER.debug("Installing action with name : %s"%address) + self._installedActions[address] = action if action._props: @@ -143,6 +159,7 @@ class TProbe(dbus.service.Object): @param action_props pickled action properties @return None """ + LOGGER.debug("Updating action at address : %s"%address) action = self._installedActions[address] if action._props: @@ -160,6 +177,7 @@ class TProbe(dbus.service.Object): @return None """ if self._installedActions.has_key(address): + LOGGER.debug("Uninstalling action : %s"%address) action = self._installedActions[address] action.undo() self._installedActions.pop(address) @@ -190,6 +208,7 @@ class TProbe(dbus.service.Object): name = self._generate_event_reference(eventfilter) self._subscribedEvents[name] = eventfilter + LOGGER.debug("Subscribed to event %s"%name) return name @dbus.service.method("org.tutorius.ProbeInterface", @@ -202,6 +221,7 @@ class TProbe(dbus.service.Object): """ if self._subscribedEvents.has_key(address): + LOGGER.debug("Unsubscribing event at address : %s"%address) eventfilter = self._subscribedEvents[address] eventfilter.remove_handlers() self._subscribedEvents.pop(address) @@ -312,9 +332,15 @@ class ProbeProxy: @param block Force a synchroneous dbus call if True @return None """ - return remote_call(self._probe.install, (pickle.dumps(action),), - save_args(self.__update_action, action, callback), - block=block) + LOGGER.debug("ProbeProxy :: installing a new action %s"%str(action)) + action_address = Future("action_install") + #remote_call(self._probe.install, (pickle.dumps(action),), + # action_address._set, block) + self._probe.install(pickle.dumps(action), reply_handler=action_address._set, error_handler=logError) + # Get the value from the future! + address_name = action_address.get() + callback(address_name) + return address_name def update(self, action_address, newaction, block=False): """ @@ -328,7 +354,14 @@ class ProbeProxy: if not action_address in self._actions.keys(): raise RuntimeWarning("Action not installed") #TODO Check error handling - return remote_call(self._probe.update, (self._actions[action_address], pickle.dumps(newaction._props)), block=block) + LOGGER.debug("ProbeProxy :: Updating action at address %s"%action_address) + future_address = Future("action_update") + # Call the update method + remote_call(self._probe.update, (self._actions[action_address], pickle.dumps(newaction._props)), + save_args(future_address._set, action_address), block=block) + # Wait for the callback to be completed + future_address.get() + return None def uninstall(self, action_address, block=False): """ @@ -337,7 +370,12 @@ class ProbeProxy: @param block Force a synchroneous dbus call if True """ if action_name in self._actions.keys(): - remote_call(self._probe.uninstall,(self._actions.pop(action_name),), block=block) + LOGGER.debug("ProbeProxy :: Uninstalling action at %s"%action_address) + future_uninstall = Future("action_uninstall") + remote_call(self._probe.uninstall, (self._actions.pop(action_name),), + save_args(future_uninstall._set, action_address), block=block) + future_uninstall.get() + LOGGER.debug("ProbeProxy :: Uninstall complete for action at %s"%action_address) def __update_event(self, event, callback, address): LOGGER.debug("ProbeProxy :: Registered event %s with address %s", str(hash(event)), str(address)) @@ -402,9 +440,13 @@ class ProbeProxy: # TODO elavoie 2009-07-25 When we will allow for patterns both # for event types and sources, we will need to revise the lookup # mechanism for which callback function to call - return remote_call(self._probe.subscribe, (pickle.dumps(event),), - save_args(self.__update_event, event, callback), - block=block) + + # TODO : Remove all the block(s) from the dbus stack + future_subscribe = Future("event_subscribe") + self._probe.subscribe(pickle.dumps(event), reply_handler=future_subscribe._set, error_handler=logError) + event_address = future_subscribe.get() + LOGGER.debug("ProbeProxy :: Registering of event %s complete"%str(hash(event))) + return self.__update_event(event, callback, event_address) def unsubscribe(self, address, block=True): """ @@ -415,9 +457,13 @@ class ProbeProxy: """ LOGGER.debug("ProbeProxy :: Unregister adress %s issued", str(address)) if address in self._subscribedEvents.keys(): + future_unsubscribe = Future("event_subscribe") remote_call(self._probe.unsubscribe, (address,), - return_cb=save_args(self.__clear_event, address), + return_cb=save_args(future_unsubscribe._set, address), block=block) + future_unsubscribe.get() + self.__clear_event(address) + LOGGER.debug("ProbeProxy :: Unsubscribing from address %s complete"%str(address)) else: LOGGER.debug("ProbeProxy :: unsubscribe address %s failed : not registered", address) @@ -426,11 +472,13 @@ class ProbeProxy: Detach the ProbeProxy from it's TProbe. All installed actions and subscribed events should be removed. """ + LOGGER.debug("ProbeProxy :: detaching...") for action_addr in self._actions.keys(): self.uninstall(action_addr, block) for address in self._subscribedEvents.keys(): self.unsubscribe(address, block) + LOGGER.debug("ProbeProxy :: detaching complete") class ProbeManager(object): |