Author: remi
Date: 2009-03-14 14:42:35 +0100 (Sat, 14 Mar 2009)
New Revision: 4071

Modified:
   
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:
* added event on stack filling for each object pusher (by uuid)
* added event on stack empty for each object pusher (by uuid)
* added a function to remove texts from the stack from a specific uuid.
  - A gadget which push a text in the TTS stack indicates its uuid. With this 
uuid 2 events are created in
    order to know when all pushed texts by a gadget are finished or aborted.
  - These changes are need to control the "real stopping time" of a gadget and 
to abort a gadget if requested.

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-13 21:09:40 UTC (rev 4070)
+++ 
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/02_robot_api/resourceTTS.py
        2009-03-14 13:42:35 UTC (rev 4071)
@@ -7,10 +7,12 @@
 
 # TTS Stack events/statuses
 ST_NAME_TTS_STACK_EMPTY = "tts_stack_empty"
+ST_NAME_TTS_STACK_FILLING = "tts_stack_filling"
 
 # TTS Stack events/statuses list
 SW_NAME_TTS_STACK = [
     ST_NAME_TTS_STACK_EMPTY,
+    ST_NAME_TTS_STACK_FILLING,
 ]
 
 # 
------------------------------------------------------------------------------
@@ -31,6 +33,8 @@
         self.__stackMutex = threading.Lock()
         self.__stackSFlag = False
         self.__stackThread = None
+        self.__currentUuid = None
+        self.__currentUuidMutex = threading.Lock()
         # Registering the TTS stack statuses only for server internal uses.
         for statusName in SW_NAME_TTS_STACK:
             eventsHandler.insert(statusName)
@@ -62,15 +66,27 @@
         self.__stackMutex.release()
         return value
 
+    def __setCurrentUuid(self, uuid):
+        self.__currentUuidMutex.acquire()
+        self.__currentUuid = uuid
+        self.__currentUuidMutex.release()
+
+    def __getCurrentUuid(self):
+        self.__currentUuidMutex.acquire()
+        uuid = self.__currentUuid
+        self.__currentUuidMutex.release()
+        return uuid
+
     def __popStack(self):
         text = None
         locutor = None
         pitch = None
+        uuid = None
         self.__stackMutex.acquire()
         if len(self.__stack) != 0:
-            text, locutor, pitch = self.__stack.pop(0)
+            text, locutor, pitch, uuid = self.__stack.pop(0)
         self.__stackMutex.release()
-        return text, locutor, pitch
+        return text, locutor, pitch, uuid
 
     def __stackSize(self):
         self.__stackMutex.acquire()
@@ -81,19 +97,42 @@
     def __popStackLoop(self):
         self.__setStackStarted(True)
         while self.__getStackStarted():
-            text, locutor, pitch = self.__popStack()
+            text, locutor, pitch, uuid = self.__popStack()
+            self.__setCurrentUuid(uuid)
             if text != None:
                 resourceTuxOSL.ttsSpeak(text, locutor, pitch)
-                time.sleep(0.1)
                 if not eventsHandler.waitCondition(ST_NAME_TTS_SOUND_STATE,
                     ("ON", None), 3.0):
+                    lastUuid = self.__getCurrentUuid()
+                    self.__setCurrentUuid(None)
+                    if not self.__checkForUuidFound(lastUuid):
+                        print "ST_NAME_TTS_STACK_EMPTY", lastUuid
+                        eventsHandler.emit(ST_NAME_TTS_STACK_EMPTY, (lastUuid,
+                            0.0))
                     continue
                 eventsHandler.waitCondition(ST_NAME_TTS_SOUND_STATE, ("OFF",
                     None), 600.0)
-                if not self.__stackSize():
-                    eventsHandler.emit(ST_NAME_TTS_STACK_EMPTY, ("", 0.0))
+                lastUuid = self.__getCurrentUuid()
+                self.__setCurrentUuid(None)
+                if not self.__checkForUuidFound(lastUuid):
+                    print "ST_NAME_TTS_STACK_EMPTY", lastUuid
+                    eventsHandler.emit(ST_NAME_TTS_STACK_EMPTY, (lastUuid, 
0.0))
             time.sleep(0.25)
 
+    def __checkForUuidFound(self, uuid):
+        result = False
+        self.__stackMutex.acquire()
+        for e in self.__stack:
+            if e[3] == uuid:
+                result = True
+                break
+        currentUuid = self.__getCurrentUuid()
+        if currentUuid != None:
+            if currentUuid == uuid:
+                result = True
+        self.__stackMutex.release()
+        return result
+
     # 
