Author: remi
Date: 2009-03-22 21:22:42 +0100 (Sun, 22 Mar 2009)
New Revision: 4169
Modified:
software_suite_v2/software/development_tools/tuxdroid-gadget-python-kit/trunk/executables/SimpleGadget/SimpleGadget.py
software_suite_v2/software/development_tools/tuxdroid-gadget-python-kit/trunk/executables/SimpleGadget/SimpleGadgetConfiguration.py
Log:
* added a new parameter.
* added the bi-directional communication with the framework
- New python gadget framework can throw messages to the gadgets through the
stdin PIPE
Modified:
software_suite_v2/software/development_tools/tuxdroid-gadget-python-kit/trunk/executables/SimpleGadget/SimpleGadget.py
===================================================================
---
software_suite_v2/software/development_tools/tuxdroid-gadget-python-kit/trunk/executables/SimpleGadget/SimpleGadget.py
2009-03-22 20:09:10 UTC (rev 4168)
+++
software_suite_v2/software/development_tools/tuxdroid-gadget-python-kit/trunk/executables/SimpleGadget/SimpleGadget.py
2009-03-22 20:22:42 UTC (rev 4169)
@@ -20,6 +20,7 @@
import traceback
import random
import platform
+import threading
ENVIRONEMENT_PREFIX = "tgp_"
@@ -38,8 +39,67 @@
"""
self.__configuration = None
self.__command = None
+ self.__runMutex = threading.Lock()
+ self.__run = False
+ self.__stdInThread = None
#
--------------------------------------------------------------------------
+ # On gadget stop event. Must be overrided
+ #
--------------------------------------------------------------------------
+ def onGadgetStop(self):
+ """On gadget stop event. Must be overrided
+ """
+ pass
+
+ #
--------------------------------------------------------------------------
+ # Stop the gadget.
+ #
--------------------------------------------------------------------------
+ def stop(self):
+ """Stop the gadget.
+ """
+ if self.__stdInThread != None:
+ if self.__stdInThread.isAlive():
+ self.__stdInThread._Thread__stop()
+ self.onGadgetStop()
+ self.throwNotification("gadget", "exit")
+
+ #
--------------------------------------------------------------------------
+ # Set the run flag value.
+ #
--------------------------------------------------------------------------
+ def __setRun(self, value):
+ """Set the run flag value.
+ @param value: Flag value. <True|False>
+ """
+ self.__runMutex.acquire()
+ self.__run = value
+ self.__runMutex.release()
+
+ #
--------------------------------------------------------------------------
+ # Get the run flag value.
+ #
--------------------------------------------------------------------------
+ def __getRun(self):
+ """Get the run flag value.
+ @return: True or False.
+ """
+ self.__runMutex.acquire()
+ result = self.__run
+ self.__runMutex.release()
+ return result
+
+ #
--------------------------------------------------------------------------
+ # Stdin polling loop.
+ #
--------------------------------------------------------------------------
+ def __stdInLoop(self):
+ """Stdin polling loop.
+ """
+ while self.__getRun():
+ line = sys.stdin.readline()
+ if line.lower().find("stop") == 0:
+ self.onGadgetStop()
+ self.__setRun(False)
+ time.sleep(0.1)
+
+ #
--------------------------------------------------------------------------
# Get the configuration object.
#
--------------------------------------------------------------------------
def configuration(self):
@@ -156,7 +216,14 @@
self.__command = arguments[0]
self.__configuration = configuration
self.__loadEnvironementData()
+ self.__setRun(True)
+ if self.__configuration.isDaemon():
+ self.__stdInThread = threading.Thread(
+ target = self.__stdInLoop)
+ self.__stdInThread.start()
self.start()
+ if not self.__configuration.isDaemon():
+ self.onGadgetStop()
except:
self.throwError("Error on gadget boot", True)
Modified:
software_suite_v2/software/development_tools/tuxdroid-gadget-python-kit/trunk/executables/SimpleGadget/SimpleGadgetConfiguration.py
===================================================================
---
software_suite_v2/software/development_tools/tuxdroid-gadget-python-kit/trunk/executables/SimpleGadget/SimpleGadgetConfiguration.py
2009-03-22 20:09:10 UTC (rev 4168)
+++
software_suite_v2/software/development_tools/tuxdroid-gadget-python-kit/trunk/executables/SimpleGadget/SimpleGadgetConfiguration.py
2009-03-22 20:22:42 UTC (rev 4169)
@@ -33,6 +33,7 @@
self.__language = "en"
self.__country = "US"
self.__locutor = "Ryan"
+ self.__daemon = False
#
--------------------------------------------------------------------------
# Get the pitch value.
@@ -123,3 +124,12 @@
@param traces: Is traced or not.
"""
self.__traces = traces
+
+ #
--------------------------------------------------------------------------
+ # Get if the gadget is a daemon or not.
+ #
--------------------------------------------------------------------------
+ def isDaemon(self):
+ """Get if the gadget is a daemon or not.
+ @return: A boolean.
+ """
+ return self.__daemon
------------------------------------------------------------------------------
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