|
INET Framework for OMNeT++/OMNEST
|
00001 // 00002 // Copyright 2004 Andras Varga 00003 // 00004 // This library is free software, you can redistribute it and/or modify 00005 // it under the terms of the GNU Lesser General Public License 00006 // as published by the Free Software Foundation; 00007 // either version 2 of the License, or any later version. 00008 // The library is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00011 // See the GNU Lesser General Public License for more details. 00012 // 00013 00014 #ifndef __INET_TCPSRVHOSTAPP_H 00015 #define __INET_TCPSRVHOSTAPP_H 00016 00017 #include <omnetpp.h> 00018 #include "TCPSocket.h" 00019 #include "TCPSocketMap.h" 00020 00021 00022 00023 class TCPServerThreadBase; 00024 00030 class INET_API TCPSrvHostApp : public cSimpleModule 00031 { 00032 protected: 00033 TCPSocket serverSocket; 00034 TCPSocketMap socketMap; 00035 00036 protected: 00037 virtual void initialize(); 00038 virtual void handleMessage(cMessage *msg); 00039 virtual void finish(); 00040 00041 virtual void updateDisplay(); 00042 00043 public: 00044 virtual void removeThread(TCPServerThreadBase *thread); 00045 }; 00046 00053 class INET_API TCPServerThreadBase : public cPolymorphic, public TCPSocket::CallbackInterface 00054 { 00055 protected: 00056 TCPSrvHostApp *hostmod; 00057 TCPSocket *sock; // ptr into socketMap managed by TCPSrvHostApp 00058 00059 protected: 00060 // internal: TCPSocket::CallbackInterface methods 00061 virtual void socketDataArrived(int, void *, cPacket *msg, bool urgent) {dataArrived(msg,urgent);} 00062 virtual void socketEstablished(int, void *) {established();} 00063 virtual void socketPeerClosed(int, void *) {peerClosed();} 00064 virtual void socketClosed(int, void *) {closed();} 00065 virtual void socketFailure(int, void *, int code) {failure(code);} 00066 virtual void socketStatusArrived(int, void *, TCPStatusInfo *status) {statusArrived(status);} 00067 public: 00068 // internal: called by TCPSrvHostApp after creating this module 00069 virtual void init(TCPSrvHostApp *hostmodule, TCPSocket *socket) {hostmod=hostmodule; sock=socket;} 00070 00071 public: 00072 TCPServerThreadBase() {sock=NULL;} 00073 virtual ~TCPServerThreadBase() {} 00074 00076 virtual TCPSocket *getSocket() {return sock;} 00077 00079 virtual TCPSrvHostApp *getHostModule() {return hostmod;} 00080 00085 virtual void scheduleAt(simtime_t t, cMessage *msg) {msg->setContextPointer(this); hostmod->scheduleAt(t,msg);} 00086 00088 virtual void cancelEvent(cMessage *msg) {hostmod->cancelEvent(msg);} 00089 00095 virtual void established() = 0; 00096 00100 virtual void dataArrived(cMessage *msg, bool urgent) = 0; 00101 00105 virtual void timerExpired(cMessage *timer) = 0; 00106 00111 virtual void peerClosed() {getSocket()->close();} 00112 00117 virtual void closed() {hostmod->removeThread(this);} 00118 00123 virtual void failure(int code) {hostmod->removeThread(this);} 00124 00130 virtual void statusArrived(TCPStatusInfo *status) {delete status;} 00132 }; 00133 00134 #endif 00135 00136