Author: remi
Date: 2009-03-23 20:46:26 +0100 (Mon, 23 Mar 2009)
New Revision: 4188

Modified:
   
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/01_robot_system/resourceGadgetFramework.py
   
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/03_advanced_api/resourceTestGadgetMessage.py
Log:
* updated resources to use the new python gadget framework.

Modified: 
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/01_robot_system/resourceGadgetFramework.py
===================================================================
--- 
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/01_robot_system/resourceGadgetFramework.py
 2009-03-23 18:39:28 UTC (rev 4187)
+++ 
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/01_robot_system/resourceGadgetFramework.py
 2009-03-23 19:46:26 UTC (rev 4188)
@@ -2,7 +2,9 @@
 # Gadget framework resource.
 # 
==============================================================================
 
-from util.gadgets.Framework import Framework
+from util.applicationserver.gadget.GadgetsContainer import GadgetsContainer
+from util.applicationserver.gadget.Gadget import SUPPORTED_LANGUAGES_LIST
+from util.applicationserver.gadget.WebGadgetTools import WebGadgetTools
 from util.misc.tuxPaths import TUXDROID_LANGUAGE
 from util.misc.tuxPaths import TUXDROID_DEFAULT_LOCUTOR
 from util.misc.tuxPaths import USER_BASE_PATH
@@ -13,6 +15,7 @@
 ST_NAME_FW_CONTAINER_ERROR = "framework_container_error"
 ST_NAME_FW_GADGET_LOADED = "framework_gadget_loaded"
 ST_NAME_FW_GADGET_UNLOADED = "framework_gadget_unloaded"
+ST_NAME_FW_GADGET_MESSAGE = "framework_gadget_message"
 ST_NAME_FW_GADGET_ERROR = "framework_gadget_error"
 ST_NAME_FW_GADGET_TRACE = "framework_gadget_trace"
 ST_NAME_FW_GADGET_NOTIFICATION = "framework_gadget_notification"
@@ -26,6 +29,7 @@
     ST_NAME_FW_CONTAINER_ERROR, # Is not sent to clients
     ST_NAME_FW_GADGET_LOADED, # Is not sent to clients
     ST_NAME_FW_GADGET_UNLOADED, # Is not sent to clients
+    ST_NAME_FW_GADGET_MESSAGE, # Is not sent to clients
     ST_NAME_FW_GADGET_ERROR, # Is not sent to clients
     ST_NAME_FW_GADGET_TRACE, # Is not sent to clients
     ST_NAME_FW_GADGET_NOTIFICATION, # Is not sent to clients
@@ -46,18 +50,13 @@
         self.name = "gadget_framework"
         self.comment = "Resource to manage the gadget framework."
         self.fileName = RESOURCE_FILENAME
-        self.__framework = Framework()
-        
self.__framework.setOnFrameworkStartingCallBack(self.__onFrameworkStarting)
-        
self.__framework.setOnFrameworkStoppedCallBack(self.__onFrameworkStopped)
-        
self.__framework.setOnContainerDeployedCallback(self.__onContainerDeployed)
-        
self.__framework.setOnContainerGadgetLoadedCallback(self.__onGadgetLoaded)
-        
self.__framework.setOnContainerGadgetUnloadedCallback(self.__onGadgetUnloaded)
-        self.__framework.setOnContainerErrorCallback(self.__onContainerError)
-        self.__framework.setOnGadgetErrorCallback(self.__onGadgetError)
-        self.__framework.setOnGadgetTraceCallback(self.__onGadgetTrace)
-        
self.__framework.setOnGadgetNotificationCallback(self.__onGadgetNotification)
-        self.__framework.setOnGadgetStartingCallback(self.__onGadgetStarting)
-        self.__framework.setOnGagdetStoppedCallback(self.__onGagdetStopped)
+        # Create a gadgets container
+        self.__gadgetsContainer = GadgetsContainer()
+        
self.__gadgetsContainer.setOnDirectoryDeployedCallback(self.__onDirectoryDeployed)
+        
self.__gadgetsContainer.setOnDirectoryUndeployedCallback(self.__onDirectoryUndeployed)
+        
self.__gadgetsContainer.setOnGadgetDeployedCallback(self.__onGadgetDeployed)
+        
self.__gadgetsContainer.setOnGadgetDeploymentErrorCallback(self.__onGadgetDeploymentError)
+        
self.__gadgetsContainer.setOnGadgetUndeployedCallback(self.__onGadgetUndeployed)
         # Registering the framework statuses and add it in the excluded list.
         # Clients have to syndicate to receive.
         for statusName in SW_NAME_FRAMEWORK:
