Author: remi
Date: 2009-06-23 11:58:56 +0200 (Tue, 23 Jun 2009)
New Revision: 4856

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/util/applicationserver/plugin/interpreters/PluginInterpreter.py
   
software_suite_v3/smart-core/smart-server/trunk/util/player/mplayer/Mplayer.py
Log:
* Improved menu RC Tux buttons, contexts and webradio stability.

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-23 09:57:58 UTC (rev 4855)
+++ 
software_suite_v3/smart-core/smart-server/trunk/resources/04_robot_content_interactions/00_resourceRobotContentInteractions.py
      2009-06-23 09:58:56 UTC (rev 4856)
@@ -175,7 +175,9 @@
         """
         """
         if not self.getPluginCommand().isNotifier():
-            self.__pluginInterpreterContext.abort()
+            while self.__pluginInterpreterContext.isRun():
+                self.__pluginInterpreterContext.abort()
+                time.sleep(0.1)
         if not self.executionIsStarted():
             return
         print "Stop execution of PGU context [%s]" % self.getPguName()
@@ -356,6 +358,7 @@
         self.__bfPguContextMutex = threading.Lock()
         self.__isStarted = False
         self.__startedMutex = threading.Lock()
+        self.__ugcInsertionMutex = threading.Lock()
         self.__loopThread = None
         self.__onDemandList = []
         self.__onDemandIndex = 0
@@ -555,6 +558,7 @@
     def __insertPguContext(self, pguContext):
         """
         """
+        self.__ugcInsertionMutex.acquire()
         # Alerts and no daemon user calls must be inserted in the stack
         # as foreground.
         if (pguContext.getContextLayer() == PGU_CONTEXT_LAYER_SCHEDULER) or\
@@ -565,6 +569,7 @@
                     # Replace the context with the same plugin command.
                     self.__pguContexts[i] = pguContext
                     self.__pguContextsMutex.release()
+                    self.__ugcInsertionMutex.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
@@ -590,6 +595,7 @@
             self.__setBackgroundPguContext(pguContext)
             self.__backgroundPguThread = threading.Thread(target = 
self.__startBackgroundPguContext)
             self.__backgroundPguThread.start()
+        self.__ugcInsertionMutex.release()
 
     def getForegroundPguContext(self):
         """
@@ -739,7 +745,7 @@
         self.__lastRunStopActionTimeMutex.release()
         return result
 
-    def __checkLastRunStopActionTime(self):
+    def __checkLastRunActionTime(self):
         """
         """
         if (time.time() - self.__getLastRunStopActionTime()) >= 1.5:
@@ -748,13 +754,22 @@
         else:
             return False
 
+    def __checkLastStopActionTime(self):
+        """
+        """
+        if (time.time() - self.__getLastRunStopActionTime()) >= 0.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():
+                if not self.__checkLastRunActionTime():
                     return
                 self.getForegroundPguContext().stopExecution()
                 return
@@ -765,14 +780,15 @@
                 if self.backgroundPguContextNeedAllUserButtons():
                     self.__contextBtOther(eventName, *args)
                     return
-                if not self.__checkLastRunStopActionTime():
+                if not self.__checkLastRunActionTime():
                     return
                 self.getBackgroundPguContext().stopExecution()
                 return
         # Else load current selected on demand gadget
         if len(self.__onDemandList) > 0:
             ugc = self.__onDemandList[self.__onDemandIndex]
-            self.__setLastRunStopActionTime()
+            if not self.__checkLastStopActionTime():
+                return
             ugc.start(ugc.getDefaultRunCommandName())
 
     def startCurrentGadget(self):
@@ -791,7 +807,8 @@
         # Else load current selected on demand gadget
         if len(self.__onDemandList) > 0:
             ugc = self.__onDemandList[self.__onDemandIndex]
-            self.__setLastRunStopActionTime()
+            if not self.__checkLastStopActionTime():
+                return
             t = threading.Thread(target = ugc.start, args = 
(ugc.getDefaultRunCommandName(),))
             t.start()
 
@@ -803,7 +820,7 @@
         # Abort foreground context if exists
         if self.getForegroundPguContext() != None:
             if self.getForegroundPguContext().executionIsStarted():
-                if not self.__checkLastRunStopActionTime():
+                if not self.__checkLastRunActionTime():
                     return
                 self.getForegroundPguContext().stopExecution()
                 return
@@ -813,7 +830,7 @@
                 # Exception for plugins commands with attribute 
"allUserButtons"
                 if self.backgroundPguContextNeedAllUserButtons():
                     return
-                if not self.__checkLastRunStopActionTime():
+                if not self.__checkLastRunActionTime():
                     return
                 self.getBackgroundPguContext().stopExecution()
                 return

Modified: 
software_suite_v3/smart-core/smart-server/trunk/util/applicationserver/plugin/interpreters/PluginInterpreter.py
===================================================================
--- 
software_suite_v3/smart-core/smart-server/trunk/util/applicationserver/plugin/interpreters/PluginInterpreter.py
     2009-06-23 09:57:58 UTC (rev 4855)
+++ 
software_suite_v3/smart-core/smart-server/trunk/util/applicationserver/plugin/interpreters/PluginInterpreter.py
     2009-06-23 09:58:56 UTC (rev 4856)
@@ -25,6 +25,7 @@
         self.__workingPath = None
         self.__executable = None
         self.__runMutex = threading.Lock()
+        self.__workMutex = threading.Lock()
         self.__run = False
         self.__process = None
         self.__pid = None
@@ -170,8 +171,11 @@
         @param command: Plugin command.
         @param daemon: Is daemon or not.
         """
