Author: remi
Date: 2009-03-14 18:20:55 +0100 (Sat, 14 Mar 2009)
New Revision: 4077

Modified:
   
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/01_robot_system/resourceGadgetFramework.py
   
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/02_robot_api/resourceTTS.py
   
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/03_advanced_api/resourceTestGadgetMessage.py
Log:
* gadget stop event is now correctly reported.

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-14 15:28:56 UTC (rev 4076)
+++ 
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/01_robot_system/resourceGadgetFramework.py
 2009-03-14 17:20:55 UTC (rev 4077)
@@ -153,12 +153,12 @@
             notificationType, messageStr])
 
     def __onGadgetStarting(self, gadgetUuid, instanceUuid):
-        self.__publishEvents(True, ST_NAME_FW_GADGET_STARTING,
-            [gadgetUuid, instanceUuid])
+        self.__publishEvents(True, ST_NAME_FW_GADGET_STARTING, [gadgetUuid,
+            instanceUuid])
 
     def __onGagdetStopped(self, gadgetUuid, instanceUuid):
-        self.__publishEvents(True, ST_NAME_FW_GADGET_STOPPED,
-            [gadgetUuid, instanceUuid])
+        self.__publishEvents(False, ST_NAME_FW_GADGET_STOPPED, [gadgetUuid,
+            instanceUuid])
 
     def getFramework(self):
         """Get the gadget framework.

Modified: 
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/02_robot_api/resourceTTS.py
===================================================================
--- 
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/02_robot_api/resourceTTS.py
        2009-03-14 15:28:56 UTC (rev 4076)
+++ 
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/02_robot_api/resourceTTS.py
        2009-03-14 17:20:55 UTC (rev 4077)
@@ -98,8 +98,8 @@
         self.__setStackStarted(True)
         while self.__getStackStarted():
             text, locutor, pitch, uuid = self.__popStack()
-            self.__setCurrentUuid(uuid)
             if text != None:
+                self.__setCurrentUuid(uuid)
                 resourceTuxOSL.ttsSpeak(text, locutor, pitch)
                 if not eventsHandler.waitCondition(ST_NAME_TTS_SOUND_STATE,
                     ("ON", None), 3.0):
@@ -135,6 +135,12 @@
     # Public methods
     # 
--------------------------------------------------------------------------
 
+    def stackIsFilled(self, uuid):
+        """Get if the stack contains texts from this uuid or not.
+        @return: A boolean.
+        """
+        return self.__checkForUuidFound(uuid)
+
     def stackFlush(self):
         """Flush the TTS stack. (clear the pending speech)
         """
@@ -218,8 +224,7 @@
         if len(text) == 0:
             return
         def async():
-            if not self.__checkForUuidFound(uuid):
-                eventsHandler.emit(ST_NAME_TTS_STACK_FILLING, (uuid, 0.0))
+            newFilling = not self.__checkForUuidFound(uuid)
             self.__stackMutex.acquire()
             if uuid != "0":
                 indexToInsert = len(self.__stack)
@@ -228,6 +233,8 @@
                         indexToInsert = i
                         break
                 self.__stack.insert(indexToInsert,(text, locutor, pitch, uuid))
+                if newFilling:
+                    eventsHandler.emit(ST_NAME_TTS_STACK_FILLING, (uuid, 0.0))
                 self.__stackMutex.release()
                 if self.__getCurrentUuid() != uuid:
                     resourceTuxOSL.ttsStop()

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-14 15:28:56 UTC (rev 4076)
+++ 
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/03_advanced_api/resourceTestGadgetMessage.py
       2009-03-14 17:20:55 UTC (rev 4077)
@@ -23,6 +23,8 @@
     def start(self):
         eventsHandler.register(ST_NAME_FW_GADGET_NOTIFICATION,
             self.__onGadgetNotification)
+        eventsHandler.register(ST_NAME_FW_GADGET_STARTING,
+            self.__onGadgetStarting)
 
     # 
--------------------------------------------------------------------------
     # Private methods
@@ -39,6 +41,43 @@
         resourceTTS.stackPush(text, gadgetTtsLocutor, int(gadgetTtsPitch),
             gadgetUuid)
 
+    def __onGadgetStarting(self, *args):
+        spl = args[0].split(":")
+        gadgetUuid = spl[0]
+        def async():
+            if not resourceTTS.stackIsFilled(gadgetUuid):
+                time.sleep(0.5)
+                if not resourceTTS.stackIsFilled(gadgetUuid):
+                    if not 
eventsHandler.waitCondition(ST_NAME_TTS_STACK_FILLING,
+                        (gadgetUuid, None), 10.0):
+                        self.__publishEvents(True, ST_NAME_FW_GADGET_STOPPED,
+                            [gadgetUuid,])
+                        return
+            eventsHandler.waitCondition(ST_NAME_TTS_STACK_EMPTY, (gadgetUuid,
+                None), 600.0)
+            self.__publishEvents(True, ST_NAME_FW_GADGET_STOPPED, 
[gadgetUuid,])
+        t = threading.Thread(target = async)
+        t.start()
+
+    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()
+
 # Create an instance of the resource
 resourceTestGadgetMessage = 
TDSResourceTestGadgetMessage("resourceTestGadgetMessage")
 # Register the resource into the resources manager


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