[tuxdroid-svn] r4828 - in software_suite_v3/smart-core/smart-server/trunk: resources/01_drivers re
Status: Beta
Brought to you by:
ks156
|
From: remi <c2m...@c2...> - 2009-06-18 14:16:38
|
Author: remi
Date: 2009-06-18 15:53:42 +0200 (Thu, 18 Jun 2009)
New Revision: 4828
Modified:
software_suite_v3/smart-core/smart-server/trunk/resources/01_drivers/01_resourceTuxOSL.py
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/05_user_configurations/00_resourceUsers.py
software_suite_v3/smart-core/smart-server/trunk/util/misc/tuxPaths.py
Log:
* added support of second language and second locutor in the user configuration.
* auto-load the voices when TuxOsl is started
* fixed file format of the resource "robot content interactions"
Modified: software_suite_v3/smart-core/smart-server/trunk/resources/01_drivers/01_resourceTuxOSL.py
===================================================================
--- software_suite_v3/smart-core/smart-server/trunk/resources/01_drivers/01_resourceTuxOSL.py 2009-06-18 08:55:41 UTC (rev 4827)
+++ software_suite_v3/smart-core/smart-server/trunk/resources/01_drivers/01_resourceTuxOSL.py 2009-06-18 13:53:42 UTC (rev 4828)
@@ -96,6 +96,17 @@
self.__tuxOSL.Start("Acapela")
time.sleep(0.5)
self.__initializeStatesInEventsHandler()
+ time.sleep(3.0)
+ # Load first voice
+ pitch = resourceUsers.getCurrentUserConfiguration()['pitch']
+ firstLocutor = resourceUsers.getCurrentUserConfiguration()['locutor1']
+ self.ttsSpeak(" ", firstLocutor, pitch)
+ time.sleep(3.0)
+ # Load second voice
+ secondLocutor = resourceUsers.getCurrentUserConfiguration()['locutor2']
+ self.ttsSpeak(" ", secondLocutor, pitch)
+ time.sleep(3.0)
+ resourceRobotContentInteractions.startMe()
if value:
t = threading.Thread(target = startTuxOsl)
t.start()
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-18 08:55:41 UTC (rev 4827)
+++ software_suite_v3/smart-core/smart-server/trunk/resources/04_robot_content_interactions/00_resourceRobotContentInteractions.py 2009-06-18 13:53:42 UTC (rev 4828)
@@ -1,892 +1,913 @@
-# 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
-
-import time
-
-PGU_CONTEXT_LAYER_USER = 0
-PGU_CONTEXT_LAYER_SCHEDULER = 1
-
-PGU_EVENT_TYPE_MESSAGE = 0
-PGU_EVENT_TYPE_ACTUATION = 1
-PGU_EVENT_TYPE_ATTITUNE = 2
-
-class PguContext(object):
- """
- """
-
- def __init__(self, pluginInterpreterContext):
- """
- """
- self.__createTime = time.time()
- self.__pluginInterpreterContext = pluginInterpreterContext
- uuid = pluginInterpreterContext.getHostUuid()
- # Get pguObject
- self.__pguObject = resourcePluginsServer.getPluginsContainer().getPluginByUuid(uuid)
- if self.__pguObject == None:
- self.__pguObject = resourceGadgetsServer.getGadgetsContainer().getGadgetByUuid(uuid)
- if self.__pguObject == None:
- self.__pguObject = resourceUgcServer.getUgcContainer().getUgcByUuid(uuid)
- # Get context layer
- self.__contextLayer = PGU_CONTEXT_LAYER_USER
- if self.__pluginInterpreterContext.getInstanceParameters().has_key("startedBy"):
- if self.__pluginInterpreterContext.getInstanceParameters()['startedBy'] == 'scheduler':
- self.__contextLayer = PGU_CONTEXT_LAYER_SCHEDULER
- self.__eventStack = []
- self.__eventStackMutex = threading.Lock()
- self.__contextComplete = False
- self.__contextCompleteMutex = threading.Lock()
- self.__startStopPauseMutex = threading.Lock()
- self.__execStarted = False
- self.__execPaused = False
-
- def getPluginInterpreterContext(self):
- """
- """
- return self.__pluginInterpreterContext
-
- def getPguUuid(self):
- """
- """
- return self.__pluginInterpreterContext.getHostUuid()
-
- def getPguName(self):
- """
- """
- return self.__pguObject.getDescription().getName()
-
- def getContextLayer(self):
- """
- """
- return self.__contextLayer
-
- def getPguObject(self):
- """
- """
- return self.__pguObject
-
- def isDaemon(self):
- """
- """
- return self.__pluginInterpreterContext.instanceIsDaemon()
-
- def getPluginCommand(self):
- """
- """
- return self.__pguObject.getCommand(
- self.__pluginInterpreterContext.getInstanceCommandName())
-
- def setContextIsComplete(self):
- """
- """
- if not self.contextIsComplete():
- print "PGU Context [%s] content is complete" % self.getPguName()
- self.__contextCompleteMutex.acquire()
- self.__contextComplete = True
- self.__contextCompleteMutex.release()
-
- def contextIsComplete(self):
- """
- """
- self.__contextCompleteMutex.acquire()
- result = self.__contextComplete
- self.__contextCompleteMutex.release()
- return result
-
- def __insertEvent(self, eventType, arguments = {}):
- """
- """
- if self.contextIsComplete():
- return
- self.__eventStackMutex.acquire()
- self.__eventStack.append({
- 'type' : eventType,
- 'arguments' : arguments,
- })
- self.__eventStackMutex.release()
- print "Inserted event in PGU context [%s] :" % self.getPguName()
- print " ", eventType
- print " ", arguments
-
- def __getEvent(self):
- """
- """
- self.__eventStackMutex.acquire()
- result = None
- if len(self.__eventStack) > 0:
- result = self.__eventStack.pop(0)
- self.__eventStackMutex.release()
- return result
-
- def insertMessage(self, message, locutor, pitch):
- """
- """
- self.__insertEvent(PGU_EVENT_TYPE_MESSAGE, {
- 'message' : message,
- 'locutor' : locutor,
- 'pitch' : pitch,
- })
-
- def insertActuation(self, actuationName, arguments = []):
- """
- """
- # Little hack for plugins audio menu
- if actuationName == "abortTts":
- self.__breakMessage()
- return
- self.__insertEvent(PGU_EVENT_TYPE_ACTUATION, {
- 'actuationName' : actuationName,
- 'actuationArguments' : arguments,
- })
-
- def insertAttitune(self, attituneName):
- """
- """
- self.__insertEvent(PGU_EVENT_TYPE_ATTITUNE, {
- 'attituneName' : attituneName,
- })
-
- def startExecution(self):
- """
- """
- if self.executionIsStarted():
- return
- expirationDelay = self.getPluginCommand().getExpirationDelay()
- if expirationDelay > 0:
- if (time.time() - self.__createTime) > expirationDelay:
- return
- self.__startStopPauseMutex.acquire()
- self.__execStarted = True
- self.__execPaused = False
- self.__startStopPauseMutex.release()
- print "Start execution of PGU context [%s]" % self.getPguName()
- self.__executionLoop()
-
- def executionIsStarted(self):
- """
- """
- self.__startStopPauseMutex.acquire()
- result = self.__execStarted
- self.__startStopPauseMutex.release()
- return result
-
- def stopExecution(self):
- """
- """
- if not self.getPluginCommand().isNotifier():
- self.__pluginInterpreterContext.abort()
- if not self.executionIsStarted():
- return
- print "Stop execution of PGU context [%s]" % self.getPguName()
- self.__startStopPauseMutex.acquire()
- self.__execStarted = False
- self.__execPaused = False
- self.__eventStackMutex.acquire()
- self.__eventStack = []
- self.__eventStackMutex.release()
- self.__startStopPauseMutex.release()
- self.__breakAttitune()
- self.__breakMessage()
- self.__breakActuation()
- print "Execution of PGU context [%s] stopped" % self.getPguName()
- if not self.getPluginCommand().isNotifier():
- if self.getContextLayer() == PGU_CONTEXT_LAYER_SCHEDULER:
- resourceTuxDriver.playSound(15, 100.0)
- else:
- resourceTuxDriver.playSound(16, 100.0)
- time.sleep(0.5)
-
- def pauseExecution(self):
- """
- """
- if not self.executionIsStarted():
- return
- if self.executionIsPaused():
- return
- print "Pause execution of PGU context [%s]" % self.getPguName()
- self.__startStopPauseMutex.acquire()
- self.__execPaused = True
- self.__startStopPauseMutex.release()
- self.__breakAttitune()
- self.__breakMessage()
- self.__breakActuation()
-
- def unpauseExecution(self):
- """
- """
- if not self.executionIsStarted():
- return
- if not self.executionIsPaused():
- return
- print "Unpause execution of PGU context [%s]" % self.getPguName()
- self.__startStopPauseMutex.acquire()
- self.__execPaused = False
- self.__startStopPauseMutex.release()
-
- def executionIsPaused(self):
- """
- """
- self.__startStopPauseMutex.acquire()
- result = self.__execPaused
- self.__startStopPauseMutex.release()
- return result
-
- def __executeAttitune(self, attituneName):
- """
- """
- resourceAttituneManager.playAttituneSync(attituneName, 0.0)
-
- def __breakAttitune(self):
- """
- """
- resourceAttituneManager.stopAttitune()
-
- 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
- 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):
- """
- """
- argsString = ""
- for argument in arguments:
- if len(argsString) > 0:
- argsString += ","
- try:
- argument = int(argument)
- argsString += str(argument)
- except:
- try:
- argument = float(argument)
- argsString += str(argument)
- except:
- argsString += '"' + str(argument) + '"'
- cmdString = "resourceTuxDriver.%s(%s)" % (actuationName, argsString)
- try:
- exec(cmdString) in globals()
- except:
- print "!!! Error in command :", cmdString
-
- def __breakActuation(self):
- """
- """
- resourceTuxDriver.clearAll()
-
- def __executionLoop(self):
- """
- """
- if not self.getPluginCommand().isNotifier():
- if self.getContextLayer() == PGU_CONTEXT_LAYER_SCHEDULER:
- resourceTuxDriver.playSound(14, 100.0)
- else:
- resourceTuxDriver.playSound(13, 100.0)
- time.sleep(0.5)
- while self.executionIsStarted():
- while self.executionIsPaused():
- time.sleep(0.1)
- nextEvent = self.__getEvent()
- if nextEvent == None:
- if self.contextIsComplete():
- self.__startStopPauseMutex.acquire()
- self.__execStarted = False
- self.__execPaused = False
- self.__startStopPauseMutex.release()
- print "Execution of PGU context [%s] stopped" % self.getPguName()
- if not self.getPluginCommand().isNotifier():
- if self.getContextLayer() == PGU_CONTEXT_LAYER_SCHEDULER:
- resourceTuxDriver.playSound(15, 100.0)
- else:
- resourceTuxDriver.playSound(16, 100.0)
- time.sleep(0.5)
- return
- else:
- print "Execute event from PGU context [%s] :" % self.getPguName()
- 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'])
- elif nextEvent['type'] == PGU_EVENT_TYPE_ACTUATION:
- self.__executeActuation(arguments['actuationName'],
- arguments['actuationArguments'])
- elif nextEvent['type'] == PGU_EVENT_TYPE_ATTITUNE:
- self.__executeAttitune(arguments['attituneName'])
- print "Event finished"
- time.sleep(0.1)
-
-class PguContextsManager(object):
- """
- """
-
- def __init__(self):
- """
- """
- self.__pguContexts = []
- self.__pguContextsMutex = threading.Lock()
- self.__backgroundPguContext = None
- self.__foregroundPguContext = None
- self.__backgroundPguThread = None
- self.__bfPguContextMutex = threading.Lock()
- self.__isStarted = False
- self.__startedMutex = threading.Lock()
- self.__loopThread = None
- self.__onDemandList = []
- self.__onDemandIndex = 0
- self.__lastRunStopActionTime = time.time()
- self.__lastRunStopActionTimeMutex = threading.Lock()
-
- def insertOnDemand(self, ugc):
- """
- """
- self.__onDemandList.append(ugc)
-
- def removeOnDemand(self, ugc):
- """
- """
- for odUgc in self.__onDemandList:
- if odUgc == ugc:
- self.__onDemandList.remove(ugc)
- return
-
- def __speakOnDemand(self):
- """
- """
- if len(self.__onDemandList) > 0:
- resourceTuxOSL.ttsStop()
- ugc = self.__onDemandList[self.__onDemandIndex]
- ugcTtsName = ugc.getDescription().getName()
- locutor = resourcePluginsServer.getPluginsContainer().getLocutor()
- pitch = resourcePluginsServer.getPluginsContainer().getPitch()
- resourceTuxDriver.openMouth()
- resourceTuxOSL.ttsSpeak(ugcTtsName, locutor, pitch)
- 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)
- resourceTuxDriver.closeMouth()
-
- def __onDemandNext(self):
- """
- """
- self.__onDemandIndex += 1
- if self.__onDemandIndex >= len(self.__onDemandList):
- self.__onDemandIndex = 0
- resourceTuxDriver.playSound(11, 100.0)
- self.__speakOnDemand()
-
- def __onDemandPrevious(self):
- """
- """
- self.__onDemandIndex -= 1
- if self.__onDemandIndex < 0:
- self.__onDemandIndex = len(self.__onDemandList) - 1
- resourceTuxDriver.playSound(11, 100.0)
- self.__speakOnDemand()
-
- def __setStarted(self, value):
- """
- """
- self.__startedMutex.acquire()
- self.__isStarted = value
- self.__startedMutex.release()
-
- def isStarted(self):
- """
- """
- self.__startedMutex.acquire()
- result = self.__isStarted
- self.__startedMutex.release()
- return result
-
- def start(self):
- """
- """
- self.__loopThread = threading.Thread(target = self.__executionLoop)
- self.__loopThread.start()
-
- def stop(self):
- """
- """
- self.__setStarted(False)
- if self.getForegroundPguContext() != None:
- self.getForegroundPguContext().stopExecution()
- if self.__loopThread != None:
- if self.__loopThread.isAlive():
- self.__loopThread.join()
-
- def mute(self):
- """
- """
- pass
-
- def unmute(self):
- """
- """
- pass
-
- def __executionLoop(self):
- """
- """
- self.__setStarted(True)
- while self.isStarted():
- if self.backgroundPguContextIsCritical():
- time.sleep(0.5)
- continue
- # Get the next pguContext which must be in foreground
- pguContext = None
- self.__pguContextsMutex.acquire()
- if len(self.__pguContexts) > 0:
- pguContext = self.__pguContexts.pop(0)
- if pguContext != None:
- self.__setForegroundPguContext(pguContext)
- self.__pguContextsMutex.release()
- if self.getBackgroundPguContext() != None:
- # If the context is exclusive then stop the background context
- if self.getForegroundPguContext().getPluginCommand().isExclusive():
- self.getBackgroundPguContext().stopExecution()
- # Else only pause-it
- else:
- self.getBackgroundPguContext().pauseExecution()
- self.getForegroundPguContext().startExecution()
- if self.getBackgroundPguContext() != None:
- # Unpause background context
- if not self.getForegroundPguContext().getPluginCommand().isExclusive():
- self.getBackgroundPguContext().unpauseExecution()
- self.__setForegroundPguContext(None)
- else:
- self.__pguContextsMutex.release()
- time.sleep(0.5)
-
- def createPguContext(self, pluginInterpreterContext):
- """
- """
- if not self.isStarted():
- return
- # Create new pguContext
- pguContext = PguContext(pluginInterpreterContext)
- # Add the new pguContext in the system
- self.__insertPguContext(pguContext)
-
- def __startBackgroundPguContext(self):
- """
- """
- self.getBackgroundPguContext().startExecution()
-
- def __insertPguContext(self, pguContext):
- """
- """
- # Alerts and no daemon user calls must be inserted in the stack
- # as foreground.
- if (pguContext.getContextLayer() == PGU_CONTEXT_LAYER_SCHEDULER) or\
- (not pguContext.isDaemon()):
- self.__pguContextsMutex.acquire()
- for i, regPguContext in enumerate(self.__pguContexts):
- if regPguContext.getPluginCommand() == pguContext.getPluginCommand():
- # Replace the context with the same plugin command.
- self.__pguContexts[i] = pguContext
- self.__pguContextsMutex.release()
- return
- # If the context command is critical and the context is run by the
- # scheduler then stop the current context and add the context on top
- # of the stack
- if (pguContext.getPluginCommand().isCritical()) and \
- (pguContext.getContextLayer() == PGU_CONTEXT_LAYER_SCHEDULER):
- self.__pguContexts.insert(0, pguContext)
- if self.getForegroundPguContext() != None:
- self.getForegroundPguContext().stopExecution()
- # Add the new context at the bottom of the stack.
- else:
- self.__pguContexts.append(pguContext)
- self.__pguContextsMutex.release()
- # Daemon user calls must be referenced as background.
- else:
- currentBackgroundPguContext = self.getBackgroundPguContext()
- if currentBackgroundPguContext != None:
- # Stop old background context if exists
- currentBackgroundPguContext.stopExecution()
- if self.__backgroundPguThread != None:
- if self.__backgroundPguThread.isAlive():
- self.__backgroundPguThread.join()
- self.__setBackgroundPguContext(pguContext)
- self.__backgroundPguThread = threading.Thread(target = self.__startBackgroundPguContext)
- self.__backgroundPguThread.start()
-
- def getForegroundPguContext(self):
- """
- """
- self.__bfPguContextMutex.acquire()
- result = self.__foregroundPguContext
- self.__bfPguContextMutex.release()
- return result
-
- def getBackgroundPguContext(self):
- """
- """
- self.__bfPguContextMutex.acquire()
- result = self.__backgroundPguContext
- self.__bfPguContextMutex.release()
- return result
-
- def backgroundPguContextIsCritical(self):
- """
- """
- self.__bfPguContextMutex.acquire()
- result = False
- if self.__backgroundPguContext != None:
- if self.__backgroundPguContext.executionIsStarted():
- if self.__backgroundPguContext.getPluginCommand().isCritical():
- result = True
- self.__bfPguContextMutex.release()
- return result
-
- def backgroundPguContextNeedAllUserButtons(self):
- """
- """
- self.__bfPguContextMutex.acquire()
- result = False
- if self.__backgroundPguContext != None:
- if self.__backgroundPguContext.executionIsStarted():
- if self.__backgroundPguContext.getPluginCommand().needAllUserButtons():
- result = True
- self.__bfPguContextMutex.release()
- return result
-
- def __setForegroundPguContext(self, pguContext):
- """
- """
- self.__bfPguContextMutex.acquire()
- self.__foregroundPguContext = pguContext
- self.__bfPguContextMutex.release()
-
- def __setBackgroundPguContext(self, pguContext):
- """
- """
- self.__bfPguContextMutex.acquire()
- self.__backgroundPguContext = pguContext
- self.__bfPguContextMutex.release()
-
- def getPguContext(self, pluginInterpreterContext, noMutex = False):
- """
- """
- result = None
- if not noMutex:
- self.__pguContextsMutex.acquire()
- for pguContext in self.__pguContexts:
- if pguContext.getPluginInterpreterContext() == pluginInterpreterContext:
- result = pguContext
- break
- if result == None:
- if self.getForegroundPguContext() != None:
- if self.getForegroundPguContext().getPluginInterpreterContext() == pluginInterpreterContext:
- result = self.getForegroundPguContext()
- if result == None:
- if self.getBackgroundPguContext() != None:
- if self.getBackgroundPguContext().getPluginInterpreterContext() == pluginInterpreterContext:
- result = self.getBackgroundPguContext()
- if not noMutex:
- self.__pguContextsMutex.release()
- return result
-
- # ==========================================================================
- # Events from plugins execution.
- # ==========================================================================
-
- def insertMessage(self, pluginInterpreterContext, message, locutor, pitch):
- """
- """
- 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 = []):
- """
- """
- self.__pguContextsMutex.acquire()
- pguContext = self.getPguContext(pluginInterpreterContext, True)
- if pguContext != None:
- pguContext.insertActuation(actuationName, arguments)
- self.__pguContextsMutex.release()
-
- def insertAttitune(self, pluginInterpreterContext, attituneName):
- """
- """
- self.__pguContextsMutex.acquire()
- pguContext = self.getPguContext(pluginInterpreterContext, True)
- if pguContext != None:
- pguContext.insertAttitune(attituneName)
- self.__pguContextsMutex.release()
-
- def setContextIsComplete(self, 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):
- """
- """
- if (time.time() - self.__getLastRunStopActionTime()) >= 1.5:
- self.__setLastRunStopActionTime()
- return True
- else:
- return False
-
- def __contextBtRunAbort(self, eventName, *args):
- """
- """
- # 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():
- # Exception for plugins commands with attribute "allUserButtons"
- if self.backgroundPguContextNeedAllUserButtons():
- self.__contextBtOther(eventName, *args)
- return
- 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):
- """
- """
- if self.getForegroundPguContext() != None:
- return
- if self.getBackgroundPguContext() != None:
- if self.getBackgroundPguContext().executionIsStarted():
- self.__contextBtOther(eventName, *args)
- return
- self.__onDemandPrevious()
-
- def __contextRBNext(self, eventName, *args):
- """
- """
- if self.getForegroundPguContext() != None:
- return
- if self.getBackgroundPguContext() != None:
- if self.getBackgroundPguContext().executionIsStarted():
- self.__contextBtOther(eventName, *args)
- return
- self.__onDemandNext()
-
- def __contextBtMute(self, eventName, *args):
- """
- """
- if self.isStarted():
- self.stop()
- resourceTuxDriver.playSound(12, 100.0)
- self.__contextBtStandby("remote", ("K_STANDBY", 0.0))
- else:
- resourceTuxDriver.playSound(12, 100.0)
- self.start()
-
- def __contextBtStandby(self, eventName, *args):
- """
- """
- # Flush the foreground stack
- self.__pguContextsMutex.acquire()
- self.__pguContexts = []
- self.__pguContextsMutex.release()
- # Stop current foreground context
- if self.getForegroundPguContext() != None:
- self.getForegroundPguContext().stopExecution()
- # Stop current background context
- if self.getBackgroundPguContext() != None:
- self.getBackgroundPguContext().stopExecution()
-
- def __contextBtOther(self, eventName, *args):
- """
- """
- if self.getForegroundPguContext() == None:
- bgPguContext = self.getBackgroundPguContext()
- if bgPguContext != None:
- bgPguContext.getPluginInterpreterContext().sendEvent(eventName,
- args)
-
- def sendEvent(self, eventName, *args):
- """
- """
- if not self.isStarted():
- if eventName == "remote":
- if args[0] == "K_MUTE":
- self.__contextBtMute(eventName, *args)
- else:
- if eventName == "head":
- if args[0] == True:
- self.__contextBtRunAbort(eventName, *args)
- elif eventName == "left":
- if args[0] == True:
- self.__contextRBNext(eventName, *args)
- elif eventName == "right":
- if args[0] == True:
- self.__contextLTPrevious(eventName, *args)
- elif eventName == "remote":
- if args[0] == "K_OK":
- self.__contextBtRunAbort(eventName, *args)
- elif args[0] == "K_LEFT":
- self.__contextLTPrevious(eventName, *args)
- elif args[0] == "K_UP":
- self.__contextLTPrevious(eventName, *args)
- elif args[0] == "K_RIGHT":
- self.__contextRBNext(eventName, *args)
- elif args[0] == "K_DOWN":
- self.__contextRBNext(eventName, *args)
- elif args[0] == "K_MUTE":
- self.__contextBtMute(eventName, *args)
- elif args[0] == "K_STANDBY":
- self.__contextBtStandby(eventName, *args)
- else:
- self.__contextBtOther(eventName, *args)
-
-# ==============================================================================
-# ******************************************************************************
-# RESOURCE DECLARATION
-# ******************************************************************************
-# ==============================================================================
-
-# ==============================================================================
-# Declaration of the resource "robot_content_interactions".
-# ==============================================================================
-class TDSResourceRobotContentInteractions(TDSResource):
- """Resource robot_content_interactions class.
- """
-
- # ==========================================================================
- # Inherited methods from TDSResource
- # ==========================================================================
-
- # --------------------------------------------------------------------------
- # Configure the resource.
- # --------------------------------------------------------------------------
- def configure(self):
- """Configure the resource.
- """
- # General configuration (inherited from ancestor)
- self.name = "robot_content_interactions"
- self.comment = "Resource to handling the robot/content interactions."
- self.fileName = RESOURCE_FILENAME
- self.__pguContextsManager = PguContextsManager()
- # Register callback on RC and robot buttons events
- eventsHandler.getEventHandler(ST_NAME_HEAD_BUTTON).register(
- self.__onHeadBtEvent)
- eventsHandler.getEventHandler(ST_NAME_LEFT_BUTTON).register(
- self.__onLeftBtEvent)
- eventsHandler.getEventHandler(ST_NAME_RIGHT_BUTTON).register(
- self.__onRightBtEvent)
- eventsHandler.getEventHandler(ST_NAME_REMOTE_BUTTON).register(
- self.__onRCBtEvent)
-
- # --------------------------------------------------------------------------
- # Start the resource.
- # --------------------------------------------------------------------------
- def start(self):
- """Start the resource.
- """
- self.__pguContextsManager.start()
-
- # --------------------------------------------------------------------------
- # Stop the resource.
- # --------------------------------------------------------------------------
- def stop(self):
- """Stop the resource.
- """
- self.__pguContextsManager.stop()
-
- def __onHeadBtEvent(self, *args):
- """
- """
- self.__pguContextsManager.sendEvent("head", *args)
-
- def __onLeftBtEvent(self, *args):
- """
- """
- self.__pguContextsManager.sendEvent("left", *args)
-
- def __onRightBtEvent(self, *args):
- """
- """
- self.__pguContextsManager.sendEvent("right", *args)
-
- def __onRCBtEvent(self, *args):
- """
- """
- self.__pguContextsManager.sendEvent("remote", *args)
-
- # ==========================================================================
- # Public methods
- # ==========================================================================
-
- def getPguContextsManager(self):
- """
- """
- return self.__pguContextsManager
-
-# Create an instance of the resource
-resourceRobotContentInteractions = TDSResourceRobotContentInteractions(
- "resourceRobotContentInteractions")
-# Register the resource into the resources manager
-resourcesManager.addResource(resourceRobotContentInteractions)
+# 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
+
+import time
+
+PGU_CONTEXT_LAYER_USER = 0
+PGU_CONTEXT_LAYER_SCHEDULER = 1
+
+PGU_EVENT_TYPE_MESSAGE = 0
+PGU_EVENT_TYPE_ACTUATION = 1
+PGU_EVENT_TYPE_ATTITUNE = 2
+
+class PguContext(object):
+ """
+ """
+
+ def __init__(self, pluginInterpreterContext):
+ """
+ """
+ self.__createTime = time.time()
+ self.__pluginInterpreterContext = pluginInterpreterContext
+ uuid = pluginInterpreterContext.getHostUuid()
+ # Get pguObject
+ self.__pguObject = resourcePluginsServer.getPluginsContainer().getPluginByUuid(uuid)
+ if self.__pguObject == None:
+ self.__pguObject = resourceGadgetsServer.getGadgetsContainer().getGadgetByUuid(uuid)
+ if self.__pguObject == None:
+ self.__pguObject = resourceUgcServer.getUgcContainer().getUgcByUuid(uuid)
+ # Get context layer
+ self.__contextLayer = PGU_CONTEXT_LAYER_USER
+ if self.__pluginInterpreterContext.getInstanceParameters().has_key("startedBy"):
+ if self.__pluginInterpreterContext.getInstanceParameters()['startedBy'] == 'scheduler':
+ self.__contextLayer = PGU_CONTEXT_LAYER_SCHEDULER
+ self.__eventStack = []
+ self.__eventStackMutex = threading.Lock()
+ self.__contextComplete = False
+ self.__contextCompleteMutex = threading.Lock()
+ self.__startStopPauseMutex = threading.Lock()
+ self.__execStarted = False
+ self.__execPaused = False
+
+ def getPluginInterpreterContext(self):
+ """
+ """
+ return self.__pluginInterpreterContext
+
+ def getPguUuid(self):
+ """
+ """
+ return self.__pluginInterpreterContext.getHostUuid()
+
+ def getPguName(self):
+ """
+ """
+ return self.__pguObject.getDescription().getName()
+
+ def getContextLayer(self):
+ """
+ """
+ return self.__contextLayer
+
+ def getPguObject(self):
+ """
+ """
+ return self.__pguObject
+
+ def isDaemon(self):
+ """
+ """
+ return self.__pluginInterpreterContext.instanceIsDaemon()
+
+ def getPluginCommand(self):
+ """
+ """
+ return self.__pguObject.getCommand(
+ self.__pluginInterpreterContext.getInstanceCommandName())
+
+ def setContextIsComplete(self):
+ """
+ """
+ if not self.contextIsComplete():
+ print "PGU Context [%s] content is complete" % self.getPguName()
+ self.__contextCompleteMutex.acquire()
+ self.__contextComplete = True
+ self.__contextCompleteMutex.release()
+
+ def contextIsComplete(self):
+ """
+ """
+ self.__contextCompleteMutex.acquire()
+ result = self.__contextComplete
+ self.__contextCompleteMutex.release()
+ return result
+
+ def __insertEvent(self, eventType, arguments = {}):
+ """
+ """
+ if self.contextIsComplete():
+ return
+ self.__eventStackMutex.acquire()
+ self.__eventStack.append({
+ 'type' : eventType,
+ 'arguments' : arguments,
+ })
+ self.__eventStackMutex.release()
+ print "Inserted event in PGU context [%s] :" % self.getPguName()
+ print " ", eventType
+ print " ", arguments
+
+ def __getEvent(self):
+ """
+ """
+ self.__eventStackMutex.acquire()
+ result = None
+ if len(self.__eventStack) > 0:
+ result = self.__eventStack.pop(0)
+ self.__eventStackMutex.release()
+ return result
+
+ def insertMessage(self, message, locutor, pitch):
+ """
+ """
+ self.__insertEvent(PGU_EVENT_TYPE_MESSAGE, {
+ 'message' : message,
+ 'locutor' : locutor,
+ 'pitch' : pitch,
+ })
+
+ def insertActuation(self, actuationName, arguments = []):
+ """
+ """
+ # Little hack for plugins audio menu
+ if actuationName == "abortTts":
+ self.__breakMessage()
+ return
+ self.__insertEvent(PGU_EVENT_TYPE_ACTUATION, {
+ 'actuationName' : actuationName,
+ 'actuationArguments' : arguments,
+ })
+
+ def insertAttitune(self, attituneName):
+ """
+ """
+ self.__insertEvent(PGU_EVENT_TYPE_ATTITUNE, {
+ 'attituneName' : attituneName,
+ })
+
+ def startExecution(self):
+ """
+ """
+ if self.executionIsStarted():
+ return
+ expirationDelay = self.getPluginCommand().getExpirationDelay()
+ if expirationDelay > 0:
+ if (time.time() - self.__createTime) > expirationDelay:
+ return
+ self.__startStopPauseMutex.acquire()
+ self.__execStarted = True
+ self.__execPaused = False
+ self.__startStopPauseMutex.release()
+ print "Start execution of PGU context [%s]" % self.getPguName()
+ self.__executionLoop()
+
+ def executionIsStarted(self):
+ """
+ """
+ self.__startStopPauseMutex.acquire()
+ result = self.__execStarted
+ self.__startStopPauseMutex.release()
+ return result
+
+ def stopExecution(self):
+ """
+ """
+ if not self.getPluginCommand().isNotifier():
+ self.__pluginInterpreterContext.abort()
+ if not self.executionIsStarted():
+ return
+ print "Stop execution of PGU context [%s]" % self.getPguName()
+ self.__startStopPauseMutex.acquire()
+ self.__execStarted = False
+ self.__execPaused = False
+ self.__eventStackMutex.acquire()
+ self.__eventStack = []
+ self.__eventStackMutex.release()
+ self.__startStopPauseMutex.release()
+ self.__breakAttitune()
+ self.__breakMessage()
+ self.__breakActuation()
+ print "Execution of PGU context [%s] stopped" % self.getPguName()
+ if not self.getPluginCommand().isNotifier():
+ if self.getContextLayer() == PGU_CONTEXT_LAYER_SCHEDULER:
+ resourceTuxDriver.playSound(15, 100.0)
+ else:
+ resourceTuxDriver.playSound(16, 100.0)
+ time.sleep(0.5)
+
+ def pauseExecution(self):
+ """
+ """
+ if not self.executionIsStarted():
+ return
+ if self.executionIsPaused():
+ return
+ print "Pause execution of PGU context [%s]" % self.getPguName()
+ self.__startStopPauseMutex.acquire()
+ self.__execPaused = True
+ self.__startStopPauseMutex.release()
+ self.__breakAttitune()
+ self.__breakMessage()
+ self.__breakActuation()
+
+ def unpauseExecution(self):
+ """
+ """
+ if not self.executionIsStarted():
+ return
+ if not self.executionIsPaused():
+ return
+ print "Unpause execution of PGU context [%s]" % self.getPguName()
+ self.__startStopPauseMutex.acquire()
+ self.__execPaused = False
+ self.__startStopPauseMutex.release()
+
+ def executionIsPaused(self):
+ """
+ """
+ self.__startStopPauseMutex.acquire()
+ result = self.__execPaused
+ self.__startStopPauseMutex.release()
+ return result
+
+ def __executeAttitune(self, attituneName):
+ """
+ """
+ resourceAttituneManager.playAttituneSync(attituneName, 0.0)
+
+ def __breakAttitune(self):
+ """
+ """
+ resourceAttituneManager.stopAttitune()
+
+ 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
+ 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):
+ """
+ """
+ argsString = ""
+ for argument in arguments:
+ if len(argsString) > 0:
+ argsString += ","
+ try:
+ argument = int(argument)
+ argsString += str(argument)
+ except:
+ try:
+ argument = float(argument)
+ argsString += str(argument)
+ except:
+ argsString += '"' + str(argument) + '"'
+ cmdString = "resourceTuxDriver.%s(%s)" % (actuationName, argsString)
+ try:
+ exec(cmdString) in globals()
+ except:
+ print "!!! Error in command :", cmdString
+
+ def __breakActuation(self):
+ """
+ """
+ resourceTuxDriver.clearAll()
+
+ def __executionLoop(self):
+ """
+ """
+ if not self.getPluginCommand().isNotifier():
+ if self.getContextLayer() == PGU_CONTEXT_LAYER_SCHEDULER:
+ resourceTuxDriver.playSound(14, 100.0)
+ else:
+ resourceTuxDriver.playSound(13, 100.0)
+ time.sleep(0.5)
+ while self.executionIsStarted():
+ while self.executionIsPaused():
+ time.sleep(0.1)
+ nextEvent = self.__getEvent()
+ if nextEvent == None:
+ if self.contextIsComplete():
+ self.__startStopPauseMutex.acquire()
+ self.__execStarted = False
+ self.__execPaused = False
+ self.__startStopPauseMutex.release()
+ print "Execution of PGU context [%s] stopped" % self.getPguName()
+ if not self.getPluginCommand().isNotifier():
+ if self.getContextLayer() == PGU_CONTEXT_LAYER_SCHEDULER:
+ resourceTuxDriver.playSound(15, 100.0)
+ else:
+ resourceTuxDriver.playSound(16, 100.0)
+ time.sleep(0.5)
+ return
+ else:
+ print "Execute event from PGU context [%s] :" % self.getPguName()
+ 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'])
+ elif nextEvent['type'] == PGU_EVENT_TYPE_ACTUATION:
+ self.__executeActuation(arguments['actuationName'],
+ arguments['actuationArguments'])
+ elif nextEvent['type'] == PGU_EVENT_TYPE_ATTITUNE:
+ self.__executeAttitune(arguments['attituneName'])
+ print "Event finished"
+ time.sleep(0.1)
+
+class PguContextsManager(object):
+ """
+ """
+
+ def __init__(self):
+ """
+ """
+ self.__pguContexts = []
+ self.__pguContextsMutex = threading.Lock()
+ self.__backgroundPguContext = None
+ self.__foregroundPguContext = None
+ self.__backgroundPguThread = None
+ self.__bfPguContextMutex = threading.Lock()
+ self.__isStarted = False
+ self.__startedMutex = threading.Lock()
+ self.__loopThread = None
+ self.__onDemandList = []
+ self.__onDemandIndex = 0
+ self.__lastRunStopActionTime = time.time()
+ self.__lastRunStopActionTimeMutex = threading.Lock()
+
+ def insertOnDemand(self, ugc):
+ """
+ """
+ self.__onDemandList.append(ugc)
+
+ def removeOnDemand(self, ugc):
+ """
+ """
+ for odUgc in self.__onDemandList:
+ if odUgc == ugc:
+ self.__onDemandList.remove(ugc)
+ return
+
+ def __speakOnDemand(self):
+ """
+ """
+ if len(self.__onDemandList) > 0:
+ resourceTuxOSL.ttsStop()
+ ugc = self.__onDemandList[self.__onDemandIndex]
+ ugcTtsName = ugc.getDescription().getName()
+ locutor = resourcePluginsServer.getPluginsContainer().getLocutor()
+ pitch = resourcePluginsServer.getPluginsContainer().getPitch()
+ resourceTuxDriver.openMouth()
+ resourceTuxOSL.ttsSpeak(ugcTtsName, locutor, pitch)
+ 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)
+ resourceTuxDriver.closeMouth()
+
+ def __onDemandNext(self):
+ """
+ """
+ self.__onDemandIndex += 1
+ if self.__onDemandIndex >= len(self.__onDemandList):
+ self.__onDemandIndex = 0
+ resourceTuxDriver.playSound(11, 100.0)
+ self.__speakOnDemand()
+
+ def __onDemandPrevious(self):
+ """
+ """
+ self.__onDemandIndex -= 1
+ if self.__onDemandIndex < 0:
+ self.__onDemandIndex = len(self.__onDemandList) - 1
+ resourceTuxDriver.playSound(11, 100.0)
+ self.__speakOnDemand()
+
+ def __setStarted(self, value):
+ """
+ """
+ self.__startedMutex.acquire()
+ self.__isStarted = value
+ self.__startedMutex.release()
+
+ def isStarted(self):
+ """
+ """
+ self.__startedMutex.acquire()
+ result = self.__isStarted
+ self.__startedMutex.release()
+ return result
+
+ def start(self):
+ """
+ """
+ self.__loopThread = threading.Thread(target = self.__executionLoop)
+ self.__loopThread.start()
+
+ def stop(self):
+ """
+ """
+ self.__setStarted(False)
+ if self.getForegroundPguContext() != None:
+ self.getForegroundPguContext().stopExecution()
+ if self.__loopThread != None:
+ if self.__loopThread.isAlive():
+ self.__loopThread.join()
+
+ def mute(self):
+ """
+ """
+ pass
+
+ def unmute(self):
+ """
+ """
+ pass
+
+ def __executionLoop(self):
+ """
+ """
+ if self.isStarted():
+ return
+ self.__setStarted(True)
+ while self.isStarted():
+ if self.backgroundPguContextIsCritical():
+ time.sleep(0.5)
+ continue
+ # Get the next pguContext which must be in foreground
+ pguContext = None
+ self.__pguContextsMutex.acquire()
+ if len(self.__pguContexts) > 0:
+ pguContext = self.__pguContexts.pop(0)
+ if pguContext != None:
+ self.__setForegroundPguContext(pguContext)
+ self.__pguContextsMutex.release()
+ if self.getBackgroundPguContext() != None:
+ # If the context is exclusive then stop the background context
+ if self.backgroundPguContextIsExclusive():
+ try:
+ self.getBackgroundPguContext().stopExecution()
+ except:
+ pass
+ # Else only pause-it
+ else:
+ self.getBackgroundPguContext().pauseExecution()
+ self.getForegroundPguContext().startExecution()
+ if self.getBackgroundPguContext() != None:
+ # Unpause background context
+ if not self.backgroundPguContextIsExclusive():
+ try:
+ self.getBackgroundPguContext().unpauseExecution()
+ except:
+ pass
+ self.__setForegroundPguContext(None)
+ else:
+ self.__pguContextsMutex.release()
+ time.sleep(0.5)
+
+ def createPguContext(self, pluginInterpreterContext):
+ """
+ """
+ if not self.isStarted():
+ return
+ # Create new pguContext
+ pguContext = PguContext(pluginInterpreterContext)
+ # Add the new pguContext in the system
+ self.__insertPguContext(pguContext)
+
+ def __startBackgroundPguContext(self):
+ """
+ """
+ self.getBackgroundPguContext().startExecution()
+
+ def __insertPguContext(self, pguContext):
+ """
+ """
+ # Alerts and no daemon user calls must be inserted in the stack
+ # as foreground.
+ if (pguContext.getContextLayer() == PGU_CONTEXT_LAYER_SCHEDULER) or\
+ (not pguContext.isDaemon()):
+ self.__pguContextsMutex.acquire()
+ for i, regPguContext in enumerate(self.__pguContexts):
+ if regPguContext.getPluginCommand() == pguContext.getPluginCommand():
+ # Replace the context with the same plugin command.
+ self.__pguContexts[i] = pguContext
+ self.__pguContextsMutex.release()
+ return
+ # If the context command is critical and the context is run by the
+ # scheduler then stop the current context and add the context on top
+ # of the stack
+ if (pguContext.getPluginCommand().isCritical()) and \
+ (pguContext.getContextLayer() == PGU_CONTEXT_LAYER_SCHEDULER):
+ self.__pguContexts.insert(0, pguContext)
+ if self.getForegroundPguContext() != None:
+ self.getForegroundPguContext().stopExecution()
+ # Add the new context at the bottom of the stack.
+ else:
+ self.__pguContexts.append(pguContext)
+ self.__pguContextsMutex.release()
+ # Daemon user calls must be referenced as background.
+ else:
+ currentBackgroundPguContext = self.getBackgroundPguContext()
+ if currentBackgroundPguContext != None:
+ # Stop old background context if exists
+ currentBackgroundPguContext.stopExecution()
+ if self.__backgroundPguThread != None:
+ if self.__backgroundPguThread.isAlive():
+ self.__backgroundPguThread.join()
+ self.__setBackgroundPguContext(pguContext)
+ self.__backgroundPguThread = threading.Thread(target = self.__startBackgroundPguContext)
+ self.__backgroundPguThread.start()
+
+ def getForegroundPguContext(self):
+ """
+ """
+ self.__bfPguContextMutex.acquire()
+ result = self.__foregroundPguContext
+ self.__bfPguContextMutex.release()
+ return result
+
+ def getBackgroundPguContext(self):
+ """
+ """
+ self.__bfPguContextMutex.acquire()
+ result = self.__backgroundPguContext
+ self.__bfPguContextMutex.release()
+ return result
+
+ def backgroundPguContextIsCritical(self):
+ """
+ """
+ self.__bfPguContextMutex.acquire()
+ result = False
+ if self.__backgroundPguContext != None:
+ if self.__backgroundPguContext.executionIsStarted():
+ if self.__backgroundPguContext.getPluginCommand().isCritical():
+ result = True
+ self.__bfPguContextMutex.release()
+ return result
+
+ def backgroundPguContextIsExclusive(self):
+ """
+ """
+ self.__bfPguContextMutex.acquire()
+ result = False
+ if self.__backgroundPguContext != None:
+ if self.__backgroundPguContext.executionIsStarted():
+ if self.__backgroundPguContext.getPluginCommand().isExclusive():
+ result = True
+ self.__bfPguContextMutex.release()
+ return result
+
+ def backgroundPguContextNeedAllUserButtons(self):
+ """
+ """
+ self.__bfPguContextMutex.acquire()
+ result = False
+ if self.__backgroundPguContext != None:
+ if self.__backgroundPguContext.executionIsStarted():
+ if self.__backgroundPguContext.getPluginCommand().needAllUserButtons():
+ result = True
+ self.__bfPguContextMutex.release()
+ return result
+
+ def __setForegroundPguContext(self, pguContext):
+ """
+ """
+ self.__bfPguContextMutex.acquire()
+ self.__foregroundPguContext = pguContext
+ self.__bfPguContextMutex.release()
+
+ def __setBackgroundPguContext(self, pguContext):
+ """
+ """
+ self.__bfPguContextMutex.acquire()
+ self.__backgroundPguContext = pguContext
+ self.__bfPguContextMutex.release()
+
+ def getPguContext(self, pluginInterpreterContext, noMutex = False):
+ """
+ """
+ result = None
+ if not noMutex:
+ self.__pguContextsMutex.acquire()
+ for pguContext in self.__pguContexts:
+ if pguContext.getPluginInterpreterContext() == pluginInterpreterContext:
+ result = pguContext
+ break
+ if result == None:
+ if self.getForegroundPguContext() != None:
+ if self.getForegroundPguContext().getPluginInterpreterContext() == pluginInterpreterContext:
+ result = self.getForegroundPguContext()
+ if result == None:
+ if self.getBackgroundPguContext() != None:
+ if self.getBackgroundPguContext().getPluginInterpreterContext() == pluginInterpreterContext:
+ result = self.getBackgroundPguContext()
+ if not noMutex:
+ self.__pguContextsMutex.release()
+ return result
+
+ # ==========================================================================
+ # Events from plugins execution.
+ # ==========================================================================
+
+ def insertMessage(self, pluginInterpreterContext, message, locutor, pitch):
+ """
+ """
+ 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 = []):
+ """
+ """
+ self.__pguContextsMutex.acquire()
+ pguContext = self.getPguContext(pluginInterpreterContext, True)
+ if pguContext != None:
+ pguContext.insertActuation(actuationName, arguments)
+ self.__pguContextsMutex.release()
+
+ def insertAttitune(self, pluginInterpreterContext, attituneName):
+ """
+ """
+ self.__pguContextsMutex.acquire()
+ pguContext = self.getPguContext(pluginInterpreterContext, True)
+ if pguContext != None:
+ pguContext.insertAttitune(attituneName)
+ self.__pguContextsMutex.release()
+
+ def setContextIsComplete(self, 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):
+ """
+ """
+ if (time.time() - self.__getLastRunStopActionTime()) >= 1.5:
+ self.__setLastRunStopActionTime()
+ ...
[truncated message content] |