00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_NET_MANAGER_H
00027 #define NL_NET_MANAGER_H
00028
00029 #include "nel/misc/types_nl.h"
00030
00031 #include <string>
00032 #include <map>
00033 #include <vector>
00034
00035 #include "nel/misc/time_nl.h"
00036 #include "nel/net/callback_net_base.h"
00037 #include "nel/net/naming_client.h"
00038
00039 namespace NLNET {
00040
00042 typedef void (*TNetManagerCallback) (const std::string &serviceName, TSockId from, void *arg);
00043
00050 struct CBaseStruct
00051 {
00052 CBaseStruct (const std::string &sn) :
00053 Name(sn), ConnectionCallback(NULL), ConnectionCbArg(NULL),
00054 DisconnectionCallback(NULL), DisconnectionCbArg(NULL), Type(Unknown)
00055 { }
00056
00059 std::string Name;
00060
00061 enum TBaseStructType { Unknown, Client, ClientWithAddr, Group, Server };
00062
00063 std::vector<std::string> ServiceNames;
00064
00066 std::vector<CCallbackNetBase*> NetBase;
00067
00068 TNetManagerCallback ConnectionCallback;
00069 void *ConnectionCbArg;
00070
00071 TNetManagerCallback DisconnectionCallback;
00072 void *DisconnectionCbArg;
00073
00074
00075 bool AutoRetry;
00076
00077 TBaseStructType Type;
00078 };
00079
00089 class CNetManager
00090 {
00091 public:
00092
00096 static void init (const CInetAddress *addr, CCallbackNetBase::TRecordingState rec );
00097
00098 static void release ();
00099
00104 static void addServer (const std::string &serviceName, uint16 servicePort = 0, bool external = false);
00105
00106 static void addServer (const std::string &serviceName, uint16 servicePort, NLNET::TServiceId &sid, bool external = false);
00107
00109 static void addClient (const std::string &serviceName, const std::string &addr, bool autoRetry = true);
00110
00112 static void addClient (const std::string &serviceName);
00113
00115 static void addGroup (const std::string &groupName, const std::string &serviceName);
00116
00118 static void addCallbackArray (const std::string &serviceName, const TCallbackItem *callbackarray, NLMISC::CStringIdArray::TStringId arraysize);
00119
00125 static void update (NLMISC::TTime timeout = 0);
00126
00128 static void send (const std::string &serviceName, const CMessage &buffer, TSockId hostid = InvalidSockId);
00129
00134 static void setConnectionCallback (const std::string &serviceName, TNetManagerCallback cb, void *arg);
00135
00140 static void setDisconnectionCallback (const std::string &serviceName, TNetManagerCallback cb, void *arg);
00141
00143 static NLMISC::CStringIdArray &getSIDA (const std::string &serviceName);
00144
00146 static CCallbackNetBase *getNetBase (const std::string &serviceName);
00147
00148 static void setUpdateTimeout (uint32 timeout);
00149
00150 static void createConnection(CBaseStruct &Base, const CInetAddress &Addr, const std::string& name);
00151
00152 static uint64 getBytesSent ();
00153 static uint64 getBytesReceived ();
00154
00155 static uint64 getReceiveQueueSize ();
00156 static uint64 getSendQueueSize ();
00157
00158 private:
00159
00160 typedef std::map<std::string, CBaseStruct> TBaseMap;
00161 typedef TBaseMap::iterator ItBaseMap;
00162
00163
00164 static TBaseMap _BaseMap;
00165
00166 static CCallbackNetBase::TRecordingState _RecordingState;
00167
00168
00169 static NLMISC::TTime _NextUpdateTime;
00170
00171
00172 static ItBaseMap find (const std::string &serviceName);
00173
00174 friend void RegistrationBroadcast (const std::string &name, TServiceId sid, const std::vector<CInetAddress> &addr);
00175
00176
00177
00178 CNetManager() { }
00179 };
00180
00181
00182 }
00183
00184
00185 #endif // NL_NET_MANAGER_H
00186
00187