Author: remi
Date: 2008-12-13 14:57:01 +0100 (Sat, 13 Dec 2008)
New Revision: 3076

Added:
   
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/
   
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/IPNClient.py
   
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/IPNServer.py
   
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/IPNStressTest.py
   
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/__init__.py
   
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/version.py
Modified:
   
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/__init__.py
Log:
* added "InterProcess Notifier" module. This module creates a light notifier 
(Based on the TCP protocol) between a server and its clients.

Added: 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/IPNClient.py
===================================================================
--- 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/IPNClient.py
                            (rev 0)
+++ 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/IPNClient.py
    2008-12-13 13:57:01 UTC (rev 3076)
@@ -0,0 +1,276 @@
+# -*- coding: utf-8 -*-
+
+import version
+__author__ = version.author
+__date__ = version.date
+__version__ = version.version
+__licence__ = version.licence
+del version
+
+#    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
+
+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"
+
+    # 
--------------------------------------------------------------------------
+    # 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()
+
+    # 
--------------------------------------------------------------------------
+    # 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 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 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"


Property changes on: 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/IPNClient.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/IPNServer.py
===================================================================
--- 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/IPNServer.py
                            (rev 0)
+++ 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/IPNServer.py
    2008-12-13 13:57:01 UTC (rev 3076)
@@ -0,0 +1,360 @@
+# -*- coding: utf-8 -*-
+
+import version
+__author__ = version.author
+__date__ = version.date
+__version__ = version.version
+__licence__ = version.licence
+del version
+
+#    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
+
+import socket
+import threading
+import time
+
+try:
+    from hashlib import md5
+except:
+    from md5 import md5
+
+# Formated PING command
+_PING_CMD = "PING\n" + "".join(" " * 123)
+
+# 
==============================================================================
+# 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.__onClientAdded = None
+        self.__onClientRemoved = 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
+
+    # 
--------------------------------------------------------------------------
+    # 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
+
+    # 
--------------------------------------------------------------------------
+    # 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()
+        # Clear the clients list
+        self.__clearClients()
+
+    # 
--------------------------------------------------------------------------
+    # 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()
+            # Wait 2 seconds beetwen the next ping cycle is no client has been
+            # removed
+            if not aClientHasRemoved:
+                time.sleep(2.)
+
+    # 
--------------------------------------------------------------------------
+    # Send a message to the connected clients.
+    # 
--------------------------------------------------------------------------
+    def notify(self, message):
+        """Send a message to the connected clients.
+        @param message: Message to notify. The maximal size of a message is 127
+                        characters.
+        """
+        # Regularize the message length (0 > correct size < 128)
+        if len(message) > 127:
+            message = message[:126]
+        if len(message) == 0:
+            message = "NOTIFY"
+        message = message + "\n" + "".join(" " * (127 - len(message)))
+        self.__cliMutex.acquire()
+        # Send the message to all registered clients
+        for cli in self.__cliLst:
+            try:
+                cli['connection'].send(message)
+            except:
+                # No special action if the client connection is broken, it will
+                # be removed by the "ping" loop
+                pass
+        # Can't sent another message while 100 msec
+        time.sleep(0.1)
+        self.__cliMutex.release()


Property changes on: 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/IPNServer.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/IPNStressTest.py
===================================================================
--- 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/IPNStressTest.py
                                (rev 0)
+++ 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/IPNStressTest.py
        2008-12-13 13:57:01 UTC (rev 3076)
