[tuxdroid-svn] r4812 - software_suite_v3/smart-core/smart-server/trunk/resources/04_robot_content_i
Status: Beta
Brought to you by:
ks156
|
From: remi <c2m...@c2...> - 2009-06-14 20:13:51
|
Author: remi
Date: 2009-06-14 22:13:42 +0200 (Sun, 14 Jun 2009)
New Revision: 4812
Modified:
software_suite_v3/smart-core/smart-server/trunk/resources/04_robot_content_interactions/00_resourceRobotContentInteractions.py
Log:
* improved stability of the gadget start/stop (for the chiness crash test ;) )
Modified: software_suite_v3/smart-core/smart-server/trunk/resources/04_robot_content_interactions/00_resourceRobotContentInteractions.py
===================================================================
--- software_suite_v3/smart-core/smart-server/trunk/resources/04_robot_content_interactions/00_resourceRobotContentInteractions.py 2009-06-14 20:08:01 UTC (rev 4811)
+++ software_suite_v3/smart-core/smart-server/trunk/resources/04_robot_content_interactions/00_resourceRobotContentInteractions.py 2009-06-14 20:13:42 UTC (rev 4812)
@@ -178,6 +178,9 @@
self.__startStopPauseMutex.acquire()
self.__execStarted = False
self.__execPaused = False
+ self.__eventStackMutex.acquire()
+ self.__eventStack = []
+ self.__eventStackMutex.release()
self.__startStopPauseMutex.release()
self.__breakAttitune()
self.__breakMessage()
@@ -225,7 +228,6 @@
self.__startStopPauseMutex.release()
return result
-
def __executeAttitune(self, attituneName):
"""
"""
@@ -239,19 +241,29 @@
def __executeMessage(self, text, locutor, pitch):
"""
"""
+ if not self.executionIsStarted():
+ return
resourceTuxDriver.openMouth()
+ if not self.executionIsStarted():
+ resourceTuxDriver.closeMouth()
+ return
resourceTuxOSL.ttsSpeak(text, locutor, pitch)
+ if not self.executionIsStarted():
+ resourceTuxDriver.closeMouth()
+ return
if not eventsHandler.waitCondition(ST_NAME_TTS_SOUND_STATE, ("ON",
None), 3.0):
return
- eventsHandler.waitCondition(ST_NAME_TTS_SOUND_STATE, ("OFF", None),
- 600.0)
+ if self.executionIsStarted():
+ eventsHandler.waitCondition(ST_NAME_TTS_SOUND_STATE, ("OFF", None),
+ 600.0)
resourceTuxDriver.closeMouth()
def __breakMessage(self):
"""
"""
resourceTuxOSL.ttsStop()
+ eventsHandler.emit(ST_NAME_TTS_SOUND_STATE, ("OFF", 0.0))
def __executeActuation(self, actuationName, arguments):
"""
@@ -312,6 +324,8 @@
print " ", nextEvent['type']
print " ", nextEvent['arguments']
arguments = nextEvent['arguments']
+ if not self.executionIsStarted():
+ continue
if nextEvent['type'] == PGU_EVENT_TYPE_MESSAGE:
self.__executeMessage(arguments['message'],
arguments['locutor'], arguments['pitch'])
@@ -341,6 +355,8 @@
self.__loopThread = None
self.__onDemandList = []
self.__onDemandIndex = 0
+ self.__lastRunStopActionTime = time.time()
+ self.__lastRunStopActionTimeMutex = threading.Lock()
def insertOnDemand(self, ugc):
"""
@@ -550,11 +566,12 @@
self.__backgroundPguContext = pguContext
self.__bfPguContextMutex.release()
- def getPguContext(self, pluginInterpreterContext):
+ def getPguContext(self, pluginInterpreterContext, noMutex = False):
"""
"""
result = None
- self.__pguContextsMutex.acquire()
+ if not noMutex:
+ self.__pguContextsMutex.acquire()
for pguContext in self.__pguContexts:
if pguContext.getPluginInterpreterContext() == pluginInterpreterContext:
result = pguContext
@@ -567,7 +584,8 @@
if self.getBackgroundPguContext() != None:
if self.getBackgroundPguContext().getPluginInterpreterContext() == pluginInterpreterContext:
result = self.getBackgroundPguContext()
- self.__pguContextsMutex.release()
+ if not noMutex:
+ self.__pguContextsMutex.release()
return result
# ==========================================================================
@@ -577,52 +595,90 @@
def insertMessage(self, pluginInterpreterContext, message, locutor, pitch):
"""
"""
- pguContext = self.getPguContext(pluginInterpreterContext)
+ self.__pguContextsMutex.acquire()
+ pguContext = self.getPguContext(pluginInterpreterContext, True)
if pguContext != None:
pguContext.insertMessage(message, locutor, pitch)
+ self.__pguContextsMutex.release()
def insertActuation(self, pluginInterpreterContext, actuationName,
arguments = []):
"""
"""
- pguContext = self.getPguContext(pluginInterpreterContext)
+ self.__pguContextsMutex.acquire()
+ pguContext = self.getPguContext(pluginInterpreterContext, True)
if pguContext != None:
pguContext.insertActuation(actuationName, arguments)
+ self.__pguContextsMutex.release()
def insertAttitune(self, pluginInterpreterContext, attituneName):
"""
"""
- pguContext = self.getPguContext(pluginInterpreterContext)
+ self.__pguContextsMutex.acquire()
+ pguContext = self.getPguContext(pluginInterpreterContext, True)
if pguContext != None:
pguContext.insertAttitune(attituneName)
+ self.__pguContextsMutex.release()
def setContextIsComplete(self, pluginInterpreterContext):
"""
"""
- pguContext = self.getPguContext(pluginInterpreterContext)
+ self.__pguContextsMutex.acquire()
+ pguContext = self.getPguContext(pluginInterpreterContext, True)
if pguContext != None:
pguContext.setContextIsComplete()
+ self.__pguContextsMutex.release()
# ==========================================================================
# Remote and robot button events
# ==========================================================================
+ def __setLastRunStopActionTime(self):
+ """
+ """
+ self.__lastRunStopActionTimeMutex.acquire()
+ self.__lastRunStopActionTime = time.time()
+ self.__lastRunStopActionTimeMutex.release()
+
+ def __getLastRunStopActionTime(self):
+ """
+ """
+ self.__lastRunStopActionTimeMutex.acquire()
+ result = self.__lastRunStopActionTime
+ self.__lastRunStopActionTimeMutex.release()
+ return result
+
+ def __checkLastRunStopActionTime(self):
+ """
+ """
+ print time.time() - self.__getLastRunStopActionTime()
+ if (time.time() - self.__getLastRunStopActionTime()) >= 1.5:
+ self.__setLastRunStopActionTime()
+ return True
+ else:
+ return False
+
def __contextBtRunAbort(self):
"""
"""
# Abort foreground context if exists
if self.getForegroundPguContext() != None:
if self.getForegroundPguContext().executionIsStarted():
+ if not self.__checkLastRunStopActionTime():
+ return
self.getForegroundPguContext().stopExecution()
return
# Else abort background context if exists
if self.getBackgroundPguContext() != None:
if self.getBackgroundPguContext().executionIsStarted():
+ if not self.__checkLastRunStopActionTime():
+ return
self.getBackgroundPguContext().stopExecution()
return
# Else load current selected on demand gadget
if len(self.__onDemandList) > 0:
ugc = self.__onDemandList[self.__onDemandIndex]
+ self.__setLastRunStopActionTime()
ugc.start(ugc.getDefaultRunCommandName())
def __contextLTPrevious(self, eventName, *args):
|