@@ -85,10 +84,108 @@
 
     def stop(self):
         self.getConfigurator().store()
-        self.__framework.stop()
+        self.__gadgetsContainer.undeploy()
         self.__publishEvents(True, ST_NAME_FW_RUN, ["False",])
 
     # 
--------------------------------------------------------------------------
+    # Gadget container events
+    # 
--------------------------------------------------------------------------
+
+    def __onDirectoryDeployed(self, observerName):
+        self.__publishEvents(True, ST_NAME_FW_CONTAINER_DEPLOYED, ["True",])
+
+    def __onDirectoryUndeployed(self, observerName):
+        self.__publishEvents(True, ST_NAME_FW_CONTAINER_DEPLOYED, ["False",])
+
+    def __onGadgetDeployed(self, gadget, gadgetWorkingPath):
+        uuid = gadget.getDescription().getUuid()
+        pngUrl = '/%s/gadget.png' % uuid
+        resourcesManager.addFileToServe(gadget.getDescription().getIconFile(),
+                pngUrl)
+        for language in SUPPORTED_LANGUAGES_LIST:
+            helpFile = gadget.getDescription().getHelpFile(language)
+            fileName = helpFile[helpFile.rfind(os.sep) + 1:]
+            helpUrl = '/%s/%s' % (uuid, fileName)
+            resourcesManager.addFileToServe(helpFile, helpUrl)
+        googleGadgetUrl = '/%s/google_gadget_code.txt' % uuid
+        googleGadgetCode = WebGadgetTools.generateGoogleGadgetCode(gadget,
+            "http://127.0.0.1:270/gadget_framework/web_gadget?";,
+            gadget.getCommands()[0].getName(), {})
+        resourcesManager.addContentToServe(googleGadgetCode,
+            googleGadgetUrl)
+        gadget.setOnGadgetNotificationCallback(self.__onGadgetNotification)
+        gadget.setOnGadgetMessageCallback(self.__onGadgetMessage)
+        gadget.setOnGadgetErrorCallback(self.__onGadgetError)
+        gadget.setOnGadgetTraceCallback(self.__onGadgetTrace)
+        gadget.setOnGadgetStartingCallback(self.__onGadgetStarting)
+        gadget.setOnGadgetStoppedCallback(self.__onGadgetStopped)
+        self.__publishEvents(False, ST_NAME_FW_GADGET_LOADED, [uuid,])
+
+    def __onGadgetDeploymentError(self, observerName, gadgetFileName, message):
+        messagesList = [
+            observerName,
+            gadgetFileName,
+            message,
+        ]
+        self.__publishEvents(False, ST_NAME_FW_CONTAINER_ERROR, messagesList)
+
+    def __onGadgetUndeployed(self, gadget, gadgetWorkingPath):
+        uuid = gadget.getDescription().getUuid()
+        pngUrl = '/%s/gadget.png' % uuid
+        resourcesManager.removeFileToServe(pngUrl)
+        for language in SUPPORTED_LANGUAGES_LIST:
+            helpFile = gadget.getDescription().getHelpFile(language)
+            fileName = helpFile[helpFile.rfind(os.sep) + 1:]
+            helpUrl = '/%s/%s' % (uuid, fileName)
+            resourcesManager.removeFileToServe(helpUrl)
+        googleGadgetUrl = '/%s/google_gadget_code.txt' % uuid
+        resourcesManager.removeFileToServe(googleGadgetUrl)
+        self.__publishEvents(False, ST_NAME_FW_GADGET_UNLOADED, [uuid,])
+
+    # 
--------------------------------------------------------------------------
+    # Gadget events
+    # 
--------------------------------------------------------------------------
+
+    def __onGadgetNotification(self, gadget, instanceParameters, messageId, 
*args):
+        messageStr = ""
+        for message in args:
+            messageStr += message
+        uuid = gadget.getDescription().getUuid()
+        locutor = instanceParameters['locutor']
+        pitch = instanceParameters['pitch']
+        self.__publishEvents(False, ST_NAME_FW_GADGET_NOTIFICATION, [uuid, "0",
+            locutor, pitch, messageId, messageStr])
+
+    def __onGadgetMessage(self, gadget, instanceParameters, message):
+        uuid = gadget.getDescription().getUuid()
+        locutor = instanceParameters['locutor']
+        pitch = instanceParameters['pitch']
+        self.__publishEvents(False, ST_NAME_FW_GADGET_MESSAGE, [uuid, "0",
+            locutor, pitch, message])
+
+    def __onGadgetError(self, gadget, instanceParameters, *messagesList):
+        messageStr = ""
+        for message in messagesList:
+            messageStr += message
+        self.__publishEvents(False, ST_NAME_FW_GADGET_ERROR, [
+            gadget.getDescription().getUuid(), "0", messageStr])
+
+    def __onGadgetTrace(self, gadget, instanceParameters, *messagesList):
+        messageStr = ""
+        for message in messagesList:
+            messageStr += message
+        self.__publishEvents(False, ST_NAME_FW_GADGET_TRACE, [
+            gadget.getDescription().getUuid(), "0", messageStr])
+
+    def __onGadgetStarting(self, gadget, instanceParameters):
+        uuid = gadget.getDescription().getUuid()
+        self.__publishEvents(True, ST_NAME_FW_GADGET_STARTING, [uuid, "0"])
+
+    def __onGadgetStopped(self, gadget, instanceParameters):
+        uuid = gadget.getDescription().getUuid()
+        self.__publishEvents(True, ST_NAME_FW_GADGET_STOPPED, [uuid, "0"])
+
+    # 
--------------------------------------------------------------------------
     # Private methods
     # 
