Author: jerome
Date: 2009-12-16 10:59:03 +0100 (Wed, 16 Dec 2009)
New Revision: 5986

Modified:
   
software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/connector.py
Log:
* Applied new comments guideline.

Modified: 
software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/connector.py
===================================================================
--- 
software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/connector.py
      2009-12-16 09:31:33 UTC (rev 5985)
+++ 
software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/connector.py
      2009-12-16 09:59:03 UTC (rev 5986)
@@ -26,42 +26,134 @@
 from time import sleep
 from threading import Thread
 from utils import ExtendedThread, SkypeClient
- 
+
+# 
==============================================================================
+# Declaration of the "connector" Object ( Skype client-api managment ).
+# 
==============================================================================
+
 class Connector(object):
     ''''
        This class manage the skype client-api connection
        '''
-    #This boolean flag indicates if Skype client was started by the connector
-    #To force close when connector shuts down.    
-    startedByConnector = False
+    #--------------------
+    # Public objects
+    #--------------------
+    
     #Event sent if Skype client was closed.
     OnSkypeClosed = None
+    #API ready event.
     OnAPIReady = None
-    triggerSkypeClosed = True
     
+    #--------------------
+    # Private objects
+    #--------------------
+    
+    #This boolean flag indicates if Skype client was started by the connector  
  
+    startedByConnector = False
+    triggerSkypeClosed = True
     #Skype4Py API object.
     skype   = None
     timeout = 60
     #Allow plugin to start commands or not. 
     lock     = False
     apiReady = False
-    
     #Skype client object.
-    skypeClient = None
-    
+    skypeClient = None 
     #Skype client Loop thread.
     __clientLoop__ = None
-    
-    
-###################################################
-#######          Private functions     ############
     
+    # 
==========================================================================
+    # Private methods
+    # 
==========================================================================
+    
+    # 
--------------------------------------------------------------------------
+    # Start the connector.
+    # 
--------------------------------------------------------------------------
+    def __start__(self, StartClient=True):
+        '''Start connection between client-application
+        '''
+        #Creating skype client helper object.
+        if os.name != 'nt':
+            self.skypeClient = SkypeClient(SkypeClient.LINUX)
+        else:
+            self.skypeClient = SkypeClient(SkypeClient.WINDOWS)
+        
+        #If skype client is not running start it and wait started to connect 
api
+        if ( not self.skypeClient.isRunning() ) and StartClient:
+            self.startedByConnector = True
+            self.skypeClient.OnSkypeStarted = self.__connect_all__
+            self.skypeClient.start()
+        #Else, connecting now.
+        else:
+            self.__connect_all__()
+    
+    # 
--------------------------------------------------------------------------
+    # Stop the connector.
+    # 
--------------------------------------------------------------------------
+    def __stop__(self, KillClient=False):
+        '''Stop all connections.
+        '''
+        self.skype.OnAttachmentStatus = None
+        if self.__clientLoop__ != None:
+            self.__clientLoop__.stop()
+        
+        if ( KillClient == True ) or self.startedByConnector:
+            #Quitting Skype client.
+            self.skypeClient.stop()
+        self.skype = None
+    
+    # 
--------------------------------------------------------------------------
+    # Initialize all ( events, skype api ) when Skype client is ready.
+    # 
--------------------------------------------------------------------------
+    def __connect_all__(self):
+        '''SkypeStarted received, so , connect all.
+        '''
+        #Initializing Skype4Py object.
+        if os.name == 'nt':
+            self.skype = Skype4Py.Skype()
+        else:
+            self.skype = Skype4Py.Skype(Transport='x11')
+
+        #Starting skype client check.
+        self.__clientLoop__ = ExtendedThread(target=self.__client_loop__)
+        self.__clientLoop__.start()
+        
+        self.skype.OnAttachmentStatus = self.__new_skype_status__
+        
+        self.apiReady = False
+        apiConnection = Thread(target= self.__connect_api__)
+        apiConnection.start()
+    
+    # 
--------------------------------------------------------------------------
+    # Connect skype api.
+    # 
--------------------------------------------------------------------------
+    def __connect_api__(self):
+        '''Connect skype api.
+        '''
+        sleep(2.0)
+        try:
+            self.skype.OnAttachmentStatus = self.__new_skype_status__
+            self.skype.Attach()
+                
+        except Exception:
+            self.apiReady = False
+    
+    # 
--------------------------------------------------------------------------
+    # Check for unexcpected client shutdown, used with 'ExtendedThread' object.
+    # 
--------------------------------------------------------------------------
+    def __client_loop__(self):
+        '''Check for skype client running(used with ExtendedThread object).
+        '''
+        #Check if skype is closed.
+        if not self.skypeClient.isRunning():
+            self.__onSkypeClosed__()
+            
+    # 
--------------------------------------------------------------------------
+    # Skype api Event handler, notify of new available API status. 
+    # 
--------------------------------------------------------------------------    
     def __new_skype_status__(self, status):
