00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00044 #ifndef _PROTLIB__TP_H_
00045 #define _PROTLIB__TP_H_
00046
00047 #include <string.h>
00048
00049 #include "protlib_types.h"
00050 #include "messages.h"
00051 #include "network_message.h"
00052 #include "address.h"
00053 #include "tperror.h"
00054
00055 namespace protlib {
00056
00063
00064
00069 class TP {
00070 public:
00072 TP(protocol_t p, const string& pname, const string& tpn,
00073 const unsigned short common_header_length,
00074 bool (*const getmsglength)(NetMsg& netmsg, uint32& msglen),
00075 uint32 mp = (uint32)-1);
00076
00078 virtual ~TP() = 0;
00079
00083 virtual void send(NetMsg* msg, const address& addr, bool use_existing_connection= false) = 0;
00084
00086 virtual void terminate(const address& addr) = 0;
00087
00089 void check_send_args(const NetMsg& msg,
00090 const address& addr) const;
00091
00093 protocol_t get_underlying_protocol() const;
00094
00096 string get_underlying_protocol_name() const;
00097
00099 string get_tp_name() const;
00100
00102 bool is_init() const;
00103
00105 uint32 get_max_payload() const;
00106 protected:
00107
00109 const protocol_t protocol;
00110
00112 const string protoname;
00113
00115 const string tp_name;
00116
00118 const unsigned short common_header_length;
00119
00122 bool (*const getmsglength) (NetMsg& m, uint32& clen_words);
00123
00125 bool init;
00126 const uint32 max_payload;
00127 };
00128
00130
00131 class TPMsg : public message {
00132
00133 public:
00134 virtual void clear_pointers();
00135
00136 public:
00138 TPMsg(NetMsg* m = NULL, address* peer = NULL, address* ownaddr = NULL, TPError* e = NULL, uint16 oif = 0);
00140 virtual ~TPMsg();
00142 const address* get_peeraddress() const;
00144 const address* get_ownaddress() const;
00146 address* set_peeraddress(address* a);
00148 address* set_ownaddress(address* a);
00150 NetMsg* get_message() const;
00152 NetMsg* set_message(NetMsg* m);
00154 TPError* get_error() const;
00156 TPError* set_error(TPError* e);
00158 void set_oif(uint16 iface) { oif=iface; }
00160 uint16 get_oif() { return oif; }
00161
00162 private:
00164 address* peeraddr;
00166 address* ownaddr;
00168 NetMsg* msg;
00169 TPError* err;
00171 uint16 oif;
00172 };
00173
00174 inline
00175 bool TP::is_init() const { return init; }
00176
00177
00178
00179
00180
00182 inline
00183 void TPMsg::clear_pointers() {
00184 peeraddr = NULL;
00185 ownaddr = NULL;
00186 msg = NULL;
00187 err = NULL;
00188 }
00189
00190
00191
00193 inline
00194 TPMsg::TPMsg(NetMsg* m, address* p, address* o, TPError* e, uint16 oif)
00195 : message(type_transport,qaddr_transport),
00196 peeraddr(p),
00197 ownaddr(o),
00198 msg(m),
00199 err(e),
00200 oif(oif)
00201 {}
00202
00204 inline
00205 TPMsg::~TPMsg() {
00206 if (msg) delete msg;
00207 if (peeraddr) delete peeraddr;
00208 if (ownaddr) delete ownaddr;
00209 if (err) delete err;
00210 }
00211
00212 inline
00213 const address* TPMsg::get_peeraddress() const { return peeraddr; }
00214
00215 inline
00216 const address* TPMsg::get_ownaddress() const { return ownaddr; }
00217
00218 inline
00219 address* TPMsg::set_peeraddress(address* peer) {
00220 register address* oa = peeraddr;
00221 peeraddr = peer;
00222 return oa;
00223 }
00224
00225 inline
00226 address* TPMsg::set_ownaddress(address* o) {
00227 register address* oa = ownaddr;
00228 ownaddr = o;
00229 return oa;
00230 }
00231
00232 inline
00233 NetMsg* TPMsg::get_message() const { return msg; }
00234
00235 inline
00236 NetMsg* TPMsg::set_message(NetMsg* m) {
00237 register NetMsg* omsg = msg;
00238 msg = m;
00239 return omsg;
00240 }
00241
00242 inline
00243 TPError* TPMsg::get_error() const { return err; }
00244
00245 inline
00246 TPError* TPMsg::set_error(TPError* e) {
00247 register TPError* oe = err;
00248 err = e;
00249 return oe;
00250 }
00251
00252
00254
00255 }
00256
00257 #endif