Author: remi
Date: 2009-04-07 12:29:17 +0200 (Tue, 07 Apr 2009)
New Revision: 4381

Modified:
   
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/01_robot_system/resourceScheduler.py
Log:
* added methods and service to load/auto-load a directory of tasks

Modified: 
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/01_robot_system/resourceScheduler.py
===================================================================
--- 
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/01_robot_system/resourceScheduler.py
       2009-04-07 09:54:40 UTC (rev 4380)
+++ 
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/01_robot_system/resourceScheduler.py
       2009-04-07 10:29:17 UTC (rev 4381)
@@ -47,12 +47,15 @@
         # Registering the scheduler manager statuses.
         for statusName in SW_NAME_SCHEDULER_MANAGER:
             eventsHandler.insert(statusName)
+        self.__publishEvents(True, ST_NAME_SCM_RUN, ["False",])
+        # Default configuration
+        self.defaultConfiguration = {
+            'auto-start' : False,
+            'tasks_path' : "",
+        }
 
-    def start(self):
-        self.__scheduler.start()
-        self.__publishEvents(True, ST_NAME_SCM_RUN, ["True",])
-
     def stop(self):
+        self.getConfigurator().store()
         self.__scheduler.stop()
         self.__publishEvents(True, ST_NAME_SCM_RUN, ["False",])
 
@@ -115,6 +118,9 @@
     # Public methods
     # 
--------------------------------------------------------------------------
 
+    def publishEvents(self, sendToClients, eventName, eventValues = []):
+        self.__publishEvents(sendToClients, eventName, eventValues)
+
     def getScheduler(self):
         """Get the scheduler.
         @return: A Scheduler object.
@@ -275,6 +281,55 @@
 resourcesManager.addResource(resourceScheduler)
 
 # 
------------------------------------------------------------------------------
+# Declaration of the service "start".
+# 
------------------------------------------------------------------------------
+class TDSServiceSchedulerStart(TDSService):
+
+    def configure(self):
+        self.parametersDict = {
+            'tasks_path' : 'string',
+        }
+        self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS
+        self.exclusiveExecution = False
+        self.name = "start"
+        self.comment = "Start the scheduler."
+
+    def start(self):
+        # Auto start of this service with the resource configuration.
+        config = resourceScheduler.getConfigurator().load(
+            "resourceScheduler.conf",
+            resourceScheduler.defaultConfiguration)
+        if config['auto-start']:
+            resourceScheduler.getScheduler().start()
+            resourceScheduler.publishEvents(True, ST_NAME_SCM_RUN, ["True",])
+            resourceScheduler.getScheduler().loadTasks(config['tasks_path'])
+
+    def execute(self, id, parameters):
+        headersStruct = self.getDefaultHeadersStruct()
+        contentStruct = self.getDefaultContentStruct()
+        contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+        # Check the directory
+        if not os.path.isdir(parameters['tasks_path']):
+            contentStruct['root']['result'] = getStrError(E_TDREST_FAILED)
+        else:
+            # Store the configuration
+            configurator = resourceScheduler.getConfigurator()
+            config = configurator.getConfiguration()
+            config['tasks_path'] = parameters['tasks_path']
+            config['auto-start'] = True
+            configurator.store()
+            # Start the scheduler
+            resourceScheduler.getScheduler().stop()
+            resourceScheduler.publishEvents(True, ST_NAME_SCM_RUN, ["False",])
+            resourceScheduler.getScheduler().start()
+            resourceScheduler.publishEvents(True, ST_NAME_SCM_RUN, ["True",])
+            resourceScheduler.getScheduler().loadTasks(config['tasks_path'])
+        return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceScheduler.addService(TDSServiceSchedulerStart)
+
+# 
------------------------------------------------------------------------------
 # Declaration of the service "tasks_infos".
 # 
------------------------------------------------------------------------------
 class TDSServiceSchedulerTasksInfos(TDSService):


------------------------------------------------------------------------------
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

Reply via email to