net_manager.h

Go to the documentation of this file.
00001 
00005 /* Copyright, 2001 Nevrax Ltd.
00006  *
00007  * This file is part of NEVRAX NEL.
00008  * NEVRAX NEL is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2, or (at your option)
00011  * any later version.
00012 
00013  * NEVRAX NEL is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * General Public License for more details.
00017 
00018  * You should have received a copy of the GNU General Public License
00019  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00020  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00021  * MA 02111-1307, USA.
00022  */
00023 
00024 
00025 
00026 
00027 /**************************************************************************
00028 ********************* THIS CLASS IS DEPRECATED ****************************
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     // autoretry is used only when Type is ClientWithAddr. If true, the CNetManager will retry to reconnect if it lost the connection
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     // Contains all the connections (client and server)
00174     static  TBaseMap    _BaseMap;
00175 
00176     static  CCallbackNetBase::TRecordingState _RecordingState;
00177 
00178     // used to synchonize the timeout in the update function
00179     static  NLMISC::TTime _NextUpdateTime;
00180 
00181     // Finds the service or add it if not found
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     // It's a static class, you can't instanciate it
00188     CNetManager() { }
00189 };
00190 
00191 
00192 } // NLNET
00193 
00194 
00195 #endif // NL_NET_MANAGER_H
00196 
00197 /* End of net_manager.h */

Generated on Thu Jan 7 08:26:23 2010 for NeL by  doxygen 1.6.1