Author: remi
Date: 2009-04-06 21:35:28 +0200 (Mon, 06 Apr 2009)
New Revision: 4368
Added:
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/scheduler/Task.py
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/scheduler/TasksContainer.py
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/Scheduler.py
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/const/ConstScheduler.py
Modified:
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/TuxAPI.py
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/scheduler/TaskDescription.py
Log:
* implemented scheduler module in the API
Modified:
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/TuxAPI.py
===================================================================
---
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/TuxAPI.py
2009-04-06 19:29:01 UTC (rev 4367)
+++
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/TuxAPI.py
2009-04-06 19:35:28 UTC (rev 4368)
@@ -18,6 +18,7 @@
from tuxdroid.const.ConstTuxOsl import *
from tuxdroid.const.ConstFramework import *
from tuxdroid.const.ConstAttitunes import *
+from tuxdroid.const.ConstScheduler import *
from tuxdroid.MouthEyes import MouthEyes
from tuxdroid.TTS import TTS
from tuxdroid.Wav import Wav
@@ -34,6 +35,7 @@
from tuxdroid.Battery import Battery
from tuxdroid.Charger import Charger
from tuxdroid.AttituneManager import AttituneManager
+from tuxdroid.Scheduler import Scheduler
#
------------------------------------------------------------------------------
# Tux Droid API.
@@ -95,6 +97,8 @@
self.framework = Framework(self, self.server)
# Create the attitune manager object
self.attitunes = AttituneManager(self, self.server)
+ # Create the scheduler object
+ self.scheduler = Scheduler(self, self.server)
# Bind some methods
self.__bindSomeMethods()
# Initialize the helper
@@ -110,6 +114,9 @@
# Attitune manager bindings
self.showAttitunes =
self.attitunes.getAttitunesContainer().showAttitunes
self.getAttitune = self.attitunes.getAttitunesContainer().getAttitune
+ # Scheduler bindings
+ self.showTasks = self.scheduler.getTasksContainer().showTasks
+ self.getTask = self.scheduler.getTasksContainer().getTask
#
--------------------------------------------------------------------------
# Get the version of this API.
Added:
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/scheduler/Task.py
===================================================================
---
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/scheduler/Task.py
(rev 0)
+++
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/scheduler/Task.py
2009-04-06 19:35:28 UTC (rev 4368)
@@ -0,0 +1,79 @@
+# Copyright (C) 2009 C2ME Sa
+# Remi Jocaille <[email protected]>
+# Distributed under the terms of the GNU General Public License
+# http://www.gnu.org/copyleft/gpl.html
+
+from tuxisalive.api.base.ApiBaseChildResource import ApiBaseChildResource
+
+from TaskDescription import *
+
+#
------------------------------------------------------------------------------
+# Class the create a scheduled task.
+#
------------------------------------------------------------------------------
+class Task(ApiBaseChildResource):
+ """Class the create a scheduled task.
+ """
+
+ #
--------------------------------------------------------------------------
+ # Constructor of the class.
+ #
--------------------------------------------------------------------------
+ def __init__(self, apiBase, apiBaseServer, parent, infosStructure):
+ """Constructor of the class.
+ @param apiBase: ApiBase parent object.
+ @param apiBaseServer: ApiBaseServer object.
+ @param parent: Parent scheduler.
+ @param infosStructure: Task structure as dictionary.
+ """
+ ApiBaseChildResource.__init__(self, apiBase, apiBaseServer)
+ self.__parent = parent
+ self.__description = TaskDescription(self, infosStructure)
+
+ #
--------------------------------------------------------------------------
+ # Get the parent scheduler.
+ #
--------------------------------------------------------------------------
+ def getScheduler(self):
+ """Get the parent scheduler.
+ @return: A scheduler object.
+ """
+ return self.__parent
+
+ #
--------------------------------------------------------------------------
+ # Get the task description object.
+ #
--------------------------------------------------------------------------
+ def getDescription(self):
+ """Get the task description object.
+ @return: The task description object.
+ """
+ return self.__description
+
+ #
--------------------------------------------------------------------------
+ # Show the description in the console.
+ #
--------------------------------------------------------------------------
+ def showDescription(self):
+ """Show the description in the console.
+ """
+ self.__description.show()
+
+ #
--------------------------------------------------------------------------
+ # Execute the action of the task.
+ #
--------------------------------------------------------------------------
+ def execute(self):
+ """Execute the action of the task.
+ """
+ argsToSend = {
+ 'task_id' : self.__description.getId(),
+ }
+ cmd = "scheduler/execute_task?"
+ return self._sendCommandBooleanResult(cmd, argsToSend)
+
+ #
--------------------------------------------------------------------------
+ # Remove the task from the scheduler.
+ #
--------------------------------------------------------------------------
+ def remove(self):
+ """Remove the task from the scheduler.
+ """
+ argsToSend = {
+ 'task_id' : self.__description.getId(),
+ }
+ cmd = "scheduler/remove_task?"
+ return self._sendCommandBooleanResult(cmd, argsToSend)
Property changes on:
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/scheduler/Task.py
___________________________________________________________________
Name: svn:keywords
+ Id
Modified:
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/scheduler/TaskDescription.py
===================================================================
---
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/scheduler/TaskDescription.py
2009-04-06 19:29:01 UTC (rev 4367)
+++
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/scheduler/TaskDescription.py
2009-04-06 19:35:28 UTC (rev 4368)
@@ -96,7 +96,7 @@
"""Get the week mask.
@return: A string.
"""
- return self.__dictionary['weekMaskString']:
+ return self.__dictionary['weekMaskString']
#
--------------------------------------------------------------------------
# Get the year value.
@@ -159,7 +159,7 @@
"""Get the user data.
@return: A dictionary.
"""
- return self.__dictionary['data']
+ return self.__dictionary['userData']
#
--------------------------------------------------------------------------
# Show the description in the console.
Added:
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/scheduler/TasksContainer.py
===================================================================
---
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/scheduler/TasksContainer.py
(rev 0)
+++
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/scheduler/TasksContainer.py
2009-04-06 19:35:28 UTC (rev 4368)
@@ -0,0 +1,115 @@
+# Copyright (C) 2009 C2ME Sa
+# Remi Jocaille <[email protected]>
+# Distributed under the terms of the GNU General Public License
+# http://www.gnu.org/copyleft/gpl.html
+
+import threading
+
+from tuxisalive.api.base.ApiBaseChildResource import ApiBaseChildResource
+from Task import Task
+
+#
------------------------------------------------------------------------------
+# Tasks container.
+#
------------------------------------------------------------------------------
+class TasksContainer(ApiBaseChildResource):
+
+ #
--------------------------------------------------------------------------
+ # Constructor of the class.
+ #
--------------------------------------------------------------------------
+ def __init__(self, apiBase, apiBaseServer, structure):
+ """Constructor of the class.
+ @param apiBase: ApiBase parent object.
+ @param apiBaseServer: ApiBaseServer object.
+ @param structure: Tasks container structure as dictionary.
+ """
+ ApiBaseChildResource.__init__(self, apiBase, apiBaseServer)
+ self.__tasks = []
+ self.__mutex = threading.Lock()
+ self._update(structure)
+
+ #
--------------------------------------------------------------------------
+ # Update the container structure.
+ #
--------------------------------------------------------------------------
+ def _update(self, structure):
+ """Update the container structure.
+ @param structure: The new container structure dictionary.
+ """
+ self.__mutex.acquire()
+ self.__tasks = []
+ for key in structure.keys():
+ if key.lower().find('data') == 0:
+ self.__tasks.append(Task(self.getParent(),
+ self.getServer(), self, structure[key]))
+ self.__mutex.release()
+
+ #
--------------------------------------------------------------------------
+ # Get the task objects list.
+ #
--------------------------------------------------------------------------
+ def getTasks(self):
+ """Get the task objects list.
+ @return: A list of Task objects.
+ """
+ self.__mutex.acquire()
+ result = self.__tasks
+ self.__mutex.release()
+ return result
+
+ #
--------------------------------------------------------------------------
+ # Get the number of tasks contained in the container.
+ #
--------------------------------------------------------------------------
+ def getCount(self):
+ """Get the number of tasks contained in the container.
+ @return: An integer.
+ """
+ self.__mutex.acquire()
+ result = len(self.__tasks)
+ self.__mutex.release()
+ return result
+
+ #
--------------------------------------------------------------------------
+ # Show the tasks list in the console.
+ #
--------------------------------------------------------------------------
+ def showTasks(self):
+ """Show the tasks list in the console.
+ """
+ result = []
+ self.__mutex.acquire()
+ for task in self.__tasks:
+ result.append("%s : %s" % (task.getDescription().getName(),
+ task.getDescription().toString()))
+ self.__mutex.release()
+ self._showStringList("Tasks list :", result)
+
+ #
--------------------------------------------------------------------------
+ # Get a task object by it name or index.
+ #
--------------------------------------------------------------------------
+ def getTask(self, task):
+ """Get a task object by it name or index.
+ @param task: The name or index of the task.
+ @return: A Task object or None.
+ """
+ self.__mutex.acquire()
+ if str(type(task)) == "<type 'int'>":
+ if task in range(len(self.__tasks)):
+ result = self.__tasks[task]
+ self.__mutex.release()
+ return result
+ else:
+ for taskObject in self.__tasks:
+ if taskObject.getDescription().getName() == task:
+ result = taskObject
+ self.__mutex.release()
+ return result
+ self.__mutex.release()
+ return None
+
+ #
--------------------------------------------------------------------------
+ # Remove a task from the scheduler.
+ #
--------------------------------------------------------------------------
+ def removeTask(self, task):
+ """Remove a task from the scheduler.
+ @param task: The name or index of the task.
+ """
+ taskObject = self.getTask(task)
+ if taskObject != None:
+ taskObject.remove()
Property changes on:
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/scheduler/TasksContainer.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added:
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/Scheduler.py
===================================================================
---
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/Scheduler.py
(rev 0)
+++
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/Scheduler.py
2009-04-06 19:35:28 UTC (rev 4368)
@@ -0,0 +1,64 @@
+# Copyright (C) 2009 C2ME Sa
+# Remi Jocaille <[email protected]>
+# Distributed under the terms of the GNU General Public License
+# http://www.gnu.org/copyleft/gpl.html
+
+from const.ConstScheduler import *
+from tuxisalive.api.scheduler.TasksContainer import TasksContainer
+from tuxisalive.api.base.ApiBaseChildResource import ApiBaseChildResource
+
+
+#
------------------------------------------------------------------------------
+# Class to control the scheduler.
+#
------------------------------------------------------------------------------
+class Scheduler(ApiBaseChildResource):
+ """Class to control the scheduler.
+ """
+
+ #
--------------------------------------------------------------------------
+ # Constructor of the class.
+ #
--------------------------------------------------------------------------
+ def __init__(self, apiBase, apiBaseServer):
+ """Constructor of the class.
+ @param apiBase: ApiBase parent object.
+ @param apiBaseServer: ApiBaseServer object.
+ """
+ ApiBaseChildResource.__init__(self, apiBase, apiBaseServer)
+ for statusName in SW_NAME_SCHEDULER_MANAGER:
+ self._insertNewEvent(statusName)
+ self.__tasksContainer = TasksContainer(apiBase, apiBaseServer, {})
+ self._registerEvent(ST_NAME_SCM_TASK_ADDED, None,
+ self.__updateTasksContainer)
+ self._registerEvent(ST_NAME_SCM_TASK_REMOVED, None,
+ self.__updateTasksContainer)
+
+ #
--------------------------------------------------------------------------
+ # Get the tasks container.
+ #
--------------------------------------------------------------------------
+ def getTasksContainer(self):
+ """Get the tasks container.
+ @return: The tasks container.
+ """
+ return self.__tasksContainer
+
+ #
--------------------------------------------------------------------------
+ # Get if the scheduler is started or not.
+ #
--------------------------------------------------------------------------
+ def isStarted(self):
+ """Get if the scheduler is started or not.
+ @return: True or False:
+ """
+ ret = self._requestOne(ST_NAME_SCM_RUN)
+ if ret == "True":
+ return True
+ else:
+ return False
+
+ #
--------------------------------------------------------------------------
+ # Update tasks list on task added/removed events.
+ #
--------------------------------------------------------------------------
+ def __updateTasksContainer(self, *args):
+ cmd = "scheduler/tasks_infos?"
+ ret, result = self._sendCommandFullResultEx(cmd)
+ if ret:
+ self.__tasksContainer._update(result)
Property changes on:
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/Scheduler.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added:
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/const/ConstScheduler.py
===================================================================
---
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/const/ConstScheduler.py
(rev 0)
+++
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/const/ConstScheduler.py
2009-04-06 19:35:28 UTC (rev 4368)
@@ -0,0 +1,16 @@
+# Copyright (C) 2009 C2ME Sa
+# Remi Jocaille <[email protected]>
+# Distributed under the terms of the GNU General Public License
+# http://www.gnu.org/copyleft/gpl.html
+
+#
+# Scheduler manager events/statuses
+#
+ST_NAME_SCM_RUN = "scheduler_manager_run"
+ST_NAME_SCM_TASK_ADDED = "scheduler_manager_task_added"
+ST_NAME_SCM_TASK_REMOVED = "scheduler_manager_task_removed"
+SW_NAME_SCHEDULER_MANAGER = [
+ ST_NAME_SCM_RUN,
+ ST_NAME_SCM_TASK_ADDED,
+ ST_NAME_SCM_TASK_REMOVED,
+]
Property changes on:
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/const/ConstScheduler.py
___________________________________________________________________
Name: svn:keywords
+ Id
------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn