[tuxdroid-svn] r6038 - in software_suite_v3/software/plugin/plugin-skype/trunk: . executables exec
Status: Beta
Brought to you by:
ks156
From: jerome <c2m...@c2...> - 2010-01-06 10:06:08
|
Author: jerome Date: 2010-01-06 11:05:48 +0100 (Wed, 06 Jan 2010) New Revision: 6038 Added: software_suite_v3/software/plugin/plugin-skype/trunk/executables/EmoticonsToAttitunes.py software_suite_v3/software/plugin/plugin-skype/trunk/executables/IPN/ software_suite_v3/software/plugin/plugin-skype/trunk/executables/IPN/IPNClient.py software_suite_v3/software/plugin/plugin-skype/trunk/executables/IPN/IPNServer.py software_suite_v3/software/plugin/plugin-skype/trunk/executables/IPN/IPNSimpleTest.py software_suite_v3/software/plugin/plugin-skype/trunk/executables/IPN/IPNStressTest.py software_suite_v3/software/plugin/plugin-skype/trunk/executables/IPN/__init__.py software_suite_v3/software/plugin/plugin-skype/trunk/executables/IPN/version.py software_suite_v3/software/plugin/plugin-skype/trunk/executables/IPNCommands.py software_suite_v3/software/plugin/plugin-skype/trunk/executables/communicator.py software_suite_v3/software/plugin/plugin-skype/trunk/executables/connector.py software_suite_v3/software/plugin/plugin-skype/trunk/executables/errors.py software_suite_v3/software/plugin/plugin-skype/trunk/executables/tests/ software_suite_v3/software/plugin/plugin-skype/trunk/executables/tests/AsyncTests.py software_suite_v3/software/plugin/plugin-skype/trunk/executables/tests/ConnectionTests.py software_suite_v3/software/plugin/plugin-skype/trunk/executables/tests/SyncTests.py software_suite_v3/software/plugin/plugin-skype/trunk/executables/utils.py software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Airplane.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Angel.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Angry.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Asleep.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Auto.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Beer.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Birthday.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Camera.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Cat.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Clock.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Coffee.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Computer.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Confused.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Crying.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Disappointed.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Dog.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Duh.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Dunno.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Eating.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Email.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Embarrassed.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Filmstrip.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Gasp.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Gift.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Happy.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Heart.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Hugging.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Idea.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Island.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Kiss.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Laughing.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Laughing2.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Laughing_evil.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Laughing_wild.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Lightning.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Martini.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Mobile.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Money.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Nerd.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Note.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Party.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Sad.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Secret.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Sheep.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Shh.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Sick.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Soccer.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Star.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Sticking_out_tongue.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Stormy.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Telephone.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Winky.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/Yeah.att software_suite_v3/software/plugin/plugin-skype/trunk/resources/attitunes/breaking.att Removed: software_suite_v3/software/plugin/plugin-skype/trunk/executables/IPN/IPNClient.py software_suite_v3/software/plugin/plugin-skype/trunk/executables/IPN/IPNServer.py software_suite_v3/software/plugin/plugin-skype/trunk/executables/IPN/IPNSimpleTest.py software_suite_v3/software/plugin/plugin-skype/trunk/executables/IPN/IPNStressTest.py software_suite_v3/software/plugin/plugin-skype/trunk/executables/IPN/__init__.py software_suite_v3/software/plugin/plugin-skype/trunk/executables/IPN/version.py software_suite_v3/software/plugin/plugin-skype/trunk/executables/tests/AsyncTests.py software_suite_v3/software/plugin/plugin-skype/trunk/executables/tests/ConnectionTests.py software_suite_v3/software/plugin/plugin-skype/trunk/executables/tests/SyncTests.py Modified: software_suite_v3/software/plugin/plugin-skype/trunk/ software_suite_v3/software/plugin/plugin-skype/trunk/executables/plugin-skype.py software_suite_v3/software/plugin/plugin-skype/trunk/resources/de.po software_suite_v3/software/plugin/plugin-skype/trunk/resources/en.po software_suite_v3/software/plugin/plugin-skype/trunk/resources/fr.po software_suite_v3/software/plugin/plugin-skype/trunk/resources/help.wiki software_suite_v3/software/plugin/plugin-skype/trunk/resources/nl.po software_suite_v3/software/plugin/plugin-skype/trunk/resources/nl.wiki software_suite_v3/software/plugin/plugin-skype/trunk/resources/plugin.pot software_suite_v3/software/plugin/plugin-skype/trunk/resources/plugin.xml Log: * Merged trunk with in_out_plugin branch ( from rev 5915 to HEAD ). Property changes on: software_suite_v3/software/plugin/plugin-skype/trunk ___________________________________________________________________ Added: svn:mergeinfo + /software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin:5915-6037 Copied: software_suite_v3/software/plugin/plugin-skype/trunk/executables/EmoticonsToAttitunes.py (from rev 6037, software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/EmoticonsToAttitunes.py) =================================================================== --- software_suite_v3/software/plugin/plugin-skype/trunk/executables/EmoticonsToAttitunes.py (rev 0) +++ software_suite_v3/software/plugin/plugin-skype/trunk/executables/EmoticonsToAttitunes.py 2010-01-06 10:05:48 UTC (rev 6038) @@ -0,0 +1,109 @@ +# Copyright (C) 2009 Kysoh Sa +# Remi Jocaille <rem...@c2...> +# Distributed under the terms of the GNU General Public License +# http://www.gnu.org/copyleft/gpl.html + +EMOTICONS_TO_ATTITUNES = { + ':)' : "msn_happy", + ':-)' : "msn_happy", + ':d' : "msn_laughing", + ':-d' : "msn_laughing", + '=d' : "msn_laughing", + 'lol' : "msn_laughing", + 'mdr' : "msn_laughing_wild", + '(rofl)' : "msn_laughing_wild", + ':(' : "msn_sad", + ':-(' : "msn_sad", + ':p' : "msn_sticking_out_tongue", + ':-p' : "msn_sticking_out_tongue", + '=p' : "msn_sticking_out_tongue", + ';)' : "msn_winky", + ';-)' : "msn_winky", + ':o' : "msn_gasp", + ':-o' : "msn_gasp", + '(h)' : "msn_yeah", + 'b-)' : "msn_yeah", + '8-)' : "msn_duh", + '(doh)' : "msn_duh", + ':@' : "msn_angry", + ':-@' : "msn_angry", + 'x(' : "msn_angry", + 'x-(' : "msn_angry", + ':s' : "msn_confused", + ':-s' : "msn_confused", + 'o_o' : "msn_confused", + 'o.o' : "msn_confused", + '^o)' : "msn_confused", + ':$' : "msn_embarrassed", + '(blush)' : "msn_embarrassed", + ':-$' : "msn_embarrassed", + ":'(" : "msn_crying", + ";(" : "msn_crying", + ":'-(" : "msn_crying", + '(a)' : "msn_angel", + '(angel)' : "msn_angel", + '8o|' : "msn_angry", + '8-|' : "msn_nerd", + ':-|' : "msn_disappointed", + ':|' : "msn_disappointed", + ':-(' : "msn_disappointed", + '+o(' : "msn_sick", + '(puke)' : "msn_sick", + '<:o)' : "msn_party", + '(party)' : "msn_party", + '|-)' : "msn_asleep", + ':-#' : "msn_shh", + ':#' : "msn_shh", + ':-*' : "msn_secret", + ':^)' : "msn_dunno", + '*-)' : "msn_dunno", + '(l)' : "msn_kiss", + ':*' : "msn_kiss", + '(inlove)' : "msn_kiss", + '(u)' : "msn_crying", + '(@)' : "msn_cat", + '(&)' : "msn_dog", + '(bah)' : "msn_sheep", + '(sn)' : "msn_disappointed", + '(s)' : "msn_asleep", + '(t)' : "msn_telephone", + '(mp)' : "msn_mobile", + '(k)' : "msn_kiss", + '(6)' : "msn_laughing_evil", + ':-[' : "msn_laughing_evil", + ']:)' : "msn_laughing_evil", + ':[' : "msn_laughing_evil", + '(devil)' : "msn_laughing_evil", + '(o)' : "msn_clock", + '(f)' : "msn_kiss", + '(ap)' : "msn_airplane", + '(au)' : "msn_auto", + '(p)' : "msn_camera", + '(mo)' : "msn_money", + '(~)' : "msn_filmstrip", + '(b)' : "msn_beer", + '(beer)' : "msn_beer", + '(d)' : "msn_martini", + '(li)' : "msn_lightning", + '(st)' : "msn_stormy", + '(um)' : "msn_stormy", + '(e)' : "msn_email", + '(n)' : "msn_disappointed", + '(y)' : "msn_yeah", + '(c)' : "msn_coffee", + '(coffee)' : "msn_coffee", + '(pl)' : "msn_eating", + '(pi)' : "msn_eating", + '(||)' : "msn_eating", + '(i)' : "msn_idea", + '(^)' : "msn_birthday", + '({)' : "msn_hugging", + '(})' : "msn_hugging", + '(co)' : "msn_computer", + '(w)' : "msn_sad", + '(ip)' : "msn_island", + '(so)' : "msn_soccer", + '(*)' : "msn_star", + '(8)' : "msn_note", + '(g)' : "msn_gift", +} Deleted: software_suite_v3/software/plugin/plugin-skype/trunk/executables/IPN/IPNClient.py =================================================================== --- software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/IPN/IPNClient.py 2010-01-06 09:56:29 UTC (rev 6037) +++ software_suite_v3/software/plugin/plugin-skype/trunk/executables/IPN/IPNClient.py 2010-01-06 10:05:48 UTC (rev 6038) @@ -1,357 +0,0 @@ -# -*- coding: utf-8 -*- - -import version -__author__ = version.author -__date__ = version.date -__version__ = version.version -__licence__ = version.licence -del version - -# Copyright (C) 2009 Kysoh Sa -# Remi Jocaille <rem...@ky...> -# Distributed under the terms of the GNU General Public License -# http://www.gnu.org/copyleft/gpl.html - -import socket -import threading -import time - -# ============================================================================== -# Public class -# ============================================================================== - -# ------------------------------------------------------------------------------ -# Interprocess Notifier Client Class. -# ------------------------------------------------------------------------------ -class IPNClient(object): - """Interprocess Notifier Client Class. - """ - - # -------------------------------------------------------------------------- - # Constructor. - # -------------------------------------------------------------------------- - def __init__(self, host = '127.0.0.1', port = 271): - """Constructor. - @param host: Host address of the server. - @param port: Host port of the server. - """ - self.__host = host - self.__port = port - self.__socket = None - self.__run = False - self.__runThread = None - self.__runMutex = threading.Lock() - self.__onNotification = None - self.__onConnected = None - self.__onDisconnected = None - self.__notifyThreadsList = [] - self.__ntlMutex = threading.Lock() - self.__id = "0" - self.__msgStack = IPNClientStack() - - # -------------------------------------------------------------------------- - # Get the indentifier of the client. - # -------------------------------------------------------------------------- - def getId(self): - """Get the indentifier of the client. - @return: The identifier if connected ortherwise '0' as string. - """ - return self.__id - - # -------------------------------------------------------------------------- - # Register a callback function to the "On notification" event. - # -------------------------------------------------------------------------- - def registerOnNotificationCallBack(self, funct): - """Register a callback function to the "On notification" event. - @param funct: Function pointer. The function must accept one parameter. - Example : - def onNotification(message): - print message - """ - self.__onNotification = funct - - # -------------------------------------------------------------------------- - # Register a callback function to the "On connected" event. - # -------------------------------------------------------------------------- - def registerOnConnectedCallBack(self, funct): - """Register a callback function to the "On connected" event. - @param funct: Function pointer. The function must accept one parameter. - Example : - def onConnected(identifier): - print "Client connected with identifier :", identifier - """ - self.__onConnected = funct - - # -------------------------------------------------------------------------- - # - # -------------------------------------------------------------------------- - def registerOnDisconnectedCallBack(self, funct): - """Register a callback function to the "On disconnected" event. - @param funct: Function pointer. - Example : - def onDisconnected(): - print "Client disconnected" - """ - self.__onDisconnected = funct - - # -------------------------------------------------------------------------- - # Start the client. - # -------------------------------------------------------------------------- - def start(self): - """Start the client. - @return: The success of the client start. - """ - # Exit the function if the client is already started - if self.__getRun(): - return True - # Create the client socket - self.__socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - # Set the socket to blocking mode before to connect it to the server - self.__socket.setblocking(1) - try: - # Connect the client to the server - self.__socket.connect((self.__host, self.__port)) - # Read my client identifier - self.__id = self.__socket.recv(128).split('\n')[0] - except socket.timeout: - self.__setRun(False) - self.__socket.setblocking(0) - # Failed to connect the client to the server - return False - except socket.error: - self.__setRun(False) - self.__socket.setblocking(0) - # Failed to connect the client to the server - return False - # Set the socket to unblocking mode - self.__socket.setblocking(0) - # Set the socket timeout to 100 msec - self.__socket.settimeout(0.1) - # Call the "On connected" event - if self.__onConnected != None: - self.__onConnected(self.__id) - # Start the message listening loop - self.__runThread = threading.Thread(target = self.__runLoop) - self.__runThread.start() - time.sleep(0.1) - # The client is successfuly connected to the server - return True - - # -------------------------------------------------------------------------- - # Stop the client. - # -------------------------------------------------------------------------- - def stop(self): - """Stop the client. - """ - # Exit the function is the client is not started - if not self.__getRun(): - return - # Stop the message listening loop - self.__setRun(False) - # Ensure that the thread of the message listening loop has been closed - if self.__runThread.isAlive(): - if not self.__runThread.join(5.0): - self.__runThread._Thread__stop() - # Ensure that the notifications thread has been closed. - self.__stopNotifyThreadList() - - # -------------------------------------------------------------------------- - # Notify a message to the server. - # -------------------------------------------------------------------------- - def notify(self, message): - """Notify a message to the server. - """ - # Exit the function is the client is not started - if not self.__getRun(): - return - # Regularize the message length (0 > correct size < 124) - if len(message) > 123: - message = message[:122] - self.__msgStack.push(message) - - # -------------------------------------------------------------------------- - # Add thread in the threaded messages list. - # -------------------------------------------------------------------------- - def __addNotifyThread(self, thread): - """Add thread in the threaded messages list. - @param thread: Thread to be added. - """ - self.__ntlMutex.acquire() - self.__notifyThreadsList.append(thread) - self.__ntlMutex.release() - - # -------------------------------------------------------------------------- - # Wait that the client has stopped. - # -------------------------------------------------------------------------- - def waitStop(self): - """Wait that the client has stopped. - """ - while self.__getRun(): - time.sleep(0.5) - time.sleep(0.5) - - # -------------------------------------------------------------------------- - # Clean the closed thread from the threaded messages list. - # -------------------------------------------------------------------------- - def __cleanNotifyThreadList(self): - """Clean the closed thread from the threaded messages list in order to - avoiding a memory leak issue. - """ - self.__ntlMutex.acquire() - newLst = [] - for t in self.__notifyThreadsList: - if t.isAlive(): - newLst.append(t) - self.__notifyThreadsList = newLst - self.__ntlMutex.release() - - # -------------------------------------------------------------------------- - # Stop all threads from the threaded messages list. - # -------------------------------------------------------------------------- - def __stopNotifyThreadList(self): - """Stop all threads from the threaded messages list. - """ - self.__ntlMutex.acquire() - for t in self.__notifyThreadsList: - if t.isAlive(): - # Wait for a hypothetical self closing of the thread - try: - if not t.join(0.1): - # Otherwise, kill it - t._Thread__stop() - except ( AssertionError, RuntimeError ): - t._Thread__stop() - self.__ntlMutex.release() - - # -------------------------------------------------------------------------- - # Get the connection state of the client. - # -------------------------------------------------------------------------- - def __getRun(self): - """Get the connection state of the client. - @return: True or False. - """ - self.__runMutex.acquire() - result = self.__run - self.__runMutex.release() - return result - - # -------------------------------------------------------------------------- - # Set the connection state of the client. - # -------------------------------------------------------------------------- - def __setRun(self, value = True): - """Set the connection state of the client. - @param value: New value (True or False) - """ - self.__runMutex.acquire() - self.__run = value - self.__runMutex.release() - - # -------------------------------------------------------------------------- - # Loop listening message. - # -------------------------------------------------------------------------- - def __runLoop(self): - """Loop listening message. - """ - self.__setRun(True) - while self.__getRun(): - # Remove the closed threads from the threads list (garbage cleaning) - self.__cleanNotifyThreadList() - try: - # Wait a message from the server. (timeout at 100msec, defined - # in the function "start()") - data = self.__socket.recv(128) - # Extract the message from the frame - data = data.split('\n')[0] - # If the message is valid - if len(data) != 0: - # It's a PING - if data == "PING": - # Responding to the server - self.__socket.send("PONG") - time.sleep(0.01) - continue - # It's a notification request message - elif data == "GETNOTIFICATION": - # Responding to the server - message = self.__msgStack.pop() - if message == None: - self.__socket.send("PONG") - else: - self.__socket.send("RET:%s" % message) - time.sleep(0.01) - continue - # It's a notification message - else: - if self.__onNotification != None: - # Call the "On notification" event through a thread - # Store the thread in the threads list in order to - # stop all threads at the client closure - t = threading.Thread(target = self.__onNotification, - args = (data,)) - self.__addNotifyThread(t) - t.start() - time.sleep(0.01) - continue - except socket.timeout: - time.sleep(0.01) - # No message from the server ... - continue - except socket.error: - time.sleep(0.01) - # Server connection was broken, exit the loop ! - break - except: - time.sleep(0.01) - # Unexpected error, should never happen ... - continue - # The client must be disconnected - try: - self.__socket.close() - except: - pass - # Call the "On disconnected" event and reset the client identifier - if self.__id != "0": - if self.__onDisconnected != None: - self.__onDisconnected() - self.__id = "0" - -# ------------------------------------------------------------------------------ -# Interprocess Notifier Client Stack Class. -# ------------------------------------------------------------------------------ -class IPNClientStack(object): - """Interprocess Notifier Client Stack Class. - """ - - # -------------------------------------------------------------------------- - # Constructor. - # -------------------------------------------------------------------------- - def __init__(self): - """Constructor. - """ - self.__stack = [] - self.__mutex = threading.Lock() - - # -------------------------------------------------------------------------- - # Push a message to the stack. - # -------------------------------------------------------------------------- - def push(self, message): - """Push a message to the stack. - @param message: Message to push. - """ - self.__mutex.acquire() - self.__stack.insert(len(self.__stack), message) - self.__mutex.release() - - # -------------------------------------------------------------------------- - # Pop a message from the stack. - # -------------------------------------------------------------------------- - def pop(self): - """Pop a message from the stack. - @return: A message or None. - """ - result = None - self.__mutex.acquire() - if len(self.__stack) > 0: - result = self.__stack.pop(0) - self.__mutex.release() - return result Copied: software_suite_v3/software/plugin/plugin-skype/trunk/executables/IPN/IPNClient.py (from rev 6037, software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/IPN/IPNClient.py) =================================================================== --- software_suite_v3/software/plugin/plugin-skype/trunk/executables/IPN/IPNClient.py (rev 0) +++ software_suite_v3/software/plugin/plugin-skype/trunk/executables/IPN/IPNClient.py 2010-01-06 10:05:48 UTC (rev 6038) @@ -0,0 +1,357 @@ +# -*- coding: utf-8 -*- + +import version +__author__ = version.author +__date__ = version.date +__version__ = version.version +__licence__ = version.licence +del version + +# Copyright (C) 2009 Kysoh Sa +# Remi Jocaille <rem...@ky...> +# Distributed under the terms of the GNU General Public License +# http://www.gnu.org/copyleft/gpl.html + +import socket +import threading +import time + +# ============================================================================== +# Public class +# ============================================================================== + +# ------------------------------------------------------------------------------ +# Interprocess Notifier Client Class. +# ------------------------------------------------------------------------------ +class IPNClient(object): + """Interprocess Notifier Client Class. + """ + + # -------------------------------------------------------------------------- + # Constructor. + # -------------------------------------------------------------------------- + def __init__(self, host = '127.0.0.1', port = 271): + """Constructor. + @param host: Host address of the server. + @param port: Host port of the server. + """ + self.__host = host + self.__port = port + self.__socket = None + self.__run = False + self.__runThread = None + self.__runMutex = threading.Lock() + self.__onNotification = None + self.__onConnected = None + self.__onDisconnected = None + self.__notifyThreadsList = [] + self.__ntlMutex = threading.Lock() + self.__id = "0" + self.__msgStack = IPNClientStack() + + # -------------------------------------------------------------------------- + # Get the indentifier of the client. + # -------------------------------------------------------------------------- + def getId(self): + """Get the indentifier of the client. + @return: The identifier if connected ortherwise '0' as string. + """ + return self.__id + + # -------------------------------------------------------------------------- + # Register a callback function to the "On notification" event. + # -------------------------------------------------------------------------- + def registerOnNotificationCallBack(self, funct): + """Register a callback function to the "On notification" event. + @param funct: Function pointer. The function must accept one parameter. + Example : + def onNotification(message): + print message + """ + self.__onNotification = funct + + # -------------------------------------------------------------------------- + # Register a callback function to the "On connected" event. + # -------------------------------------------------------------------------- + def registerOnConnectedCallBack(self, funct): + """Register a callback function to the "On connected" event. + @param funct: Function pointer. The function must accept one parameter. + Example : + def onConnected(identifier): + print "Client connected with identifier :", identifier + """ + self.__onConnected = funct + + # -------------------------------------------------------------------------- + # + # -------------------------------------------------------------------------- + def registerOnDisconnectedCallBack(self, funct): + """Register a callback function to the "On disconnected" event. + @param funct: Function pointer. + Example : + def onDisconnected(): + print "Client disconnected" + """ + self.__onDisconnected = funct + + # -------------------------------------------------------------------------- + # Start the client. + # -------------------------------------------------------------------------- + def start(self): + """Start the client. + @return: The success of the client start. + """ + # Exit the function if the client is already started + if self.__getRun(): + return True + # Create the client socket + self.__socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + # Set the socket to blocking mode before to connect it to the server + self.__socket.setblocking(1) + try: + # Connect the client to the server + self.__socket.connect((self.__host, self.__port)) + # Read my client identifier + self.__id = self.__socket.recv(128).split('\n')[0] + except socket.timeout: + self.__setRun(False) + self.__socket.setblocking(0) + # Failed to connect the client to the server + return False + except socket.error: + self.__setRun(False) + self.__socket.setblocking(0) + # Failed to connect the client to the server + return False + # Set the socket to unblocking mode + self.__socket.setblocking(0) + # Set the socket timeout to 100 msec + self.__socket.settimeout(0.1) + # Call the "On connected" event + if self.__onConnected != None: + self.__onConnected(self.__id) + # Start the message listening loop + self.__runThread = threading.Thread(target = self.__runLoop) + self.__runThread.start() + time.sleep(0.1) + # The client is successfuly connected to the server + return True + + # -------------------------------------------------------------------------- + # Stop the client. + # -------------------------------------------------------------------------- + def stop(self): + """Stop the client. + """ + # Exit the function is the client is not started + if not self.__getRun(): + return + # Stop the message listening loop + self.__setRun(False) + # Ensure that the thread of the message listening loop has been closed + if self.__runThread.isAlive(): + if not self.__runThread.join(5.0): + self.__runThread._Thread__stop() + # Ensure that the notifications thread has been closed. + self.__stopNotifyThreadList() + + # -------------------------------------------------------------------------- + # Notify a message to the server. + # -------------------------------------------------------------------------- + def notify(self, message): + """Notify a message to the server. + """ + # Exit the function is the client is not started + if not self.__getRun(): + return + # Regularize the message length (0 > correct size < 124) + if len(message) > 123: + message = message[:122] + self.__msgStack.push(message) + + # -------------------------------------------------------------------------- + # Add thread in the threaded messages list. + # -------------------------------------------------------------------------- + def __addNotifyThread(self, thread): + """Add thread in the threaded messages list. + @param thread: Thread to be added. + """ + self.__ntlMutex.acquire() + self.__notifyThreadsList.append(thread) + self.__ntlMutex.release() + + # -------------------------------------------------------------------------- + # Wait that the client has stopped. + # -------------------------------------------------------------------------- + def waitStop(self): + """Wait that the client has stopped. + """ + while self.__getRun(): + time.sleep(0.5) + time.sleep(0.5) + + # -------------------------------------------------------------------------- + # Clean the closed thread from the threaded messages list. + # -------------------------------------------------------------------------- + def __cleanNotifyThreadList(self): + """Clean the closed thread from the threaded messages list in order to + avoiding a memory leak issue. + """ + self.__ntlMutex.acquire() + newLst = [] + for t in self.__notifyThreadsList: + if t.isAlive(): + newLst.append(t) + self.__notifyThreadsList = newLst + self.__ntlMutex.release() + + # -------------------------------------------------------------------------- + # Stop all threads from the threaded messages list. + # -------------------------------------------------------------------------- + def __stopNotifyThreadList(self): + """Stop all threads from the threaded messages list. + """ + self.__ntlMutex.acquire() + for t in self.__notifyThreadsList: + if t.isAlive(): + # Wait for a hypothetical self closing of the thread + try: + if not t.join(0.1): + # Otherwise, kill it + t._Thread__stop() + except ( AssertionError, RuntimeError ): + t._Thread__stop() + self.__ntlMutex.release() + + # -------------------------------------------------------------------------- + # Get the connection state of the client. + # -------------------------------------------------------------------------- + def __getRun(self): + """Get the connection state of the client. + @return: True or False. + """ + self.__runMutex.acquire() + result = self.__run + self.__runMutex.release() + return result + + # -------------------------------------------------------------------------- + # Set the connection state of the client. + # -------------------------------------------------------------------------- + def __setRun(self, value = True): + """Set the connection state of the client. + @param value: New value (True or False) + """ + self.__runMutex.acquire() + self.__run = value + self.__runMutex.release() + + # -------------------------------------------------------------------------- + # Loop listening message. + # -------------------------------------------------------------------------- + def __runLoop(self): + """Loop listening message. + """ + self.__setRun(True) + while self.__getRun(): + # Remove the closed threads from the threads list (garbage cleaning) + self.__cleanNotifyThreadList() + try: + # Wait a message from the server. (timeout at 100msec, defined + # in the function "start()") + data = self.__socket.recv(128) + # Extract the message from the frame + data = data.split('\n')[0] + # If the message is valid + if len(data) != 0: + # It's a PING + if data == "PING": + # Responding to the server + self.__socket.send("PONG") + time.sleep(0.01) + continue + # It's a notification request message + elif data == "GETNOTIFICATION": + # Responding to the server + message = self.__msgStack.pop() + if message == None: + self.__socket.send("PONG") + else: + self.__socket.send("RET:%s" % message) + time.sleep(0.01) + continue + # It's a notification message + else: + if self.__onNotification != None: + # Call the "On notification" event through a thread + # Store the thread in the threads list in order to + # stop all threads at the client closure + t = threading.Thread(target = self.__onNotification, + args = (data,)) + self.__addNotifyThread(t) + t.start() + time.sleep(0.01) + continue + except socket.timeout: + time.sleep(0.01) + # No message from the server ... + continue + except socket.error: + time.sleep(0.01) + # Server connection was broken, exit the loop ! + break + except: + time.sleep(0.01) + # Unexpected error, should never happen ... + continue + # The client must be disconnected + try: + self.__socket.close() + except: + pass + # Call the "On disconnected" event and reset the client identifier + if self.__id != "0": + if self.__onDisconnected != None: + self.__onDisconnected() + self.__id = "0" + +# ------------------------------------------------------------------------------ +# Interprocess Notifier Client Stack Class. +# ------------------------------------------------------------------------------ +class IPNClientStack(object): + """Interprocess Notifier Client Stack Class. + """ + + # -------------------------------------------------------------------------- + # Constructor. + # -------------------------------------------------------------------------- + def __init__(self): + """Constructor. + """ + self.__stack = [] + self.__mutex = threading.Lock() + + # -------------------------------------------------------------------------- + # Push a message to the stack. + # -------------------------------------------------------------------------- + def push(self, message): + """Push a message to the stack. + @param message: Message to push. + """ + self.__mutex.acquire() + self.__stack.insert(len(self.__stack), message) + self.__mutex.release() + + # -------------------------------------------------------------------------- + # Pop a message from the stack. + # -------------------------------------------------------------------------- + def pop(self): + """Pop a message from the stack. + @return: A message or None. + """ + result = None + self.__mutex.acquire() + if len(self.__stack) > 0: + result = self.__stack.pop(0) + self.__mutex.release() + return result Deleted: software_suite_v3/software/plugin/plugin-skype/trunk/executables/IPN/IPNServer.py =================================================================== --- software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/IPN/IPNServer.py 2010-01-06 09:56:29 UTC (rev 6037) +++ software_suite_v3/software/plugin/plugin-skype/trunk/executables/IPN/IPNServer.py 2010-01-06 10:05:48 UTC (rev 6038) @@ -1,490 +0,0 @@ -# -*- coding: utf-8 -*- - -import version -__author__ = version.author -__date__ = version.date -__version__ = version.version -__licence__ = version.licence -del version - -# Copyright (C) 2009 Kysoh Sa -# Remi Jocaille <rem...@ky...> -# Distributed under the terms of the GNU General Public License -# http://www.gnu.org/copyleft/gpl.html - -import socket -import threading -import time - -try: - from hashlib import md5 -except: - from md5 import md5 - -#from tuxisalive.lib.logger import * - -# Formated PING command -_PING_CMD = "PING\n" + "".join(" " * 123) -# Formated GETNOTIFICATION command -_GETNOTIFICATION_CMD = "GETNOTIFICATION\n" + "".join(" " * 112) - -# ============================================================================== -# Public class -# ============================================================================== - -# ------------------------------------------------------------------------------ -# Interprocess Notifier Server Class. -# ------------------------------------------------------------------------------ -class IPNServer(object): - """Interprocess Notifier Server Class. - """ - - # -------------------------------------------------------------------------- - # Constructor. - # -------------------------------------------------------------------------- - def __init__(self, host = '127.0.0.1', port = 271): - """Constructor. - @param host: Host IP to listen. - Example : '127.0.0.1' for local loop only. - Example : '192.168.0.1' for local network only. - Example : '' for internet access. - @param port: TCP port to listen. - """ - self.__cliLst = [] - self.__cliMutex = threading.Lock() - self.__socket = None - self.__host = host - self.__port = port - self.__runLst = False - self.__runLstThread = None - self.__runLstMutex = threading.Lock() - self.__runPing = False - self.__runPingThread = None - self.__runPingMutex = threading.Lock() - self.__notifyThreadsList = [] - self.__ntlMutex = threading.Lock() - self.__onClientAdded = None - self.__onClientRemoved = None - self.__onClientNotification = None - - # -------------------------------------------------------------------------- - # Register a callback function to the "On client added" event. - # -------------------------------------------------------------------------- - def registerOnClientAddedCallBack(self, funct): - """Register a callback function to the "On client added" event. - @param funct: Function pointer. The function must accept one parameter. - Example : - def onClientAdded(idClient): - print idClient - """ - self.__onClientAdded = funct - - # -------------------------------------------------------------------------- - # Register a callback function to the "On client removed" event. - # -------------------------------------------------------------------------- - def registerOnClientRemovedCallBack(self, funct): - """Register a callback function to the "On client removed" event. - @param funct: Function pointer. The function must accept one parameter. - Example : - def onClientRemoved(idClient): - print idClient - """ - self.__onClientRemoved = funct - - # -------------------------------------------------------------------------- - # Register a callback function to the "On client notification" event. - # -------------------------------------------------------------------------- - def registerOnClientNotificationCallBack(self, funct): - """Register a callback function to the "On client notification" event. - @param funct: Function pointer. The function must accept one parameter. - Example : - def onClientNotification(idClient, message): - print idClient - """ - self.__onClientNotification = funct - - # -------------------------------------------------------------------------- - # Check if a client exists. - # -------------------------------------------------------------------------- - def clientExists(self, id): - """Check if a client exists. - @param id: Id client. - @return: True or False. - """ - self.__cliMutex.acquire() - result = False - for cli in self.__cliLst: - if cli['id'] == id: - result = True - break - self.__cliMutex.release() - return result - - # -------------------------------------------------------------------------- - # Check if there have at least one connected client. - # -------------------------------------------------------------------------- - def hasClient(self): - '''Check if there have at least one connected client. - ''' - self.__cliMutex.acquire() - hasClient = 0 - try: - hasClient = len(self.__cliLst) > 0 - except: - pass - self.__cliMutex.release() - return hasClient - - # -------------------------------------------------------------------------- - # Start the server. - # -------------------------------------------------------------------------- - def start(self): - """Start the server. - @return: The success of the server start. True or False. - """ - # Exit the function if the server is already started - if self.__getRunLst(): - return True - # Create the server socket - self.__socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - try: - # Bind the socket - self.__socket.bind((self.__host, self.__port)) - # Set the socket to listen mode - self.__socket.listen(50) - #Run the listen loop and the ping loop - self.__runLstThread = threading.Thread(target = self.__listenLoop) - self.__runLstThread.start() - self.__runPingThread = threading.Thread(target = self.__pingLoop) - self.__runPingThread.start() - time.sleep(0.1) - # Server successfuly started - return True - except socket.timeout: - self.__setRunLst(False) - # Failed to start the server - return False - except socket.error: - self.__setRunLst(False) - # Failed to start the server - return False - except: - self.__setRunLst(False) - # Failed to start the server - return False - - # -------------------------------------------------------------------------- - # Stop the server. - # -------------------------------------------------------------------------- - def stop(self): - """Stop the server. - """ - # If the server don't runs then exit the function - if not self.__getRunLst(): - return - # Stop the listen loop - self.__setRunLst(False) - # Stop the ping loop - self.__setRunPing(False) - # Close the server socket - self.__socket.close() - time.sleep(0.1) - # Ensure that the threads have been stopped - if self.__runLstThread.isAlive(): - self.__runLstThread._Thread__stop() - if self.__runPingThread.isAlive(): - self.__runPingThread.join() - self.__stopNotifyThreadList() - # Clear the clients list - self.__clearClients() - - # -------------------------------------------------------------------------- - # Wait that the server has stopped. - # -------------------------------------------------------------------------- - def waitStop(self): - """Wait that the server has stopped. - """ - while self.__getRunLst(): - time.sleep(0.5) - time.sleep(0.5) - - # -------------------------------------------------------------------------- - # Add thread in the threaded messages list. - # -------------------------------------------------------------------------- - def __addNotifyThread(self, thread): - """Add thread in the threaded messages list. - @param thread: Thread to be added. - """ - self.__ntlMutex.acquire() - self.__notifyThreadsList.append(thread) - self.__ntlMutex.release() - - # -------------------------------------------------------------------------- - # Clean the closed thread from the threaded messages list. - # -------------------------------------------------------------------------- - def __cleanNotifyThreadList(self): - """Clean the closed thread from the threaded messages list in order to - avoiding a memory leak issue. - """ - self.__ntlMutex.acquire() - newLst = [] - for t in self.__notifyThreadsList: - if t.isAlive(): - newLst.append(t) - self.__notifyThreadsList = newLst - self.__ntlMutex.release() - - # -------------------------------------------------------------------------- - # Stop all threads from the threaded messages list. - # -------------------------------------------------------------------------- - def __stopNotifyThreadList(self): - """Stop all threads from the threaded messages list. - """ - self.__ntlMutex.acquire() - for t in self.__notifyThreadsList: - if t.isAlive(): - # Wait for a hypothetical self closing of the thread - if not t.join(0.1): - # Otherwise, kill it - t._Thread__stop() - self.__ntlMutex.release() - - # -------------------------------------------------------------------------- - # Get the state of the listening loop. - # -------------------------------------------------------------------------- - def __getRunLst(self): - """Get the state of the listening loop. - @return: True or False. - """ - self.__runLstMutex.acquire() - result = self.__runLst - self.__runLstMutex.release() - return result - - # -------------------------------------------------------------------------- - # Set the state of the listening loop. - # -------------------------------------------------------------------------- - def __setRunLst(self, value = True): - """Set the state of the listening loop. - @param value: New value (True or False) - """ - self.__runLstMutex.acquire() - self.__runLst = value - self.__runLstMutex.release() - - # -------------------------------------------------------------------------- - # Get the state of the ping loop. - # -------------------------------------------------------------------------- - def __getRunPing(self): - """Get the state of the ping loop. - @return: True or False. - """ - self.__runPingMutex.acquire() - result = self.__runPing - self.__runPingMutex.release() - return result - - # -------------------------------------------------------------------------- - # Set the state of the ping loop. - # -------------------------------------------------------------------------- - def __setRunPing(self, value = True): - """Set the state of the ping loop. - @param value: New value (True or False) - """ - self.__runPingMutex.acquire() - self.__runPing = value - self.__runPingMutex.release() - - # -------------------------------------------------------------------------- - # Add a new client in the clients list. - # -------------------------------------------------------------------------- - def __addClient(self, connection, address): - """Add a new client in the clients list. - @param connection: Client socket. - @param address: Client address. - """ - self.__cliMutex.acquire() - # Create a md5 hash of the socket address in order to make an unique - # identifier for the client. - md5H = md5() - md5H.update(str(address[0]) + str(address[1])) - id = md5H.hexdigest() - # Create a dictionary for the client configuration - cliConf = { - 'connection' : connection, - 'address' : address, - 'id' : id, - } - # Add the client to the list - self.__cliLst.append(cliConf) - # Create a 128 bytes length string with the id client. - idToSend = id + "\n" + "".join(" " * (127 - len(id))) - try: - # Send the identifer to the client - connection.send(idToSend) - except: - pass - self.__cliMutex.release() - # Call the "On client added" event - if self.__onClientAdded != None: - self.__onClientAdded(id) - - # -------------------------------------------------------------------------- - # Remove a client from the clients list. - # -------------------------------------------------------------------------- - def __removeClient(self, address): - """Remove a client from the clients list. - @param address: Client address. - """ - self.__cliMutex.acquire() - removedId = None - # Search the client address in the registered clients - for cli in self.__cliLst: - if cli['address'] == address: - cli['connection'].close() - self.__cliLst.remove(cli) - removedId = cli['id'] - break - self.__cliMutex.release() - # If the client has been removed then call the "On client removed" event - if removedId != None: - if self.__onClientRemoved != None: - self.__onClientRemoved(removedId) - - # -------------------------------------------------------------------------- - # Clear the clients list. - # -------------------------------------------------------------------------- - def __clearClients(self): - """Clear the clients list. - """ - self.__cliMutex.acquire() - self.__cliLst = [] - self.__cliMutex.release() - - # -------------------------------------------------------------------------- - # Socket listening loop. - # -------------------------------------------------------------------------- - def __listenLoop(self): - """Socket listening loop. - """ - self.__setRunLst(True) - while self.__getRunLst(): - try: - # Wait for a new client connection. This function is blocking - # the loop. The parent loop must be killed. - connection, address = self.__socket.accept() - # If the client socket is valid then add it to the clients list - if (connection != None) and (address != None): - self.__addClient(connection, address) - except: - pass - - # -------------------------------------------------------------------------- - # Ping loop. - # -------------------------------------------------------------------------- - def __pingLoop(self): - """Ping loop. - """ - self.__setRunPing(True) - while self.__getRunPing(): - aClientHasRemoved = False - self.__cliMutex.acquire() - # Ping all clients - for cli in self.__cliLst: - try: - # Send the PING command - cli['connection'].send(_PING_CMD) - # Read the client response - data = cli['connection'].recv(128) - except: - self.__cliMutex.release() - # If an error occuring during the client ping then remove it - # from the clients list - self.__removeClient(cli['address']) - aClientHasRemoved = True - self.__cliMutex.acquire() - break - if data != "PONG": - self.__cliMutex.release() - # If the client response is invalid then remove it from the - # clients list - self.__removeClient(cli['address']) - aClientHasRemoved = True - self.__cliMutex.acquire() - break - self.__cliMutex.release() - if aClientHasRemoved: - continue - # Read clients notifications (20x). - for i in range(20): - if not self.__getRunPing(): - break - # Remove the closed threads from the threads list - # (garbage cleaning) - self.__cleanNotifyThreadList() - self.__cliMutex.acquire() - for cli in self.__cliLst: - try: - # Send the GETNOTIFICATION command - cli['connection'].send(_GETNOTIFICATION_CMD) - # Read the client response - data = cli['connection'].recv(128) - except: - self.__cliMutex.release() - # If an error occuring during the client ping then remove it - # from the clients list - self.__removeClient(cli['addr... [truncated message content] |