Author: jerome
Date: 2009-12-09 14:00:01 +0100 (Wed, 09 Dec 2009)
New Revision: 5964

Modified:
   
software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/plugin-skype.py
   
software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/utils.py
Log:
* Added some functionalities 
* Removed 'self' keyword for two static methods
* Start to implement IPN service.
* Added different commands.

Modified: 
software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/plugin-skype.py
===================================================================
--- 
software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/plugin-skype.py
   2009-12-09 11:56:53 UTC (rev 5963)
+++ 
software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/plugin-skype.py
   2009-12-09 13:00:01 UTC (rev 5964)
@@ -35,8 +35,11 @@
 import connector
 from communicator import SynchroniousCommands, AsynchroniousCommands
 from errors import EquipmentException, UnavailableContactException, 
UserNotFindException
-from utils import StringUtils
+from utils import StringUtils, TuxDroidServerUtils
 
+from IPN.IPNServer import IPNServer
+from IPN.IPNClient import IPNClient
+
 from util.SimplePlugin.SimplePluginConfiguration import 
SimplePluginConfiguration
 from util.SimplePlugin.SimplePlugin import SimplePlugin
  
@@ -75,28 +78,96 @@
     '''
     Skype plugin base class.
     '''
-    
+    #plugin uuid
+    uuid = "8349ed52-572d-4c3f-a7b8-f6d4a5ae2c0"
+    port = 270
     #Skype client - api objects.
     synchronious  = None
     asynchronious = None
     connectorObj  = None
     
+    ##----------------------------------------------------------------
+    ## * Skype plugin main entry point.
+    ##----------------------------------------------------------------
     def start(self):
         '''
         Plugin entry point.
         This method should be used to dispatch commands.
         '''
+        #Init port.
+        self.port = TuxDroidServerUtils.getServerPort()
+        
+        #Check for the command.
         if self.getCommand() == "runDaemon":
             self.runDaemon()
+        elif self.getCommand() == "incomingCall":
+            self.incomingCall()
+        elif self.getCommand() == "outgoingCall":
+            self.outgoingCall()
+        elif self.getCommand() == "endCall":
+            self.endCall()
         else:
             self.runDaemon()
     
+    ##----------------------------------------------------------------
+    ## * PLUGIN COMMAND : Set Tux Droid for an incoming call.
+    ##----------------------------------------------------------------
+    def incomingCall(self):
+        '''
+        Initialize Tux Droid switches for a call ( incoming or outgoing )
+        '''
+        self.initializeCommandsClient()
+        
+        #Create Tux Droid api and repare events.
+        
+        #Run main loop.
     
     
+    ##----------------------------------------------------------------
+    ## * PLUGIN COMMAND : Set Tux Droid for an incoming call.
+    ##----------------------------------------------------------------
+    def outgoingCall(self):
+        '''
+        Initialize Tux Droid for an outgoing call.
+        '''
+        self.initializeCommandsClient()
+    
+    
+    ##----------------------------------------------------------------
+    ## * PLUGIN COMMAND : Finish an incoming / outgoing call
+    ##----------------------------------------------------------------
+    def endCall(self):
+        '''
+        End an incoming or outgoing call.
+        '''
+        self.client.notify('finish_call')
+    
+    
+    def initializeCommandsClient(self):
+        '''
+        Initialize the commands sender ( client / server ).
+        '''
+        self.client = IPNClient('127.0.0.1', 48536)
+        self.client.registerOnNotificationCallBack(self.ClientOnNotification)
+        self.client.registerOnConnectedCallBack(self.ClientOnConnected)
+        self.client.registerOnDisconnectedCallBack(self.ClientOnDisconnected)
+        self.client.start()
+        
+    ##----------------------------------------------------------------
+    ##  * DAEMON command and functions.
+    ##----------------------------------------------------------------
+    
     def runDaemon(self):
         '''
         Run plugin command.
         '''
+        #Creating and starting server.
+        self.serv = IPNServer('127.0.0.1', 48536)
+        self.serv.registerOnClientAddedCallBack(self.ServerOnClientAdded)
+        self.serv.registerOnClientRemovedCallBack(self.ServerOnClientRemoved)
+        
self.serv.registerOnClientNotificationCallBack(self.ServerOnClientNotification)
+        self.serv.start()
+        
         #Initialize skype client and api objects.
         self.connectorObj = connector.Connector()
         self.connectorObj.OnAPIReady = self.initializeDaemon
@@ -142,7 +213,7 @@
         Incomming call refused because a call is already in progress
         '''
         #Sending a message to the call partner.
-        message = "Sorry, I'm already in call, please try again later"
+        message = "I am currently in a conversation, please call me back later"
         self.synchronious.sendTextMessage(contactHandle, message)
     
     
@@ -160,8 +231,17 @@
     
     def OnIncomingCall(self, contactHandle):
         '''
+        Incoming call event.
         '''
-        pass
+        #Set up Tux Droid motors.
+        self.throwActuation("upFlippers")
+        self.throwActuation("openMouth")
+        
+        #Starting the plugin with 'incomingCall' command.
+        command = 'incomingCall'
+        request = '/plugins_server/start_plugin?command='+ command + '&uuid='+ 
self.uuid +'&parameters='
+        
+        TuxDroidServerUtils.sendRequest("127.0.0.1", self.port, request)
     
     
     def OnIncomingFinished(self, contactHandle):
@@ -229,6 +309,8 @@
             time.sleep(2.0)
             #Setting Tux Droid as audio peripheral.
             try:
+                #Starting server that will listen to requests.
+                self.serv.start()
                 #in try statement to take calls in care.
                 if ( self.synchronious != None ) and ( not 
self.synchronious.isTuxDroidAudioCard() ):
                     self.synchronious.setAudioCards()
@@ -241,10 +323,53 @@
         '''
         OnPluginStop event.
         '''
-        self.connectorObj.stop()
+        if self.connectorObj != None:
+            if self.getCommand() == 'outgoingCall':
+                self.connectorObj.stop(KillClient=True)
+            else:
+                #In other cases, close connection but not skype client.
+                self.connectorObj.stop()
      
+     
+    ##----------------------------------------------------------------
+    ##  * DAEMON Client / Server IPN Communication.
+    ##----------------------------------------------------------------
+    def ServerOnClientAdded(self, idClient):
+        '''
+        '''
+        pass
+        
+    
+    def ServerOnClientRemoved(self, idClient):
+        '''
+        '''
+        pass
+        
+        
+    def ServerOnClientNotification(self, idClient, Message):
+        '''
+        '''
+        pass
+    
+    
+    def ClientOnNotification(self, Message):
+        '''
+        '''
+        pass
+        
+    
+    def ClientOnConnected(self, id):
+        '''
+        '''
+        pass
+        
+        
+    def ClientOnDisconnected(self):
+        '''
+        '''
+        pass
+        
 
-
 if __name__ == "__main__":
     plugin = SkypePlugin()
     plugin.boot(sys.argv[1:], SkypePluginConfiguration())   

Modified: 
software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/utils.py
===================================================================
--- 
software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/utils.py
  2009-12-09 11:56:53 UTC (rev 5963)
+++ 
software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/utils.py
  2009-12-09 13:00:01 UTC (rev 5964)
@@ -347,7 +347,7 @@
     Provide Tux Droid server utils functions.
     '''    
     
-    def getServerPort(self):
+    def getServerPort():
         '''
         Return the current server port.
         '''
@@ -360,7 +360,7 @@
                 return 54321
     
     
-    def sendRequest(self, host, port, request):
+    def sendRequest(host, port, request):
         '''
         Send a request to tuxhttpserver.
         '''


------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to