Author: remi
Date: 2009-03-13 20:32:21 +0100 (Fri, 13 Mar 2009)
New Revision: 4064

Modified:
   software_suite_v2/tuxware/tuxdroidserver/trunk/util/gadgets/Framework.py
Log:
* added a logger

Modified: 
software_suite_v2/tuxware/tuxdroidserver/trunk/util/gadgets/Framework.py
===================================================================
--- software_suite_v2/tuxware/tuxdroidserver/trunk/util/gadgets/Framework.py    
2009-03-13 18:18:22 UTC (rev 4063)
+++ software_suite_v2/tuxware/tuxdroidserver/trunk/util/gadgets/Framework.py    
2009-03-13 19:32:21 UTC (rev 4064)
@@ -8,6 +8,7 @@
 
 from FrameworkBridge import FrameworkBridge
 from GadgetsContainer import GadgetsContainer
+from util.logger.SimpleLogger import *
 
 # 
------------------------------------------------------------------------------
 # Gadget description.
@@ -42,6 +43,9 @@
         self.__pitch = 130
         self.__gadgetsContainer = GadgetsContainer({})
         self.__startMutex = threading.Lock()
+        self.__logger = SimpleLogger("gadget_framework")
+        self.__logger.setLevel(LOG_LEVEL_DEBUG)
+        self.__logger.setTarget(LOG_TARGET_BOTH)
 
     # 
--------------------------------------------------------------------------
     # Start the gadget framework.