+        self.__workMutex.acquire()
         if self.__getRun():
+            self.__workMutex.release()
             return
+        self.__setRun(True)
         self.__daemon = daemon
         shellCommand = self.prepareCommand()
         shellCommand.append(command)
@@ -179,21 +183,26 @@
         if self.__daemon:
             shellEnv['tgp_daemon'] = 'true'
         shellCwd = self.__workingPath
-        self.__process = subprocess.Popen(
-            shellCommand,
-            stdin = subprocess.PIPE,
-            stdout = subprocess.PIPE,
-            stderr = subprocess.STDOUT,
-            cwd = self.__workingPath,
-            env = self.__shellEnv)
+        try:
+            self.__process = subprocess.Popen(
+                shellCommand,
+                stdin = subprocess.PIPE,
+                stdout = subprocess.PIPE,
+                stderr = subprocess.STDOUT,
+                cwd = self.__workingPath,
+                env = self.__shellEnv)
+        except:
+            self.__setRun(False)
+            self.__workMutex.release()
+            return
         if os.name == 'nt':
             self.__pid = self.__process._handle
         else:
             self.__pid = self.__process.pid
-        self.__setRun(True)
         t = threading.Thread(target = self.__stdOutLoop)
         t.start()
         time.sleep(0.1)
+        self.__workMutex.release()
 
     # 
--------------------------------------------------------------------------
     # Abort the current execution of the interpreter.
@@ -210,7 +219,9 @@
                     pass
             else:
                 os.system("kill -3 -15 -9 " + str(self.__pid))
+        self.__workMutex.acquire()
         if not self.__getRun():
+            self.__workMutex.release()
             return
         if self.__daemon:
             try:
@@ -230,6 +241,8 @@
                 self.__onPluginStoppedCallback()
         else:
             killMe()
+            self.__setRun(False)
+        self.__workMutex.release()
 
     # 
--------------------------------------------------------------------------
     # Send event to the plugin. (Daemon mode)

Modified: 
software_suite_v3/smart-core/smart-server/trunk/util/player/mplayer/Mplayer.py
===================================================================
--- 
software_suite_v3/smart-core/smart-server/trunk/util/player/mplayer/Mplayer.py  
    2009-06-23 09:57:58 UTC (rev 4855)
+++ 
software_suite_v3/smart-core/smart-server/trunk/util/player/mplayer/Mplayer.py  
    2009-06-23 09:58:56 UTC (rev 4856)
@@ -61,6 +61,7 @@
         """
         if not self.__getRun():
             return
+        self.__runMutex.acquire()
         if self.__process != None:
             if os.name == 'nt':
                 import win32api
@@ -70,9 +71,10 @@
                     pass
             else:
                 os.system("kill -3 -15 -9 " + str(self.__process.pid))
-        self.__setRun(False)
+        self.__run = False
         self.__process = None
         time.sleep(0.25)
+        self.__runMutex.release()
 
     # 
--------------------------------------------------------------------------
     # Restart mplayer.
@@ -140,7 +142,7 @@
         """
         if self.__getRun():
             return
-        self.__setRun(True)
+        self.__runMutex.acquire()
         cmd = [
             self.__appMplayer,
             "-slave",
@@ -153,12 +155,18 @@
         if uri.lower().find(".m3u") == -1:
             if uri.lower().find("http") != 0:
                 cmd.pop(4)
-        self.__process = subprocess.Popen(
-            cmd,
-            stdin = subprocess.PIPE,
-            stdout = subprocess.PIPE,
-            stderr = subprocess.PIPE)
+        try:
+            self.__process = subprocess.Popen(
+                cmd,
+                stdin = subprocess.PIPE,
+                stdout = subprocess.PIPE,
+                stderr = subprocess.PIPE)
+        except:
+            self.__runMutex.release()
+            return
         incompleteLine = ""
+        self.__run = True
+        self.__runMutex.release()
         while self.__getRun():
             try:
                 buffer = self.__process.stdout.read(100)


------------------------------------------------------------------------------
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to