-        ''' Skype api Event handler. 
-        If Skype is closed and reopened, it informs us about it
-        so we can reattach.
+        '''If Skype is closed and reopened we can reattach.
         '''
-        
         #If api is not attached, then setting 'api not ready' values
         if status != Skype4Py.apiAttachSuccess:
             self.apiReady = False
@@ -80,23 +172,12 @@
                 #Notify client.
                 thread = Thread(target=self.OnAPIReady)
                 thread.start()
-            
-    
-    
-    def __client_loop__(self):
-        '''
-        Check for unexcpected client shutdown.
-        Used with 'ExtendedThread' object.
-        '''
-        #Check if skype is closed.
-        if not self.skypeClient.isRunning():
-            self.__onSkypeClosed__()
-    
-    
-    
+           
+    # 
--------------------------------------------------------------------------
+    # Skype client closed event.
+    # 
--------------------------------------------------------------------------
     def __onSkypeClosed__(self):
-        '''
-        Handle the case where Skype was closed, crashed, ...
+        '''Handle the case where Skype was closed, crashed, ...
         '''
         self.apiReady = False
                  
@@ -104,155 +185,94 @@
         if self.triggerSkypeClosed:
             if(self.OnSkypeClosed != None):
                 self.triggerSkypeClosed = False
-                self.OnSkypeClosed()
-      
-    
-    def __connect_api__(self):
-        '''
-        Connect skype api.
-        '''
-        sleep(2.0)
-        try:
-            self.skype.OnAttachmentStatus = self.__new_skype_status__
-            self.skype.Attach()
-                
-        except Exception:
-            self.apiReady = False
-        
-    
-    
-    def __connect_all__(self):
-        '''
-        SkypeStarted received, so , connect all.
-        '''
-        #Initializing Skype4Py object.
-        if os.name == 'nt':
-            self.skype = Skype4Py.Skype()
-        else:
-            self.skype = Skype4Py.Skype(Transport='x11')
-
-        #Starting skype client check.
-        self.__clientLoop__ = ExtendedThread(target=self.__client_loop__)
-        self.__clientLoop__.start()
-        
-        self.skype.OnAttachmentStatus = self.__new_skype_status__
-        
-        self.apiReady = False
-        apiConnection = Thread(target= self.__connect_api__)
-        apiConnection.start()
-    
-    
-    
-    def __start__(self, StartClient=True):
-        '''
-        Start connection between client-application
-        '''
-        #Creating skype client helper object.
-        if os.name != 'nt':
-            self.skypeClient = SkypeClient(SkypeClient.LINUX)
-        else:
-            self.skypeClient = SkypeClient(SkypeClient.WINDOWS)
-        
-        #If skype client is not running start it and wait started to connect 
api
-        if ( not self.skypeClient.isRunning() ) and StartClient:
-            self.startedByConnector = True
-            self.skypeClient.OnSkypeStarted = self.__connect_all__
-            self.skypeClient.start()
-        #Else, connecting now.
-        else:
-            self.__connect_all__()
-    
-    
-    
-    def __stop__(self, KillClient=False):
-        '''
-        Stop all connection and close Skyp application if needed.
-        '''
-        self.skype.OnAttachmentStatus = None
-        if self.__clientLoop__ != None:
-            self.__clientLoop__.stop()
-        
-        if ( KillClient == True ) or self.startedByConnector:
-            #Quitting Skype client.
-            self.skypeClient.stop()
-        self.skype = None
-    
+                self.OnSkypeClosed()
 