--------------------------------------------------------------------------
 
@@ -111,94 +208,20 @@
         t = threading.Thread(target = async)
         t.start()
 
-    def __onFrameworkStarting(self):
-        self.__publishEvents(True, ST_NAME_FW_RUN, ["True",])
+    # 
--------------------------------------------------------------------------
+    # Shared methods
+    # 
--------------------------------------------------------------------------
 
-    def __onFrameworkStopped(self):
-        self.__publishEvents(True, ST_NAME_FW_RUN, ["False",])
+    def publishEvents(self, sendToClients, eventName, eventValues = []):
+        """
+        """
+        self.__publishEvents(sendToClients, eventName, eventValues)
 
-    def __onContainerDeployed(self):
-        # Serve the png and help files of the gadgets
-        for gadget in self.__framework.getGadgetsContainer().getGadgets():
-            description = gadget.getDescription()
-            struct = description.getStructure()
-            workingPath = 
os.path.split(os.path.split(description.getIconFile())[0])[0]
-            struct['working_path'] = workingPath
-            pngUrl = '/%s/gadget.png' % description.getUuid()
-            helpUrl = '/%s/help.html' % description.getUuid()
-            resourcesManager.addFileToServe(description.getIconFile(),
-                pngUrl)
-            resourcesManager.addFileToServe(description.getHelpFile(),
-                helpUrl)
-            struct['icon_file'] = pngUrl
-            struct['help_file'] = helpUrl
-            googleGadgetUrl = '/%s/google_gadget_code.txt' % 
description.getUuid()
-            struct['google_gadget_code'] = googleGadgetUrl
-            googleGadgetCode = gadget.generateGoogleGadgetCode(
-                "http://127.0.0.1:270/gadget_framework/web_gadget?";,
-                gadget.getCommands()[0].getName(), {})
-            resourcesManager.addContentToServe(googleGadgetCode,
-                googleGadgetUrl)
-            struct['web_gadget_url'] = gadget.getWebGadgetUrl(
-                "http://127.0.0.1:270/gadget_framework/web_gadget?";,
-                gadget.getCommands()[0].getName(), {})
-            description.setStructure(struct)
-        self.__publishEvents(True, ST_NAME_FW_CONTAINER_DEPLOYED, ["True",])
-
-    def __onContainerError(self, messagesList):
-        self.__publishEvents(False, ST_NAME_FW_CONTAINER_ERROR, messagesList)
-
-    def __onGadgetLoaded(self, gadgetUuid):
-        self.__publishEvents(False, ST_NAME_FW_GADGET_LOADED, [gadgetUuid,])
-
-    def __onGadgetUnloaded(self, gadgetUuid):
-        # Unserve the png and help html files of the unloaded gadget
-        for gadget in self.__framework.getGadgetsContainer().getGadgets():
-            description = gadget.getDescription()
-            if description.getUuid() == gadgetUuid:
-                pngUrl = '/%s/gadget.png' % gadgetUuid
-                helpUrl = '/%s/help.html' % gadgetUuid
-                resourcesManager.removeFileToServe(pngUrl)
-                resourcesManager.removeFileToServe(helpUrl)
-                break
-        self.__publishEvents(False, ST_NAME_FW_GADGET_UNLOADED, [gadgetUuid,])
-
-    def __onGadgetError(self, gadgetUuid, instanceUuid, messagesList):
-        messageStr = ""
-        for message in messagesList:
-            messageStr += message
-        self.__publishEvents(False, ST_NAME_FW_GADGET_ERROR,
-            [gadgetUuid, instanceUuid, messageStr])
-
-    def __onGadgetTrace(self, gadgetUuid, instanceUuid, messagesList):
-        messageStr = ""
-        for message in messagesList:
-            messageStr += message
-        self.__publishEvents(False, ST_NAME_FW_GADGET_TRACE,
-            [gadgetUuid, instanceUuid, messageStr])
-
-    def __onGadgetNotification(self, gadgetUuid, instanceUuid, 
gadgetTtsLocutor,
-        gadgetTtsPitch, notificationType, messagesList):
-        messageStr = ""
-        for message in messagesList:
-            messageStr += message
-        self.__publishEvents(False, ST_NAME_FW_GADGET_NOTIFICATION,
-            [gadgetUuid, instanceUuid, gadgetTtsLocutor, gadgetTtsPitch,
-            notificationType, messageStr])
-
-    def __onGadgetStarting(self, gadgetUuid, instanceUuid):
-        self.__publishEvents(True, ST_NAME_FW_GADGET_STARTING, [gadgetUuid,
-            instanceUuid])
-
-    def __onGagdetStopped(self, gadgetUuid, instanceUuid):
-        self.__publishEvents(False, ST_NAME_FW_GADGET_STOPPED, [gadgetUuid,
-            instanceUuid])
-
-    def getFramework(self):
-        """Get the gadget framework.
-        @return: A Framework object.
+    def getGadgetsContainer(self):
+        """Get the gadgets container.
+        @return: The gadgets container.
         """
-        return self.__framework
+        return self.__gadgetsContainer
 
     def insertGadgetInContainer(self, tgfFilename):
         """Insert a gadget in the framework container.
