Author: remi
Date: 2008-12-14 15:04:42 +0100 (Sun, 14 Dec 2008)
New Revision: 3114

Modified:
   
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/osl/TuxOSL.py
   
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/osl/__init__.py
   
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/osl/version.py
Log:
* added comments and doxygen
* added a logger
* updated the encoding format
* updated the version

Modified: 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/osl/TuxOSL.py
===================================================================
--- 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/osl/TuxOSL.py
       2008-12-14 13:55:17 UTC (rev 3113)
+++ 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/osl/TuxOSL.py
       2008-12-14 14:04:42 UTC (rev 3114)
@@ -1,4 +1,4 @@
-# -*- coding: latin1 -*-
+# -*- coding: utf-8 -*-
 
 import version
 __author__ = version.author
@@ -7,15 +7,17 @@
 __licence__ = version.licence
 del version
 
-#    Copyright (C) 2008 C2ME Sa
-#    R�mi Jocaille <[email protected]>
+#    Copyleft (C) 2008 C2ME Sa
+#    Remi Jocaille <[email protected]>
 #    Distributed under the terms of the GNU General Public License
 #    http://www.gnu.org/copyleft/gpl.html
 
 from ctypes import *
 import os
 
-# Error codes enumeration.
+from tuxisalive.lib.logger import *
+
+# Error codes list
 E_TUXOSL_BEGIN                = 256
 E_TUXOSL_NOERROR              = 0
 E_TUXOSL_PARSERISDISABLED     = E_TUXOSL_BEGIN
@@ -33,7 +35,7 @@
 E_TUXOSL_NOTRUNNING           = E_TUXOSL_BEGIN + 12
 E_TUXOSL_TTSENGINENOTFOUND    = E_TUXOSL_BEGIN + 13
 
-# Id enumeration of high level statuses
+# Identifiers list of the statuses
 SW_ID_OSL_SYMBOLIC_VERSION          = 0
 SW_ID_OSL_GENERAL_SOUND_STATE       = 1
 SW_ID_OSL_WAV_VOLUME                = 2
@@ -60,7 +62,7 @@
 SW_ID_OSL_TTS0_VOICE_LIST           = 23
 SW_ID_OSL_WAV_CHANNEL_START         = 24
 
-# Status names
+# Names list of the statuses
 SW_NAME_OSL = [
     "osl_symbolic_version",
     "general_sound_state",
@@ -89,215 +91,415 @@
     "tts_wav_channel_start",
 ]
 
+# Callback type defines
 TUX_OSL_STATUS_CALLBACK = CFUNCTYPE(None, c_char_p)
 TUX_OSL_BUFFER_CALLBACK = CFUNCTYPE(c_int, c_int, c_char_p)
 
+# 
==============================================================================
+# Public class
+# 
==============================================================================
+
+# 
------------------------------------------------------------------------------
+# libtuxosl wrapper class.
+# 
------------------------------------------------------------------------------
 class TuxOSL(object):
+    """libtuxosl wrapper class.
+    """
 
+    # 
--------------------------------------------------------------------------
+    # Constructor.
+    # 
--------------------------------------------------------------------------
     def __init__(self, library_path = None):
+        """Constructor.
+        @param library_path: Path of libtuxosl library. (Default None)
+        """
+        self.__logger = SimpleLogger("libtuxosl_wrapper")
+        self.__logger.setTarget(LOG_TARGET_FILE)
+        self.__logger.setLevel(LOG_LEVEL_INFO)
+        self.__logger.resetLog()
+        
self.__logger.logInfo("-----------------------------------------------")
+        self.__logger.logInfo("libtuxosl wrapper v%s" % __version__)
+        self.__logger.logInfo("Author : %s" % __author__)
+        self.__logger.logInfo("Licence : %s" % __licence__)
+        
self.__logger.logInfo("-----------------------------------------------")
         if library_path == None:
             mPath, mFile = os.path.split(__file__)
             if os.name == 'nt':
                 library_path = os.path.join(mPath, "libtuxosl.dll")
             else:
                 library_path = os.path.join(mPath, "libtuxosl.so")
