net_manager.h
Go to the documentation of this file.00001
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 #ifdef NL_OS_WINDOWS
00032 # pragma message(NL_LOC_WRN "You are using a deprecated feature of NeL, consider rewriting your code with replacement feature")
00033 #else // NL_OS_UNIX
00034 # warning "You are using a deprecated feature of NeL, consider rewriting your code with replacement feature"
00035 #endif
00036
00037 #ifndef NL_NET_MANAGER_H
00038 #define NL_NET_MANAGER_H
00039
00040 #include "nel/misc/types_nl.h"
00041
00042 #include <string>
00043 #include <map>
00044 #include <vector>
00045
00046 #include "nel/misc/time_nl.h"
00047 #include "nel/misc/string_id_array.h"
00048
00049 #include "callback_net_base.h"
00050 #include "naming_client.h"
00051
00052 namespace NLNET {
00053
00055 typedef void (*TNetManagerCallback) (const std::string &serviceName, TSockId from, void *arg);
00056
00063 struct CBaseStruct
00064 {
00065 CBaseStruct (const std::string &sn) :
00066 Name(sn), ConnectionCallback(NULL), ConnectionCbArg(NULL),
00067 DisconnectionCallback(NULL), DisconnectionCbArg(NULL), Type(Unknown)
00068 { }
00069
00072 std::string Name;
00073
00074 enum TBaseStructType { Unknown, Client, ClientWithAddr, Group, Server };
00075
00076 std::vector<std::string> ServiceNames;
00077
00079 std::vector<CCallbackNetBase*> NetBase;
00080
00081 TNetManagerCallback ConnectionCallback;
00082 void *ConnectionCbArg;
00083
00084 TNetManagerCallback DisconnectionCallback;
00085 void *DisconnectionCbArg;
00086
00087
00088 bool AutoRetry;
00089
00090 TBaseStructType Type;
00091 };
00092
00102 class CNetManager
00103 {
00104 public:
00105
00109 static void init (const CInetAddress *addr, CCallbackNetBase::TRecordingState rec );
00110
00111 static void release ();
00112
00117 static void addServer (const std::string &serviceName, uint16 servicePort = 0, bool external = false);
00118
00119 static void addServer (const std::string &serviceName, uint16 servicePort, NLNET::TServiceId &sid, bool external = false);
00120
00122 static void addClient (const std::string &serviceName, const std::string &addr, bool autoRetry = true);
00123
00125 static void addClient (const std::string &serviceName);
00126
00128 static void addGroup (const std::string &groupName, const std::string &serviceName);
00129
00131 static void addCallbackArray (const std::string &serviceName, const TCallbackItem *callbackarray, NLMISC::CStringIdArray::TStringId arraysize);
00132
00138 static void update (NLMISC::TTime timeout = 0);
00139
00141 static void send (const std::string &serviceName, const CMessage &buffer, TSockId hostid = InvalidSockId);
00142
00147 static void setConnectionCallback (const std::string &serviceName, TNetManagerCallback cb, void *arg);
00148
00153 static void setDisconnectionCallback (const std::string &serviceName, TNetManagerCallback cb, void *arg);
00154
00156 static CCallbackNetBase *getNetBase (const std::string &serviceName);
00157
00158 static void setUpdateTimeout (uint32 timeout);
00159
00160 static void createConnection(CBaseStruct &Base, const CInetAddress &Addr, const std::string& name);
00161
00162 static uint64 getBytesSent ();
00163 static uint64 getBytesReceived ();
00164
00165 static uint64 getReceiveQueueSize ();
00166 static uint64 getSendQueueSize ();
00167
00168 private:
00169
00170 typedef std::map<std::string, CBaseStruct> TBaseMap;
00171 typedef TBaseMap::iterator ItBaseMap;
00172
00173
00174 static TBaseMap _BaseMap;
00175
00176 static CCallbackNetBase::TRecordingState _RecordingState;
00177
00178
00179 static NLMISC::TTime _NextUpdateTime;
00180
00181
00182 static ItBaseMap find (const std::string &serviceName);
00183
00184 friend void RegistrationBroadcast (const std::string &name, TServiceId sid, const std::vector<CInetAddress> &addr);
00185
00186
00187
00188 CNetManager() { }
00189 };
00190
00191
00192 }
00193
00194
00195 #endif // NL_NET_MANAGER_H
00196
00197