[tuxdroid-svn] r5971 - software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/execut
Status: Beta
Brought to you by:
ks156
|
From: jerome <c2m...@c2...> - 2009-12-13 12:51:56
|
Author: jerome
Date: 2009-12-13 13:22:25 +0100 (Sun, 13 Dec 2009)
New Revision: 5971
Modified:
software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/plugin-skype.py
Log:
* Getting incoming calls.
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-13 12:19:10 UTC (rev 5970)
+++ software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/plugin-skype.py 2009-12-13 12:22:25 UTC (rev 5971)
@@ -79,12 +79,18 @@
'''
#plugin uuid
uuid = "8349ed52-572d-4c3f-a7b8-f6d4a5ae2c0"
+
port = 270
#Skype client - api objects.
synchronious = None
asynchronious = None
connectorObj = None
+ #Used for run command only.
+ ready = False
+ command = ""
+ canrun = True
+
##----------------------------------------------------------------
## * Skype plugin main entry point.
##----------------------------------------------------------------
@@ -99,78 +105,62 @@
#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()
+ elif self.getCommand() == "run":
+ self.run()
else:
self.runDaemon()
##----------------------------------------------------------------
- ## * PLUGIN COMMAND : Set Tux Droid for an incoming call.
+ ## * PLUGIN COMMAND : Set Tux Droid for a call.
##----------------------------------------------------------------
- def incomingCall(self):
+ def run(self):
'''
Initialize Tux Droid switches for a call ( incoming or outgoing )
'''
- self.initializeCommandsClient()
+ self.client = IPNClient('127.0.0.1', 48536)
+ self.client.registerOnNotificationCallBack(self.ClientOnNotification)
+ self.client.registerOnConnectedCallBack(self.ClientOnConnected)
+ self.client.start()
- #Run main loop.
- thread = threading.Thread(target=self.mainloop)
- thread.start()
def incomingPluginEvent(self, eventName, eventValues):
'''
Tux Droid plugin event callback.
'''
- try:
- #Check for IPN client started.
- if not self.client.start():
- return
+ if not self.ready:
+ return
+
+ if self.command == 'incoming':
#Accept call
if eventName == 'head':
self.client.notify('accept_call')
#Reject Call
elif eventName in ['left', 'right']:
self.client.notify('reject_call')
- finally:
- #Quit plugin
-
-
-
- ##----------------------------------------------------------------
- ## * PLUGIN COMMAND : Set Tux Droid for an incoming call.
- ##----------------------------------------------------------------
- def outgoingCall(self):
+ #Quit run mode plugin.
+ self.stop()
+
+
+ def ClientOnNotification(self, Message):
'''
- Initialize Tux Droid for an outgoing call.
+ Recieved a message from server.
'''
- self.initializeCommandsClient()
+ if Message == 'command>incoming':
+ self.throwNotification("start")
+ self.throwActuation("upFlippers")
+ self.throwActuation("openMouth")
+ self.throwNotification("stop")
+ self.ready = True
+ self.command = 'incoming'
+
-
- ##----------------------------------------------------------------
- ## * PLUGIN COMMAND : Finish an incoming / outgoing call
- ##----------------------------------------------------------------
- def endCall(self):
+ def ClientOnConnected(self, id):
'''
- 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()
+ pass
+
##----------------------------------------------------------------
## * DAEMON command and functions.
##----------------------------------------------------------------
@@ -252,20 +242,29 @@
Incoming call event.
'''
#Set up Tux Droid motors.
- self.throwActuation("upFlippers")
- self.throwActuation("openMouth")
-
- #Starting the plugin with 'incomingCall' command.
- command = 'incomingCall'
+ thread = threading.Thread(target=self.startRunMode)
+ thread.start()
+
+
+
+ def startRunMode(self):
+ '''
+ Starting the plugin with 'incomingCall' command.
+ '''
+ command = 'run'
request = '/plugins_server/start_plugin?command='+ command + '&uuid='+ self.uuid +'¶meters='
-
TuxDroidServerUtils.sendRequest("127.0.0.1", self.port, request)
+ self.command = 'incoming'
def OnIncomingFinished(self, contactHandle):
'''
'''
- pass
+ #Set up Tux Droid motors.
+ self.throwNotification("start")
+ self.throwActuation("downFlippers")
+ self.throwActuation("closeMouth")
+ self.throwNotification("stop")
@@ -318,7 +317,6 @@
pass
-
def mainloop(self):
'''
Run main loop.
@@ -327,8 +325,6 @@
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()
@@ -346,6 +342,7 @@
'''
if self.connectorObj != None:
if self.getCommand() == 'outgoingCall':
+ #TODO update this function.
self.connectorObj.stop(KillClient=True)
else:
#In other cases, close connection but not skype client.
@@ -360,19 +357,18 @@
@param eventValues: Event values.
'''
#Start the adequate function for each plugin command.
- if self.getCommand() == 'incomingCall':
+ if self.getCommand() == 'run':
self.incomingPluginEvent(eventName, eventValues)
- else:
- pass
+
+
-
##----------------------------------------------------------------
## * DAEMON Client / Server IPN Communication.
##----------------------------------------------------------------
def ServerOnClientAdded(self, idClient):
'''
'''
- pass
+ self.serv.notify( "command>" + self.command )
def ServerOnClientRemoved(self, idClient):
@@ -384,26 +380,14 @@
def ServerOnClientNotification(self, idClient, Message):
'''
'''
- pass
-
-
- def ClientOnNotification(self, Message):
- '''
- '''
- pass
+ if Message == 'accept_call':
+ if self.asynchronious.call != None:
+ #Take call
+ self.synchronious.acceptCall(self.asynchronious.call)
+ elif Message == 'reject_call' :
+ #Reject call.
+ self.synchronious.rejectCall()
-
- def ClientOnConnected(self, id):
- '''
- '''
- pass
-
-
- def ClientOnDisconnected(self):
- '''
- '''
- pass
-
if __name__ == "__main__":
plugin = SkypePlugin()
|