00001
00002 #ifndef UDPConnection_h_DEFINED
00003 #define UDPConnection_h_DEFINED
00004
00005 #include <ant.h>
00006 #include <IPAddress.h>
00007 #include <OPENR/OSyslog.h>
00008
00010 enum ConnectionState {
00011 CONNECTION_INVALID =0,
00012 CONNECTION_CLOSED =1,
00013 CONNECTION_BINDED =2,
00014 CONNECTION_WAITING =3,
00015 CONNECTION_LISTENING =4,
00016 CONNECTION_SENDING =5,
00017 CONNECTION_RECEIVING =6,
00018 CONNECTION_CLOSING =7,
00019 CONNECTION_WAITING_ACK =8
00020 };
00021
00024 class UDPConnection {
00025 public:
00028 UDPConnection() {state = CONNECTION_INVALID;};
00032 UDPConnection(antStackRef ipStack) {ipstackRef=ipStack; state = CONNECTION_CLOSED; };
00033
00035 virtual ~UDPConnection() {};
00036
00039 inline antModuleRef& getEndpoint() {return endpoint;};
00042 inline void setState(ConnectionState st) {state = st;};
00045 inline ConnectionState getState() {return state;};
00046
00051 virtual OStatus initConnection() = 0;
00057 virtual OStatus stop() = 0;
00058
00059 protected:
00060 antModuleRef endpoint;
00061 antStackRef ipstackRef;
00063 ConnectionState state;
00065 };
00066
00069 class UDPRecvConnection : public UDPConnection {
00070 public:
00072 UDPRecvConnection() {};
00077 UDPRecvConnection(antStackRef ipStack, int bs, Port port);
00078
00080 ~UDPRecvConnection();
00081
00085 OStatus initConnection();
00091 OStatus stop();
00092
00095 inline byte* getRecvData() { return recvData;};
00098 inline int getRecvSize() { return recvSize;}
00099
00100 private:
00101
00102 antSharedBuffer recvBuffer;
00103 byte* recvData;
00104 int recvSize;
00105
00106 Port recvPort;
00107
00108 OStatus initBuffer();
00109 OStatus initUdpEndpoint();
00110 OStatus initBind();
00111 };
00112
00113
00116 class UDPSendConnection : public UDPConnection {
00117 public:
00119 UDPSendConnection() {};
00123 UDPSendConnection(antStackRef ipStack, int bs);
00124
00126 ~UDPSendConnection();
00127
00131 OStatus initConnection();
00137 OStatus stop();
00138
00142 byte* getSendData() {return sendData;};
00146 inline int getSendSize() { return sendSize;}
00150 inline void setSendSize(int size) { sendSize=size;}
00151
00152 private:
00153
00154 antSharedBuffer sendBuffer;
00155 byte* sendData;
00156 int bufferSize;
00157 int sendSize;
00158
00159 OStatus initBuffer();
00160 OStatus initUdpEndpoint();
00161 OStatus initBind();
00162 };
00163
00164 #endif // UDPConnection_h_DEFINED