-###################################################
-#######          User functions    ################    
-     
+    # 
==========================================================================
+    # Private methods
+    # 
==========================================================================   
+    
+    # 
--------------------------------------------------------------------------
+    # Start connection.
+    # 
--------------------------------------------------------------------------
     def start(self, StartSkype=True):
-        '''
-        Start connection.
+        '''Start connection.
         '''
         self.__start__(StartClient = StartSkype)
-
     
+    # 
--------------------------------------------------------------------------
+    # Stop connection
+    # 
--------------------------------------------------------------------------
     def stop(self, KillClient=False):
+        '''Stop connection.
         '''
-        Stop connection.
-        '''
         self.__stop__(KillClient)
         
-    
+    # 
--------------------------------------------------------------------------
+    # Start skype client.
+    # 
--------------------------------------------------------------------------
     def startClient(self, OnStarted=None):
+        '''Start skype client.
         '''
-        Start skype client.
-        '''
         if OnStarted != None:
             self.skypeClient.OnSkypeStarted = OnStarted 
         self.skypeClient.start()
     
-    
+    # 
--------------------------------------------------------------------------
+    # Stop skype client.
+    # 
--------------------------------------------------------------------------
     def stopClient(self):
+        '''stop skype client.
         '''
-        stop skype client.
-        '''
         self.skypeClient.stop()
     
-    
+    # 
--------------------------------------------------------------------------
+    # Return client state
+    # 
--------------------------------------------------------------------------
     def isClientRunning(self):
+        '''Return client state
         '''
-        Return true if client is running, false otherwise.
-        '''
         return self.skypeClient.isRunning()
     
-    
+    # 
--------------------------------------------------------------------------
+    # Return Skype API state.
+    # 
--------------------------------------------------------------------------
     def isAPIReady(self):
+        '''Return true if skype api is ready.
         '''
-        Return true if skype api is ready.
-        '''
         return self.apiReady
     
-    
+    # 
--------------------------------------------------------------------------
+    # Return the shared skype api object.
+    # 
--------------------------------------------------------------------------
     def getSkypeAPI(self):
+        '''Return the shared skype api object.
         '''
-        Return the skype api object.
-        '''
         return self.skype
         
-    
+    # 
--------------------------------------------------------------------------
+    # Return 'lock' state.
+    # 
--------------------------------------------------------------------------
     def isSkypeLocked(self):
+        '''Return True if 'lock' was requested.
         '''
-        Return True if 'lock' was requested.
-        '''
         return self.lock 
     
-    
+    # 
--------------------------------------------------------------------------
+    # Get the lock.
+    # 
--------------------------------------------------------------------------
     def requestSkypeLock(self):
+        '''Get the lock ( lock will avoid to start commands ).
         '''
-        Get the lock ( lock will avoid to start commands ).
-        '''
         if(not self.lock):
             self.lock = True
         return self.lock
     
-    
+    # 
--------------------------------------------------------------------------
+    # Release a requested lock.
+    # 
--------------------------------------------------------------------------
     def releaseSkypeLock(self):
+        '''Release a requested lock.
         '''
-        Release a requested lock.
-        '''
         if(self.lock):
             self.lock = False
         return not self.lock
-


------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to