[tuxdroid-svn] r4678 - in software_suite_v3/smart-core/smart-server/trunk/resources: . 00_smart_se
Status: Beta
Brought to you by:
ks156
|
From: remi <c2m...@c2...> - 2009-05-26 16:28:56
|
Author: remi
Date: 2009-05-26 18:28:45 +0200 (Tue, 26 May 2009)
New Revision: 4678
Added:
software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/
software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/00_resourceServer.py
software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/01_resourceStatus.py
software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/02_resourceAccess.py
software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/03_resourceClient.py
software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/04_resourceMenu.py
software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/10_resourceScheduler.py
software_suite_v3/smart-core/smart-server/trunk/resources/01_drivers/
software_suite_v3/smart-core/smart-server/trunk/resources/01_drivers/00_resourceTuxDriver.py
software_suite_v3/smart-core/smart-server/trunk/resources/01_drivers/01_resourceTuxOSL.py
software_suite_v3/smart-core/smart-server/trunk/resources/02_robot/
software_suite_v3/smart-core/smart-server/trunk/resources/02_robot/00_resourceAttitune.py
software_suite_v3/smart-core/smart-server/trunk/resources/02_robot/01_resourceEyes.py
software_suite_v3/smart-core/smart-server/trunk/resources/02_robot/02_resourceFlippers.py
software_suite_v3/smart-core/smart-server/trunk/resources/02_robot/03_resourceLeds.py
software_suite_v3/smart-core/smart-server/trunk/resources/02_robot/04_resourceMacro.py
software_suite_v3/smart-core/smart-server/trunk/resources/02_robot/05_resourceMouth.py
software_suite_v3/smart-core/smart-server/trunk/resources/02_robot/06_resourceSoundFlash.py
software_suite_v3/smart-core/smart-server/trunk/resources/02_robot/07_resourceSpinning.py
software_suite_v3/smart-core/smart-server/trunk/resources/02_robot/08_resourceTTS.py
software_suite_v3/smart-core/smart-server/trunk/resources/02_robot/09_resourceWav.py
software_suite_v3/smart-core/smart-server/trunk/resources/03_content_servers/
software_suite_v3/smart-core/smart-server/trunk/resources/03_content_servers/00_resourceAttituneManager.py
software_suite_v3/smart-core/smart-server/trunk/resources/03_content_servers/01_resourcePluginsServer.py
software_suite_v3/smart-core/smart-server/trunk/resources/03_content_servers/02_resourceGagdetsServer.py
software_suite_v3/smart-core/smart-server/trunk/resources/03_content_servers/03_resourceUgcServer.py
software_suite_v3/smart-core/smart-server/trunk/resources/04_user_configurations/
software_suite_v3/smart-core/smart-server/trunk/resources/05_updates/
software_suite_v3/smart-core/smart-server/trunk/resources/06_web_interfaces/
software_suite_v3/smart-core/smart-server/trunk/resources/06_web_interfaces/00_resourceWIDevel.py
Removed:
software_suite_v3/smart-core/smart-server/trunk/resources/00_server_base/
software_suite_v3/smart-core/smart-server/trunk/resources/01_robot_system/
software_suite_v3/smart-core/smart-server/trunk/resources/02_robot_api/
software_suite_v3/smart-core/smart-server/trunk/resources/03_advanced_api/
software_suite_v3/smart-core/smart-server/trunk/resources/04_web_interface/
Log:
* reorganized server resources
Added: software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/00_resourceServer.py
===================================================================
--- software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/00_resourceServer.py (rev 0)
+++ software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/00_resourceServer.py 2009-05-26 16:28:45 UTC (rev 4678)
@@ -0,0 +1,82 @@
+# ==============================================================================
+# Server resource.
+# ==============================================================================
+
+# ------------------------------------------------------------------------------
+# Declaration of the resource "server".
+# ------------------------------------------------------------------------------
+class TDSResourceServer(TDSResource):
+
+ # --------------------------------------------------------------------------
+ # Inherited methods from TDSResource
+ # --------------------------------------------------------------------------
+
+ def configure(self):
+ self.name = "server"
+ self.comment = "Resource to manage the server."
+ self.fileName = RESOURCE_FILENAME
+
+ # --------------------------------------------------------------------------
+ # Public methods
+ # --------------------------------------------------------------------------
+
+ def stopServer(self):
+ """Stop the server.
+ """
+ httpServer.stop()
+
+ def getVersion(self):
+ """Get the server version.
+ @return: The server version.
+ """
+ return serverVersion
+
+# Create an instance of the resource
+resourceServer = TDSResourceServer("resourceServer")
+# Register the resource into the resources manager
+resourcesManager.addResource(resourceServer)
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "stop".
+# ------------------------------------------------------------------------------
+class TDSServiceServerStop(TDSService):
+
+ def configure(self):
+ self.parametersDict = {}
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS
+ self.exclusiveExecution = False
+ self.name = "stop"
+ self.comment = "Stop the server."
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ contentStruct = self.getDefaultContentStruct()
+ contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+ resourceServer.stopServer()
+ return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceServer.addService(TDSServiceServerStop)
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "version".
+# ------------------------------------------------------------------------------
+class TDSServiceServerVersion(TDSService):
+
+ def configure(self):
+ self.parametersDict = {}
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS
+ self.exclusiveExecution = False
+ self.name = "version"
+ self.comment = "Get the server version."
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ contentStruct = self.getDefaultContentStruct()
+ contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+ data = {'version' : resourceServer.getVersion()}
+ contentStruct['root']['data'] = data
+ return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceServer.addService(TDSServiceServerVersion)
Property changes on: software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/00_resourceServer.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/01_resourceStatus.py
===================================================================
--- software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/01_resourceStatus.py (rev 0)
+++ software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/01_resourceStatus.py 2009-05-26 16:28:45 UTC (rev 4678)
@@ -0,0 +1,283 @@
+# ==============================================================================
+# Status resource.
+# ==============================================================================
+
+SW_NAME_EXTERNAL_STATUS = "external_status"
+
+# ------------------------------------------------------------------------------
+# Declaration of the resource "status".
+# ------------------------------------------------------------------------------
+class TDSResourceStatus(TDSResource):
+
+ # --------------------------------------------------------------------------
+ # Inherited methods from TDSResource
+ # --------------------------------------------------------------------------
+
+ def configure(self):
+ self.name = "status"
+ self.comment = "Resource to manage the statuses and events."
+ self.fileName = RESOURCE_FILENAME
+
+ # Registering the "external" status in the events handler
+ eventsHandler.insert(SW_NAME_EXTERNAL_STATUS)
+ # Registering the "external" status in the default excluded events list
+ clientsManager.addDefaultExcludedEvent(SW_NAME_EXTERNAL_STATUS)
+
+ # --------------------------------------------------------------------------
+ # Public methods
+ # --------------------------------------------------------------------------
+
+ def getEvents(self, idClient):
+ """Get the last events from a client stack.
+ - This function only affect the HTTP/REST clients.
+ @param idClient: Id client.
+ @return: The events from the client stack as list.
+ """
+ client = clientsManager.getClient(idClient)
+ if client == None:
+ return []
+ return client.popEvents()
+
+ def requestOne(self, statusName):
+ """Request the current state of a status.
+ @param statusName: Name of the status.
+ @return: The current state of the status as dictionary.
+ """
+ eventHandler = eventsHandler.getEventHandler(statusName)
+ if eventHandler == None:
+ return None
+ else:
+ stateStruct = eventHandler.getLastState()
+ if stateStruct != None:
+ state = {
+ 'name' : statusName,
+ 'value' : stateStruct[0],
+ 'delay' : stateStruct[1],
+ }
+ else:
+ state = {
+ 'name' : statusName,
+ 'value' : '',
+ 'delay' : 0.0,
+ }
+ return state
+
+ def requestAll(self):
+ """Request the current state of all statuses.
+ @return: The current state of all statuses as dictionary.
+ """
+ eventsNameList = eventsHandler.getEventsNameList()
+ states = []
+ for eventName in eventsNameList:
+ state = self.requestOne(eventName)
+ if state != None:
+ states.append(state)
+ return states
+
+ def sendStatus(self, name, value):
+ """Send a free status.
+ - This function inject a status in the events handler. This kind of
+ statuses are handled in the special event handler named
+ "SW_NAME_EXTERNAL_STATUS" because their names are not knowed by the
+ server.
+ @param name: Status name.
+ @param value: Status value.
+ """
+ statusStruct = {}
+ statusStruct['name'] = SW_NAME_EXTERNAL_STATUS
+ statusStruct['value'] = "%s|%s" % (name, value)
+ statusStruct['delay'] = 0.0
+ statusStruct['type'] = "string"
+ def async():
+ eventsHandler.emit(statusStruct['name'], (statusStruct['value'],
+ float(statusStruct['delay'])))
+ clientsManager.pushEvents([statusStruct,])
+ t = threading.Thread(target = async)
+ t.start()
+
+ def addExcludedEvent(self, idClient, eventName):
+ """Add an event in the excluded events list of a client.
+ - The effect is that the event/status will be anymore sent to this
+ client.
+ @idClient: Client id.
+ @eventName: Status/event name.
+ """
+ def async():
+ client = clientsManager.getClient(idClient)
+ if client != None:
+ client.addExcludedEvent(eventName)
+ t = threading.Thread(target = async)
+ t.start()
+
+ def removeExcludedEvent(self, idClient, eventName):
+ """Remove an event from the excluded events list of a client.
+ @idClient: Client id.
+ @eventName: Status/event name.
+ """
+ def async():
+ client = clientsManager.getClient(idClient)
+ if client != None:
+ client.removeExcludedEvent(eventName)
+ t = threading.Thread(target = async)
+ t.start()
+
+# Create an instance of the resource
+resourceStatus = TDSResourceStatus("resourceStatus")
+# Register the resource into the resources manager
+resourcesManager.addResource(resourceStatus)
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "events".
+# ------------------------------------------------------------------------------
+class TDSServiceStatusEvents(TDSService):
+
+ def configure(self):
+ self.parametersDict = {}
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_FREE
+ self.exclusiveExecution = False
+ self.name = "events"
+ self.comment = "Get the last events from a client stack."
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ contentStruct = self.getDefaultContentStruct()
+ contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+ events = resourceStatus.getEvents(id)
+ if len(events) > 0:
+ i = 0
+ for event in events:
+ data_name = "data|%d" % i
+ i += 1
+ contentStruct['root'][data_name] = event
+ return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceStatus.addService(TDSServiceStatusEvents)
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "request_one".
+# ------------------------------------------------------------------------------
+class TDSServiceStatusRequestOne(TDSService):
+
+ def configure(self):
+ self.parametersDict = {
+ 'status_name' : 'string',
+ }
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS
+ self.exclusiveExecution = False
+ self.name = "request_one"
+ self.comment = "Request the current state of a status."
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ contentStruct = self.getDefaultContentStruct()
+ contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+ state = resourceStatus.requestOne(parameters['status_name'])
+ if state == None:
+ contentStruct['root']['result'] = getStrError(E_TDREST_FAILED)
+ else:
+ contentStruct['root']['data'] = state
+ return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceStatus.addService(TDSServiceStatusRequestOne)
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "request_all".
+# ------------------------------------------------------------------------------
+class TDSServiceStatusRequestAll(TDSService):
+
+ def configure(self):
+ self.parametersDict = {}
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS
+ self.exclusiveExecution = False
+ self.name = "request_all"
+ self.comment = "Request the current state of all statuses."
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ contentStruct = self.getDefaultContentStruct()
+ contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+ states = resourceStatus.requestAll()
+ i = 0
+ for state in states:
+ dataName = "data|%d" % i
+ i += 1
+ contentStruct['root'][dataName] = state
+ return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceStatus.addService(TDSServiceStatusRequestAll)
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "send".
+# ------------------------------------------------------------------------------
+class TDSServiceStatusSend(TDSService):
+
+ def configure(self):
+ self.parametersDict = {
+ 'name' : 'string',
+ 'value' : 'string',
+ }
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS
+ self.exclusiveExecution = True
+ self.name = "send"
+ self.comment = "Send a free status."
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ contentStruct = self.getDefaultContentStruct()
+ contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+ resourceStatus.sendStatus(parameters['name'], parameters['value'])
+ return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceStatus.addService(TDSServiceStatusSend)
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "register_event".
+# ------------------------------------------------------------------------------
+class TDSServiceStatusRegisterEvent(TDSService):
+
+ def configure(self):
+ self.parametersDict = {
+ 'event_name' : 'string',
+ }
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_FREE
+ self.exclusiveExecution = False
+ self.name = "register_event"
+ self.comment = "Add an event inthe registered events list of the client."
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ contentStruct = self.getDefaultContentStruct()
+ contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+ resourceStatus.removeExcludedEvent(id, parameters['event_name'])
+ return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceStatus.addService(TDSServiceStatusRegisterEvent)
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "unregister_event".
+# ------------------------------------------------------------------------------
+class TDSServiceStatusUnregisterEvent(TDSService):
+
+ def configure(self):
+ self.parametersDict = {
+ 'event_name' : 'string',
+ }
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_FREE
+ self.exclusiveExecution = False
+ self.name = "unregister_event"
+ self.comment = "Remove an event from the registered events list of the client."
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ contentStruct = self.getDefaultContentStruct()
+ contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+ resourceStatus.addExcludedEvent(id, parameters['event_name'])
+ return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceStatus.addService(TDSServiceStatusUnregisterEvent)
Property changes on: software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/01_resourceStatus.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/02_resourceAccess.py
===================================================================
--- software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/02_resourceAccess.py (rev 0)
+++ software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/02_resourceAccess.py 2009-05-26 16:28:45 UTC (rev 4678)
@@ -0,0 +1,225 @@
+# ==============================================================================
+# Access resource.
+# ==============================================================================
+
+# ------------------------------------------------------------------------------
+# Declaration of the resource "access".
+# ------------------------------------------------------------------------------
+class TDSResourceAccess(TDSResource):
+
+ # --------------------------------------------------------------------------
+ # Inherited methods from TDSResource
+ # --------------------------------------------------------------------------
+
+ def configure(self):
+ self.name = "access"
+ self.comment = "Resource to manage the access to the robot resources."
+ self.fileName = RESOURCE_FILENAME
+
+ # --------------------------------------------------------------------------
+ # Public methods
+ # --------------------------------------------------------------------------
+
+ def acquireAccess(self, idClient, priorityLevel):
+ """Acquire the access to the robot resources.
+ - This function only affects the RESTRICTED clients
+ @param idClient: Id client.
+ @param priorityLevel: Priority level.
+ 0 : LOW
+ 1 : NORMAL
+ 2 : HIGH
+ 3 : CRITICAL
+ @return: True or False
+ """
+ client = clientsManager.getClient(idClient)
+ if client == None:
+ return False
+ return client.acquireAccess(priorityLevel)
+
+ def releaseAccess(self, idClient):
+ """Release the access to the robot resources.
+ - This function only affects the RESTRICTED clients
+ @param idClient: Id client.
+ """
+ accessManager.releaseAccess(idClient)
+
+ def forcingReleaseAccess(self):
+ """Forcing to release the access to the robot resources.
+ - This function only affects the RESTRICTED clients
+ - This function should be called by only the ROOT client
+ """
+ accessManager.releaseAccess()
+
+ def forcingAcquireAccess(self, idClient, priorityLevel):
+ """Forcing to acquire the access to the robot resources.
+ - This function only affects the RESTRICTED clients
+ - This function should be called by only the ROOT client
+ @param idClient: Id client.
+ @param priorityLevel: Priority level.
+ 0 : LOW
+ 1 : NORMAL
+ 2 : HIGH
+ 3 : CRITICAL
+ @return: True or False
+ """
+ accessManager.releaseAccess()
+ return accessManager.acquireAccess(idClient, priorityLevel)
+
+ def lockAccess(self):
+ """Lock the access to the robot resources.
+ - This function only affects the RESTRICTED clients
+ - This function should be called by only the ROOT client
+ """
+ accessManager.setLocked(True)
+
+ def unlockAccess(self):
+ """Lock the access to the robot resources.
+ - This function only affects the RESTRICTED clients
+ - This function should be called by only the ROOT client
+ """
+ accessManager.setLocked(False)
+
+# Create an instance of the resource
+resourceAccess = TDSResourceAccess("resourceAccess")
+# Register the resource into the resources manager
+resourcesManager.addResource(resourceAccess)
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "acquire".
+# ------------------------------------------------------------------------------
+class TDSServiceAccessAcquire(TDSService):
+
+ def configure(self):
+ self.parametersDict = {
+ 'priority_level' : 'int',
+ }
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_RESTRICTED
+ self.exclusiveExecution = False
+ self.name = "acquire"
+ self.comment = "Acquire the access to the robot resources."
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ contentStruct = self.getDefaultContentStruct()
+ contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+ if not resourceAccess.acquireAccess(id, parameters['priority_level']):
+ contentStruct['root']['result'] = getStrError(E_TDREST_FAILED)
+ return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceAccess.addService(TDSServiceAccessAcquire)
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "release".
+# ------------------------------------------------------------------------------
+class TDSServiceAccessRelease(TDSService):
+
+ def configure(self):
+ self.parametersDict = {}
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_RESTRICTED
+ self.exclusiveExecution = False
+ self.name = "release"
+ self.comment = "Release the access to the robot resources."
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ contentStruct = self.getDefaultContentStruct()
+ contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+ resourceAccess.releaseAccess(id)
+ return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceAccess.addService(TDSServiceAccessRelease)
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "forcing_release".
+# ------------------------------------------------------------------------------
+class TDSServiceAccessForcingRelease(TDSService):
+
+ def configure(self):
+ self.parametersDict = {}
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_ROOT
+ self.exclusiveExecution = False
+ self.name = "forcing_release"
+ self.comment = "Forcing to release the access to the robot resources."
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ contentStruct = self.getDefaultContentStruct()
+ contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+ resourceAccess.forcingReleaseAccess()
+ return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceAccess.addService(TDSServiceAccessForcingRelease)
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "forcing_acquire".
+# ------------------------------------------------------------------------------
+class TDSServiceAccessForcingAcquire(TDSService):
+
+ def configure(self):
+ self.parametersDict = {
+ 'id_client' : 'string',
+ 'priority_level' : 'int',
+ }
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_ROOT
+ self.exclusiveExecution = False
+ self.name = "forcing_acquire"
+ self.comment = "Forcing to acquire the access to the robot resources."
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ contentStruct = self.getDefaultContentStruct()
+ contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+ if not resourceAccess.forcingAcquireAccess(parameters['id_client'],
+ parameters['priority_level']):
+ contentStruct['root']['result'] = getStrError(E_TDREST_FAILED)
+ return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceAccess.addService(TDSServiceAccessForcingAcquire)
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "lock".
+# ------------------------------------------------------------------------------
+class TDSServiceAccessLock(TDSService):
+
+ def configure(self):
+ self.parametersDict = {}
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_ROOT
+ self.exclusiveExecution = False
+ self.name = "lock"
+ self.comment = "Lock the access to the robot resources."
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ contentStruct = self.getDefaultContentStruct()
+ contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+ resourceAccess.lockAccess()
+ return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceAccess.addService(TDSServiceAccessLock)
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "unlock".
+# ------------------------------------------------------------------------------
+class TDSServiceAccessUnlock(TDSService):
+
+ def configure(self):
+ self.parametersDict = {}
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_ROOT
+ self.exclusiveExecution = False
+ self.name = "unlock"
+ self.comment = "Lock the access to the robot resources."
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ contentStruct = self.getDefaultContentStruct()
+ contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+ resourceAccess.unlockAccess()
+ return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceAccess.addService(TDSServiceAccessUnlock)
Property changes on: software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/02_resourceAccess.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/03_resourceClient.py
===================================================================
--- software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/03_resourceClient.py (rev 0)
+++ software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/03_resourceClient.py 2009-05-26 16:28:45 UTC (rev 4678)
@@ -0,0 +1,134 @@
+# ==============================================================================
+# Client resource.
+# ==============================================================================
+
+# ------------------------------------------------------------------------------
+# Declaration of the resource "client".
+# ------------------------------------------------------------------------------
+class TDSResourceClient(TDSResource):
+
+ # --------------------------------------------------------------------------
+ # Inherited methods from TDSResource
+ # --------------------------------------------------------------------------
+
+ def configure(self):
+ self.name = "client"
+ self.comment = "Resource to manage the clients."
+ self.fileName = RESOURCE_FILENAME
+
+ # --------------------------------------------------------------------------
+ # Public methods
+ # --------------------------------------------------------------------------
+
+ def createClient(self, clientName, clientLevel):
+ """Create a new client.
+ @clientName: Client name.
+ @clientLevel: Client level.
+ -1 : ANONYMOUS
+ 0 : FREE
+ 1 : RESTRICTED
+ 2 : ROOT
+ @return: The id of the new client or -1 if fail.
+ """
+ if clientLevel == TDS_CLIENT_LEVEL_ANONYMOUS:
+ return -1
+ idClient = clientsManager.addRESTClient(clientName, clientLevel)
+ return idClient
+
+ def destroyClient(self, idClient):
+ """Destroy a client.
+ - This function only affect the HTTP/REST clients.
+ @idClient: Client id.
+ """
+ clientsManager.removeRESTClient(idClient)
+
+ def listing(self):
+ """Get the clients listing with their informations.
+ @return: A dictionary.
+ """
+ clientsInfo = clientsManager.getClientsInfo()
+ result = {}
+ for i, clientInfo in enumerate(clientsInfo):
+ nodeName = "data|%d" % i
+ result[nodeName] = clientInfo
+ return result
+
+# Create an instance of the resource
+resourceClient = TDSResourceClient("resourceClient")
+# Register the resource into the resources manager
+resourcesManager.addResource(resourceClient)
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "create".
+# ------------------------------------------------------------------------------
+class TDSServiceClientCreate(TDSService):
+
+ def configure(self):
+ self.parametersDict = {
+ 'name' : 'string',
+ 'level' : 'uint8',
+ }
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS
+ self.exclusiveExecution = False
+ self.name = "create"
+ self.comment = "Create a client."
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ contentStruct = self.getDefaultContentStruct()
+ contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+ idClient = resourceClient.createClient(parameters['name'],
+ parameters['level'])
+ if idClient == None:
+ contentStruct['root']['result'] = getStrError(E_TDREST_FAILED)
+ else:
+ contentStruct['root']['data'] = {}
+ contentStruct['root']['data']['client_id'] = idClient
+ return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceClient.addService(TDSServiceClientCreate)
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "destroy".
+# ------------------------------------------------------------------------------
+class TDSServiceClientDestroy(TDSService):
+
+ def configure(self):
+ self.parametersDict = {}
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_FREE
+ self.exclusiveExecution = False
+ self.name = "destroy"
+ self.comment = "Destroy a client."
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ contentStruct = self.getDefaultContentStruct()
+ contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+ resourceClient.destroyClient(id)
+ return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceClient.addService(TDSServiceClientDestroy)
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "listing".
+# ------------------------------------------------------------------------------
+class TDSServiceClientListing(TDSService):
+
+ def configure(self):
+ self.parametersDict = {}
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_FREE
+ self.exclusiveExecution = False
+ self.name = "listing"
+ self.comment = "Get the clients listing with their informations."
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ contentStruct = self.getDefaultContentStruct()
+ contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+ contentStruct['root']['data'] = resourceClient.listing()
+ return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceClient.addService(TDSServiceClientListing)
Property changes on: software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/03_resourceClient.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/04_resourceMenu.py
===================================================================
--- software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/04_resourceMenu.py (rev 0)
+++ software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/04_resourceMenu.py 2009-05-26 16:28:45 UTC (rev 4678)
@@ -0,0 +1,229 @@
+# ==============================================================================
+# Menu resource.
+# ==============================================================================
+
+# ------------------------------------------------------------------------------
+# Declaration of the resource "menu".
+# ------------------------------------------------------------------------------
+class TDSResourceMenu(TDSResource):
+
+ # --------------------------------------------------------------------------
+ # Inherited methods from TDSResource
+ # --------------------------------------------------------------------------
+
+ def configure(self):
+ self.name = "menu"
+ self.comment = "Menu resource."
+ self.fileName = RESOURCE_FILENAME
+
+# Create an instance of the resource
+resourceMenu = TDSResourceMenu("resourceMenu")
+# Register the resource into the resources manager
+resourcesManager.addResource(resourceMenu)
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "index".
+# ------------------------------------------------------------------------------
+class TDSServiceMenuIndex(TDSService):
+
+ def configure(self):
+ self.parametersDict = {}
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS
+ self.exclusiveExecution = False
+ self.name = "index"
+ self.comment = "Main menu of the server."
+ self.haveXsl = True
+ self.xslPath = "/data/xsl/menu.xsl"
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ contentStruct = {'root' : self.__createXmlIndex()}
+ return headersStruct, contentStruct
+
+ def __createXmlIndex(self):
+ contentStruct = {
+ 'title' : 'Tux Droid Server V %s' % serverVersion,
+ 'section' : 'Index',
+ 'items' : {
+ 'Resources' : 'menu/resources?resource_name=index',
+ 'Logs' : 'menu/logs?log_name=index',
+ 'Clients' : 'menu/clients?',
+ }
+ }
+ return contentStruct
+
+# Register the service into the resource
+resourceMenu.addService(TDSServiceMenuIndex)
+# Bind the root url to this service
+resourcesManager.addBinding("ROOT", "menu", "index")
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "resources".
+# ------------------------------------------------------------------------------
+class TDSServiceMenuResources(TDSService):
+
+ def configure(self):
+ self.parametersDict = {
+ 'resource_name' : 'string',
+ }
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS
+ self.exclusiveExecution = False
+ self.name = "resources"
+ self.comment = "Resources menu."
+ self.haveXsl = True
+ self.xslPath = "/data/xsl/menu.xsl"
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ if parameters['resource_name'] == 'index':
+ contentStruct = {'root' : self.__createXmlIndex()}
+ else:
+ contentStruct = {
+ 'root' : self.__createXmlResource(parameters['resource_name'])
+ }
+ return headersStruct, contentStruct
+
+ def __createXmlIndex(self):
+ self.xslPath = "/data/xsl/menu_resources.xsl"
+ contentStruct = {
+ 'title' : 'Tux Droid Server V %s' % serverVersion,
+ 'section' : 'Resources',
+ 'items' : {}
+ }
+ resourcesList = resourcesManager.getResourcesList()
+ resourcePathsList = resourcesManager.getResourcePathsList()
+ for path in resourcePathsList:
+ path = os.path.basename(path)
+ contentStruct['items']["Layer_%s" % path] = {}
+ for resourceName in resourcesList:
+ resource = resourcesManager.getResource(resourceName)
+ resourcePath = os.path.basename(os.path.split(
+ resource.fileName)[-2])
+ if resourcePath == path:
+ url = '?resource_name=%s' % resourceName
+ contentStruct['items']["Layer_%s" % path][resourceName] = url
+ return contentStruct
+
+ def __createXmlResource(self, resourceName):
+ self.xslPath = "/data/xsl/resource.xsl"
+ resource = resourcesManager.getResource(resourceName)
+ if resource == None:
+ result = {}
+ else:
+ result = resource.getXmlStructure()
+ result['title'] = 'Tux Droid Server V %s' % serverVersion
+ result['section'] = 'Resource : %s' % resourceName
+ # complete the url
+ for service in result['services'].keys():
+ address = TDS_CONF_HOST_ADDRESS
+ if address == "":
+ address = '127.0.0.1'
+ cmdProt = 'http://%s:%d/<id_client>/%s/%s?%s' % (address,
+ TDS_HTTP_PORT, resourceName, service,
+ result['services'][service]['parameters'])
+ result['services'][service]['commandPrototype'] = cmdProt
+ return result
+
+# Register the service into the resource
+resourceMenu.addService(TDSServiceMenuResources)
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "logs".
+# ------------------------------------------------------------------------------
+class TDSServiceMenuLogs(TDSService):
+
+ def configure(self):
+ self.parametersDict = {
+ 'log_name' : 'string',
+ }
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS
+ self.exclusiveExecution = False
+ self.name = "logs"
+ self.comment = "Logs menu."
+ self.haveXsl = True
+ self.xslPath = "/data/xsl/menu.xsl"
+ if os.name == 'nt':
+ self.__logPath = os.path.expanduser("~")
+ else:
+ self.__logPath = "/var/log/tuxdroid"
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ if parameters['log_name'] == 'index':
+ contentStruct = {'root' : self.__createXmlIndex()}
+ else:
+ contentStruct = {'root' : self.__createXmlLog(parameters['log_name'])}
+ return headersStruct, contentStruct
+
+ def __createXmlIndex(self):
+ self.xslPath = "/data/xsl/menu.xsl"
+ contentStruct = {
+ 'title' : 'Tux Droid Server V %s' % serverVersion,
+ 'section' : 'Logs',
+ 'items' : {
+ 'Global_Server' : 'logs?log_name=%s' % TDS_FILENAME_TUXDROIDSERVER_LOG,
+ 'HTTP.REST_Server' : 'logs?log_name=%s' % TDS_FILENAME_HTTPSERVER_LOG,
+ 'Resources_manager' : 'logs?log_name=%s' % TDS_FILENAME_RESOURCES_LOG,
+ 'Clients_manager_TCP.IP_Server' : 'logs?log_name=%s' % TDS_FILENAME_CLIENTS_LOG,
+ 'Tux_driver' : 'logs?log_name=libtuxdriver_wrapper',
+ 'Tux_OSL' : 'logs?log_name=libtuxosl_wrapper',
+ }
+ }
+ return contentStruct
+
+ def __createXmlLog(self, logName):
+ self.xslPath = "/data/xsl/log.xsl"
+ filePath = os.path.join(self.__logPath, "%s.log" % logName)
+ if not os.path.isfile(filePath):
+ return {}
+ logText = open(filePath, 'r').read()
+ logDict = {}
+ for i, log in enumerate(logText.split('\n')):
+ if log != '':
+ logDict['log_%.5d' % i] = log
+ contentStruct = {
+ 'data' : {
+ 'log_file_path' : filePath,
+ 'log_text' : logDict,
+ }
+ }
+ return contentStruct
+
+# Register the service into the resource
+resourceMenu.addService(TDSServiceMenuLogs)
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "clients".
+# ------------------------------------------------------------------------------
+class TDSServiceMenuClients(TDSService):
+
+ def configure(self):
+ self.parametersDict = {}
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS
+ self.exclusiveExecution = False
+ self.name = "clients"
+ self.comment = "Clients index."
+ self.haveXsl = True
+ self.xslPath = "/data/xsl/clients.xsl"
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ contentStruct = {'root' : self.__createXmlIndex()}
+ return headersStruct, contentStruct
+
+ def __createXmlIndex(self):
+ clientsInfo = clientsManager.getClientsInfo()
+ clients = {}
+ for i, clientInfo in enumerate(clientsInfo):
+ clientInfo['name'] = clientInfo['name'].replace(' ', '')
+ clientInfo['name'] = "client%.2d_%s" % (i, clientInfo['name'])
+ clients[clientInfo['name']] = clientInfo
+ contentStruct = {
+ 'title' : 'Tux Droid Server V %s' % serverVersion,
+ 'section' : 'Clients',
+ 'clients' : clients,
+ }
+ return contentStruct
+
+# Register the service into the resource
+resourceMenu.addService(TDSServiceMenuClients)
Property changes on: software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/04_resourceMenu.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/10_resourceScheduler.py
===================================================================
--- software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/10_resourceScheduler.py (rev 0)
+++ software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/10_resourceScheduler.py 2009-05-26 16:28:45 UTC (rev 4678)
@@ -0,0 +1,389 @@
+# ==============================================================================
+# Scheduler resource.
+# ==============================================================================
+
+# This resource depends of the following resources :
+
+import datetime
+
+from util.scheduler.Scheduler import Scheduler
+from util.scheduler.Task import *
+
+# 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"
+ST_NAME_SCM_TASKS_LOADED = "scheduler_manager_tasks_loaded"
+ST_NAME_SCM_TASKS_UNLOADED = "scheduler_manager_tasks_unloaded"
+
+# Attitune manager events/statuses list
+SW_NAME_SCHEDULER_MANAGER = [
+ ST_NAME_SCM_RUN,
+ ST_NAME_SCM_TASK_ADDED,
+ ST_NAME_SCM_TASK_REMOVED,
+ ST_NAME_SCM_TASKS_LOADED,
+ ST_NAME_SCM_TASKS_UNLOADED,
+]
+
+# ------------------------------------------------------------------------------
+# Declaration of the resource "scheduler".
+# ------------------------------------------------------------------------------
+class TDSResourceScheduler(TDSResource):
+
+ # --------------------------------------------------------------------------
+ # Inherited methods from TDSResource
+ # --------------------------------------------------------------------------
+
+ def configure(self):
+ self.name = "scheduler"
+ self.comment = "Resource to manage the scheduler."
+ self.fileName = RESOURCE_FILENAME
+ # Create the scheduler.
+ self.__scheduler = Scheduler(globals())
+ self.__scheduler.setOnTaskAddedCallback(self.__onTaskAdded)
+ self.__scheduler.setOnTaskRemovedCallback(self.__onTaskRemoved)
+ self.__scheduler.setOnTasksLoadedCallback(self.__onTasksLoaded)
+ self.__scheduler.setOnTasksUnloadedCallback(self.__onTasksUnloaded)
+ # Registering the scheduler manager statuses.
+ for statusName in SW_NAME_SCHEDULER_MANAGER:
+ eventsHandler.insert(statusName)
+ self.__scheduler.start()
+ self.__publishEvents(True, ST_NAME_SCM_RUN, ["True",])
+
+ def stop(self):
+ self.__scheduler.stop()
+ self.__publishEvents(True, ST_NAME_SCM_RUN, ["False",])
+
+ # --------------------------------------------------------------------------
+ # Private methods
+ # --------------------------------------------------------------------------
+
+ def __publishEvents(self, sendToClients, eventName, eventValues = []):
+ def async():
+ values = ""
+ for value in eventValues:
+ values += value + ":"
+ if len(values) > 0:
+ values = values[:-1]
+ eventStruct = {
+ 'name' : eventName,
+ 'value' : values,
+ 'delay' : "0.0",
+ 'type' : "string"
+ }
+ if sendToClients:
+ clientsManager.pushEvents([eventStruct,])
+ eventsHandler.emit(eventName, (values, 0.0))
+ t = threading.Thread(target = async)
+ t.start()
+
+ def __onTaskAdded(self, task):
+ print "Task added :", task.getDescription().getName(), task.getDescription().toString()
+ self.__publishEvents(False, ST_NAME_SCM_TASK_ADDED,
+ [task.getDescription().getId(), task.getDescription().getName()])
+
+ def __onTaskRemoved(self, task):
+ print "Task removed :", task.getDescription().toString()
+ self.__publishEvents(False, ST_NAME_SCM_TASK_REMOVED,
+ [task.getDescription().getId(), task.getDescription().getName()])
+
+ def __onTasksLoaded(self):
+ print "Tasks loaded"
+ self.__publishEvents(True, ST_NAME_SCM_TASKS_LOADED, ["True",])
+
+ def __onTasksUnloaded(self):
+ print "Tasks unloaded"
+ self.__publishEvents(True, ST_NAME_SCM_TASKS_UNLOADED, ["True",])
+
+ def weekMaskStringToList(self, weekMaskString):
+ result = [True, True, True, True, True, True, True]
+ try:
+ splitedStr = weekMaskString.split(",")
+ if len(splitedStr) == 7:
+ for i, value in enumerate(splitedStr):
+ if value == "true":
+ result[i] = True
+ else:
+ result[i] = False
+ except:
+ pass
+ return result
+
+ def dateStringToList(self, dateString):
+ result = [0, 0, 0]
+ try:
+ splitedStr = dateString.split("/")
+ if len(splitedStr) == 3:
+ for i, value in enumerate(splitedStr):
+ result[i] = int(value)
+ except:
+ pass
+ return result
+
+ def timeStringToList(self, timeString):
+ result = [0, 0, 0]
+ try:
+ splitedStr = timeString.split(":")
+ if len(splitedStr) == 3:
+ for i, value in enumerate(splitedStr):
+ result[i] = int(value)
+ except:
+ pass
+ return result
+
+ # --------------------------------------------------------------------------
+ # Public methods
+ # --------------------------------------------------------------------------
+
+ def publishEvents(self, sendToClients, eventName, eventValues = []):
+ self.__publishEvents(sendToClients, eventName, eventValues)
+
+ def getScheduler(self):
+ """Get the scheduler.
+ @return: A Scheduler object.
+ """
+ return self.__scheduler
+
+ def createTask_RunEveryX(self, name, weekMask, hoursBegin, hoursEnd, delay,
+ command, arguments, data):
+ """Create a task which start every x delay.
+ - hour, minute, second define the time delay between 2 executions.
+ - Typically for a pooling task.
+ @param name: Task name.
+ @param weekMask: Week mask. [True, True, True, True, True, True, True]
+ @param hoursBegin: Hours begin. [Hour, Minute, Second]
+ @param hoursEnd: Hours end. [Hour, Minute, Second]
+ @param delay: Delay. [Hour, Minute, Second]
+ @param command: Command to execute.
+ @param arguments: Arguments of the command.
+ @param data: User data.
+ @return: The task id and the task name or None None.
+ """
+ task = Task(SCH_LOOP_REL, weekMask, [0, 0, 0], hoursBegin, hoursEnd,
+ delay, command, arguments, data)
+ return self.__scheduler.insertTask(task, name)
+
+ def createTask_RunEveryXFromFullHour(self, name, weekMask, hoursBegin,
+ hoursEnd, delay, command, arguments, data):
+ """Create a task which start every x delay synchronized with hh:00:00.
+ - Typically for an alarm task. (Clock gadget start at hour:00, 15, 30, 45)
+ - The first execution will be at hour begin + delay time.
+ @param name: Task name.
+ @param weekMask: Week mask. [True, True, True, True, True, True, True]
+ @param hoursBegin: Hours begin. [Hour, Minute, Second]
+ @param hoursEnd: Hours end. [Hour, Minute, Second]
+ @param delay: Delay. [Hour, Minute, Second]
+ @param command: Command to execute.
+ @param arguments: Arguments of the command.
+ @param data: User data.
+ @return: The task id and the task name or None None.
+ """
+ task = Task(SCH_LOOP_ABS, weekMask, [0, 0, 0], hoursBegin, hoursEnd,
+ delay, command, arguments, data)
+ return self.__scheduler.insertTask(task, name)
+
+ def createTask_RunDailyAtTime(self, name, weekMask, hoursBegin, command,
+ arguments, data):
+ """Create a daily task which run at fixed time.
+ @param name: Task name.
+ @param weekMask: Week mask. [True, True, True, True, True, True, True]
+ @param hoursBegin: Hours begin. [Hour, Minute, Second]
+ @param command: Command to execute.
+ @param arguments: Arguments of the command.
+ @param data: User data.
+ @return: The task id and the task name or None None.
+ """
+ task = Task(SCH_ONCE_ABS, weekMask, [0, 0, 0], hoursBegin, [0, 0, 0],
+ [0, 0, 0], command, arguments, data)
+ return self.__scheduler.insertTask(task, name)
+
+ def createTask_RunOnceAtDateTime(self, name, date, hoursBegin, command,
+ arguments, data):
+ """Create a task which run once time at a specific date time.
+ @param name: Task name.
+ @param date: Date. [Year, Month, Day]
+ @param hoursBegin: Hours begin. [Hour, Minute, Second]
+ @param command: Command to execute.
+ @param arguments: Arguments of the command.
+ @param data: User data.
+ @return: The task id and the task name or None None.
+ """
+ task = Task(SCH_ONCE_ABS, [True, True, True, True, True, True, True],
+ date, hoursBegin, [0, 0, 0], [0, 0, 0], command, arguments, data)
+ return self.__scheduler.insertTask(task, name)
+
+ def createTask_RunOnceDelayed(self, name, delay, command, arguments, data):
+ """Create a task which run once time after a delay.
+ @param name: Task name.
+ @param delay: Delay. [Hour, Minute, Second]
+ @param command: Command to execute.
+ @param arguments: Arguments of the command.
+ @param data: User data.
+ @return: The task id and the task name or None None.
+ """
+ task = Task(SCH_ONCE_REL, [True, True, True, True, True, True, True],
+ [0, 0, 0], [0, 0, 0], [0, 0, 0], delay, command, arguments, data)
+ return self.__scheduler.insertTask(task, name)
+
+ def createTask(self, command, arguments, taskType, taskName, weekMask, date,
+ hoursBegin, hoursEnd, delay, data):
+ """Create a task to start a gadget.
+ @param command: Command to execute.
+ @param arguments: Arguments of the command.
+ @param taskType: <EVERY X|EVERY X FROM FULL HOUR|DAILY AT|ONCE AT|
+ ONCE DELAYED>
+ @param taskName: Task name.
+ @param weekMask: Week mask. [True, True, True, True, True, True, True]
+ @param date: Date. [Year, Month, Day]
+ @param hoursBegin: Hours begin. [Hour, Minute, Second]
+ @param hoursEnd: Hours end. [Hour, Minute, Second]
+ @param delay: Delay. [Hour, Minute, Second]
+ @param data: User data.
+ @return: The task id and the task name or None None.
+ """
+ if taskType == "EVERY X":
+ return self.createTask_RunEveryX(taskName, weekMask, hoursBegin,
+ hoursEnd, delay, command, arguments, data)
+ if taskType == "EVERY X FROM FULL HOUR":
+ return self.createTask_RunEveryXFromFullHour(taskName, weekMask,
+ hoursBegin, hoursEnd, delay, command, arguments, data)
+ if taskType == "DAILY AT":
+ return self.createTask_RunDailyAtTime(taskName, weekMask,
+ hoursBegin, command, arguments, data)
+ if taskType == "ONCE AT":
+ return self.createTask_RunOnceAtDateTime(taskName, date, hoursBegin,
+ command, arguments, data)
+ if taskType == "ONCE DELAYED":
+ return self.createTask_RunOnceDelayed(taskName, delay,
+ command, arguments, data)
+ return None, None
+
+ def executeTask(self, taskId):
+ """Execute the action of a scheduled task.
+ @param taskId: Task id.
+ @return: A boolean.
+ """
+ tasks = self.__scheduler.getTasks()
+ for task in tasks:
+ if task.getDescription().getId() == taskId:
+ task.execute(globals())
+ return True
+ return False
+
+ def removeTask(self, taskId):
+ """Remove a task from the scheduler.
+ @param taskId: Task id.
+ """
+ self.__scheduler.removeTask(taskId)
+
+ def clear(self):
+ """Clear the scheduler.
+ """
+ self.__scheduler.clear()
+
+# Create an instance of the resource
+resourceScheduler = TDSResourceScheduler("resourceScheduler")
+# Register the resource into the resources manager
+resourcesManager.addResource(resourceScheduler)
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "tasks_infos".
+# ------------------------------------------------------------------------------
+class TDSServiceSchedulerTasksInfos(TDSService):
+
+ def configure(self):
+ self.parametersDict = {}
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS
+ self.exclusiveExecution = False
+ self.name = "tasks_infos"
+ self.comment = "Get the informations about the tasks."
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ contentStruct = self.getDefaultContentStruct()
+ contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+ tasks = resourceScheduler.getScheduler().getTasks()
+ tasksNameList = []
+ for task in tasks:
+ tasksNameList.append(task.getDescription().getName())
+ tasksNameList.sort()
+ for i, taskName in enumerate(tasksNameList):
+ task = resourceScheduler.getScheduler().getTaskByName(taskName)
+ d_name = "data|%.3d" % i
+ struct = task.getDictionary()
+ contentStruct['root'][d_name] = struct
+ return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceScheduler.addService(TDSServiceSchedulerTasksInfos)
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "clear".
+# ------------------------------------------------------------------------------
+class TDSServiceSchedulerClear(TDSService):
+
+ def configure(self):
+ self.parametersDict = {}
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS
+ self.exclusiveExecution = False
+ self.name = "clear"
+ self.comment = "Clear the scheduler."
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ contentStruct = self.getDefaultContentStruct()
+ contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+ resourceScheduler.clear()
+ return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceScheduler.addService(TDSServiceSchedulerClear)
+
+# ---------------------------------------------------------...
[truncated message content] |