@@ -0,0 +1,97 @@
+# -*- coding: utf-8 -*-
+
+import version
+__author__ = version.author
+__date__ = version.date
+__version__ = version.version
+__licence__ = version.licence
+del version
+
+#    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
+
+import threading
+import time
+
+from IPNServer import IPNServer
+from IPNClient import IPNClient
+
+# 
==============================================================================
+# Server functions
+# 
==============================================================================
+
+# 
------------------------------------------------------------------------------
+# Callback function on "client added" event.
+# 
------------------------------------------------------------------------------
+def serverOnClientAdded(idClient):
+    print "[Server] New client :", idClient
+
+# 
------------------------------------------------------------------------------
+# Callback function on "client removed" event.
+# 
------------------------------------------------------------------------------
+def serverOnClientRemoved(idClient):
+    print "[Server] Removed client :", idClient
+
+# 
------------------------------------------------------------------------------
+# Function to create a IPN server.
+# 
------------------------------------------------------------------------------
+def serverProcess(timeout = 100.0):
+    serv = IPNServer()
+    serv.registerOnClientAddedCallBack(serverOnClientAdded)
+    serv.registerOnClientRemovedCallBack(serverOnClientRemoved)
+    if serv.start():
+        for i in range(int(timeout / 0.1)):
+            serv.notify("Hello")
+            time.sleep(0.001)
+        serv.stop()
+
+# 
==============================================================================
+# Client functions
+# 
==============================================================================
+
+# 
------------------------------------------------------------------------------
+# Callback function on "connected" event.
+# 
------------------------------------------------------------------------------
+def clientOnConnected(id):
+    print "[Client] Connected with id : ", id
+
+# 
------------------------------------------------------------------------------
+# Callback function on "disconnected" event.
+# 
------------------------------------------------------------------------------
+def clientOnDisconnected():
+    print "[Client] Disconnected"
+
+# 
------------------------------------------------------------------------------
+# Callback function on "notification" event.
+# 
------------------------------------------------------------------------------
+def clientOnNotification(message):
+    print "[Client] Message :", message
+
+# 
------------------------------------------------------------------------------
+# Create a IPN client.
+# 
------------------------------------------------------------------------------
+def clientProcess(timeout = 10.0):
+    cli = IPNClient()
+    #cli.registerOnNotificationCallBack(clientOnNotification)
+    cli.registerOnConnectedCallBack(clientOnConnected)
+    cli.registerOnDisconnectedCallBack(clientOnDisconnected)
+    if cli.start():
+        time.sleep(timeout)
+        cli.stop()
+    else:
+        print "Client can't be connected"
+
+# 
------------------------------------------------------------------------------
+# Main
+# 
------------------------------------------------------------------------------
+if __name__ == '__main__':
+    # Create a IPN server
+    t = threading.Thread(target = serverProcess, args = (15.0,))
+    t.start()
+    # Create 50 IPN clients
+    for i in range(50):
+        t = threading.Thread(target = clientProcess, args = (5.0,))
+        t.start()
+        time.sleep(0.02)


Property changes on: 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/IPNStressTest.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/__init__.py
===================================================================
--- 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/__init__.py
                             (rev 0)
+++ 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/__init__.py
     2008-12-13 13:57:01 UTC (rev 3076)
@@ -0,0 +1,29 @@
+# -*- coding: utf-8 -*-
+
+"""
+IPN
+===
+
+    InterProcess Notifier module.
+
+    http://www.tuxisalive.com
+"""
+
+import version
+__name__ = version.name
+__author__ = version.author
+__date__ = version.date
+__version__ = version.version
+__licence__ = version.licence
+del version
+
+#    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
+
+#
+# IPN package modules
+#
+from tuxisalive.lib.IPN.IPNServer import *
+from tuxisalive.lib.IPN.IPNClient import *


Property changes on: 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/version.py
===================================================================
--- 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/version.py
                              (rev 0)
+++ 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/version.py
      2008-12-13 13:57:01 UTC (rev 3076)
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+
+"""Version data for tuxisalive.lib.IPN"""
+
+__author__ = "Remi 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.IPN'
+version = '0.0.1'
+author = "Remi Jocaille ([email protected])"
+
+description = "InterProcess Notifier module"
+
+licence = "GPL"
+date = "December 2008"


Property changes on: 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/version.py
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/__init__.py
===================================================================
--- 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/__init__.py
 2008-12-13 13:46:06 UTC (rev 3075)
+++ 
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/__init__.py
 2008-12-13 13:57:01 UTC (rev 3076)
@@ -7,6 +7,7 @@
 import tuxup
 import misc
 import attitunes
+import IPN
 
 import os
 if os.name == 'nt':


------------------------------------------------------------------------------
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