TCPSrvHostApp Class Reference

#include <TCPSrvHostApp.h>

List of all members.


Detailed Description

Hosts a server application, to be subclassed from TCPServerProcess (which is a sSimpleModule). Creates one instance (using dynamic module creation) for each incoming connection. More info in the corresponding NED file.

Public Member Functions

virtual void removeThread (TCPServerThreadBase *thread)

Protected Member Functions

virtual void initialize ()
virtual void handleMessage (cMessage *msg)
virtual void finish ()
virtual void updateDisplay ()

Protected Attributes

TCPSocket serverSocket
TCPSocketMap socketMap

Member Function Documentation

void TCPSrvHostApp::initialize (  )  [protected, virtual]

00022 {
00023     const char *address = par("address");
00024     int port = par("port");
00025 
00026     serverSocket.setOutputGate(gate("tcpOut"));
00027     serverSocket.bind(address[0] ? IPvXAddress(address) : IPvXAddress(), port);
00028     serverSocket.listen();
00029 }

void TCPSrvHostApp::handleMessage ( cMessage *  msg  )  [protected, virtual]

00041 {
00042     if (msg->isSelfMessage())
00043     {
00044         TCPServerThreadBase *thread = (TCPServerThreadBase *)msg->getContextPointer();
00045         thread->timerExpired(msg);
00046     }
00047     else
00048     {
00049         TCPSocket *socket = socketMap.findSocketFor(msg);
00050         if (!socket)
00051         {
00052             // new connection -- create new socket object and server process
00053             socket = new TCPSocket(msg);
00054             socket->setOutputGate(gate("tcpOut"));
00055 
00056             const char *serverThreadClass = par("serverThreadClass");
00057             TCPServerThreadBase *proc = check_and_cast<TCPServerThreadBase *>(createOne(serverThreadClass));
00058 
00059             socket->setCallbackObject(proc);
00060             proc->init(this, socket);
00061 
00062             socketMap.addSocket(socket);
00063 
00064             updateDisplay();
00065         }
00066         socket->processMessage(msg);
00067     }
00068 }

void TCPSrvHostApp::finish (  )  [protected, virtual]

00071 {
00072 }

void TCPSrvHostApp::updateDisplay (  )  [protected, virtual]

Referenced by handleMessage(), and removeThread().

00032 {
00033     if (!ev.isGUI()) return;
00034 
00035     char buf[32];
00036     sprintf(buf, "%d threads", socketMap.size());
00037     getDisplayString().setTagArg("t", 0, buf);
00038 }

void TCPSrvHostApp::removeThread ( TCPServerThreadBase thread  )  [virtual]

00075 {
00076     // remove socket
00077     socketMap.removeSocket(thread->getSocket());
00078 
00079     // remove thread object
00080     delete thread;
00081 
00082     updateDisplay();
00083 }


Member Data Documentation

Referenced by initialize().


The documentation for this class was generated from the following files:

Generated on Fri Mar 20 18:51:22 2009 for INET Framework for OMNeT++/OMNEST by  doxygen 1.5.5