--------------------------------------------------------------------------
     # Public methods
     # 
--------------------------------------------------------------------------
@@ -101,23 +140,78 @@
     def stackFlush(self):
         """Flush the TTS stack. (clear the pending speech)
         """
+        uuidElementsList = []
         self.__stackMutex.acquire()
+        for e in self.__stack:
+            if e[3] not in uuidElementsList:
+                uuidElementsList.append(e[3])
+        currentUuid = self.__getCurrentUuid()
+        if currentUuid != None:
+            if currentUuid not in uuidElementsList:
+                uuidElementsList.append(currentUuid)
         self.__stack = []
         self.__stackMutex.release()
-        eventsHandler.emit(ST_NAME_TTS_STACK_EMPTY, ("", 0.0))
+        if len(uuidElementsList) > 0:
+            resourceTuxOSL.ttsStop()
+            eventsHandler.emit(ST_NAME_TTS_SOUND_STATE, ("OFF", 0.0))
+            for uuid in uuidElementsList:
+                print "ST_NAME_TTS_STACK_EMPTY", uuid
+                eventsHandler.emit(ST_NAME_TTS_STACK_EMPTY, (uuid, 0.0))
 
-    def stackPush(self, text, locutor, pitch):
+    def stackRemoveByUuid(self, uuid):
+        """Remove elements from the TTS stack.
+        @param uuid: Uuid of the texts to remove.
+        """
+        haveUuidElement = False
+        self.__stackMutex.acquire()
+        newStack = []
+        for e in self.__stack:
+            if e[3] != uuid:
+                newStack.append(e)
+            else:
+                haveUuidElement = True
+        self.__stack = newStack
+        if self.__currentUuid != None:
+            if self.__currentUuid == uuid:
+                haveUuidElement = True
+        self.__stackMutex.release()
+        if haveUuidElement:
+            currentUuid = self.__getCurrentUuid()
+            if currentUuid != None:
+                if currentUuid == uuid:
+                    resourceTuxOSL.ttsStop()
+                    eventsHandler.emit(ST_NAME_TTS_SOUND_STATE, ("OFF", 0.0))
+            print "ST_NAME_TTS_STACK_EMPTY", uuid
+            eventsHandler.emit(ST_NAME_TTS_STACK_EMPTY, (uuid, 0.0))
+
+    def stackPush(self, text, locutor, pitch, uuid = "0"):
         """Push a speech in the stack.
         @param text: Text to speak.
         @param locutor: Locutor/voice.
         @param pitch: Pitch of the voice. <50..250>
+        @param uuid: Uuid of the element which has pushed a text.
+            Default "0"
         """
         if len(text) == 0:
             return
         def async():
+            if not self.__checkForUuidFound(uuid):
+                print "ST_NAME_TTS_STACK_FILLING", uuid
+                eventsHandler.emit(ST_NAME_TTS_STACK_FILLING, (uuid, 0.0))
             self.__stackMutex.acquire()
-            self.__stack.append((text, locutor, pitch))
-            self.__stackMutex.release()
+            if uuid != "0":
+                indexToInsert = len(self.__stack)
+                for i, e in enumerate(self.__stack):
+                    if e[3] != uuid:
+                        indexToInsert = i
+                        break
+                self.__stack.insert(indexToInsert,(text, locutor, pitch, uuid))
+                self.__stackMutex.release()
+                if self.__getCurrentUuid() != uuid:
+                    resourceTuxOSL.ttsStop()
+            else:
+                self.__stack.append((text, locutor, pitch, uuid))
+                self.__stackMutex.release()
         t = threading.Thread(target = async)
         t.start()
 

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-13 21:09:40 UTC (rev 4070)
+++ 
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/03_advanced_api/resourceTestGadgetMessage.py
       2009-03-14 13:42:35 UTC (rev 4071)
@@ -36,7 +36,8 @@
         gadgetTtsPitch = spl[3]
         notificationType = spl[4]
         text = spl[5]
-        resourceTTS.stackPush(text, gadgetTtsLocutor, int(gadgetTtsPitch))
+        resourceTTS.stackPush(text, gadgetTtsLocutor, int(gadgetTtsPitch),
+            gadgetUuid)
 
 # Create an instance of the resource
 resourceTestGadgetMessage = 
TDSResourceTestGadgetMessage("resourceTestGadgetMessage")


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