[tuxdroid-svn] r4691 - in software_suite_v3/smart-core/smart-server/trunk/resources: 00_smart_serv
Status: Beta
Brought to you by:
ks156
|
From: remi <c2m...@c2...> - 2009-05-28 09:42:14
|
Author: remi Date: 2009-05-28 11:41:58 +0200 (Thu, 28 May 2009) New Revision: 4691 Modified: 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/00_resourceTuxDriver.py software_suite_v3/smart-core/smart-server/trunk/resources/01_drivers/01_resourceTuxOSL.py Log: * typo Modified: 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 2009-05-28 08:31:55 UTC (rev 4690) +++ software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/00_resourceServer.py 2009-05-28 09:41:58 UTC (rev 4691) @@ -1,38 +1,62 @@ +# Copyright (C) 2009 C2ME Sa +# Remi Jocaille <rem...@c2...> +# Distributed under the terms of the GNU General Public License +# http://www.gnu.org/copyleft/gpl.html + # ============================================================================== -# Server resource. +# ****************************************************************************** +# RESOURCE DECLARATION +# ****************************************************************************** # ============================================================================== -# ------------------------------------------------------------------------------ +# ============================================================================== # Declaration of the resource "server". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSResourceServer(TDSResource): + """Resource server class. + """ - # -------------------------------------------------------------------------- + # ========================================================================== # Inherited methods from TDSResource + # ========================================================================== + # -------------------------------------------------------------------------- - + # Configure the resource. + # -------------------------------------------------------------------------- def configure(self): + """Configure the resource. + """ self.name = "server" self.comment = "Resource to manage the server." self.fileName = RESOURCE_FILENAME - # -------------------------------------------------------------------------- + # ========================================================================== # Public methods + # ========================================================================== + # -------------------------------------------------------------------------- - + # Stop the server. + # -------------------------------------------------------------------------- def stopServer(self): """Stop the server. """ httpServer.stop() + # -------------------------------------------------------------------------- + # Restart the server. + # -------------------------------------------------------------------------- def restartServer(self): """Restart the server. """ # TODO: Restart on linux if os.name == 'nt': - t = threading.Thread(target = os.system, args = ["tuxhttpserver_restart.exe",]) + t = threading.Thread(target = os.system, + args = ["tuxhttpserver_restart.exe",]) t.start() + # -------------------------------------------------------------------------- + # Get the server version. + # -------------------------------------------------------------------------- def getVersion(self): """Get the server version. @return: The server version. @@ -44,19 +68,39 @@ # Register the resource into the resources manager resourcesManager.addResource(resourceServer) -# ------------------------------------------------------------------------------ +# ============================================================================== +# ****************************************************************************** +# SERVICES DECLARATION +# ****************************************************************************** +# ============================================================================== + +# ============================================================================== # Declaration of the service "stop". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSServiceServerStop(TDSService): + # -------------------------------------------------------------------------- + # Configure the service. + # -------------------------------------------------------------------------- def configure(self): + """Configure the service. + """ self.parametersDict = {} self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS self.exclusiveExecution = False self.name = "stop" self.comment = "Stop the server." + # -------------------------------------------------------------------------- + # Execute the service. + # -------------------------------------------------------------------------- def execute(self, id, parameters): + """Execute the service. + @param id: Client identifier. + @param parameters: Request parameters. + @return: The headers as list and the content dictionary of the request + answer. + """ headersStruct = self.getDefaultHeadersStruct() contentStruct = self.getDefaultContentStruct() contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS) @@ -66,19 +110,33 @@ # Register the service into the resource resourceServer.addService(TDSServiceServerStop) -# ------------------------------------------------------------------------------ +# ============================================================================== # Declaration of the service "restart". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSServiceServerRestart(TDSService): + # -------------------------------------------------------------------------- + # Configure the service. + # -------------------------------------------------------------------------- def configure(self): + """Configure the service. + """ self.parametersDict = {} self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS self.exclusiveExecution = False self.name = "restart" self.comment = "Restart the server." + # -------------------------------------------------------------------------- + # Execute the service. + # -------------------------------------------------------------------------- def execute(self, id, parameters): + """Execute the service. + @param id: Client identifier. + @param parameters: Request parameters. + @return: The headers as list and the content dictionary of the request + answer. + """ headersStruct = self.getDefaultHeadersStruct() contentStruct = self.getDefaultContentStruct() contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS) @@ -88,19 +146,33 @@ # Register the service into the resource resourceServer.addService(TDSServiceServerRestart) -# ------------------------------------------------------------------------------ +# ============================================================================== # Declaration of the service "version". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSServiceServerVersion(TDSService): + # -------------------------------------------------------------------------- + # Configure the service. + # -------------------------------------------------------------------------- def configure(self): + """Configure the service. + """ self.parametersDict = {} self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS self.exclusiveExecution = False self.name = "version" self.comment = "Get the server version." + # -------------------------------------------------------------------------- + # Execute the service. + # -------------------------------------------------------------------------- def execute(self, id, parameters): + """Execute the service. + @param id: Client identifier. + @param parameters: Request parameters. + @return: The headers as list and the content dictionary of the request + answer. + """ headersStruct = self.getDefaultHeadersStruct() contentStruct = self.getDefaultContentStruct() contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS) Modified: 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 2009-05-28 08:31:55 UTC (rev 4690) +++ software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/01_resourceStatus.py 2009-05-28 09:41:58 UTC (rev 4691) @@ -1,19 +1,33 @@ +# Copyright (C) 2009 C2ME Sa +# Remi Jocaille <rem...@c2...> +# Distributed under the terms of the GNU General Public License +# http://www.gnu.org/copyleft/gpl.html + +SW_NAME_EXTERNAL_STATUS = "external_status" + # ============================================================================== -# Status resource. +# ****************************************************************************** +# RESOURCE DECLARATION +# ****************************************************************************** # ============================================================================== -SW_NAME_EXTERNAL_STATUS = "external_status" - -# ------------------------------------------------------------------------------ +# ============================================================================== # Declaration of the resource "status". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSResourceStatus(TDSResource): + """Resource status class. + """ - # -------------------------------------------------------------------------- + # ========================================================================== # Inherited methods from TDSResource + # ========================================================================== + # -------------------------------------------------------------------------- - + # Configure the resource. + # -------------------------------------------------------------------------- def configure(self): + """Configure the resource. + """ self.name = "status" self.comment = "Resource to manage the statuses and events." self.fileName = RESOURCE_FILENAME @@ -22,11 +36,14 @@ eventsHandler.insert(SW_NAME_EXTERNAL_STATUS) # Registering the "external" status in the default excluded events list clientsManager.addDefaultExcludedEvent(SW_NAME_EXTERNAL_STATUS) - - # -------------------------------------------------------------------------- + + # ========================================================================== # Public methods + # ========================================================================== + # -------------------------------------------------------------------------- - + # Get the last events from a client stack. + # -------------------------------------------------------------------------- def getEvents(self, idClient): """Get the last events from a client stack. - This function only affect the HTTP/REST clients. @@ -37,7 +54,10 @@ if client == None: return [] return client.popEvents() - + + # -------------------------------------------------------------------------- + # Request the current state of a status. + # -------------------------------------------------------------------------- def requestOne(self, statusName): """Request the current state of a status. @param statusName: Name of the status. @@ -61,7 +81,10 @@ 'delay' : 0.0, } return state - + + # -------------------------------------------------------------------------- + # Request the current state of all statuses. + # -------------------------------------------------------------------------- def requestAll(self): """Request the current state of all statuses. @return: The current state of all statuses as dictionary. @@ -73,7 +96,10 @@ if state != None: states.append(state) return states - + + # -------------------------------------------------------------------------- + # Send a free status. + # -------------------------------------------------------------------------- def sendStatus(self, name, value): """Send a free status. - This function inject a status in the events handler. This kind of @@ -94,7 +120,37 @@ clientsManager.pushEvents([statusStruct,]) t = threading.Thread(target = async) t.start() - + + # -------------------------------------------------------------------------- + # Publish events through the events handler. + # -------------------------------------------------------------------------- + def publishEvents(self, sendToClients, eventName, eventValues = []): + """Publish events through the events handler. + @param sendToClients: Send or not the the api clients. + @param eventName: Event name. + @param eventValues: Values as string array. + """ + 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() + + # -------------------------------------------------------------------------- + # Add an event in the excluded events list of a client. + # -------------------------------------------------------------------------- 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 @@ -108,7 +164,10 @@ client.addExcludedEvent(eventName) t = threading.Thread(target = async) t.start() - + + # -------------------------------------------------------------------------- + # Remove an event from the excluded events list of a client. + # -------------------------------------------------------------------------- def removeExcludedEvent(self, idClient, eventName): """Remove an event from the excluded events list of a client. @idClient: Client id. @@ -126,19 +185,41 @@ # Register the resource into the resources manager resourcesManager.addResource(resourceStatus) -# ------------------------------------------------------------------------------ +# ============================================================================== +# ****************************************************************************** +# SERVICES DECLARATION +# ****************************************************************************** +# ============================================================================== + +# ============================================================================== # Declaration of the service "events". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSServiceStatusEvents(TDSService): + """Get the last events from a client stack. + """ + # -------------------------------------------------------------------------- + # Configure the service. + # -------------------------------------------------------------------------- def configure(self): + """Configure the service. + """ self.parametersDict = {} self.minimalUserLevel = TDS_CLIENT_LEVEL_FREE self.exclusiveExecution = False self.name = "events" self.comment = "Get the last events from a client stack." + # -------------------------------------------------------------------------- + # Execute the service. + # -------------------------------------------------------------------------- def execute(self, id, parameters): + """Execute the service. + @param id: Client identifier. + @param parameters: Request parameters. + @return: The headers as list and the content dictionary of the request + answer. + """ headersStruct = self.getDefaultHeadersStruct() contentStruct = self.getDefaultContentStruct() contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS) @@ -154,12 +235,19 @@ # Register the service into the resource resourceStatus.addService(TDSServiceStatusEvents) -# ------------------------------------------------------------------------------ +# ============================================================================== # Declaration of the service "request_one". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSServiceStatusRequestOne(TDSService): + """Request the current state of a status. + """ + # -------------------------------------------------------------------------- + # Configure the service. + # -------------------------------------------------------------------------- def configure(self): + """Configure the service. + """ self.parametersDict = { 'status_name' : 'string', } @@ -168,7 +256,16 @@ self.name = "request_one" self.comment = "Request the current state of a status." + # -------------------------------------------------------------------------- + # Execute the service. + # -------------------------------------------------------------------------- def execute(self, id, parameters): + """Execute the service. + @param id: Client identifier. + @param parameters: Request parameters. + @return: The headers as list and the content dictionary of the request + answer. + """ headersStruct = self.getDefaultHeadersStruct() contentStruct = self.getDefaultContentStruct() contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS) @@ -182,19 +279,35 @@ # Register the service into the resource resourceStatus.addService(TDSServiceStatusRequestOne) -# ------------------------------------------------------------------------------ +# ============================================================================== # Declaration of the service "request_all". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSServiceStatusRequestAll(TDSService): + """Request the current state of all statuses. + """ + # -------------------------------------------------------------------------- + # Configure the service. + # -------------------------------------------------------------------------- def configure(self): + """Configure the service. + """ self.parametersDict = {} self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS self.exclusiveExecution = False self.name = "request_all" self.comment = "Request the current state of all statuses." + # -------------------------------------------------------------------------- + # Execute the service. + # -------------------------------------------------------------------------- def execute(self, id, parameters): + """Execute the service. + @param id: Client identifier. + @param parameters: Request parameters. + @return: The headers as list and the content dictionary of the request + answer. + """ headersStruct = self.getDefaultHeadersStruct() contentStruct = self.getDefaultContentStruct() contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS) @@ -209,12 +322,19 @@ # Register the service into the resource resourceStatus.addService(TDSServiceStatusRequestAll) -# ------------------------------------------------------------------------------ +# ============================================================================== # Declaration of the service "send". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSServiceStatusSend(TDSService): + """Send a free status. + """ + # -------------------------------------------------------------------------- + # Configure the service. + # -------------------------------------------------------------------------- def configure(self): + """Configure the service. + """ self.parametersDict = { 'name' : 'string', 'value' : 'string', @@ -224,7 +344,16 @@ self.name = "send" self.comment = "Send a free status." + # -------------------------------------------------------------------------- + # Execute the service. + # -------------------------------------------------------------------------- def execute(self, id, parameters): + """Execute the service. + @param id: Client identifier. + @param parameters: Request parameters. + @return: The headers as list and the content dictionary of the request + answer. + """ headersStruct = self.getDefaultHeadersStruct() contentStruct = self.getDefaultContentStruct() contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS) @@ -234,21 +363,37 @@ # Register the service into the resource resourceStatus.addService(TDSServiceStatusSend) -# ------------------------------------------------------------------------------ +# ============================================================================== # Declaration of the service "register_event". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSServiceStatusRegisterEvent(TDSService): + """Add an event in the registered events list of the client. + """ + # -------------------------------------------------------------------------- + # Configure the service. + # -------------------------------------------------------------------------- def configure(self): + """Configure the service. + """ 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." + self.comment = "Add an event in the registered events list of the client." + # -------------------------------------------------------------------------- + # Execute the service. + # -------------------------------------------------------------------------- def execute(self, id, parameters): + """Execute the service. + @param id: Client identifier. + @param parameters: Request parameters. + @return: The headers as list and the content dictionary of the request + answer. + """ headersStruct = self.getDefaultHeadersStruct() contentStruct = self.getDefaultContentStruct() contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS) @@ -258,12 +403,19 @@ # Register the service into the resource resourceStatus.addService(TDSServiceStatusRegisterEvent) -# ------------------------------------------------------------------------------ +# ============================================================================== # Declaration of the service "unregister_event". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSServiceStatusUnregisterEvent(TDSService): + """Remove an event from the registered events list of the client. + """ + # -------------------------------------------------------------------------- + # Configure the service. + # -------------------------------------------------------------------------- def configure(self): + """Configure the service. + """ self.parametersDict = { 'event_name' : 'string', } @@ -272,7 +424,16 @@ self.name = "unregister_event" self.comment = "Remove an event from the registered events list of the client." + # -------------------------------------------------------------------------- + # Execute the service. + # -------------------------------------------------------------------------- def execute(self, id, parameters): + """Execute the service. + @param id: Client identifier. + @param parameters: Request parameters. + @return: The headers as list and the content dictionary of the request + answer. + """ headersStruct = self.getDefaultHeadersStruct() contentStruct = self.getDefaultContentStruct() contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS) Modified: 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 2009-05-28 08:31:55 UTC (rev 4690) +++ software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/02_resourceAccess.py 2009-05-28 09:41:58 UTC (rev 4691) @@ -1,25 +1,42 @@ +# Copyright (C) 2009 C2ME Sa +# Remi Jocaille <rem...@c2...> +# Distributed under the terms of the GNU General Public License +# http://www.gnu.org/copyleft/gpl.html + # ============================================================================== -# Access resource. +# ****************************************************************************** +# RESOURCE DECLARATION +# ****************************************************************************** # ============================================================================== -# ------------------------------------------------------------------------------ +# ============================================================================== # Declaration of the resource "access". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSResourceAccess(TDSResource): + """Resource access class. + """ - # -------------------------------------------------------------------------- + # ========================================================================== # Inherited methods from TDSResource + # ========================================================================== + # -------------------------------------------------------------------------- - + # Configure the resource. + # -------------------------------------------------------------------------- def configure(self): + """Configure the resource. + """ self.name = "access" self.comment = "Resource to manage the access to the robot resources." self.fileName = RESOURCE_FILENAME - # -------------------------------------------------------------------------- + # ========================================================================== # Public methods + # ========================================================================== + # -------------------------------------------------------------------------- - + # Acquire the access to the robot resources. + # -------------------------------------------------------------------------- def acquireAccess(self, idClient, priorityLevel): """Acquire the access to the robot resources. - This function only affects the RESTRICTED clients @@ -36,6 +53,9 @@ return False return client.acquireAccess(priorityLevel) + # -------------------------------------------------------------------------- + # Release the access to the robot resources. + # -------------------------------------------------------------------------- def releaseAccess(self, idClient): """Release the access to the robot resources. - This function only affects the RESTRICTED clients @@ -43,6 +63,9 @@ """ accessManager.releaseAccess(idClient) + # -------------------------------------------------------------------------- + # Forcing to release the access to the robot resources. + # -------------------------------------------------------------------------- def forcingReleaseAccess(self): """Forcing to release the access to the robot resources. - This function only affects the RESTRICTED clients @@ -50,6 +73,9 @@ """ accessManager.releaseAccess() + # -------------------------------------------------------------------------- + # Forcing to acquire the access to the robot resources. + # -------------------------------------------------------------------------- def forcingAcquireAccess(self, idClient, priorityLevel): """Forcing to acquire the access to the robot resources. - This function only affects the RESTRICTED clients @@ -65,6 +91,9 @@ accessManager.releaseAccess() return accessManager.acquireAccess(idClient, priorityLevel) + # -------------------------------------------------------------------------- + # Lock the access to the robot resources. + # -------------------------------------------------------------------------- def lockAccess(self): """Lock the access to the robot resources. - This function only affects the RESTRICTED clients @@ -72,6 +101,9 @@ """ accessManager.setLocked(True) + # -------------------------------------------------------------------------- + # Lock the access to the robot resources. + # -------------------------------------------------------------------------- def unlockAccess(self): """Lock the access to the robot resources. - This function only affects the RESTRICTED clients @@ -84,12 +116,25 @@ # Register the resource into the resources manager resourcesManager.addResource(resourceAccess) -# ------------------------------------------------------------------------------ +# ============================================================================== +# ****************************************************************************** +# SERVICES DECLARATION +# ****************************************************************************** +# ============================================================================== + +# ============================================================================== # Declaration of the service "acquire". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSServiceAccessAcquire(TDSService): + """Acquire the access to the robot resources. + """ + # -------------------------------------------------------------------------- + # Configure the service. + # -------------------------------------------------------------------------- def configure(self): + """Configure the service. + """ self.parametersDict = { 'priority_level' : 'int', } @@ -98,7 +143,16 @@ self.name = "acquire" self.comment = "Acquire the access to the robot resources." + # -------------------------------------------------------------------------- + # Execute the service. + # -------------------------------------------------------------------------- def execute(self, id, parameters): + """Execute the service. + @param id: Client identifier. + @param parameters: Request parameters. + @return: The headers as list and the content dictionary of the request + answer. + """ headersStruct = self.getDefaultHeadersStruct() contentStruct = self.getDefaultContentStruct() contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS) @@ -109,19 +163,35 @@ # Register the service into the resource resourceAccess.addService(TDSServiceAccessAcquire) -# ------------------------------------------------------------------------------ +# ============================================================================== # Declaration of the service "release". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSServiceAccessRelease(TDSService): + """Release the access to the robot resources. + """ + # -------------------------------------------------------------------------- + # Configure the service. + # -------------------------------------------------------------------------- def configure(self): + """Configure the service. + """ self.parametersDict = {} self.minimalUserLevel = TDS_CLIENT_LEVEL_RESTRICTED self.exclusiveExecution = False self.name = "release" self.comment = "Release the access to the robot resources." + # -------------------------------------------------------------------------- + # Execute the service. + # -------------------------------------------------------------------------- def execute(self, id, parameters): + """Execute the service. + @param id: Client identifier. + @param parameters: Request parameters. + @return: The headers as list and the content dictionary of the request + answer. + """ headersStruct = self.getDefaultHeadersStruct() contentStruct = self.getDefaultContentStruct() contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS) @@ -131,19 +201,35 @@ # Register the service into the resource resourceAccess.addService(TDSServiceAccessRelease) -# ------------------------------------------------------------------------------ +# ============================================================================== # Declaration of the service "forcing_release". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSServiceAccessForcingRelease(TDSService): + """Forcing to release the access to the robot resources. + """ + # -------------------------------------------------------------------------- + # Configure the service. + # -------------------------------------------------------------------------- def configure(self): + """Configure the service. + """ 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." + # -------------------------------------------------------------------------- + # Execute the service. + # -------------------------------------------------------------------------- def execute(self, id, parameters): + """Execute the service. + @param id: Client identifier. + @param parameters: Request parameters. + @return: The headers as list and the content dictionary of the request + answer. + """ headersStruct = self.getDefaultHeadersStruct() contentStruct = self.getDefaultContentStruct() contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS) @@ -153,12 +239,19 @@ # Register the service into the resource resourceAccess.addService(TDSServiceAccessForcingRelease) -# ------------------------------------------------------------------------------ +# ============================================================================== # Declaration of the service "forcing_acquire". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSServiceAccessForcingAcquire(TDSService): + """Forcing to acquire the access to the robot resources. + """ + # -------------------------------------------------------------------------- + # Configure the service. + # -------------------------------------------------------------------------- def configure(self): + """Configure the service. + """ self.parametersDict = { 'id_client' : 'string', 'priority_level' : 'int', @@ -168,7 +261,16 @@ self.name = "forcing_acquire" self.comment = "Forcing to acquire the access to the robot resources." + # -------------------------------------------------------------------------- + # Execute the service. + # -------------------------------------------------------------------------- def execute(self, id, parameters): + """Execute the service. + @param id: Client identifier. + @param parameters: Request parameters. + @return: The headers as list and the content dictionary of the request + answer. + """ headersStruct = self.getDefaultHeadersStruct() contentStruct = self.getDefaultContentStruct() contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS) @@ -180,19 +282,35 @@ # Register the service into the resource resourceAccess.addService(TDSServiceAccessForcingAcquire) -# ------------------------------------------------------------------------------ +# ============================================================================== # Declaration of the service "lock". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSServiceAccessLock(TDSService): + """Lock the access to the robot resources. + """ + # -------------------------------------------------------------------------- + # Configure the service. + # -------------------------------------------------------------------------- def configure(self): + """Configure the service. + """ self.parametersDict = {} self.minimalUserLevel = TDS_CLIENT_LEVEL_ROOT self.exclusiveExecution = False self.name = "lock" self.comment = "Lock the access to the robot resources." + # -------------------------------------------------------------------------- + # Execute the service. + # -------------------------------------------------------------------------- def execute(self, id, parameters): + """Execute the service. + @param id: Client identifier. + @param parameters: Request parameters. + @return: The headers as list and the content dictionary of the request + answer. + """ headersStruct = self.getDefaultHeadersStruct() contentStruct = self.getDefaultContentStruct() contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS) @@ -202,19 +320,35 @@ # Register the service into the resource resourceAccess.addService(TDSServiceAccessLock) -# ------------------------------------------------------------------------------ +# ============================================================================== # Declaration of the service "unlock". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSServiceAccessUnlock(TDSService): + """Unlock the access to the robot resources. + """ + # -------------------------------------------------------------------------- + # Configure the service. + # -------------------------------------------------------------------------- def configure(self): + """Configure the service. + """ self.parametersDict = {} self.minimalUserLevel = TDS_CLIENT_LEVEL_ROOT self.exclusiveExecution = False self.name = "unlock" - self.comment = "Lock the access to the robot resources." + self.comment = "Unlock the access to the robot resources." + # -------------------------------------------------------------------------- + # Execute the service. + # -------------------------------------------------------------------------- def execute(self, id, parameters): + """Execute the service. + @param id: Client identifier. + @param parameters: Request parameters. + @return: The headers as list and the content dictionary of the request + answer. + """ headersStruct = self.getDefaultHeadersStruct() contentStruct = self.getDefaultContentStruct() contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS) Modified: 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 2009-05-28 08:31:55 UTC (rev 4690) +++ software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/03_resourceClient.py 2009-05-28 09:41:58 UTC (rev 4691) @@ -1,25 +1,42 @@ +# Copyright (C) 2009 C2ME Sa +# Remi Jocaille <rem...@c2...> +# Distributed under the terms of the GNU General Public License +# http://www.gnu.org/copyleft/gpl.html + # ============================================================================== -# Client resource. +# ****************************************************************************** +# RESOURCE DECLARATION +# ****************************************************************************** # ============================================================================== -# ------------------------------------------------------------------------------ +# ============================================================================== # Declaration of the resource "client". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSResourceClient(TDSResource): + """Resource client class. + """ - # -------------------------------------------------------------------------- + # ========================================================================== # Inherited methods from TDSResource + # ========================================================================== + # -------------------------------------------------------------------------- - + # Configure the resource. + # -------------------------------------------------------------------------- def configure(self): + """Configure the resource. + """ self.name = "client" self.comment = "Resource to manage the clients." self.fileName = RESOURCE_FILENAME - # -------------------------------------------------------------------------- + # ========================================================================== # Public methods + # ========================================================================== + # -------------------------------------------------------------------------- - + # Create a new client. + # -------------------------------------------------------------------------- def createClient(self, clientName, clientLevel): """Create a new client. @clientName: Client name. @@ -35,6 +52,9 @@ idClient = clientsManager.addRESTClient(clientName, clientLevel) return idClient + # -------------------------------------------------------------------------- + # Destroy a client. + # -------------------------------------------------------------------------- def destroyClient(self, idClient): """Destroy a client. - This function only affect the HTTP/REST clients. @@ -42,6 +62,9 @@ """ clientsManager.removeRESTClient(idClient) + # -------------------------------------------------------------------------- + # Get the clients listing with their informations. + # -------------------------------------------------------------------------- def listing(self): """Get the clients listing with their informations. @return: A dictionary. @@ -58,12 +81,25 @@ # Register the resource into the resources manager resourcesManager.addResource(resourceClient) -# ------------------------------------------------------------------------------ +# ============================================================================== +# ****************************************************************************** +# SERVICES DECLARATION +# ****************************************************************************** +# ============================================================================== + +# ============================================================================== # Declaration of the service "create". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSServiceClientCreate(TDSService): + """Create a client. + """ + # -------------------------------------------------------------------------- + # Configure the service. + # -------------------------------------------------------------------------- def configure(self): + """Configure the service. + """ self.parametersDict = { 'name' : 'string', 'level' : 'uint8', @@ -73,7 +109,16 @@ self.name = "create" self.comment = "Create a client." + # -------------------------------------------------------------------------- + # Execute the service. + # -------------------------------------------------------------------------- def execute(self, id, parameters): + """Execute the service. + @param id: Client identifier. + @param parameters: Request parameters. + @return: The headers as list and the content dictionary of the request + answer. + """ headersStruct = self.getDefaultHeadersStruct() contentStruct = self.getDefaultContentStruct() contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS) @@ -89,19 +134,35 @@ # Register the service into the resource resourceClient.addService(TDSServiceClientCreate) -# ------------------------------------------------------------------------------ +# ============================================================================== # Declaration of the service "destroy". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSServiceClientDestroy(TDSService): + """Destroy a client. + """ + # -------------------------------------------------------------------------- + # Configure the service. + # -------------------------------------------------------------------------- def configure(self): + """Configure the service. + """ self.parametersDict = {} self.minimalUserLevel = TDS_CLIENT_LEVEL_FREE self.exclusiveExecution = False self.name = "destroy" self.comment = "Destroy a client." + # -------------------------------------------------------------------------- + # Execute the service. + # -------------------------------------------------------------------------- def execute(self, id, parameters): + """Execute the service. + @param id: Client identifier. + @param parameters: Request parameters. + @return: The headers as list and the content dictionary of the request + answer. + """ headersStruct = self.getDefaultHeadersStruct() contentStruct = self.getDefaultContentStruct() contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS) @@ -111,19 +172,35 @@ # Register the service into the resource resourceClient.addService(TDSServiceClientDestroy) -# ------------------------------------------------------------------------------ +# ============================================================================== # Declaration of the service "listing". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSServiceClientListing(TDSService): + """Get the clients listing with their informations. + """ + # -------------------------------------------------------------------------- + # Configure the service. + # -------------------------------------------------------------------------- def configure(self): + """Configure the service. + """ self.parametersDict = {} self.minimalUserLevel = TDS_CLIENT_LEVEL_FREE self.exclusiveExecution = False self.name = "listing" self.comment = "Get the clients listing with their informations." + # -------------------------------------------------------------------------- + # Execute the service. + # -------------------------------------------------------------------------- def execute(self, id, parameters): + """Execute the service. + @param id: Client identifier. + @param parameters: Request parameters. + @return: The headers as list and the content dictionary of the request + answer. + """ headersStruct = self.getDefaultHeadersStruct() contentStruct = self.getDefaultContentStruct() contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS) Modified: 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 2009-05-28 08:31:55 UTC (rev 4690) +++ software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/04_resourceMenu.py 2009-05-28 09:41:58 UTC (rev 4691) @@ -1,17 +1,31 @@ +# Copyright (C) 2009 C2ME Sa +# Remi Jocaille <rem...@c2...> +# Distributed under the terms of the GNU General Public License +# http://www.gnu.org/copyleft/gpl.html + # ============================================================================== -# Menu resource. +# ****************************************************************************** +# RESOURCE DECLARATION +# ****************************************************************************** # ============================================================================== -# ------------------------------------------------------------------------------ +# ============================================================================== # Declaration of the resource "menu". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSResourceMenu(TDSResource): + """Resource menu class. + """ - # -------------------------------------------------------------------------- + # ========================================================================== # Inherited methods from TDSResource + # ========================================================================== + # -------------------------------------------------------------------------- - + # Configure the resource. + # -------------------------------------------------------------------------- def configure(self): + """Configure the resource. + """ self.name = "menu" self.comment = "Menu resource." self.fileName = RESOURCE_FILENAME @@ -21,12 +35,25 @@ # Register the resource into the resources manager resourcesManager.addResource(resourceMenu) -# ------------------------------------------------------------------------------ +# ============================================================================== +# ****************************************************************************** +# SERVICES DECLARATION +# ****************************************************************************** +# ============================================================================== + +# ============================================================================== # Declaration of the service "index". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSServiceMenuIndex(TDSService): + """Main menu of the server. + """ + # -------------------------------------------------------------------------- + # Configure the service. + # -------------------------------------------------------------------------- def configure(self): + """Configure the service. + """ self.parametersDict = {} self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS self.exclusiveExecution = False @@ -35,12 +62,27 @@ self.haveXsl = True self.xslPath = "/data/web_interface/server_menu/xsl/menu.xsl" + # -------------------------------------------------------------------------- + # Execute the service. + # -------------------------------------------------------------------------- def execute(self, id, parameters): + """Execute the service. + @param id: Client identifier. + @param parameters: Request parameters. + @return: The headers as list and the content dictionary of the request + answer. + """ headersStruct = self.getDefaultHeadersStruct() contentStruct = {'root' : self.__createXmlIndex()} return headersStruct, contentStruct + # -------------------------------------------------------------------------- + # Create xml data dict for the menu index. + # -------------------------------------------------------------------------- def __createXmlIndex(self): + """Create xml data dict for the menu index. + @return: The xml content as dictionary. + """ contentStruct = { 'title' : 'Tux Droid Server V %s' % serverVersion, 'section' : 'Index', @@ -57,12 +99,19 @@ # Bind the root url to this service resourcesManager.addBinding("ROOT", "menu", "index") -# ------------------------------------------------------------------------------ +# ============================================================================== # Declaration of the service "resources". -# ------------------------------------------------------------------------------ +# ============================================================================== class TDSServiceMenuResources(TDSService): + """Resources menu. + """ + # -------------------------------------------------------------------------- + # Configure the service. + # -------------------------------------------------------------------------- def configure(self): + """Configure the service. + """ self.parametersDict = { 'resource_name' : 'string', } @@ -73,7 +122,16 @@ self.haveXsl = True self.xslPath = "/data/web_interface/server_menu/xsl/menu.xsl" + # -------------------------------------------------------------------------- + # Execute the service. + # -------------------------------------------------------------------------- def execute(self, id, parameters): + """Execute the service. + @param id: Client identifier. + @param parameters: Request parameters. + @return: The headers as list and the content dictionary of the request + answer. + """ headersStruct = self.getDefaultHeadersStruct() if parameters['resource_name'] == 'index': contentStruct = {'root' : self.__createXmlIndex()} @@ -83,7 +141,13 @@ } return headersStruct, contentStruct + # -------------------------------------------------------------------------- + # Create xml data dict for the resources index. + # -------------------------------------------------------------------------- def __createXmlIndex(self): + """Create xml data dict for the resources index. + @return: The xml content as dictionary. + """ self.xslPath = "/data/web_interface/server_menu/xsl/menu_resources.xsl" contentStruct = { 'title' : 'Tux Droid Server V %s' % serverVersion, @@ -104,7 +168,14 @@ contentStruct['items']["Layer_%s" % path][resourceName] = url return contentStruct + # -------------------------------------------------------------------------- + # Create xml data dict for a resource. + # -------------------------------------------------------------------------- def __createXmlResource(self, resourceName): + """Create xml data dict for a resource. + @resourceName: Name of the resource. + @return: The xml content as dictionary. + """ self.xslPath = "/data/web_interface/server_menu/xsl/resource.xsl" resource = resourcesManager.getResource(resourceName) if resource == None: @@ -127,12 +198,19 @@ # Register the service into the resource resourceMenu.addService(TDSServiceMenuResources) -# ---------------... [truncated message content] |