Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorius/TProbe.py
diff options
context:
space:
mode:
authormike <michael.jmontcalm@gmail.com>2009-11-22 04:24:14 (GMT)
committer mike <michael.jmontcalm@gmail.com>2009-11-22 04:24:14 (GMT)
commit00c4fe9e5f2373fcefe6fb3f46e641a3c416423e (patch)
tree7e9dadd6322fe3fde25de423ab71aefde1a55c19 /tutorius/TProbe.py
parent79349369000d53741a8874929044af4b6b48f2f4 (diff)
LP 448319 : Moving action installation to asynchronous version with confirmation
Diffstat (limited to 'tutorius/TProbe.py')
-rw-r--r--tutorius/TProbe.py64
1 files changed, 43 insertions, 21 deletions
diff --git a/tutorius/TProbe.py b/tutorius/TProbe.py
index 3a57161..37a5e0f 100644
--- a/tutorius/TProbe.py
+++ b/tutorius/TProbe.py
@@ -1,3 +1,19 @@
+# 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 1 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
@@ -13,7 +29,7 @@ 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, ignore, logError
import copy
"""
@@ -305,18 +321,19 @@ class ProbeProxy:
def __clear_action(self, action):
self._actions.pop(action, None)
- def install(self, action, callback, block=False):
+ def install(self, action, action_installed_cb, error_cb):
"""
Install an action on the TProbe's activity
@param action Action to install
- @param block Force a synchroneous dbus call if True
+ @param action_installed_cb The callback function to call once the action is installed
+ @param error_cb The callback function to call when an error happens
@return None
"""
- return remote_call(self._probe.install, (pickle.dumps(action),),
- save_args(self.__update_action, action, callback),
- block=block)
+ self._probe.install(pickle.dumps(action),
+ reply_handler=save_args(self.__update_action, action, action_installed_cb),
+ error_handler=save_args(error_cb, action))
- def update(self, action_address, newaction, block=False):
+ def update(self, action_address, newaction):
"""
Update an already installed action's properties and run it again
@param action_address The address of the action to update. This is
@@ -329,9 +346,9 @@ class ProbeProxy:
if not action_address in self._actions.values():
raise RuntimeWarning("Action not installed")
#TODO Check error handling
- return remote_call(self._probe.update, (action_address, pickle.dumps(newaction._props)), block=block)
+ return remote_call(self._probe.update, (action_address, pickle.dumps(newaction._props)), block=False)
- def uninstall(self, action_address, block=False):
+ def uninstall(self, action_address):
"""
Uninstall an installed action
@param action_address The address of the action to uninstall. This address was given
@@ -340,7 +357,7 @@ class ProbeProxy:
"""
for (this_action, this_address) in self._actions.items():
if this_address == action_address:
- remote_call(self._probe.uninstall,(action_address,), block=block)
+ remote_call(self._probe.uninstall,(action_address,))
del self._actions[this_action]
break
@@ -392,11 +409,13 @@ class ProbeProxy:
else:
LOGGER.debug("ProbeProxy :: unsubsribe address %s inconsistency : not registered", address)
- def subscribe(self, event, callback, block=True):
+ def subscribe(self, event, notification_cb, event_installed_cb=ignore, error_cb=logError, block=True):
"""
Register an event listener
@param event Event to listen for
- @param callback callable that will be called when the event occurs
+ @param notification_cb callable that will be called when the event occurs
+ @param event_installed_cb callable that will be called once the event is subscribed to
+ @param error_cb callable that will be called if the subscription fails
@param block Force a synchroneous dbus call if True (Not allowed yet)
@return address identifier used for unsubscribing
"""
@@ -408,7 +427,8 @@ class ProbeProxy:
# for event types and sources, we will need to revise the lookup
# mecanism for which callback function to call
return remote_call(self._probe.subscribe, (pickle.dumps(event),),
- save_args(self.__update_event, event, callback),
+ return_cb=save_args(self.__update_event, event, notification_cb),
+ error_cb=save_args(error_cb, event),
block=block)
def unsubscribe(self, address, block=True):
@@ -432,10 +452,10 @@ class ProbeProxy:
subscribed events should be removed.
"""
for action_addr in self._actions.keys():
- self.uninstall(action_addr, block)
+ self.uninstall(action_addr)
for address in self._subscribedEvents.keys():
- self.unsubscribe(address, block)
+ self.unsubscribe(address)
class ProbeManager(object):
@@ -471,19 +491,21 @@ class ProbeManager(object):
currentActivity = property(fget=getCurrentActivity, fset=setCurrentActivity)
- def install(self, action, callback, block=False):
+ def install(self, action, action_installed_cb, error_cb):
"""
Install an action on the current activity
@param action Action to install
+ @param action_installed_cb The callback to call once the action is installed
+ @param error_cb The callback that will be called if there is an error during installation
@param block Force a synchroneous dbus call if True
@return None
"""
if self.currentActivity:
- return self._first_proxy(self.currentActivity).install(action, callback, block)
+ return self._first_proxy(self.currentActivity).install(action, action_installed_cb, error_cb)
else:
raise RuntimeWarning("No activity attached")
- def update(self, action_address, newaction, block=False):
+ def update(self, action_address, newaction):
"""
Update an already installed action's properties and run it again
@param action_address Action to update
@@ -492,18 +514,18 @@ class ProbeManager(object):
@return None
"""
if self.currentActivity:
- return self._first_proxy(self.currentActivity).update(action_address, newaction, block)
+ return self._first_proxy(self.currentActivity).update(action_address, newaction)
else:
raise RuntimeWarning("No activity attached")
- def uninstall(self, action_address, block=False):
+ def uninstall(self, action_address):
"""
Uninstall an installed action
@param action Action to uninstall
@param block Force a synchroneous dbus call if True
"""
if self.currentActivity:
- return self._first_proxy(self.currentActivity).uninstall(action_address, block)
+ return self._first_proxy(self.currentActivity).uninstall(action_address)
else:
raise RuntimeWarning("No activity attached")