+        self.__logger.logInfo("Libtuxosl path : (%s)" % library_path)
         self.__callback_container = []
         self.tux_osl_lib = None
         if os.path.isfile(library_path):
             try:
                 self.tux_osl_lib = CDLL(library_path)
+                self.__logger.logInfo("The shared library was found.")
             except:
                 self.tux_osl_lib = None
-                print "Path (%s) not found ! TuxOSL is not handled in your 
application." % library_path
+                txt = "Error on handling the library in your application."
+                self.__logger.logError(txt)
                 return
+            self.__logger.logInfo("Initialize the library")
             self.tux_osl_lib.TuxOSL_InitModule()
         else:
-            print "Path (%s) not found ! TuxOSL is not handled in your 
application." % library_path
-    
+            txt = "Path (%s) not found !" % library_path
+            self.__logger.logError(txt)
+            txt = "The shared library was not handled in your application."
+            self.__logger.logError(txt)
+
+    # 
--------------------------------------------------------------------------
+    # Register a callback function to the "status" event.
+    # 
--------------------------------------------------------------------------
     def SetStatusCallback(self, funct = None):
+        """Register a callback function to the "status" event.
+        @param funct: Pointer to the function.
+        """
         if self.tux_osl_lib == None:
             return
-            
+
         if funct == None:
             return
-    
+
         cb = TUX_OSL_STATUS_CALLBACK(funct)
         self.__callback_container.append(cb)
         self.tux_osl_lib.TuxOSL_SetStatusCallback(cb)
         return
-        
+
+    # 
--------------------------------------------------------------------------
+    # Register a callback function to the "TTS buffer" event.
+    # 
--------------------------------------------------------------------------
     def SetTTSBufferCallback(self, funct = None):
+        """Register a callback function to the "TTS buffer" event.
+        @param funct: Pointer to the function.
+        """
         if self.tux_osl_lib == None:
             return
-            
+
         if funct == None:
             return
-    
+
         cb = TUX_OSL_BUFFER_CALLBACK(funct)
         self.__callback_container.append(cb)
         self.tux_osl_lib.TuxOSL_SetTTSBufferCallback(cb)
         return
-        
+
+    # 
--------------------------------------------------------------------------
+    # Start libtuxosl.
+    # 
--------------------------------------------------------------------------
     def Start(self, tts_engine_path):
+        """Start libtuxosl.
+        @param tts_engine_path: TTS engine path (Not yet used)
+        @return: The success of the starting.
+        """
         if self.tux_osl_lib == None:
             return E_TUXOSL_NOTRUNNING