@@ -58,7 +62,10 @@
         """
         def async():
             self.__startMutex.acquire()
+            self.__logger.logInfo("[Framework] Starting : Begin")
+            self.__logger.logDebug("[Framework] Stop the previous instance")
             self.__gadgetFramework.stop()
+            self.__logger.logDebug("[Framework] Previous instance stopped")
             if self.__onFrameworkStoppedCallBack != None:
                 self.__onFrameworkStoppedCallBack()
             self.__gadgetsDictionary = {}
@@ -66,7 +73,9 @@
             self.__currentGadgetLoad = {}
             self.__currentGadgetLoadState = "HEAD"
             self.__containerDirectory = None
+            self.__logger.logDebug("[Framework] Start the new instance")
             self.__gadgetFramework.start()
+            self.__logger.logDebug("[Framework] New instance started")
             time.sleep(0.5)
             self.__language = language
             self.__country = country
@@ -77,6 +86,7 @@
             self.__containerStart(gadgetsPath)
             if self.__onFrameworkStartingCallBack != None:
                 self.__onFrameworkStartingCallBack()
+            self.__logger.logInfo("[Framework] Starting : End")
             self.__startMutex.release()
         t = threading.Thread(target = async)
         t.start()
@@ -87,6 +97,7 @@
     def stop(self):
         """Stop the gadget framework.
         """
+        self.__logger.logInfo("[Framework] Stop")
         self.__gadgetFramework.stop()
 
     # 
--------------------------------------------------------------------------
@@ -387,29 +398,42 @@
     def __onFrameworkEvent(self, args):
         if args[0] == "CONTAINER":
             if args[1] == "ERROR":
+                self.__logger.logWarning("[Framework] Attempt to load an 
invalid gadget.")
                 if self.__onContainerErrorCallback != None:
                     self.__onContainerErrorCallback(args[2:])
             elif args[1] == "GADGET":
                 if args[2] == "LOADED":
                     self.__onGadgetLoad(args[3:])
                     if args[3] == "END":
+                        self.__logger.logInfo("[Framework] Gadget has been 
loaded (%s)" % args[4])
                         if self.__onContainerGadgetLoadedCallback != None:
                             self.__onContainerGadgetLoadedCallback(args[4])
                 elif args[2] == "UNLOADED":
                     if args[3] == "END":
                         self.__onGadgetUnload(args[4])
+                        self.__logger.logInfo("[Framework] Gadget has been 
unloaded (%s)" % args[4])
                         if self.__onContainerGadgetUnloadedCallback != None:
                             self.__onContainerGadgetUnloadedCallback(args[4])
             elif args[1] == "DEPLOYED":
+                self.__logger.logInfo("[Framework] Gadget has been deployed")
                 self.__onContainerDeployed()
                 if self.__onContainerDeployedCallback != None:
                     self.__onContainerDeployedCallback()
         elif args[0] == "GADGET":
             if args[1] == "ERROR":
+                message = ""
+                for line in args[7:]:
+                    message += line
+                self.__logger.logWarning("[Framework] Gadget error (%s) : 
(%s)" % (args[2], message))
                 if self.__onGadgetErrorCallback != None:
                     self.__onGadgetErrorCallback(args[2], args[3], args[4:])
             elif args[1] == "NOTIFICATION":
                 if self.__onGadgetNotificationCallback != None:
+                    message = ""
+                    for line in args[7:]:
+                        message += line
+                    self.__logger.logDebug("[Framework] Gadget notification 
(%s, %s, %s, %s, %s, %s)" % (
+                        args[2], args[3], args[4], args[5], args[6], message))
                     self.__onGadgetNotificationCallback(args[2], args[3],
                         args[4], args[5], args[6], args[7:])
             elif args[1] == "STARTING":
@@ -419,6 +443,10 @@
                 if self.__onGagdetStoppedCallback != None:
                     self.__onGagdetStoppedCallback(args[2], args[3])
             elif args[1] == "TRACE":
+                message = ""
+                for line in args[7:]:
+                    message += line
+                self.__logger.logInfo("[Framework] Gadget trace (%s) : (%s)" % 
(args[2], message))
                 if self.__onGadgetTraceCallback != None:
                     self.__onGadgetTraceCallback(args[2], args[3], args[4:])
 
@@ -431,6 +459,7 @@
                 if len(args) != 9:
                     self.__currentGadgetLoadState = "HEAD"
                 else:
+                    self.__logger.logDebug("[Framework] Parse gadget 
description : Begin")
                     self.__currentGadgetLoad['description']['name'] = args[0]
                     self.__currentGadgetLoad['description']['translated_name'] 
= args[1]
                     self.__currentGadgetLoad['description']['uuid'] = args[2]
@@ -440,11 +469,13 @@
                     self.__currentGadgetLoad['description']['icon_file'] = 
args[6]
                     self.__currentGadgetLoad['description']['help_file'] = 
args[7]
                     self.__currentGadgetLoad['description']['tgf_file'] = 
args[8]
+                    self.__logger.logDebug("[Framework] Parse gadget 
description : End")
                     return
             elif self.__currentGadgetLoadState == "GETPARAMETERS":
                 if len(args) != 9:
                     self.__currentGadgetLoadState = "HEAD"
                 else:
+                    self.__logger.logDebug("[Framework] Parse gadget parameter 
: Begin")
                     idx = "parameter_%.3d" % 
len(self.__currentGadgetLoad['parameters'].keys())
                     self.__currentGadgetLoad['parameters'][idx] = {
                         'name' : args[0],
@@ -457,17 +488,20 @@
                         'min_value' : args[7],
                         'max_value' : args[8],
                     }
+                    self.__logger.logDebug("[Framework] Parse gadget parameter 
: End")
                     return
             elif self.__currentGadgetLoadState == "GETCOMMANDS":
                 if len(args) != 3:
                     self.__currentGadgetLoadState = "HEAD"
                 else:
+                    self.__logger.logDebug("[Framework] Parse gadget command : 
Begin")
                     idx = "command_%.3d" % 
len(self.__currentGadgetLoad['commands'].keys())
                     self.__currentGadgetLoad['commands'][idx] = {
                         'name' : args[0],
                         'translated_name' : args[1],
                         'description' : args[2],
                     }
+                    self.__logger.logDebug("[Framework] Parse gadget command : 
End")
                     return
             if self.__currentGadgetLoadState == "HEAD":
                 if args[0] == "BEGIN":
@@ -498,6 +532,8 @@
                         self.__currentGadgetLoadState = "HEAD"
         except:
             # Error in the retrieved structure, retry ...
+            self.__logger.logError("[Framework] Error on gadget information 
parsing !")
+            self.__logger.logError("[Framework] Relaunch the framework staring 
...")
             self.start(self.__containerDirectory, self.__language,
                 self.__country, self.__locutor, self.__pitch)
 
@@ -541,6 +577,7 @@
         cmd = "CONTAINER"
         subCmd = "START"
         args = [gadgetsPath]
+        self.__logger.logInfo("[Framework] Load a gadget directory (%s)" % 
gadgetsPath)
         return self.__gadgetFramework.sendCommand(cmd, subCmd, args)
 
     # 
--------------------------------------------------------------------------
@@ -549,6 +586,8 @@
     def __containerSetLocales(self, language, country, locutor, pitch):
         cmd = "CONTAINER"
         subCmd = "SETLOCALE"
+        self.__logger.logInfo("[Framework] Set the locales (%s, %s, %s, %s)" % 
(
+                language, country, locutor, pitch))
         args = [language, country, locutor, str(pitch)]
         return self.__gadgetFramework.sendCommand(cmd, subCmd, args)
 
@@ -558,4 +597,5 @@
     def __containerRestart(self):
         cmd = "CONTAINER"
         subCmd = "RESTART"
+        self.__logger.logInfo("[Framework] Restart the container")
         return self.__gadgetFramework.sendCommand(cmd, subCmd)


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