Public Member Functions | Protected Member Functions | Protected Attributes

TCPSrvHostApp Class Reference

#include <TCPSrvHostApp.h>

List of all members.

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

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.

Definition at line 30 of file TCPSrvHostApp.h.


Member Function Documentation

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

Definition at line 70 of file TCPSrvHostApp.cc.

{
}

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

Definition at line 40 of file TCPSrvHostApp.cc.

{
    if (msg->isSelfMessage())
    {
        TCPServerThreadBase *thread = (TCPServerThreadBase *)msg->getContextPointer();
        thread->timerExpired(msg);
    }
    else
    {
        TCPSocket *socket = socketMap.findSocketFor(msg);
        if (!socket)
        {
            // new connection -- create new socket object and server process
            socket = new TCPSocket(msg);
            socket->setOutputGate(gate("tcpOut"));

            const char *serverThreadClass = par("serverThreadClass");
            TCPServerThreadBase *proc = check_and_cast<TCPServerThreadBase *>(createOne(serverThreadClass));

            socket->setCallbackObject(proc);
            proc->init(this, socket);

            socketMap.addSocket(socket);

            updateDisplay();
        }
        socket->processMessage(msg);
    }
}

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

Definition at line 21 of file TCPSrvHostApp.cc.

{
    const char *address = par("address");
    int port = par("port");

    serverSocket.setOutputGate(gate("tcpOut"));
    serverSocket.bind(address[0] ? IPvXAddress(address) : IPvXAddress(), port);
    serverSocket.listen();
}

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

Definition at line 74 of file TCPSrvHostApp.cc.

{
    // remove socket
    socketMap.removeSocket(thread->getSocket());

    // remove thread object
    delete thread;

    updateDisplay();
}

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

Definition at line 31 of file TCPSrvHostApp.cc.

Referenced by handleMessage(), and removeThread().

{
    if (!ev.isGUI()) return;

    char buf[32];
    sprintf(buf, "%d threads", socketMap.size());
    getDisplayString().setTagArg("t", 0, buf);
}


Member Data Documentation

Definition at line 33 of file TCPSrvHostApp.h.

Referenced by initialize().

Definition at line 34 of file TCPSrvHostApp.h.

Referenced by handleMessage(), removeThread(), and updateDisplay().


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