@@ -208,11 +231,13 @@
         - After the success of the gadget insertion the framework will 
detected it.
         """
         # Check that the framework is started
-        if not self.__framework.isStarted():
+        if not self.__gadgetsContainer.isDeployed():
             return False
         # Check that the container directory is selected
-        if self.__framework.getGadgetsDirectory() == None:
+        directories = self.__gadgetsContainer.getDirectories()
+        if len(directories) == 0:
             return False
+        directory = directories[-1]
         # Check the file extension
         if tgfFilename.lower().rfind(".tgf") == -1:
             return False
@@ -226,8 +251,7 @@
         import shutil
         try:
             tfgName = os.path.split(tgfFilename)[-1]
-            tfgName = os.path.join(self.__framework.getGadgetsDirectory(),
-                tfgName)
+            tfgName = os.path.join(directory, tfgName)
             shutil.copy(cFile.getOutputFilePath(), tfgName)
         except:
             result = False
@@ -240,12 +264,11 @@
         @return: The success.
         """
         # Check that the framework is started
-        if not self.__framework.isStarted():
+        if not self.__gadgetsContainer.isDeployed():
             return False
-        container = self.__framework.getGadgetsContainer()
-        for gadget in container.getGadgets():
-            if gadget.getDescription.getUuid() == gadgetUuid:
-                tgfFile = gadget.getDescription.getTgfFile()
+        for gadget in self.__gadgetsContainer.getGadgets():
+            if gadget.getDescription().getUuid() == gadgetUuid:
+                tgfFile = gadget.getDescription().getTgfFile()
                 # Remove the tfg file
                 DirectoriesAndFilesTools.RMFile(tgfFile)
                 return True
