OverSim
BaseTcpSupport.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2010 Institut fuer Telematik, Karlsruher Institut fuer Technologie (KIT)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
24 #ifndef BASETCPSUPPORT_H_
25 #define BASETCPSUPPORT_H_
26 
27 #include <omnetpp.h>
28 #include <map>
29 #include <TransportAddress.h>
30 #include <TCPSocket.h>
31 #include <ExtTCPSocketMap.h>
32 
33 class BaseTcpSupport : public TCPSocket::CallbackInterface
34 {
35 public:
36 
37  // Event codes
39 
40  // Utility methods of the CallbackInterface
41  virtual void socketDataArrived(int connId, void *yourPtr, cPacket *msg, bool urgent);
42  virtual void socketEstablished(int connId, void *yourPtr);
43  virtual void socketPeerClosed(int connId, void *yourPtr);
44 // virtual void socketClosed(int connId, void *yourPtr);
45  virtual void socketFailure(int connId, void *yourPtr, int code);
46  virtual void socketStatusArrived(int connId, void *yourPtr, TCPStatusInfo *status) {delete status;}
47 
48 protected:
49 
53  void handleTCPMessage(cMessage* msg);
54 
60  void bindAndListenTcp(int port);
61 
68 
75 
82  void sendTcpData(cPacket* msg, TransportAddress address);
83 
90  virtual void handleConnectionEvent(EvCode code, TransportAddress address);
91 
99  virtual void handleDataReceived(TransportAddress address, cPacket* msg, bool urgent);
100 
106  virtual void handleIncomingConnection(TransportAddress address);
107 
113  void closeTcpConnection(TransportAddress address);
114 
120  void setTcpOut(cGate* gate) {tcpOut = gate;}
121 
127  cGate* getTcpOut() {return tcpOut;}
128 
129 private:
130 
132  typedef std::vector<cMessage*> msgQueue;
133  typedef std::map<TransportAddress, msgQueue*> transQueue;
135 
136  cGate* tcpOut;
137 };
138 
139 #endif /* BASETCPSUPPORT_H_ */