-            
-        return self.tux_osl_lib.TuxOSL_Start(c_char_p(tts_engine_path))
-        
-    def Stop(self): 
+
+        ret = self.tux_osl_lib.TuxOSL_Start(c_char_p(tts_engine_path))
+
+        if ret == E_TUXOSL_NOERROR:
+            self.__logger.logInfo("Libtuxosl successfuly started.")
+            voicesList = self.GetStatusValue(SW_ID_OSL_TTS0_VOICE_LIST)
+            self.__logger.logInfo(voicesList)
+        else:
+            self.__logger.logError("Libtuxosl can't start : code(%d) 
expl(%s)."\
+                % (ret, self.StrError(ret)))
+
+        return ret
+
+    # 
--------------------------------------------------------------------------
+    # Stop libtuxosl.
+    # 
--------------------------------------------------------------------------
+    def Stop(self):
+        """Stop libtuxosl.
+        """
         if self.tux_osl_lib == None:
             return
-            
+
+        self.__logger.logInfo("Stop the library.")
         self.tux_osl_lib.TuxOSL_Stop()
-        
+
+    # 
--------------------------------------------------------------------------
+    # Get the log file path.
+    # 
--------------------------------------------------------------------------
+    def getLogFilePath(self):
+        """Get the log file path.
+        @return: The log file path.
+        """
+        return self.__logger.getLogFilePath()
+
+    # 
--------------------------------------------------------------------------
+    # Perform a command through libtuxosl.
+    # 
--------------------------------------------------------------------------
     def PerformCommand(self, delay, command):
+        """Perform a command through libtuxosl.
+        @param delay: Delay before the command execution.
+        @param command: Command to execute.
+        @return: The success of the command performing.
+        """
         if self.tux_osl_lib == None:
             return E_TUXOSL_PARSERISDISABLED
-        
-        ret = self.tux_osl_lib.TuxOSL_PerformCommand(c_double(delay), 
c_char_p(command))
-        
+
+        ret = self.tux_osl_lib.TuxOSL_PerformCommand(c_double(delay),
+            c_char_p(command))
+
+        self.__logger.logDebug("Perform the cmd : cmd(%s) delay (%f)" % \
+            (command, delay))
+        self.__logger.logDebug("Returned : code(%s) expl(%s)" % (str(ret),
+            self.StrError(ret)))
+
         return ret
-            
+
+    # 
--------------------------------------------------------------------------
+    # Perform the content of a macro commands file through libtuxosl.
+    # 
--------------------------------------------------------------------------
     def PerformMacroFile(self, file_path = ""):
+        """Perform the content of a macro commands file through libtuxosl.
+        @param file_path: Macro commands file path.
+        @return: The success of the performing.
+        """
         if self.tux_osl_lib == None:
             return E_TUXOSL_PARSERISDISABLED
-            
+
         ret = self.tux_osl_lib.TuxOSL_PerformMacroFile(c_char_p(file_path))
-        
+
+        self.__logger.logDebug("Perform a macro : path(%s)" % file_path)
+        self.__logger.logDebug("Returned : code(%s) expl(%s)" % (str(ret),
+            self.StrError(ret)))
+
         return ret
-            
+
+    # 
--------------------------------------------------------------------------
+    # Perform a macro commands through libtuxosl.
+    # 
--------------------------------------------------------------------------
     def PerformMacroText(self, macro = ""):
+        """Perform a macro commands through libtuxosl.
+        @param macro: Macro commands text.
+        @return: The success of the performing.
+        """
         if self.tux_osl_lib == None:
             return E_TUXOSL_PARSERISDISABLED
-            
+
         ret = self.tux_osl_lib.TuxOSL_PerformMacroText(c_char_p(macro))
-        
+
+        self.__logger.logDebug("Perform a macro text : -->")
+        for line in macro.split('\n'):
+            self.__logger.logDebug("%s" % line)
+        self.__logger.logDebug("Returned : code(%s) expl(%s)" % (str(ret),
+            self.StrError(ret)))
+
         return ret
-            
+
+    # 
--------------------------------------------------------------------------
+    # Clear the stack of delayed commands.
+    # 
--------------------------------------------------------------------------
     def ClearCommandStack(self):
+        """Clear the stack of delayed commands.
+        """
         if self.tux_osl_lib == None:
             return
-            
+
         self.tux_osl_lib.TuxOSL_ClearCommandStack()
-        
+
+        self.__logger.logDebug("Clear the commands stack")
+
         return
 
+    # 
--------------------------------------------------------------------------
+    # Get the identifier of a status.
+    # 
--------------------------------------------------------------------------
     def GetStatusId(self, name = "osl_symbolic_version"):
+        """Get the identifier of a status.
+        @param name: Status name.
+        @return: The identifier as Integer.
+        """
         if self.tux_osl_lib == None:
             return -1
-            
+
         idc = c_int(0)
         idcp = pointer(idc)
         ret = self.tux_osl_lib.TuxOSL_GetStatusId(c_char_p(name), idcp)
-        
+
+        self.__logger.logDebug("Get status id : (%s) -> (%d)" % (name,
+            idc.value))
+        self.__logger.logDebug("Returned : code(%s) expl(%s)" % (str(ret),
+            self.StrError(ret)))
+
         if ret != E_TUXOSL_NOERROR:
             idc.value = -1
-            
+
         return idc.value
-    
+
+    # 
--------------------------------------------------------------------------
+    # Get the name of a status.
+    # 
--------------------------------------------------------------------------
     def GetStatusName(self, id = 0):
+        """Get the name of a status.
+        @param id: Identifier of the status.
+        @return: The name of the status or "UNDEFINED".
+        """
         if self.tux_osl_lib == None:
             return "UNDEFINED"
-            
+
         result = " " * 256
-        ret = self.tux_osl_lib.TuxOSL_GetStatusName(c_int(id), 
+        ret = self.tux_osl_lib.TuxOSL_GetStatusName(c_int(id),
             c_char_p(result))
         result = result.replace(" ", "")
-        
+
+        self.__logger.logDebug("Get status name : (%d) -> (%s)" % (id,
+            result))
+        self.__logger.logDebug("Returned : code(%s) expl(%s)" % (str(ret),
+            self.StrError(ret)))
+
         if ret == E_TUXOSL_NOERROR:
             return result
         else:
             return "UNDEFINED"
-        
+
+    # 
--------------------------------------------------------------------------
+    # Set the level of the internal logger of the libtuxdriver library.
+    # 
--------------------------------------------------------------------------
+    def SetLogLevel(self, level = LOG_LEVEL_INFO):
+        """Set the level of the internal logger of the libtuxdriver library.
+        @param level: (LOG_LEVEL_DEBUG|LOG_LEVEL_INFO|LOG_LEVEL_WARNING
+                      LOG_LEVEL_ERROR|LOG_LEVEL_NONE)
+        """
+        self.__logger.setLevel(level)
+
+    # 
--------------------------------------------------------------------------
+    # Get the state of a status.
+    # 
--------------------------------------------------------------------------
     def GetStatusState(self, id = 0):
+        """Get the state of a status.
+        @param id: Identifier of the status.
+        @return: The state of the status or "UNDEFINED".
+        """
         if self.tux_osl_lib == None:
             return "UNDEFINED"
-            
+
         result = " " * 256
-        ret = self.tux_osl_lib.TuxOSL_GetStatusState(c_int(id), 
+        ret = self.tux_osl_lib.TuxOSL_GetStatusState(c_int(id),
             c_char_p(result))
         result = result.replace(" ", "")
-        
+
+        self.__logger.logDebug("Get status state : (%d) -> (%s)" % (id,
+            result))
+        self.__logger.logDebug("Returned : code(%s) expl(%s)" % (str(ret),
+            self.StrError(ret)))
+
         if ret == E_TUXOSL_NOERROR:
             return result
         else:
             return "UNDEFINED"
-            
+
+    # 
--------------------------------------------------------------------------
+    # Get the value of a status.
+    # 
--------------------------------------------------------------------------
     def GetStatusValue(self, id = 0):
+        """Get the value of a status.
+        @param id: Identifier of the status.
+        @return: The value of the status or "UNDEFINED".
+        """
         if self.tux_osl_lib == None:
             return "UNDEFINED"
-            
+
         result = " " * 256
-        ret = self.tux_osl_lib.TuxOSL_GetStatusValue(c_int(id), 
+        ret = self.tux_osl_lib.TuxOSL_GetStatusValue(c_int(id),
             c_char_p(result))
         result = result.replace(" ", "")
-        
+
+        self.__logger.logDebug("Get status value : (%d) -> (%s)" % (id,
+            result))
+        self.__logger.logDebug("Returned : code(%s) expl(%s)" % (str(ret),
+            self.StrError(ret)))
+
         if ret == E_TUXOSL_NOERROR:
             return result
         else:
             return "UNDEFINED"
-            
+
+    # 
--------------------------------------------------------------------------
+    # Get the state of all statuses.
+    # 
--------------------------------------------------------------------------
     def GetAllStatusState(self):
+        """Get the state of all statuses.
+        @return: The state of all statuses.
+        """
         if self.tux_osl_lib == None:
             return ""
-            
+
         result = " " * 8182
         self.tux_osl_lib.TuxOSL_GetAllStatusState(c_char_p(result))
         result = result.replace(" ", "")
-        
+
+        self.__logger.logDebug("Get all statuses state : -->")
+        for line in result.split("\n"):
+            self.__logger.logDebug(line)
+
         return result
-            
+
+    # 
--------------------------------------------------------------------------
+    # Tokenize the state of a status.
+    # 
--------------------------------------------------------------------------
     def TokenizeStatus(self, status = ""):
+        """Tokenize the state of a status.
+        @param status: The state of the status.
+        @return: A tokens list.
+        """
         if self.tux_osl_lib == None:
             return []
-            
+
         result = status.split(":")
         if len(result) == 1:
             if result[0] == '':
                 result = []
         return result
-        
+
+    # 
--------------------------------------------------------------------------
+    # Get the structure of a status.
+    # 
--------------------------------------------------------------------------
     def GetStatusStruct(self, status = ""):
-        result = {'name' : "None", 'value' : None, 'delay' : 0.0}
-        
+        """Get the structure of a status.
+        @param status: The state of the status.
+        @return: The structure of a status.
+        """
+        result = {
+            'name' : "None",
+            'value' : None,
+            'delay' : 0.0,
+            'type' : 'string'
+        }
+
         if self.tux_osl_lib == None:
             return result
-            
+
         status_s = self.TokenizeStatus(status)
-        if len(status_s) == 0:
+        if len(status_s) != 4:
+            self.__logger.logError("Error in status structure : (%s)" % status)
             return result
-            
+
         result['name'] = status_s[0]
         result['delay'] = status_s[3]
-        
+        result['type'] = status_s[1]
+
         if status_s[1] in ['uint8', 'int8', 'int', 'float', 'bool']:
             result['value'] = eval(status_s[2])
         elif status_s[1] == 'string':
             result['value'] = status_s[2]
-            
+
         return result
-        
+
+    # 
--------------------------------------------------------------------------
+    # Get the explanation of an error code.
+    # 
--------------------------------------------------------------------------
     def StrError(self, error_code):
+        """Get the explanation of an error code.
+        @param error_code: Error code.
+        @return: The explanation as String.
+        """
         if self.tux_osl_lib == None:
             return "Shared library not found"
-         
+
         result = self.tux_osl_lib.TuxOSL_StrError(c_int(error_code))
 
         return c_char_p(result).value
-        
-if __name__ == "__main__":
-    
-    def on_status_event(status):
-        status_struct =  tux_osl.GetStatusStruct(status)
-        print status_struct
-        
-    tux_osl = TuxOSL()
-    
-    err = tux_osl.Start("Acapela")
-    if err != E_TUXOSL_NOERROR:
-        print tux_osl.StrError(err)
-        
-    tux_osl.PerformCommand(0.0, "OSL_CMD:TTS:SPEAK:Salut la compagnie !")
-        
-    import time
-    time.sleep(5)

Modified: 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/osl/__init__.py
===================================================================
--- 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/osl/__init__.py
     2008-12-14 13:55:17 UTC (rev 3113)
+++ 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/osl/__init__.py
     2008-12-14 14:04:42 UTC (rev 3114)
@@ -1,4 +1,4 @@
-# -*- coding: latin1 -*-
+# -*- coding: utf-8 -*-
 
 """
 LibTuxOSL
@@ -17,8 +17,8 @@
 __licence__ = version.licence
 del version
 
-#    Copyright (C) 2008 C2ME Sa
-#    R�mi Jocaille <[email protected]>
+#    Copyleft (C) 2008 C2ME Sa
+#    Remi Jocaille <[email protected]>
 #    Distributed under the terms of the GNU General Public License
 #    http://www.gnu.org/copyleft/gpl.html
 

Modified: 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/osl/version.py
===================================================================
--- 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/osl/version.py
      2008-12-14 13:55:17 UTC (rev 3113)
+++ 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/osl/version.py
      2008-12-14 14:04:42 UTC (rev 3114)
@@ -1,19 +1,19 @@
-# -*- coding: latin1 -*-
+# -*- coding: utf-8 -*-
 
 """Version data for LibTuxOSL"""
 
 __author__ = "Remi Jocaille ([email protected])"
 
-#    Copyright (C) 2008 C2ME Sa
-#    R�mi Jocaille <[email protected]>
+#    Copyleft (C) 2008 C2ME Sa
+#    Remi Jocaille <[email protected]>
 #    Distributed under the terms of the GNU General Public License
 #    http://www.gnu.org/copyleft/gpl.html
 
 name = 'tuxisalive.lib.osl'
-version = '0.0.2'
+version = '0.0.3'
 author = "Remi Jocaille ([email protected])"
 
-description = "Wrapper to libtuxosl shared library."
+description = "Wrapper of libtuxosl."
 
 licence = "GPL"
-date = "May 2008"
\ No newline at end of file
+date = "December 2008"
\ No newline at end of file


------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to