@@ -280,27 +303,46 @@
             "resourceFramework.conf",
             resourceGadgetFramework.defaultConfiguration)
         if config['auto-start']:
-            
resourceGadgetFramework.getFramework().start(config['gadgets_path'],
-                config['language'], config['country'],
+            gadgetsContainer = resourceGadgetFramework.getGadgetsContainer()
+            for directory in gadgetsContainer.getDirectories():
+                gadgetsContainer.removeDirectory(directory)
+            gadgetsContainer.setLocales(config['language'], config['country'],
                 config['locutor'], config['pitch'])
+            gadgetsContainer.addDirectory(config['gadgets_path'])
+            gadgetsContainer.deploy()
+            resourceGadgetFramework.publishEvents(True, ST_NAME_FW_RUN, 
["True",])
 
     def execute(self, id, parameters):
         headersStruct = self.getDefaultHeadersStruct()
         contentStruct = self.getDefaultContentStruct()
         contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
-        # Start the framework
-        
resourceGadgetFramework.getFramework().start(parameters['gadgets_path'],
-            parameters['language'], parameters['country'],
-            parameters['locutor'], parameters['pitch'])
-        # Store the configuration
-        configurator = resourceGadgetFramework.getConfigurator()
-        config = configurator.getConfiguration()
-        config['language'] = parameters['language']
-        config['country'] = parameters['country']
-        config['locutor'] = parameters['locutor']
-        config['pitch'] = parameters['pitch']
-        config['gadgets_path'] = parameters['gadgets_path']
-        configurator.store()
+        # Check the directory
+        if not os.path.isdir(parameters['gadgets_path']):
+            contentStruct['root']['result'] = getStrError(E_TDREST_FAILED)
+        else:
+            # Store the configuration
+            configurator = resourceGadgetFramework.getConfigurator()
+            config = configurator.getConfiguration()
+            config['language'] = parameters['language']
+            config['country'] = parameters['country']
+            config['locutor'] = parameters['locutor']
+            config['pitch'] = parameters['pitch']
+            config['gadgets_path'] = parameters['gadgets_path']
+            configurator.store()
+            # Start the framework
+            gadgetsContainer = resourceGadgetFramework.getGadgetsContainer()
+            resourceGadgetFramework.publishEvents(True, ST_NAME_FW_RUN,
+                ["False",])
+            gadgetsContainer.undeploy()
+            for directory in gadgetsContainer.getDirectories():
+                gadgetsContainer.removeDirectory(directory)
+            gadgetsContainer.setLocales(parameters['language'],
+                parameters['country'], parameters['locutor'],
+                parameters['pitch'])
+            gadgetsContainer.addDirectory(parameters['gadgets_path'])
+            gadgetsContainer.deploy()
+            resourceGadgetFramework.publishEvents(True, ST_NAME_FW_RUN,
+                ["True",])
         return headersStruct, contentStruct
 
 # Register the service into the resource
@@ -327,19 +369,18 @@
         headersStruct = self.getDefaultHeadersStruct()
         contentStruct = self.getDefaultContentStruct()
         contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
-        if not 
resourceGadgetFramework.getFramework().updateLocales(parameters['language'],
-            parameters['country'], parameters['locutor'], parameters['pitch']):
-            contentStruct['root']['result'] = getStrError(E_TDREST_FAILED)
-        else:
-            # Store the configuration
-            configurator = resourceGadgetFramework.getConfigurator()
-            config = configurator.getConfiguration()
-            config['language'] = parameters['language']
-            config['country'] = parameters['country']
-            config['locutor'] = parameters['locutor']
-            config['pitch'] = parameters['pitch']
-            config['gadgets_path'] = parameters['gadgets_path']
-            configurator.store()
+        gadgetsContainer = resourceGadgetFramework.getGadgetsContainer()
+        gadgetsContainer.setLocales(parameters['language'],
+            parameters['country'], parameters['locutor'], parameters['pitch'])
+        # Store the configuration
+        configurator = resourceGadgetFramework.getConfigurator()
+        config = configurator.getConfiguration()
+        config['language'] = parameters['language']
+        config['country'] = parameters['country']
+        config['locutor'] = parameters['locutor']
+        config['pitch'] = parameters['pitch']
+        config['gadgets_path'] = parameters['gadgets_path']
+        configurator.store()
         return headersStruct, contentStruct
 
 # Register the service into the resource
@@ -363,10 +404,21 @@
         headersStruct = self.getDefaultHeadersStruct()
         contentStruct = self.getDefaultContentStruct()
         contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
-        gadgetsInfos = 
resourceGadgetFramework.getFramework().getGadgetsStructure()
-        for i, gadgetKey in enumerate(gadgetsInfos):
+        gadgets = resourceGadgetFramework.getGadgetsContainer().getGadgets()
+        for i, gadget in enumerate(gadgets):
             d_name = "data|%d" % i
-            contentStruct['root'][d_name] = gadgetsInfos[gadgetKey]
+            structure = WebGadgetTools.generateWebGadgetStructure(gadget,
+                'http://127.0.0.1:270/gadget_framework/web_gadget?',
+                gadget.getCommands()[0].getName(), {})
+            #del structure['command']
+            structure['commands'] = {}
+            for j, command in enumerate(gadget.getCommands()):
+                c_name = "command_%.3d" % j
+                structure['commands'][c_name] = {}
+                structure['commands'][c_name]['name'] = command.getName()
+                structure['commands'][c_name]['translated_name'] = 
command.getTranslatedName()
+                structure['commands'][c_name]['description'] = 
command.getDescription()
+            contentStruct['root'][d_name] = structure
         return headersStruct, contentStruct
 
 # Register the service into the resource
@@ -401,11 +453,12 @@
             if len(param) == 2:
                 params[param[0]] = param[1]
         uuid = parameters['uuid']
-        gadget = 
resourceGadgetFramework.getFramework().getGadgetsContainer().getGadgetByUuid(uuid)
+        gadget = 
resourceGadgetFramework.getGadgetsContainer().getGadgetByUuid(uuid)
         structure = None
         if gadget != None:
-            structure = 
gadget.generateWebGadgetStructure(parameters['command'],
-                params)
+            structure = WebGadgetTools.generateWebGadgetStructure(gadget,
+                'http://127.0.0.1:270/gadget_framework/web_gadget?',
+                parameters['command'], params)
         if structure == None:
             contentStruct['root']['result'] = getStrError(E_TDREST_FAILED)
         else:
@@ -444,7 +497,7 @@
             if len(param) == 2:
                 params[param[0]] = param[1]
         gadgetStarted = False
-        gadget = 
resourceGadgetFramework.getFramework().getGadgetsContainer().getGadgetByUuid(uuid)
+        gadget = 
resourceGadgetFramework.getGadgetsContainer().getGadgetByUuid(uuid)
         if gadget != None:
             gadgetStarted = gadget.start(command, params)
         if not gadgetStarted:
@@ -483,7 +536,7 @@
             if len(param) == 2:
                 params[param[0]] = param[1]
         gadgetStarted = False
-        gadget = 
resourceGadgetFramework.getFramework().getGadgetsContainer().getGadgetByName(name)
+        gadget = 
resourceGadgetFramework.getGadgetsContainer().getGadgetByName(name)
         if gadget != None:
             gadgetStarted = gadget.start(command, params)
         if not gadgetStarted:
@@ -512,13 +565,9 @@
         contentStruct = self.getDefaultContentStruct()
         contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
         uuid = parameters['uuid']
-        gadgetStopped = False
-        gadget = 
resourceGadgetFramework.getFramework().getGadgetsContainer().getGadgetByUuid(uuid)
+        gadget = 
resourceGadgetFramework.getGadgetsContainer().getGadgetByUuid(uuid)
         if gadget != None:
-            gadgetStopped = gadget.stop()
-        if not gadgetStopped:
-            contentStruct['root']['result'] = getStrError(E_TDREST_FAILED)
-        else:
+            gadget.stop()
             resourceTTS.stackRemoveByUuid(uuid)
         return headersStruct, contentStruct
 
@@ -545,12 +594,9 @@
         contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
         name = parameters['name']
         gadgetStopped = False
-        gadget = 
resourceGadgetFramework.getFramework().getGadgetsContainer().getGadgetByName(name)
+        gadget = 
resourceGadgetFramework.getGadgetsContainer().getGadgetByName(name)
         if gadget != None:
-            gadgetStopped = gadget.stop()
-        if not gadgetStopped:
-            contentStruct['root']['result'] = getStrError(E_TDREST_FAILED)
-        else:
+            gadget.stop()
             resourceTTS.stackRemoveByUuid(gadget.getDescription().getUuid())
         return headersStruct, contentStruct
 
@@ -573,10 +619,8 @@
         headersStruct = self.getDefaultHeadersStruct()
         contentStruct = self.getDefaultContentStruct()
         contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
-        if not 
resourceGadgetFramework.getFramework().getGadgetsContainer().stopAllGadgets():
-            contentStruct['root']['result'] = getStrError(E_TDREST_FAILED)
-        else:
-            resourceTTS.stackFlushExceptedUuid("0")
+        resourceGadgetFramework.getGadgetsContainer().stopAllGadgets()
+        resourceTTS.stackFlushExceptedUuid("0")
         return headersStruct, contentStruct
 
 # Register the service into the resource

Modified: 
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/03_advanced_api/resourceTestGadgetMessage.py
===================================================================
--- 
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/03_advanced_api/resourceTestGadgetMessage.py
       2009-03-23 18:39:28 UTC (rev 4187)
+++ 
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/03_advanced_api/resourceTestGadgetMessage.py
       2009-03-23 19:46:26 UTC (rev 4188)
@@ -23,6 +23,8 @@
     def start(self):
         eventsHandler.register(ST_NAME_FW_GADGET_NOTIFICATION,
             self.__onGadgetNotification)
+        eventsHandler.register(ST_NAME_FW_GADGET_MESSAGE,
+            self.__onGadgetMessage)
         eventsHandler.register(ST_NAME_FW_GADGET_STARTING,
             self.__onGadgetStarting)
 
@@ -39,10 +41,26 @@
         notificationType = spl[4]
         text = ""
         for line in spl[5:]:
+            if len(text) > 0:
+                text += " "
             text += line
         resourceTTS.stackPush(text, gadgetTtsLocutor, int(gadgetTtsPitch),
             gadgetUuid)
 
+    def __onGadgetMessage(self, *args):
+        spl = args[0].split(":")
+        gadgetUuid = spl[0]
+        instanceUuid = spl[1]
+        gadgetTtsLocutor = spl[2]
+        gadgetTtsPitch = spl[3]
+        text = ""
+        for line in spl[4:]:
+            if len(text) > 0:
+                text += " : "
+            text += line
+        resourceTTS.stackPush(text, gadgetTtsLocutor, int(gadgetTtsPitch),
+            gadgetUuid)
+
     def __onGadgetStarting(self, *args):
         spl = args[0].split(":")
         gadgetUuid = spl[0]


------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to