From 0ea5fc66924303d1bf73ba283a383e2aadee02f2 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sat, 11 Aug 2018 20:21:34 +0200 Subject: Initial commit --- docs/doxygen/nel/a03632.html | 4627 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 4627 insertions(+) create mode 100644 docs/doxygen/nel/a03632.html (limited to 'docs/doxygen/nel/a03632.html') diff --git a/docs/doxygen/nel/a03632.html b/docs/doxygen/nel/a03632.html new file mode 100644 index 00000000..e1b0a298 --- /dev/null +++ b/docs/doxygen/nel/a03632.html @@ -0,0 +1,4627 @@ + + +NeL: NLNET::CUnifiedNetwork class Reference + + + +
+

NLNET::CUnifiedNetwork Class Reference

#include <unified_network.h> +

+


Detailed Description

+Layer 5

+

Author:
Vianney Lecroart, Benjamin Legros

+Nevrax France

+
Date:
2002
+ +

+ +

+Definition at line 71 of file unified_network.h. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Public Member Functions

void addCallbackArray (const TUnifiedCallbackItem *callbackarray, NLMISC::CStringIdArray::TStringId arraysize)
void addDefaultNetwork (const std::string &defnet)
void addNetworkAssociation (const std::string &networkName, uint8 nid)
void addService (const std::string &name, const std::vector< CInetAddress > &addr, bool sendId=true, bool external=true, uint16 sid=0, bool autoRetry=true, bool shouldBeAlreayInserted=false)
void addService (const std::string &name, const CInetAddress &addr, bool sendId=true, bool external=true, uint16 sid=0, bool autoRetry=true, bool shouldBeAlreayInserted=false)
void clearDefaultNetwork ()
 Clear all default network.

void clearNetworkAssociation ()
void connect ()
void displayInternalTables (NLMISC::CLog *log=NLMISC::InfoLog)
void displayUnifiedConnection (uint16 sid, NLMISC::CLog *log=NLMISC::InfoLog)
TUnifiedMsgCallback findCallback (const std::string &callbackName)
 Find a callback in the array.

uint64 getBytesReceived ()
 Gets the total number of bytes received.

uint64 getBytesSent ()
 Gets the total number of bytes sent.

const std::vector< uint16 > & getConnectionList () const
 Return the service ids of the active connections.

CCallbackNetBasegetNetBase (uint16 sid, TSockId &host, uint8 nid=0xFF)
 Gets the CCallbackNetBase of the service.

CCallbackNetBasegetNetBase (const std::string &name, TSockId &host, uint8 nid=0xFF)
 Gets the CCallbackNetBase of the service.

uint64 getReceiveQueueSize ()
 Gets the total number of bytes queued after receiving.

uint64 getSendQueueSize ()
 Gets the total number of bytes queued for sending.

std::string getServiceName (uint16 sid)
 Return the name of the specified service, or "" if not found.

std::string getServiceUnifiedName (uint16 sid)
 Return a string identifying the service, using the format "NAME-sid" (or "sid" only if not found).

bool init (const CInetAddress *addr, CCallbackNetBase::TRecordingState rec, const std::string &shortName, uint16 port, TServiceId &sid)
bool isServiceLocal (const std::string &serviceName)
 Returns true if the serviceName service is on the same computer than this service.

bool isServiceLocal (uint16 sid)
 Returns true if the sid service is on the same computer than this service.

void release ()
bool send (uint16 serviceId, const CMessage &msg, uint8 nid=0xFF)
bool send (const std::string &serviceName, const CMessage &msg, uint8 nid=0xFF)
void sendAll (const CMessage &msg, uint8 nid=0xFF)
void setServiceDownCallback (const std::string &serviceName, TUnifiedNetCallback cb, void *arg=0, bool back=true)
void setServiceUpCallback (const std::string &serviceName, TUnifiedNetCallback cb, void *arg=0, bool back=true)
void update (NLMISC::TTime timeout=0)

Static Public Member Functions

CUnifiedNetworkgetInstance ()
bool isUsed ()

Private Types

typedef std::pair< TUnifiedNetCallback,
+ void * > 
TCallbackArgItem
 A callback and its user data.

typedef std::map< std::string,
+ TUnifiedMsgCallback
TMsgMappedCallback
 A map of callbacks, refered by message name.

typedef std::hash_map< std::string,
+ std::list< TCallbackArgItem > > 
TNameMappedCallback
 A map of service up/down callbacks with their user data.


Private Member Functions

void addNamedCnx (const std::string &name, uint16 sid)
void autoCheck ()
void callServiceDownCallback (const std::string &serviceName, uint16 sid, bool callGlobalCallback=true)
void callServiceUpCallback (const std::string &serviceName, uint16 sid, bool callGlobalCallback=true)
 CUnifiedNetwork ()
uint8 findConnectionId (uint16 sid, uint8 nid)
CUnifiedConnectiongetUnifiedConnection (uint16 sid, bool warn=true)
bool haveNamedCnx (const std::string &name, uint16 sid)
void removeNamedCnx (const std::string &name, uint16 sid)
 ~CUnifiedNetwork ()

Private Attributes

TMsgMappedCallback _Callbacks
 Map of callbacks.

CCallbackServer_CbServer
 The callback server.

std::vector< std::string > _DefaultNetwork
 for each services, which network to take

TNameMappedCallback _DownCallbacks
std::vector< TCallbackArgItem_DownUniCallback
uint16 _ExtSId
 Used for external service.

std::vector< CUnifiedConnection_IdCnx
 Vector of connections by service id (sid is the entry in this array, it means that there s some hole).

bool _Initialised
 true if initialisation function called

NLMISC::TTime _LastRetry
 Last time of retry.

std::string _Name
 Service name.

TNameMappedConnection _NamedCnx
 Map of connections by service name.

NLNET::CInetAddress _NamingServiceAddr
 Naming service.

std::vector< uint32_NetworkAssociations
 for each nid, which network address

NLMISC::TTime _NextUpdateTime
 Time of the theorical next update.

CCallbackNetBase::TRecordingState _RecordingState
 Recording state.

uint16 _ServerPort
 The server port.

TServiceId _SId
 Service id of the running service.

TNameMappedCallback _UpCallbacks
 Map of the up/down service callbacks.

std::vector< TCallbackArgItem_UpUniCallback
std::vector< uint16_UsedConnection
 This vector contains only an index to the unified connection. It is used to have quick access on the available connections.


Static Private Attributes

CUnifiedNetwork_Instance = NULL
 The main instance.


Friends

struct isServiceLocalClass
struct l5CallbackClass
struct l5QueuesStatsClass
void uncbConnection (TSockId from, void *arg)
void uncbDisconnection (TSockId from, void *arg)
void uncbMsgProcessing (CMessage &msgin, TSockId from, CCallbackNetBase &netbase)
void uncbServiceIdentification (CMessage &msgin, TSockId from, CCallbackNetBase &netbase)
void uNetRegistrationBroadcast (const std::string &name, TServiceId sid, const std::vector< CInetAddress > &addr)
void uNetUnregistrationBroadcast (const std::string &name, TServiceId sid, const std::vector< CInetAddress > &addr)
+


Member Typedef Documentation

+

+ + + + +
+ + +
typedef std::pair<TUnifiedNetCallback, void *> NLNET::CUnifiedNetwork::TCallbackArgItem [private] +
+
+ + + + + +
+   + + +

+A callback and its user data. +

+ +

+Definition at line 245 of file unified_network.h.

+

+ + + + +
+ + +
typedef std::map<std::string, TUnifiedMsgCallback> NLNET::CUnifiedNetwork::TMsgMappedCallback [private] +
+
+ + + + + +
+   + + +

+A map of callbacks, refered by message name. +

+ +

+Definition at line 242 of file unified_network.h.

+

+ + + + +
+ + +
typedef std::hash_map<std::string, std::list<TCallbackArgItem> > NLNET::CUnifiedNetwork::TNameMappedCallback [private] +
+
+ + + + + +
+   + + +

+A map of service up/down callbacks with their user data. +

+ +

+Definition at line 248 of file unified_network.h.

+


Constructor & Destructor Documentation

+

+ + + + +
+ + + + + + + + + +
NLNET::CUnifiedNetwork::CUnifiedNetwork  )  [inline, private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 481 of file unified_network.h. +

+References _CbServer, _ExtSId, and _LastRetry. +

+Referenced by getInstance(). +

+

00481                           : _CbServer(0), _ExtSId(256), _LastRetry(0), _NextUpdateTime(0), _Initialised(false)
+00482         {
+00483         }
+
+

+ + + + +
+ + + + + + + + + +
NLNET::CUnifiedNetwork::~CUnifiedNetwork  )  [inline, private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 485 of file unified_network.h. +

+

00485 { }
+
+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NLNET::CUnifiedNetwork::addCallbackArray const TUnifiedCallbackItem callbackarray,
NLMISC::CStringIdArray::TStringId  arraysize
+
+ + + + + +
+   + + +

+Adds a callback array in the system. You can add callback only *after* adding the server, the client or the group. +

+Definition at line 1188 of file unified_network.cpp. +

+References _Callbacks, NLMISC::CStringIdArray::TStringId, and uint. +

+Referenced by NLNET::IService::main(). +

+

01189 {
+01190         uint    i;
+01191 
+01192         for (i=0; i<(uint)arraysize; ++i)
+01193                 _Callbacks.insert(make_pair(string(callbackarray[i].Key),callbackarray[i].Callback));
+01194 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLNET::CUnifiedNetwork::addDefaultNetwork const std::string &  defnet  )  [inline]
+
+ + + + + +
+   + + +

+This array says to wich network we need to send the message for the default nid. For example you can says that message for AES will use the network 0 and message for LS will use the network 1. To do that, just call the function with string "AES0" and "LS1" the number is the nid (look at addNetworkAssociation()) addNetworkAssociation("192.168.0.0", 0); addNetworkAssociation("192.168.1.0", 1); In this case if you send a message to AES with default nid, it'll be send to 192.168.0.x In this case if you send a message to LS with default nid, it'll be send to 192.168.1.y +

+Definition at line 184 of file unified_network.h. +

+References _DefaultNetwork, and nlinfo. +

+

00184 { nlinfo ("HNETL5: Add default network '%s'", defnet.c_str()); _DefaultNetwork.push_back (defnet); }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NLNET::CUnifiedNetwork::addNamedCnx const std::string &  name,
uint16  sid
[private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 1700 of file unified_network.cpp. +

+References _NamedCnx, NLNET::allstuffs, AUTOCHECK_DISPLAY, range, NLMISC::toString(), and uint16. +

+Referenced by addService(), NLNET::uncbServiceIdentification(), and update(). +

+

01701 {
+01702         // check if not already inserted
+01703         CUnifiedNetwork::TNameMappedConnection::iterator                                                                                        it;
+01704         pair<CUnifiedNetwork::TNameMappedConnection::iterator,CUnifiedNetwork::TNameMappedConnection::iterator> range;
+01705         range = _NamedCnx.equal_range(name);
+01706 
+01707         if (range.first != range.second)
+01708         {
+01709                 for (it=range.first; it!=range.second && (*it).second!=sid; ++it)
+01710                         ;
+01711 
+01712                 if (it != range.second)
+01713                 {
+01714                         AUTOCHECK_DISPLAY ("HNETL5: Try to add 2 times the same connection %s-%hu", name.c_str(), sid);
+01715                         return;
+01716                 }
+01717         }
+01718 
+01719 
+01720         // insert the name in the map to be able to send message with the name
+01721         _NamedCnx.insert(make_pair(name, sid));
+01722 
+01723         allstuffs += "+name "+name+"-"+toString(sid)+"\n";
+01724         test.displayNL ("+name %s-%hu", name.c_str (), sid);
+01725 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NLNET::CUnifiedNetwork::addNetworkAssociation const std::string &  networkName,
uint8  nid
+
+ + + + + +
+   + + +

+Associate a string with a network id If the send don't set a specific nid, it ll use the 0, so be sure that the nid 0 is set to a network. You must call this function before the connect() function.

Parameters:
+ + + +
networkName must be in a xxx.xxx.xxx.xxx format. The low value will be ignore depending of the network class.
nid a number (used as an index in a vector for constant access so numbers should be contiguous) that will be use to send to this network.
+
+ +

+Definition at line 1759 of file unified_network.cpp. +

+References _NetworkAssociations, NLNET::internalIPAddressToString(), nlinfo, NLNET::stringToInternalIPAddress(), uint16, and uint8. +

+

01760 {
+01761         if (nid >= _NetworkAssociations.size ())
+01762                 _NetworkAssociations.resize (nid+1, 0xFF);
+01763 
+01764         _NetworkAssociations[nid] = stringToInternalIPAddress (networkName);
+01765         nlinfo ("HNETL5: Associate network '%s' 0x%08x '%s' to nid %hu", networkName.c_str(), _NetworkAssociations[nid], internalIPAddressToString (_NetworkAssociations[nid]).c_str(), (uint16)nid);
+01766 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void NLNET::CUnifiedNetwork::addService const std::string &  name,
const std::vector< CInetAddress > &  addr,
bool  sendId = true,
bool  external = true,
uint16  sid = 0,
bool  autoRetry = true,
bool  shouldBeAlreayInserted = false
+
+ + + + + +
+   + + +

+ +

+Definition at line 653 of file unified_network.cpp. +

+References _DefaultNetwork, _ExtSId, _IdCnx, _NetworkAssociations, _UsedConnection, addNamedCnx(), addr, NLNET::allstuffs, AUTOCHECK_DISPLAY, NLNET::CUnifiedNetwork::CUnifiedConnection::AutoRetry, callServiceUpCallback(), NLNET::CCallbackClient::connect(), NLNET::CUnifiedNetwork::CUnifiedConnection::Connection, NLNET::CUnifiedNetwork::CUnifiedConnection::ExtAddress, NLNET::CCallbackClient::getSockId(), NLMISC::getThreadId(), NLNET::CUnifiedNetwork::CUnifiedConnection::IsExternal, nlassert, nlassertex, nldebug, nlinfo, nlwarning, NLNET::CCallbackClient::send(), NLNET::CUnifiedNetwork::CUnifiedConnection::SendId, NLMISC::CMemStream::serial(), NLNET::CUnifiedNetwork::CUnifiedConnection::ServiceId, NLNET::CUnifiedNetwork::CUnifiedConnection::ServiceName, NLNET::CBufSock::setAppId(), NLNET::CCallbackNetBase::setDefaultCallback(), NLNET::CCallbackClient::setDisconnectionCallback(), NLNET::CUnifiedNetwork::CUnifiedConnection::setupNetworkAssociation(), NLNET::CUnifiedNetwork::CUnifiedConnection::State, NLNET::ThreadCreator, NLMISC::toString(), uint, uint16, uint8, NLNET::uncbDisconnection(), NLNET::uncbMsgProcessing(), and NLNET::vectorCInetAddressToString(). +

+

00654 {
+00655         nlassertex(_Initialised == true, ("Try to CUnifiedNetwork::addService() whereas it is not initialised yet"));
+00656 
+00657         if (ThreadCreator != NLMISC::getThreadId()) nlwarning ("HNETL5: Multithread access but this class is not thread safe thread creator = %u thread used = %u", ThreadCreator, NLMISC::getThreadId());
+00658 
+00659         if (external)
+00660                 sid = _ExtSId++;
+00661 
+00662         nlinfo("HNETL5: addService %s-%hu '%s'", name.c_str(), sid, vectorCInetAddressToString(addr).c_str());
+00663 
+00664         allstuffs += "addService "+name+"-"+toString(sid)+"\n";
+00665         test.displayNL ("+service %s-%hu", name.c_str (), (uint16)sid);
+00666 
+00667         if (external && addr.size () != 1)
+00668         {
+00669                 AUTOCHECK_DISPLAY ("HNETL5: Can't add external service with more than one connection");
+00670         }
+00671 
+00672         // add the entry in the unified connection table
+00673 
+00674         if (sid >= _IdCnx.size())
+00675                 _IdCnx.resize(sid+1);
+00676 
+00677         CUnifiedConnection      *uc = &_IdCnx[sid];
+00678 
+00679         // at this point it s possible that the service already added in the _IdCnx by the uNetRegistrationBroadcast()
+00680 
+00681         if (shouldBeAlreayInserted && _IdCnx[sid].State == CUnifiedNetwork::CUnifiedConnection::NotUsed)  AUTOCHECK_DISPLAY ("HNETL5: the unified connection should already set by the naming reg broadcast and is not (%hu)", sid);
+00682         if (!shouldBeAlreayInserted && _IdCnx[sid].State == CUnifiedNetwork::CUnifiedConnection::Ready)  AUTOCHECK_DISPLAY ("HNETL5: the unified connection should not already set but is (%hu)", sid);
+00683 
+00684         if (_IdCnx[sid].State == CUnifiedNetwork::CUnifiedConnection::NotUsed)
+00685         {
+00686                 *uc = CUnifiedConnection(name, sid, external);
+00687                 _UsedConnection.push_back (sid);
+00688         }
+00689         else
+00690         {
+00691                 // If the entry already set, check that all is correct
+00692                 if (name != uc->ServiceName) AUTOCHECK_DISPLAY ("HNETL5: name are different in addService %s %s", name.c_str (), uc->ServiceName.c_str ());
+00693                 if (sid != uc->ServiceId) AUTOCHECK_DISPLAY ("HNETL5: sid are different in addService %hu %hu", sid, uc->ServiceId);
+00694                 if (addr != uc->ExtAddress) AUTOCHECK_DISPLAY ("HNETL5: external addr are different in addService '%s' '%s'", vectorCInetAddressToString(addr).c_str(), vectorCInetAddressToString(uc->ExtAddress).c_str ());
+00695         }
+00696         uc->AutoRetry = autoRetry;
+00697         uc->SendId = sendId;
+00698         uc->ExtAddress = addr;
+00699         nlassert (!addr.empty());
+00700 
+00701         // associate nid with ext address
+00702         uc->setupNetworkAssociation (_NetworkAssociations, _DefaultNetwork);
+00703 
+00704         // connect to all connection
+00705         bool    connectSuccess;
+00706         
+00707         if (uc->Connection.size () < addr.size ())
+00708         {
+00709                 uc->Connection.resize (addr.size ());
+00710         }
+00711 
+00712         vector<CInetAddress> laddr = CInetAddress::localAddresses();
+00713 
+00714         for (uint i = 0; i < addr.size(); i++)
+00715         {
+00716                 // first we have to look if we have a network that can established the connection
+00717 
+00718                 uint j = 0;
+00719                 // it s 127.0.0.1, it s ok
+00720                 if (!addr[i].is127001 ())
+00721                 {
+00722                         for (j = 0; j < laddr.size (); j++)
+00723                         {
+00724                                 if (laddr[j].internalNetAddress () == addr[i].internalNetAddress ())
+00725                                 {
+00726                                         // it's ok, we can try
+00727                                         break;
+00728                                 }
+00729                         }
+00730 
+00731                         // If we don't found a valid network, we'll try with the first one.
+00732                         // It's happen, for example, when you try to connect to a service that is not in the network but use IP translation
+00733                         if (j == laddr.size ())
+00734                         {
+00735                                 nlwarning ("HNETL5: I can't access '%s' because I haven't a net card on this network, we'll use the first network", addr[i].asString ().c_str ());
+00736                                 j = 0;
+00737                         }
+00738                 }
+00739 
+00740                 // create a new connection with the service, setup callback and connect
+00741                 CCallbackClient *cbc = new CCallbackClient();
+00742                 cbc->setDisconnectionCallback(uncbDisconnection, NULL);
+00743                 cbc->setDefaultCallback(uncbMsgProcessing);
+00744                 cbc->getSockId()->setAppId(sid);
+00745 
+00746                 try
+00747                 {
+00748                         cbc->connect(addr[i]);
+00749                         connectSuccess = true;
+00750                         
+00751                         allstuffs += "+lconnect "+name+"-"+toString(sid)+"\n";
+00752                         test.displayNL ("+lconnect %s-%hu", name.c_str (), (uint16)sid);
+00753                 }
+00754                 catch (ESocketConnectionFailed &e)
+00755                 {
+00756                         nlwarning ("HNETL5: can't connect to %s (sid %u) now (%s) '%s'", name.c_str(), sid, e.what (), addr[i].asString ().c_str());
+00757                         connectSuccess = false;
+00758 
+00759                         allstuffs += "+lconnect failed "+name+"-"+toString((uint16)sid)+"\n";
+00760                         test.displayNL ("+lconnect failed %s-%hu", name.c_str (), (uint16)sid);
+00761                 }
+00762 
+00763                 if (!connectSuccess && !autoRetry)
+00764                 {
+00765                         nlwarning ("HNETL5: Can't add service because no retry and can't connect");
+00766                         delete cbc;
+00767                 }
+00768                 else
+00769                 {
+00770                         uc->Connection[i] = CUnifiedNetwork::CUnifiedConnection::TConnection(cbc);
+00771 
+00772 //                      nlinfo ("HNETL5: %s", allstuffs.c_str ());
+00773                 }
+00774 
+00775                 if (connectSuccess && sendId)
+00776                 {
+00777                         // send identification to the service
+00778                         CMessage        msg("UN_SIDENT");
+00779                         msg.serial(_Name);
+00780                         uint16          ssid = _SId;
+00781                         if (uc->IsExternal)
+00782                         {
+00783                                 // in the case that the service is external, we can't send our sid because the external service can
+00784                                 // have other connectin with the same sid (for example, LS can have 2 WS with same sid => sid = 0 and leave
+00785                                 // the other side to find a good number
+00786                                 ssid = 0;
+00787                         }
+00788                         msg.serial(ssid);       // serializes a 16 bits service id
+00789                         uint8 pos = j;
+00790                         msg.serial(pos);        // send the position in the connection table
+00791                         msg.serial (uc->IsExternal);
+00792                         cbc->send (msg);
+00793                 }
+00794         }
+00795 
+00796         if (addr.size () != uc->Connection.size())
+00797         {
+00798                 nlwarning ("HNETL5: Can't connect to all connections to the service %d/%d", addr.size (), uc->Connection.size());
+00799         }
+00800 
+00801         bool cntok = false;
+00802         for (uint j = 0; j < uc->Connection.size(); j++)
+00803         {
+00804                 if (uc->Connection[j].CbNetBase != NULL)
+00805                 {
+00806                         if (uc->Connection[j].CbNetBase->connected ())
+00807                         {
+00808                                 cntok = true;
+00809                                 break;
+00810                         }
+00811                 }
+00812         }
+00813 
+00814         if (cntok)
+00815         {
+00816                 // add the name only if at least one connection is ok
+00817                 addNamedCnx (name, sid);
+00818 
+00819                 callServiceUpCallback (name, sid, !external);
+00820                 
+00821 /*              
+00822                 // call the connection callback associated to this service
+00823                 TNameMappedCallback::iterator   itcb = _UpCallbacks.find(name);
+00824                 if (itcb != _UpCallbacks.end())
+00825                 {
+00826                         for (list<TCallbackArgItem> it2 = (*itcb).second.begin(); it2 != (*itcb).second.end(); it2++)
+00827                         {                               
+00828                                 TUnifiedNetCallback     cb = (*it2).first;
+00829                                 if (cb) cb(name, sid, (*it2).second);
+00830                         }
+00831                 }
+00832 
+00833                 if (!external)
+00834                 {
+00835                         for (uint i = 0; i < _UpUniCallback.size (); i++)
+00836                         {
+00837                                 if (_UpUniCallback[i].first != NULL)
+00838                                         _UpUniCallback[i].first (name, sid, _UpUniCallback[i].second);
+00839                         }
+00840                 }
+00841 */      }
+00842 
+00843         nldebug ("HNETL5: addService was successful");
+00844 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void NLNET::CUnifiedNetwork::addService const std::string &  name,
const CInetAddress addr,
bool  sendId = true,
bool  external = true,
uint16  sid = 0,
bool  autoRetry = true,
bool  shouldBeAlreayInserted = false
+
+ + + + + +
+   + + +

+Adds a specific service to the list of connected services. +

+Definition at line 646 of file unified_network.cpp. +

+References addr, and uint16. +

+Referenced by connect(). +

+

00647 {
+00648         vector <CInetAddress> addrs;
+00649         addrs.push_back (addr);
+00650         addService (name, addrs, sendId, external, sid, autoRetry, shouldBeAlreayInserted);
+00651 }
+
+

+ + + + +
+ + + + + + + + + +
void NLNET::CUnifiedNetwork::autoCheck  )  [private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 1517 of file unified_network.cpp. +

+References _IdCnx, _NamedCnx, _NetworkAssociations, _UsedConnection, AUTOCHECK_DISPLAY, H_AUTO, NL_I64, and uint. +

+Referenced by update(). +

+

01518 {
+01519         H_AUTO(L5UpdateAutoCheck);
+01520         uint i, j;
+01521 
+01522         for (i = 0; i < _IdCnx.size (); i++)
+01523         {
+01524                 if (_IdCnx[i].State == CUnifiedNetwork::CUnifiedConnection::Ready)
+01525                 {
+01526                         _IdCnx[i].AutoCheck = 1;
+01527                 }
+01528                 else
+01529                 {
+01530                         _IdCnx[i].AutoCheck = 0;
+01531                 }
+01532         }
+01533 
+01534         TNameMappedConnection::iterator itn;
+01535         for (itn = _NamedCnx.begin(); itn != _NamedCnx.end(); ++itn)
+01536         {
+01537                 if ((*itn).first != _IdCnx[(*itn).second].ServiceName) AUTOCHECK_DISPLAY ("HLNET5: problem with name syncro between _NameCnx and _IdCnx '%s' '%s' '%d'", (*itn).first.c_str(), _IdCnx[(*itn).second].ServiceName.c_str (), (*itn).second);
+01538                 if (_IdCnx[(*itn).second].AutoCheck == 0)  AUTOCHECK_DISPLAY ("HLNET5: problem with name syncro between _NameCnx '%s' and _IdCnx '%s' '%d'", (*itn).first.c_str(), _IdCnx[(*itn).second].ServiceName.c_str (), (*itn).second);
+01539                 if (_IdCnx[(*itn).second].AutoCheck > 1)  AUTOCHECK_DISPLAY ("HLNET5: problem with name syncro between _NameCnx and _IdCnx '%s' '%d' more than one entry in named with the same name", (*itn).first.c_str(), _IdCnx[(*itn).second].ServiceName.c_str (),(*itn).second);
+01540                 _IdCnx[(*itn).second].AutoCheck++;
+01541         }
+01542 
+01543         for (i = 0; i < _UsedConnection.size (); i++)
+01544         {
+01545                 if (_IdCnx[_UsedConnection[i]].State != CUnifiedNetwork::CUnifiedConnection::Ready) AUTOCHECK_DISPLAY ("HLNET5: problem with the _UsedConnection syncro sid %d is not used in _IdCnx", _UsedConnection[i]);
+01546         }
+01547         
+01548         for (i = 0; i < _IdCnx.size (); i++)
+01549         {
+01550                 if (_IdCnx[i].State == CUnifiedNetwork::CUnifiedConnection::Ready)
+01551                 {
+01552                         for (j = 0; j < _UsedConnection.size (); j++)
+01553                         {
+01554                                 if (_UsedConnection[j] == i) break;
+01555                         }
+01556                         if (j == _UsedConnection.size ()) AUTOCHECK_DISPLAY ("HLNET5: problem with the _UsedConnection syncro sid %d is not in _UsedConnection", i);
+01557                 }
+01558         }
+01559         
+01560         for (i = 0; i < _IdCnx.size (); i++)
+01561         {
+01562                 if (_IdCnx[i].State == CUnifiedNetwork::CUnifiedConnection::NotUsed)
+01563                 {
+01564                         if (_IdCnx[i].ServiceName != "DEAD") AUTOCHECK_DISPLAY ("HLNET5: sid %d name should be DEAD and is '%s'", i, _IdCnx[i].ServiceName.c_str ());
+01565                         if (_IdCnx[i].ServiceId != 0xDEAD) AUTOCHECK_DISPLAY ("HLNET5: sid %d sid should be 0xDEAD and is 0x%X", i, _IdCnx[i].ServiceId);
+01566                         if (!_IdCnx[i].Connection.empty ()) AUTOCHECK_DISPLAY ("HLNET5: sid %d connection size should be 0 and is %d", i, _IdCnx[i].Connection.size ());
+01567                         if (!_IdCnx[i].ExtAddress.empty ()) AUTOCHECK_DISPLAY ("HLNET5: sid %d ext addr size should be 0 and is %d", i, _IdCnx[i].ExtAddress.size ());
+01568                         if (_IdCnx[i].AutoCheck != 0) AUTOCHECK_DISPLAY ("HLNET5: sid %d prob with syncro with _NamedCnx", i);
+01569                 }
+01570                 else if (_IdCnx[i].State == CUnifiedNetwork::CUnifiedConnection::Ready)
+01571                 {
+01572                         if (_IdCnx[i].ServiceId != i) AUTOCHECK_DISPLAY ("HNETL5: Bad syncro sid index sid entry for %d %d", i, _IdCnx[i].ServiceId);
+01573 
+01574                         if (_IdCnx[i].ServiceName == "DEAD") AUTOCHECK_DISPLAY ("HLNET5: sid %d name should not be DEAD and is '%s'", i, _IdCnx[i].ServiceName.c_str ());
+01575                         if (_IdCnx[i].ServiceId == 0xDEAD) AUTOCHECK_DISPLAY ("HLNET5: sid %d sid should not be 0xDEAD and is 0x%X", i, _IdCnx[i].ServiceId);
+01576                         if (!_IdCnx[i].ExtAddress.empty () && _IdCnx[i].Connection.size () > _IdCnx[i].ExtAddress.size()) AUTOCHECK_DISPLAY ("HLNET5: sid %d ext addr size should not be 0 and is %d", i, _IdCnx[i].ExtAddress.size ());
+01577 
+01578                         if (_IdCnx[i].AutoRetry == true && _IdCnx[i].Connection.size () > 1) AUTOCHECK_DISPLAY ("HLNET5: sid %d auto retry with more than one connection %d", i, _IdCnx[i].Connection.size ());
+01579                         if (_IdCnx[i].AutoRetry == true && _IdCnx[i].IsExternal == false) AUTOCHECK_DISPLAY ("HLNET5: sid %d auto retry with internal connection", i);
+01580                         if (_IdCnx[i].AutoRetry == true && _IdCnx[i].Connection[0].valid() == false) AUTOCHECK_DISPLAY ("HLNET5: sid %d auto retry with invalid connection", i);
+01581 
+01582                         for (j = 0; j < _IdCnx[i].Connection.size (); j++)
+01583                         {
+01584                                 if (_IdCnx[i].Connection[j].valid() && !_IdCnx[i].Connection[j].IsServerConnection && _IdCnx[i].Connection[j].CbNetBase->connected () && _IdCnx[i].Connection[j].getAppId() != i) AUTOCHECK_DISPLAY ("HLNET5: sid %d bad appid %"NL_I64"X", i, _IdCnx[i].Connection[j].getAppId());
+01585                         }
+01586 
+01587                         for (j = 0; j < _IdCnx[i].NetworkConnectionAssociations.size (); j++)
+01588                         {
+01589                                 if (_IdCnx[i].NetworkConnectionAssociations[j] != 0)
+01590                                 {
+01591                                         if (_NetworkAssociations[j] != _IdCnx[i].ExtAddress[_IdCnx[i].NetworkConnectionAssociations[j]].internalNetAddress ()) AUTOCHECK_DISPLAY ("HLNET5: sid %d nid %d have address 0x%08x and is not the good connection net 0x%08x", i, j, _NetworkAssociations[j], _IdCnx[i].ExtAddress[_IdCnx[i].NetworkConnectionAssociations[j]].internalNetAddress ());
+01592                                 }
+01593                         }
+01594                 }
+01595         }
+01596 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void NLNET::CUnifiedNetwork::callServiceDownCallback const std::string &  serviceName,
uint16  sid,
bool  callGlobalCallback = true
[private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 1797 of file unified_network.cpp. +

+References _DownCallbacks, _DownUniCallback, nlwarning, NLNET::TUnifiedNetCallback, uint, and uint16. +

+Referenced by NLNET::uncbDisconnection(), and NLNET::uNetUnregistrationBroadcast(). +

+

01798 {
+01799         // now we warn the user
+01800         CUnifiedNetwork::TNameMappedCallback::iterator  it = _DownCallbacks.find(serviceName);
+01801         if (it != _DownCallbacks.end())
+01802         {
+01803                 // call it
+01804                 for (list<TCallbackArgItem>::iterator it2 = (*it).second.begin(); it2 != (*it).second.end(); it2++)
+01805                 {
+01806                         TUnifiedNetCallback     cb = (*it2).first;
+01807                         if (cb)
+01808                                 cb(serviceName, sid, (*it2).second);
+01809                         else
+01810                                 nlwarning ("HNETL5: User set an empty callback for '%s' service down", serviceName.c_str());
+01811                 }
+01812         }
+01813         
+01814         if(callGlobalCallback)
+01815         {
+01816                 for (uint c = 0; c < _DownUniCallback.size (); c++)
+01817                 {
+01818                         if (_DownUniCallback[c].first != NULL)
+01819                                 _DownUniCallback[c].first (serviceName, sid, _DownUniCallback[c].second);
+01820                         else
+01821                                 nlwarning ("HNETL5: User set an empty callback for '*' service down");
+01822                 }
+01823         }
+01824 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void NLNET::CUnifiedNetwork::callServiceUpCallback const std::string &  serviceName,
uint16  sid,
bool  callGlobalCallback = true
[private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 1768 of file unified_network.cpp. +

+References _UpCallbacks, _UpUniCallback, nlwarning, NLNET::TUnifiedNetCallback, uint, and uint16. +

+Referenced by addService(), NLNET::uncbServiceIdentification(), and update(). +

+

01769 {
+01770         // now we warn the user
+01771         CUnifiedNetwork::TNameMappedCallback::iterator  it = _UpCallbacks.find(serviceName);
+01772         if (it != _UpCallbacks.end())
+01773         {
+01774                 // call it
+01775                 for (list<TCallbackArgItem>::iterator it2 = (*it).second.begin(); it2 != (*it).second.end(); it2++)
+01776                 {
+01777                         TUnifiedNetCallback     cb = (*it2).first;
+01778                         if (cb)
+01779                                 cb(serviceName, sid, (*it2).second);
+01780                         else
+01781                                 nlwarning ("HNETL5: User set an empty callback for '%s' service up", serviceName.c_str());
+01782                 }
+01783         }
+01784         
+01785         if(callGlobalCallback)
+01786         {
+01787                 for (uint c = 0; c < _UpUniCallback.size (); c++)
+01788                 {
+01789                         if (_UpUniCallback[c].first != NULL)
+01790                                 _UpUniCallback[c].first (serviceName, sid, _UpUniCallback[c].second);
+01791                         else
+01792                                 nlwarning ("HNETL5: User set an empty callback for '*' service up");
+01793                 }
+01794         }
+01795 }
+
+

+ + + + +
+ + + + + + + + + +
void NLNET::CUnifiedNetwork::clearDefaultNetwork  )  [inline]
+
+ + + + + +
+   + + +

+Clear all default network. +

+ +

+Definition at line 187 of file unified_network.h. +

+References _DefaultNetwork. +

+

00187 { _DefaultNetwork.clear (); }
+
+

+ + + + +
+ + + + + + + + + +
void NLNET::CUnifiedNetwork::clearNetworkAssociation  )  [inline]
+
+ + + + + +
+   + + +

+Clear all network association +

+Definition at line 175 of file unified_network.h. +

+References _NetworkAssociations. +

+

00175 { _NetworkAssociations.clear (); }
+
+

+ + + + +
+ + + + + + + + + +
void NLNET::CUnifiedNetwork::connect  ) 
+
+ + + + + +
+   + + +

+Registers to the Naming Service, and connects to the present services +

+Definition at line 566 of file unified_network.cpp. +

+References addService(), NLMISC::getThreadId(), nlassertex, nlwarning, and NLNET::ThreadCreator. +

+

00567 {
+00568         nlassertex(_Initialised == true, ("Try to CUnifiedNetwork::connect() whereas it is not initialised yet"));
+00569 
+00570         if (ThreadCreator != NLMISC::getThreadId()) nlwarning ("HNETL5: Multithread access but this class is not thread safe thread creator = %u thread used = %u", ThreadCreator, NLMISC::getThreadId());
+00571 
+00572 
+00573         if (CNamingClient::connected())
+00574         {
+00575                 // get the services list
+00576                 const list<CNamingClient::CServiceEntry>        &services = CNamingClient::getRegisteredServices();
+00577 
+00578                 // connects to the registered services
+00579                 list<CNamingClient::CServiceEntry>::const_iterator      its;
+00580 
+00581                 // don't connect to itself
+00582                 for (its = services.begin(); its != services.end(); ++its)
+00583                 {
+00584                         if (_SId != (*its).SId)
+00585                         {
+00586                                 // add service with name, address, ident, not external, service id, and not autoretry (obsolete)
+00587                                 // we put the last true because the name callback should already inserted it by uNetRegistrationBroadcast()
+00588                                 addService((*its).Name, (*its).Addr, true, false, (*its).SId, false, true);
+00589                         }
+00590                         else
+00591                         {
+00592                                 // don't process services received after mine because they'll connect to me
+00593                                 break;
+00594                         }
+00595                 }
+00596         }
+00597 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLNET::CUnifiedNetwork::displayInternalTables NLMISC::CLog log = NLMISC::InfoLog  ) 
+
+ + + + + +
+   + + +

+ +

+Definition at line 1599 of file unified_network.cpp. +

+References _IdCnx, _NamedCnx, _NetworkAssociations, _UsedConnection, NLMISC::CLog::displayNL(), NLNET::internalIPAddressToString(), uint, and uint16. +

+Referenced by NLNET::NLMISC_COMMAND(). +

+

01600 {
+01601         uint i, j;
+01602         log->displayNL ("%d Named Connections:", _NamedCnx.size ());
+01603         for (TNameMappedConnection::iterator it = _NamedCnx.begin(); it != _NamedCnx.end (); it++)
+01604         {
+01605                 log->displayNL ("> '%s' -> %hu", (*it).first.c_str(), (*it).second);
+01606         }
+01607 
+01608         uint nbused = 0;
+01609         for (i = 0; i < _IdCnx.size (); i++)
+01610         {
+01611                 if(_IdCnx[i].State != CUnifiedNetwork::CUnifiedConnection::NotUsed)
+01612                         nbused++;
+01613         }
+01614 
+01615         log->displayNL ("%u/%u Unified Connections:", nbused, _IdCnx.size ());
+01616         for (i = 0; i < _IdCnx.size (); i++)
+01617         {
+01618                 if(_IdCnx[i].State != CUnifiedNetwork::CUnifiedConnection::NotUsed)
+01619                 {
+01620 /*                      log->displayNL ("> %s-%hu %s %s %s (%d extaddr %d cnx) tcbc %d", _IdCnx[i].ServiceName.c_str (), _IdCnx[i].ServiceId, _IdCnx[i].IsExternal?"ext":"int", _IdCnx[i].AutoRetry?"autoretry":"noautoretry", _IdCnx[i].SendId?"sendid":"nosendid", _IdCnx[i].ExtAddress.size (), _IdCnx[i].Connection.size (), _IdCnx[i].TotalCallbackCalled);
+01621                         uint maxc = _IdCnx[i].Connection.size ();
+01622                         if(_IdCnx[i].Connection.size () <= _IdCnx[i].ExtAddress.size ())
+01623                                 maxc = _IdCnx[i].ExtAddress.size ();
+01624 
+01625                         for (j = 0; j < maxc; j++)
+01626                         {
+01627                                 string base;
+01628                                 if(j < _IdCnx[i].ExtAddress.size ())
+01629                                 {
+01630                                         base += _IdCnx[i].ExtAddress[j].asString ();
+01631                                 }
+01632                                 else
+01633                                 {
+01634                                         base += "notvalid";
+01635                                 }
+01636 
+01637                                 string ext;
+01638                                 if(j < _IdCnx[i].Connection.size () && _IdCnx[i].Connection[j].valid())
+01639                                 {
+01640                                         if(_IdCnx[i].Connection[j].IsServerConnection)
+01641                                         {
+01642                                                 ext += "server ";
+01643                                         }
+01644                                         else
+01645                                         {
+01646                                                 ext += "client ";
+01647                                         }
+01648                                         ext += _IdCnx[i].Connection[j].CbNetBase->getSockId (_IdCnx[i].Connection[j].HostId)->asString ();
+01649                                         ext += " appid:" + toString(_IdCnx[i].Connection[j].getAppId());
+01650                                         if (_IdCnx[i].Connection[j].CbNetBase->connected ())
+01651                                                 ext += " connected";
+01652                                         else
+01653                                                 ext += " notconnected";
+01654                                 }
+01655                                 else
+01656                                 {
+01657                                         ext += "notvalid";
+01658                                 }
+01659 
+01660                                 log->displayNL ("     - %s %s", base.c_str (), ext.c_str ());
+01661                         }*/
+01662 
+01663                         _IdCnx[i].display (false, log);
+01664                         for (j = 0; j < _IdCnx[i].NetworkConnectionAssociations.size (); j++)
+01665                         {
+01666                                 log->displayNL ("     * nid %d -> cnxn %hu", j, (uint16)_IdCnx[i].NetworkConnectionAssociations[j]);
+01667                         }
+01668                 }
+01669         }
+01670 
+01671         log->displayNL ("%u Used Unified Connections:", _UsedConnection.size());
+01672         for (i = 0; i < _UsedConnection.size (); i++)
+01673         {
+01674                 log->displayNL ("> %hu", _UsedConnection[i]);
+01675         }
+01676 
+01677         log->displayNL ("%u Network Associations:", _NetworkAssociations.size());
+01678         for (i = 0; i < _NetworkAssociations.size (); i++)
+01679         {
+01680                 log->displayNL ("> 0x%08x -> '%s'", _NetworkAssociations[i], internalIPAddressToString (_NetworkAssociations[i]).c_str ());
+01681         }
+01682 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NLNET::CUnifiedNetwork::displayUnifiedConnection uint16  sid,
NLMISC::CLog log = NLMISC::InfoLog
[inline]
+
+ + + + + +
+   + + +

+ +

+Definition at line 231 of file unified_network.h. +

+References NLNET::CUnifiedNetwork::CUnifiedConnection::display(), getUnifiedConnection(), and uint16. +

+

00232         {
+00233                 getUnifiedConnection(sid)->display(false, log);
+00234         }
+
+

+ + + + +
+ + + + + + + + + + +
TUnifiedMsgCallback NLNET::CUnifiedNetwork::findCallback const std::string &  callbackName  ) 
+
+ + + + + +
+   + + +

+Find a callback in the array. +

+ +

+Definition at line 1393 of file unified_network.cpp. +

+References _Callbacks, and NLNET::TUnifiedMsgCallback. +

+Referenced by NLNET::NLMISC_COMMAND(). +

+

01394 {
+01395         TMsgMappedCallback::iterator    itcb = _Callbacks.find(callbackName);
+01396         if (itcb == _Callbacks.end())
+01397                 return NULL;
+01398         else
+01399                 return (*itcb).second;
+01400 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
uint8 NLNET::CUnifiedNetwork::findConnectionId uint16  sid,
uint8  nid
[private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 1030 of file unified_network.cpp. +

+References _IdCnx, nlwarning, uint16, and uint8. +

+Referenced by getNetBase(), send(), and sendAll(). +

+

01031 {
+01032         if (_IdCnx[sid].Connection.size () == 0)
+01033         {
+01034                 nlwarning ("HNETL5: Can't send message to %s because no connection are available", _IdCnx[sid].ServiceName.c_str ());
+01035                 return 0xFF;
+01036         }
+01037 
+01038         // by default, connection id will be the default one
+01039         uint8 connectionId = _IdCnx[sid].DefaultNetwork;
+01040 
+01041         if (nid == 0xFF)
+01042         {
+01043                 // it s often appen because they didn't set a good network configuration, so it s in debug to disable it easily
+01044                 //nldebug ("HNETL5: nid %hu, will use the default connection %hu", (uint16)nid, (uint16)connectionId);
+01045         }
+01046         else if (nid >= _IdCnx[sid].NetworkConnectionAssociations.size())
+01047         {
+01048                 nlwarning ("HNETL5: No net association for nid %hu, use the default connection %hu", (uint16)nid, (uint16)connectionId);
+01049         }
+01050         else
+01051         {
+01052                 if (_IdCnx[sid].NetworkConnectionAssociations[nid] >= _IdCnx[sid].Connection.size ())
+01053                 {
+01054                         nlwarning ("HNETL5: Can't send message to %s because nid %d point on a bad connection (%d and only have %d cnx), use default connection", _IdCnx[sid].ServiceName.c_str (), nid, connectionId, _IdCnx[sid].Connection.size ());
+01055                 }
+01056                 else
+01057                 {
+01058                         connectionId = _IdCnx[sid].NetworkConnectionAssociations[nid];
+01059                 }
+01060         }
+01061 
+01062         if (connectionId >= _IdCnx[sid].Connection.size() || !_IdCnx[sid].Connection[connectionId].valid() || !_IdCnx[sid].Connection[connectionId].CbNetBase->connected())
+01063         {
+01064                 // there's a problem with the selected connectionID, so try to find a valid one
+01065                 nlwarning ("HNETL5: Can't find selected connection id %hu to send message to %s because connection is not valid or connected, find a valid connection id", (uint16)connectionId, _IdCnx[sid].ServiceName.c_str ());
+01066 
+01067                 for (connectionId = 0; connectionId < _IdCnx[sid].Connection.size(); connectionId++)
+01068                 {
+01069                         if (_IdCnx[sid].Connection[connectionId].valid() && _IdCnx[sid].Connection[connectionId].CbNetBase->connected())
+01070                         {
+01071                                 // we found one at last, use this one
+01072                                 //nldebug ("HNETL5: Ok, we found a valid connectionid, use %hu",  (uint16)connectionId);
+01073                                 break;
+01074                         }
+01075                 }
+01076 
+01077                 if (connectionId == _IdCnx[sid].Connection.size())
+01078                 {
+01079                         nlwarning ("HNETL5: Can't send message to %s because default connection is not exist, valid or connected", _IdCnx[sid].ServiceName.c_str ());
+01080                         return 0xFF;
+01081                 }
+01082         }
+01083         return connectionId;
+01084 }
+
+

+ + + + +
+ + + + + + + + + +
uint64 NLNET::CUnifiedNetwork::getBytesReceived  ) 
+
+ + + + + +
+   + + +

+Gets the total number of bytes received. +

+ +

+Definition at line 1263 of file unified_network.cpp. +

+References _CbServer, _IdCnx, _UsedConnection, NLNET::CCallbackNetBase::getBytesReceived(), uint, and uint64. +

+Referenced by NLNET::NLMISC_DYNVARIABLE(). +

+

01264 {
+01265         uint64  received = 0;
+01266         uint    j;
+01267 
+01268         for (vector<uint16>::iterator it = _UsedConnection.begin (); it != _UsedConnection.end(); it++)
+01269         {
+01270                 if (_IdCnx[(*it)].State == CUnifiedNetwork::CUnifiedConnection::Ready)
+01271                         for (j=0; j<_IdCnx[(*it)].Connection.size (); ++j)
+01272                                 if(_IdCnx[(*it)].Connection[j].valid () && !_IdCnx[(*it)].Connection[j].IsServerConnection)
+01273                                         received += _IdCnx[(*it)].Connection[j].CbNetBase->getBytesReceived();
+01274         }
+01275         
+01276 /*      for (i=0; i<_IdCnx.size(); ++i)
+01277                 if (_IdCnx[i].State == CUnifiedNetwork::CUnifiedConnection::Ready)
+01278                         for (j=0; j<_IdCnx[i].Connection.size (); ++j)
+01279                                 if(_IdCnx[i].Connection[j].valid () && !_IdCnx[i].Connection[j].IsServerConnection)
+01280                                         received += _IdCnx[i].Connection[j].CbNetBase->getBytesReceived();
+01281 */
+01282         if (_CbServer)
+01283                 received += _CbServer->getBytesReceived();
+01284         return received;
+01285 }
+
+

+ + + + +
+ + + + + + + + + +
uint64 NLNET::CUnifiedNetwork::getBytesSent  ) 
+
+ + + + + +
+   + + +

+Gets the total number of bytes sent. +

+ +

+Definition at line 1239 of file unified_network.cpp. +

+References _CbServer, _IdCnx, _UsedConnection, NLNET::CCallbackNetBase::getBytesSent(), uint, and uint64. +

+Referenced by NLNET::NLMISC_DYNVARIABLE(). +

+

01240 {
+01241         uint64  sent = 0;
+01242         uint    j;
+01243 
+01244         for (vector<uint16>::iterator it = _UsedConnection.begin (); it != _UsedConnection.end(); it++)
+01245         {
+01246                 if (_IdCnx[(*it)].State == CUnifiedNetwork::CUnifiedConnection::Ready)
+01247                         for (j=0; j<_IdCnx[(*it)].Connection.size (); ++j)
+01248                                 if(_IdCnx[(*it)].Connection[j].valid () && !_IdCnx[(*it)].Connection[j].IsServerConnection)
+01249                                         sent += _IdCnx[(*it)].Connection[j].CbNetBase->getBytesSent();
+01250         }
+01251 
+01252 /*      for (i=0; i<_IdCnx.size(); ++i)
+01253                 if (_IdCnx[i].State == CUnifiedNetwork::CUnifiedConnection::Ready)
+01254                         for (j=0; j<_IdCnx[i].Connection.size (); ++j)
+01255                                 if(_IdCnx[i].Connection[j].valid () && !_IdCnx[i].Connection[j].IsServerConnection)
+01256                                         sent += _IdCnx[i].Connection[j].CbNetBase->getBytesSent();
+01257 */
+01258         if(_CbServer)
+01259                 sent += _CbServer->getBytesSent();
+01260         return sent;
+01261 }
+
+

+ + + + +
+ + + + + + + + + +
const std::vector<uint16>& NLNET::CUnifiedNetwork::getConnectionList  )  const [inline]
+
+ + + + + +
+   + + +

+Return the service ids of the active connections. +

+ +

+Definition at line 227 of file unified_network.h. +

+References _UsedConnection. +

+

00227 { return _UsedConnection; }
+
+

+ + + + +
+ + + + + + + + + +
CUnifiedNetwork * NLNET::CUnifiedNetwork::getInstance  )  [static]
+
+ + + + + +
+   + + +

+Returns the singleton instance of the CUnifiedNetwork class. +

+Definition at line 1481 of file unified_network.cpp. +

+References CUnifiedNetwork(). +

+Referenced by NLNET::IService::main(). +

+

01482 {
+01483         if (_Instance == NULL)
+01484                 _Instance = new CUnifiedNetwork();
+01485 
+01486         return _Instance;
+01487 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
CCallbackNetBase * NLNET::CUnifiedNetwork::getNetBase uint16  sid,
TSockId host,
uint8  nid = 0xFF
+
+ + + + + +
+   + + +

+Gets the CCallbackNetBase of the service. +

+ +

+Definition at line 1368 of file unified_network.cpp. +

+References _IdCnx, findConnectionId(), NLMISC::getThreadId(), nlassertex, nlwarning, NLNET::ThreadCreator, NLNET::TSockId, uint16, and uint8. +

+

01369 {
+01370         nlassertex(_Initialised == true, ("Try to CUnifiedNetwork::getNetBase() whereas it is not initialised yet"));
+01371 
+01372         if (ThreadCreator != NLMISC::getThreadId()) nlwarning ("HNETL5: Multithread access but this class is not thread safe thread creator = %u thread used = %u", ThreadCreator, NLMISC::getThreadId());
+01373 
+01374         if (sid >= _IdCnx.size () || _IdCnx[sid].State != CUnifiedNetwork::CUnifiedConnection::Ready)
+01375         {
+01376                 nlwarning ("HNETL5: Can't get net base to the service '%hu' because not in _IdCnx", sid);
+01377                 host = InvalidSockId;
+01378                 return NULL;
+01379         }
+01380 
+01381         uint8 connectionId = findConnectionId (sid, nid);
+01382         if (connectionId == 0xff)       // failed
+01383         {
+01384                 nlwarning ("HNETL5: Can't getNetBase %hu because no connection available", sid);
+01385                 host = InvalidSockId;
+01386                 return NULL;
+01387         }
+01388 
+01389         host = _IdCnx[sid].Connection[connectionId].HostId;
+01390         return _IdCnx[sid].Connection[connectionId].CbNetBase;
+01391 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
CCallbackNetBase * NLNET::CUnifiedNetwork::getNetBase const std::string &  name,
TSockId host,
uint8  nid = 0xFF
+
+ + + + + +
+   + + +

+Gets the CCallbackNetBase of the service. +

+

Warning:
You should not use getNetBase functions because it could have more than one connection to a service and in this case it ll return the first connection
+ +

+Definition at line 1335 of file unified_network.cpp. +

+References _IdCnx, _NamedCnx, count, findConnectionId(), NLMISC::getThreadId(), nlassertex, nlwarning, sint, NLNET::ThreadCreator, NLNET::TSockId, and uint8. +

+Referenced by NLNET::NLMISC_COMMAND(). +

+

01336 {
+01337         nlassertex(_Initialised == true, ("Try to CUnifiedNetwork::getNetBase() whereas it is not initialised yet"));
+01338 
+01339         if (ThreadCreator != NLMISC::getThreadId()) nlwarning ("HNETL5: Multithread access but this class is not thread safe thread creator = %u thread used = %u", ThreadCreator, NLMISC::getThreadId());
+01340 
+01341         sint    count = _NamedCnx.count(name);
+01342 
+01343         if (count <= 0)
+01344         {
+01345                 nlwarning ("HNETL5: couldn't access the service %s", name.c_str());
+01346                 host = InvalidSockId;
+01347                 return NULL;
+01348         }
+01349         else if (count > 1)
+01350         {
+01351                 nlwarning ("HNETL5: %d services %s to getNetBase, returns the first valid", count, name.c_str());
+01352         }
+01353 
+01354         TNameMappedConnection::const_iterator   itnmc = _NamedCnx.find(name);
+01355 
+01356         uint8 connectionId = findConnectionId ((*itnmc).second, nid);
+01357         if (connectionId == 0xff)       // failed
+01358         {
+01359                 nlwarning ("HNETL5: Can't getNetBase %s because no connection available", name.c_str());
+01360                 host = InvalidSockId;
+01361                 return NULL;
+01362         }
+01363 
+01364         host = _IdCnx[(*itnmc).second].Connection[connectionId].HostId;
+01365         return _IdCnx[(*itnmc).second].Connection[connectionId].CbNetBase;
+01366 }
+
+

+ + + + +
+ + + + + + + + + +
uint64 NLNET::CUnifiedNetwork::getReceiveQueueSize  ) 
+
+ + + + + +
+   + + +

+Gets the total number of bytes queued after receiving. +

+ +

+Definition at line 1311 of file unified_network.cpp. +

+References _CbServer, _IdCnx, _UsedConnection, NLNET::CCallbackServer::getReceiveQueueSize(), uint, and uint64. +

+Referenced by NLNET::NLMISC_DYNVARIABLE(). +

+

01312 {
+01313         uint64  received = 0;
+01314         uint    j;
+01315 
+01316         for (vector<uint16>::iterator it = _UsedConnection.begin (); it != _UsedConnection.end(); it++)
+01317         {
+01318                 if (_IdCnx[(*it)].State == CUnifiedNetwork::CUnifiedConnection::Ready)
+01319                         for (j=0; j<_IdCnx[(*it)].Connection.size (); ++j)
+01320                                 if(_IdCnx[(*it)].Connection[j].valid () && !_IdCnx[(*it)].Connection[j].IsServerConnection)
+01321                                         received += _IdCnx[(*it)].Connection[j].CbNetBase->getReceiveQueueSize();
+01322         }
+01323 
+01324 /*      for (i=0; i<_IdCnx.size(); ++i)
+01325                 if (_IdCnx[i].State == CUnifiedNetwork::CUnifiedConnection::Ready)
+01326                         for (j=0; j<_IdCnx[i].Connection.size (); ++j)
+01327                                 if(_IdCnx[i].Connection[j].valid () && !_IdCnx[i].Connection[j].IsServerConnection)
+01328                                         received += _IdCnx[i].Connection[j].CbNetBase->getReceiveQueueSize();
+01329 */
+01330         if (_CbServer)
+01331                 received += _CbServer->getReceiveQueueSize();
+01332         return received;
+01333 }
+
+

+ + + + +
+ + + + + + + + + +
uint64 NLNET::CUnifiedNetwork::getSendQueueSize  ) 
+
+ + + + + +
+   + + +

+Gets the total number of bytes queued for sending. +

+ +

+Definition at line 1287 of file unified_network.cpp. +

+References _CbServer, _IdCnx, _UsedConnection, NLNET::CCallbackServer::getSendQueueSize(), uint, and uint64. +

+Referenced by NLNET::NLMISC_DYNVARIABLE(). +

+

01288 {
+01289         uint64  sent = 0;
+01290         uint    j;
+01291 
+01292         for (vector<uint16>::iterator it = _UsedConnection.begin (); it != _UsedConnection.end(); it++)
+01293         {
+01294                 if (_IdCnx[(*it)].State == CUnifiedNetwork::CUnifiedConnection::Ready)
+01295                         for (j=0; j<_IdCnx[(*it)].Connection.size (); ++j)
+01296                                 if(_IdCnx[(*it)].Connection[j].valid () && !_IdCnx[(*it)].Connection[j].IsServerConnection)
+01297                                         sent += _IdCnx[(*it)].Connection[j].CbNetBase->getSendQueueSize();
+01298         }
+01299 
+01300 /*      for (i=0; i<_IdCnx.size(); ++i)
+01301                 if (_IdCnx[i].State == CUnifiedNetwork::CUnifiedConnection::Ready)
+01302                         for (j=0; j<_IdCnx[i].Connection.size (); ++j)
+01303                                 if(_IdCnx[i].Connection[j].valid () && !_IdCnx[i].Connection[j].IsServerConnection)
+01304                                         sent += _IdCnx[i].Connection[j].CbNetBase->getSendQueueSize();
+01305 */
+01306         if (_CbServer)
+01307                 sent += _CbServer->getSendQueueSize();
+01308         return sent;
+01309 }
+
+

+ + + + +
+ + + + + + + + + + +
std::string NLNET::CUnifiedNetwork::getServiceName uint16  sid  ) 
+
+ + + + + +
+   + + +

+Return the name of the specified service, or "" if not found. +

+ +

+Definition at line 1451 of file unified_network.cpp. +

+References getUnifiedConnection(), s, NLNET::CUnifiedNetwork::CUnifiedConnection::ServiceName, and uint16. +

+

01452 {
+01453         string s;
+01454         CUnifiedConnection *c = getUnifiedConnection(sid, false);
+01455         if (c)
+01456                 s = c->ServiceName;
+01457         return s;
+01458 }
+
+

+ + + + +
+ + + + + + + + + + +
std::string NLNET::CUnifiedNetwork::getServiceUnifiedName uint16  sid  ) 
+
+ + + + + +
+   + + +

+Return a string identifying the service, using the format "NAME-sid" (or "sid" only if not found). +

+ +

+Definition at line 1464 of file unified_network.cpp. +

+References getUnifiedConnection(), s, NLNET::CUnifiedNetwork::CUnifiedConnection::ServiceName, NLMISC::toString(), and uint16. +

+

01465 {
+01466         string s;
+01467         CUnifiedConnection *c = getUnifiedConnection(sid, false);
+01468         if (c)
+01469                 s = c->ServiceName + "-";
+01470         s += toString(sid);
+01471         return s;
+01472 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
CUnifiedNetwork::CUnifiedConnection * NLNET::CUnifiedNetwork::getUnifiedConnection uint16  sid,
bool  warn = true
[private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 1498 of file unified_network.cpp. +

+References _IdCnx, AUTOCHECK_DISPLAY, nlwarning, and uint16. +

+Referenced by displayUnifiedConnection(), getServiceName(), getServiceUnifiedName(), NLNET::uncbDisconnection(), NLNET::uncbMsgProcessing(), and NLNET::uNetUnregistrationBroadcast(). +

+

01499 {
+01500         if (sid < _IdCnx.size () && _IdCnx[sid].State == CUnifiedConnection::Ready)
+01501         {
+01502                 if (sid != _IdCnx[sid].ServiceId)
+01503                 {
+01504                         AUTOCHECK_DISPLAY ("HNETL5: Sid index %hu is not the same that in the entry %hu", sid, _IdCnx[sid].ServiceId);
+01505                         return NULL;
+01506                 }
+01507                 return &_IdCnx[sid];
+01508         }
+01509         else
+01510         {
+01511                 if ( warn )
+01512                         nlwarning ("HNETL5: Try to get a bad unified connection (sid %hu is not in the table)", sid);
+01513                 return NULL;
+01514         }
+01515 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
bool NLNET::CUnifiedNetwork::haveNamedCnx const std::string &  name,
uint16  sid
[private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 1684 of file unified_network.cpp. +

+References _NamedCnx, range, and uint16. +

+Referenced by update(). +

+

01685 {
+01686         CUnifiedNetwork::TNameMappedConnection::iterator                                                                                        it;
+01687         pair<CUnifiedNetwork::TNameMappedConnection::iterator,CUnifiedNetwork::TNameMappedConnection::iterator> range;
+01688         range = _NamedCnx.equal_range(name);
+01689 
+01690         if (range.first != range.second)
+01691         {
+01692                 for (it=range.first; it!=range.second && (*it).second!=sid; ++it)
+01693                         ;
+01694                 
+01695                 return (it != range.second);
+01696         }
+01697         return false;
+01698 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
bool NLNET::CUnifiedNetwork::init const CInetAddress addr,
CCallbackNetBase::TRecordingState  rec,
const std::string &  shortName,
uint16  port,
TServiceId sid
+
+ + + + + +
+   + + +

+Creates the connection to the Naming Service. If the connection failed, ESocketConnectionFailed exception is generated. This function is called automatically called by the service class at the beginning.

+

Parameters:
+ + + +
addr address of the naming service (0 is you don't want to use the naming service)
rec recording state to know if we have to record or replay messages
+
+
Returns:
false if the instance startup was denied by the naming service
+ +

+Definition at line 479 of file unified_network.cpp. +

+References _CbServer, _NamingServiceAddr, _ServerPort, NLNET::CCallbackNetBase::addCallbackArray(), addr, AUTOCHECK_DISPLAY, NLNET::fd, NLMISC::getThreadId(), NLNET::CBufServer::init(), NLNET::CInetAddress::isValid(), nlassert, nlinfo, NLNET::CCallbackServer::setConnectionCallback(), NLNET::CCallbackNetBase::setDefaultCallback(), NLNET::CCallbackServer::setDisconnectionCallback(), NLMISC::CFileDisplayer::setParam(), NLNET::ThreadCreator, NLMISC::toString(), NLNET::TServiceId, uint, uint16, NLNET::uncbConnection(), NLNET::uncbDisconnection(), NLNET::uncbMsgProcessing(), NLNET::uNetRegistrationBroadcast(), NLNET::uNetUnregistrationBroadcast(), and NLNET::unServerCbArray. +

+

00481 {
+00482         //DebugLog->addNegativeFilter ("HNETL5");
+00483 
+00484         if (_Initialised)
+00485         {
+00486                 AUTOCHECK_DISPLAY ("HNETL5: Unified network layer already initialized");
+00487                 return true;
+00488         }
+00489 
+00490         ThreadCreator = NLMISC::getThreadId();
+00491 
+00492         vector<CInetAddress> laddr = CInetAddress::localAddresses();
+00493 
+00494         _RecordingState = rec;
+00495         _Name = shortName;
+00496         _SId = sid;
+00497         
+00498         if (addr != 0)
+00499                 _NamingServiceAddr = *addr;
+00500 
+00501         // if the address isn't 0, uses the naming service
+00502         if (_NamingServiceAddr.isValid ())
+00503         {
+00504                 // connect the callback to know when a new service comes in or goes down
+00505                 CNamingClient::setRegistrationBroadcastCallback(uNetRegistrationBroadcast);
+00506                 CNamingClient::setUnregistrationBroadcastCallback(uNetUnregistrationBroadcast);
+00507 
+00508                 // connect to the naming service (may generate a ESocketConnectionFailed exception)
+00509                 CNamingClient::connect(_NamingServiceAddr, _RecordingState, laddr);
+00510 
+00511                 if (port == 0)
+00512                         port = CNamingClient::queryServicePort ();
+00513         }
+00514 
+00515         // setup the server callback only if server port != 0, otherwise there's no server callback
+00516         _ServerPort = port;
+00517 
+00518         if(_ServerPort != 0)
+00519         {
+00520                 nlassert (_CbServer == 0);
+00521                 _CbServer = new CCallbackServer;
+00522                 _CbServer->init(port);
+00523                 _CbServer->addCallbackArray(unServerCbArray, 1);                                // the service ident callback
+00524                 _CbServer->setDefaultCallback(uncbMsgProcessing);                               // the default callback wrapper
+00525                 _CbServer->setConnectionCallback(uncbConnection, NULL);
+00526                 _CbServer->setDisconnectionCallback(uncbDisconnection, NULL);
+00527         }
+00528         else
+00529         {
+00530                 nlinfo ("HNETL5: ServerPort is 0 so I don't create a CCallbackServer");
+00531         }
+00532 
+00533         if (CNamingClient::connected())
+00534         {
+00535                 // register the service
+00536                 for (uint i = 0; i < laddr.size(); i++)
+00537                         laddr[i].setPort(_ServerPort);
+00538 
+00539                 if (_SId == 0)
+00540                 {
+00541                         if ( ! CNamingClient::registerService(_Name, laddr, _SId) )
+00542                         {
+00543                                 nlinfo ("HNETL5: Registration denied");
+00544                                 return false;
+00545                         }
+00546                 }
+00547                 else
+00548                 {
+00549                         CNamingClient::registerServiceWithSId(_Name, laddr, _SId);
+00550                 }
+00551 
+00552                 sid = _SId;
+00553 
+00554                 nlinfo ("HNETL5: Server '%s' added, registered and listen to port %hu", _Name.c_str (), _ServerPort);
+00555         }
+00556 
+00557         string fn = _Name+"_"+toString(_SId)+".log";
+00558         fd.setParam (fn);
+00559         test.addDisplayer (&fd);
+00560         test.displayNL ("**************INIT***************");
+00561 
+00562         _Initialised = true;
+00563         return true;
+00564 }
+
+

+ + + + +
+ + + + + + + + + + +
bool NLNET::CUnifiedNetwork::isServiceLocal const std::string &  serviceName  ) 
+
+ + + + + +
+   + + +

+Returns true if the serviceName service is on the same computer than this service. +

+ +

+Definition at line 1402 of file unified_network.cpp. +

+References _NamedCnx, isServiceLocal(), range, and uint16. +

+

01403 {
+01404         // it s me, of course we are local
+01405         if (serviceName == _Name)
+01406                 return true;
+01407 
+01408         pair<TNameMappedConnection::const_iterator,TNameMappedConnection::const_iterator>       range;
+01409         range = _NamedCnx.equal_range(serviceName);
+01410 
+01411         if (range.first != _NamedCnx.end())
+01412         {
+01413                 uint16  sid = (*(range.first)).second;
+01414                 return isServiceLocal (sid);
+01415         }
+01416 
+01417         return false;
+01418 }
+
+

+ + + + +
+ + + + + + + + + + +
bool NLNET::CUnifiedNetwork::isServiceLocal uint16  sid  ) 
+
+ + + + + +
+   + + +

+Returns true if the sid service is on the same computer than this service. +

+ +

+Definition at line 1420 of file unified_network.cpp. +

+References _IdCnx, uint, and uint16. +

+Referenced by isServiceLocal(), and NLNET::NLMISC_COMMAND(). +

+

01421 {
+01422         // it s me, of course we are local
+01423         if (sid == _SId)
+01424                 return true;
+01425 
+01426         if (sid >= _IdCnx.size () || _IdCnx[sid].State != CUnifiedNetwork::CUnifiedConnection::Ready)
+01427         {
+01428                 return false;
+01429         }
+01430 
+01431         vector<CInetAddress> laddr = CInetAddress::localAddresses();
+01432 
+01433         for (uint i = 0; i < laddr.size(); i++)
+01434         {
+01435                 for (uint j = 0; j < _IdCnx[sid].ExtAddress.size(); j++)
+01436                 {
+01437                         if (_IdCnx[sid].ExtAddress[j].is127001 ())
+01438                                 return true;
+01439 
+01440                         if (_IdCnx[sid].ExtAddress[j].internalIPAddress () == laddr[i].internalIPAddress ())
+01441                                 return true;
+01442                 }
+01443         }
+01444         return false;
+01445 }
+
+

+ + + + +
+ + + + + + + + + +
bool NLNET::CUnifiedNetwork::isUsed  )  [static]
+
+ + + + + +
+   + + +

+Returns true if the application called getInstance(). This function is used to know if the user is using layer 4 or layer 5 +

+Definition at line 1489 of file unified_network.cpp. +

+

01490 {
+01491         return (_Instance != NULL);
+01492 }
+
+

+ + + + +
+ + + + + + + + + +
void NLNET::CUnifiedNetwork::release  ) 
+
+ + + + + +
+   + + +

+Closes the connection to the naming service, every other connection and free. +

+Definition at line 599 of file unified_network.cpp. +

+References _Callbacks, _CbServer, _DownCallbacks, _IdCnx, _NamedCnx, _UpCallbacks, _UsedConnection, NLNET::CCallbackServer::disconnect(), NLMISC::getThreadId(), nlwarning, NLNET::ThreadCreator, and uint. +

+

00600 {
+00601         if (!_Initialised)
+00602                 return;
+00603 
+00604         if (ThreadCreator != NLMISC::getThreadId()) nlwarning ("HNETL5: Multithread access but this class is not thread safe thread creator = %u thread used = %u", ThreadCreator, NLMISC::getThreadId());
+00605 
+00606         // disconnect all clients
+00607         if(_CbServer)
+00608         {
+00609                 _CbServer->disconnect(InvalidSockId);
+00610                 delete _CbServer;
+00611                 _CbServer = 0;
+00612         }
+00613 
+00614         // disconnect all connections to servers
+00615         for (uint i = 0; i<_IdCnx.size(); ++i)
+00616         {
+00617                 if (_IdCnx[i].State != CUnifiedNetwork::CUnifiedConnection::NotUsed)
+00618                 {
+00619                         for(uint j = 0 ; j < _IdCnx[i].Connection.size (); j++)
+00620                         {
+00621                                 if (_IdCnx[i].Connection[j].valid() && !_IdCnx[i].Connection[j].IsServerConnection)
+00622                                 {
+00623                                         if (_IdCnx[i].Connection[j].CbNetBase->connected ())
+00624                                                 _IdCnx[i].Connection[j].CbNetBase->disconnect();
+00625                                 
+00626                                         delete _IdCnx[i].Connection[j].CbNetBase;
+00627                                 }
+00628                         }
+00629                         _IdCnx[i].Connection.clear ();
+00630                 }
+00631         }
+00632 
+00633         // clear all other data
+00634         _IdCnx.clear();
+00635         _UsedConnection.clear ();
+00636         _NamedCnx.clear();
+00637         _UpCallbacks.clear();
+00638         _DownCallbacks.clear();
+00639         _Callbacks.clear();
+00640 
+00641         // disconnect the connection with the naming service
+00642         if (CNamingClient::connected ())
+00643                 CNamingClient::disconnect ();
+00644 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NLNET::CUnifiedNetwork::removeNamedCnx const std::string &  name,
uint16  sid
[private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 1727 of file unified_network.cpp. +

+References _NamedCnx, NLNET::allstuffs, AUTOCHECK_DISPLAY, range, NLMISC::toString(), and uint16. +

+Referenced by NLNET::uncbDisconnection(), and NLNET::uNetUnregistrationBroadcast(). +

+

01728 {
+01729         // get all map nodes of that service name
+01730         CUnifiedNetwork::TNameMappedConnection::iterator                                                                                        it;
+01731         pair<CUnifiedNetwork::TNameMappedConnection::iterator,CUnifiedNetwork::TNameMappedConnection::iterator> range;
+01732         range = _NamedCnx.equal_range(name);
+01733 
+01734         // assume not empty
+01735         if (range.first == range.second)
+01736         {
+01737                 AUTOCHECK_DISPLAY ("HNETL5: The unified connection %s-%hu wasn't on the _NamedCnx", name.c_str(), sid);
+01738                 return;
+01739         }
+01740 
+01741         // select good service id
+01742         for (it=range.first; it!=range.second && (*it).second!=sid; ++it)
+01743                 ;
+01744 
+01745         // assume id exists
+01746         if (it == range.second)
+01747         {
+01748                 AUTOCHECK_DISPLAY ("HNETL5: The unified connection %s-%hu wasn't on the _NamedCnx", name.c_str(), sid);
+01749                 return;
+01750         }
+01751 
+01752         // remove service for map
+01753         _NamedCnx.erase(it);
+01754 
+01755         allstuffs += "-name "+name+"-"+toString(sid)+"\n";
+01756         test.displayNL ("-name %s-%hu", name.c_str (), sid);
+01757 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
bool NLNET::CUnifiedNetwork::send uint16  serviceId,
const CMessage msg,
uint8  nid = 0xFF
+
+ + + + + +
+   + + +

+Sends a message to a specific serviceId.

Parameters:
+ + + + +
serviceId Id of the service you want to send the message.
msg the message you want to send.
nid Network Id specify to which network the message must pass throw (0xFF mean the default network)
+
+
Returns:
true if the service was found (may return true even if the sending failed)
+ +

+Definition at line 1136 of file unified_network.cpp. +

+References _IdCnx, findConnectionId(), NLMISC::getThreadId(), nlassertex, nlwarning, NLNET::ThreadCreator, uint16, and uint8. +

+

01137 {
+01138         nlassertex(_Initialised == true, ("Try to CUnifiedNetwork::send(uint16, const CMessage&) whereas it is not initialised yet"));
+01139 
+01140         if (ThreadCreator != NLMISC::getThreadId()) nlwarning ("HNETL5: Multithread access but this class is not thread safe thread creator = %u thread used = %u", ThreadCreator, NLMISC::getThreadId());
+01141 
+01142         if (sid >= _IdCnx.size () || _IdCnx[sid].State != CUnifiedNetwork::CUnifiedConnection::Ready)
+01143         {
+01144                 // happen when trying to send a message to an unknown service id
+01145                 nlwarning ("HNETL5: Can't send to the service '%hu' because not in _IdCnx", sid);
+01146                 return false;
+01147         }
+01148 
+01149         uint8 connectionId = findConnectionId (sid, nid);
+01150         if (connectionId == 0xff)       // failed
+01151         {
+01152                 nlwarning ("HNETL5: Can't send to the service '%hu' because no connection available", sid);
+01153                 return false;
+01154         }
+01155 
+01156         _IdCnx[sid].Connection[connectionId].CbNetBase->send (msgout, _IdCnx[sid].Connection[connectionId].HostId);
+01157         return true;
+01158 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
bool NLNET::CUnifiedNetwork::send const std::string &  serviceName,
const CMessage msg,
uint8  nid = 0xFF
+
+ + + + + +
+   + + +

+Sends a message to a specific serviceName. If there's more than one service with this name, all services of this name will receive the message.

Parameters:
+ + + + +
serviceName name of the service you want to send the message (may not be unique.)
msg the message you want to send.
nid Network Id specify to which network the message must pass throw (0xFF mean the default network)
+
+
Returns:
true if the service was found (one or more instances) (may return true even if the sending failed)
+ +

+Definition at line 1091 of file unified_network.cpp. +

+References _IdCnx, _NamedCnx, findConnectionId(), NLNET::CMessage::getName(), NLMISC::getThreadId(), nlassertex, nlwarning, range, NLNET::ThreadCreator, uint16, and uint8. +

+

01092 {
+01093         nlassertex(_Initialised == true, ("Try to CUnifiedNetwork::send(const string&, const CMessage&) whereas it is not initialised yet"));
+01094 
+01095         if (ThreadCreator != NLMISC::getThreadId()) nlwarning ("HNETL5: Multithread access but this class is not thread safe thread creator = %u thread used = %u", ThreadCreator, NLMISC::getThreadId());
+01096 
+01097         TNameMappedConnection::const_iterator                                                           it;
+01098         pair<TNameMappedConnection::const_iterator,TNameMappedConnection::const_iterator>       range;
+01099         range = _NamedCnx.equal_range(serviceName);
+01100 
+01101         bool found = false;
+01102         if (range.first != _NamedCnx.end())
+01103         {
+01104                 for (it=range.first; it!=range.second; ++it)
+01105                 {
+01106                         uint16  sid = (*it).second;
+01107                         if (sid >= _IdCnx.size () || _IdCnx[sid].State != CUnifiedNetwork::CUnifiedConnection::Ready)
+01108                         {
+01109                                 // It often happen when the service is down (connection broke and the naming not already say that it s down)
+01110                                 // In this case, just warn
+01111                                 nlwarning ("HNETL5: Can't send to the service '%s' because it was in the _NamedCnx but not in _IdCnx (means that the service is down)", serviceName.c_str ());
+01112                                 return false;
+01113                         }
+01114 
+01115                         found = true;
+01116 
+01117                         uint8 connectionId = findConnectionId (sid, nid);
+01118                         if (connectionId == 0xff)       // failed
+01119                         {
+01120                                 nlwarning ("HNETL5: Can't send message to %hu because no connection available", sid);
+01121                                 found = false;
+01122                                 continue;
+01123                         }
+01124 
+01125                         //nldebug ("HNETL5: send message to %s using nid %d cnx %d / %s", serviceName.c_str (), nid, connectionId, connectionId<_IdCnx[sid].ExtAddress.size ()?_IdCnx[sid].ExtAddress[connectionId].asString().c_str():"???");
+01126                         _IdCnx[sid].Connection[connectionId].CbNetBase->send (msgout, _IdCnx[sid].Connection[connectionId].HostId);
+01127                 }
+01128         }
+01129 
+01130         if (!found)
+01131                 nlwarning ("HNETL5: can't find service %s to send message %s", serviceName.c_str(), msgout.getName().c_str());
+01132 
+01133         return found;
+01134 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NLNET::CUnifiedNetwork::sendAll const CMessage msg,
uint8  nid = 0xFF
+
+ + + + + +
+   + + +

+Broadcasts a message to all connected services.

Parameters:
+ + + +
msg the message you want to send.
nid Network Id specify to which network the message must pass throw (0xFF mean the default network)
+
+ +

+Definition at line 1160 of file unified_network.cpp. +

+References _IdCnx, findConnectionId(), NLMISC::getThreadId(), nlassertex, nlwarning, NLNET::ThreadCreator, uint, and uint8. +

+

01161 {
+01162         nlassertex(_Initialised == true, ("Try to CUnifiedNetwork::send(const CMessage&) whereas it is not initialised yet"));
+01163 
+01164         if (ThreadCreator != NLMISC::getThreadId()) nlwarning ("HNETL5: Multithread access but this class is not thread safe thread creator = %u thread used = %u", ThreadCreator, NLMISC::getThreadId());
+01165 
+01166         uint    i;
+01167         for (i=0; i<_IdCnx.size(); ++i)
+01168         {
+01169                 if (_IdCnx[i].State == CUnifiedNetwork::CUnifiedConnection::Ready)
+01170                 {
+01171                         uint8 connectionId = findConnectionId (i, nid);
+01172                         if (connectionId == 0xff)       // failed
+01173                         {
+01174                                 nlwarning ("HNETL5: Can't send message to %u because no connection available", i);
+01175                                 continue;
+01176                         }
+01177 
+01178                         _IdCnx[i].Connection[connectionId].CbNetBase->send (msgout, _IdCnx[i].Connection[connectionId].HostId);
+01179                 }
+01180         }
+01181 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void NLNET::CUnifiedNetwork::setServiceDownCallback const std::string &  serviceName,
TUnifiedNetCallback  cb,
void *  arg = 0,
bool  back = true
+
+ + + + + +
+   + + +

+Sets callback for disconnections. On a client, the callback will be call each time the connection to the server is lost. On a server, the callback is called each time a client is disconnected.

+You can set more than one callback, each one will be called one after one. If the serviceName is "*", the callback will be call for any services If you set the same callback for a specific service S and for "*", the callback might be call twice (in case the service S is down)

+

Parameters:
+ + +
back if true, put the callback at the end of the callback array, otherwise but on the beginning. You should always use true
+
+ +

+Definition at line 1216 of file unified_network.cpp. +

+References _DownCallbacks, _DownUniCallback, nlassert, and NLNET::TUnifiedNetCallback. +

+

01217 {
+01218         nlassert (cb != NULL);
+01219         if (serviceName == "*")
+01220         {
+01221                 if (back)
+01222                         _DownUniCallback.push_back (make_pair(cb, arg));
+01223                 else
+01224                         _DownUniCallback.insert (_DownUniCallback.begin(), make_pair(cb, arg));
+01225         }
+01226         else
+01227         {
+01228                 if (back)
+01229                         _DownCallbacks[serviceName].push_back (make_pair(cb, arg));
+01230                 else
+01231                         _DownCallbacks[serviceName].insert (_DownCallbacks[serviceName].begin(), make_pair(cb, arg));
+01232         }
+01233 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void NLNET::CUnifiedNetwork::setServiceUpCallback const std::string &  serviceName,
TUnifiedNetCallback  cb,
void *  arg = 0,
bool  back = true
+
+ + + + + +
+   + + +

+Sets callback for incoming connections. On a client, the callback will be call when the connection to the server is established (the first connection or after the server shutdown and started) On a server, the callback is called each time a new client is connected to him

+You can set more than one callback, each one will be called one after one. If the serviceName is "*", the callback will be call for any services If you set the same callback for a specific service S and for "*", the callback might be call twice (in case the service S is up)

+

Parameters:
+ + +
back if true, put the callback at the end of the callback array, otherwise but on the beginning. You should always use true
+
+ +

+Definition at line 1197 of file unified_network.cpp. +

+References _UpCallbacks, _UpUniCallback, nlassert, and NLNET::TUnifiedNetCallback. +

+

01198 {
+01199         nlassert (cb != NULL);
+01200         if (serviceName == "*")
+01201         {
+01202                 if (back)
+01203                         _UpUniCallback.push_back (make_pair(cb, arg));
+01204                 else
+01205                         _UpUniCallback.insert (_UpUniCallback.begin(), make_pair(cb, arg));
+01206         }
+01207         else
+01208         {
+01209                 if (back)
+01210                         _UpCallbacks[serviceName].push_back (make_pair(cb, arg));
+01211                 else
+01212                         _UpCallbacks[serviceName].insert (_UpCallbacks[serviceName].begin(), make_pair(cb, arg));
+01213         }       
+01214 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLNET::CUnifiedNetwork::update NLMISC::TTime  timeout = 0  ) 
+
+ + + + + +
+   + + +

+Call it evenly. the parameter select the timeout value in seconds for each update. You are absolutely certain that this function will not be returns before this amount of time you set. If you set the update timeout value higher than 0, all messages in queues will be process until the time is greater than the timeout user update(). If you set the update timeout value to 0, all messages in queues will be process one time before calling the user update(). In this case, we don't nlSleep(1). +

+Definition at line 857 of file unified_network.cpp. +

+References _CbServer, _IdCnx, _LastRetry, _NamingServiceAddr, _ServerPort, _UsedConnection, addNamedCnx(), NLNET::CInetAddress::asString(), autoCheck(), NLNET::CUnifiedNetwork::CUnifiedConnection::AutoRetry, callServiceUpCallback(), NLNET::CCallbackClient::connect(), NLNET::CUnifiedNetwork::CUnifiedConnection::Connection, NLNET::CUnifiedNetwork::CUnifiedConnection::ExtAddress, NLMISC::getThreadId(), H_AUTO, H_TIME, haveNamedCnx(), NLNET::CUnifiedNetwork::CUnifiedConnection::IsExternal, NLNET::CInetAddress::isValid(), nlassert, nlassertex, nlinfo, NLMISC::nlSleep(), nlwarning, NLNET::CUnifiedNetwork::CUnifiedConnection::SendId, NLMISC::CMemStream::serial(), NLNET::CUnifiedNetwork::CUnifiedConnection::ServiceId, NLNET::CUnifiedNetwork::CUnifiedConnection::ServiceName, NLNET::CUnifiedNetwork::CUnifiedConnection::State, NLNET::ThreadCreator, NLMISC::TTime, uint, uint16, uint8, and NLNET::CCallbackServer::update(). +

+

00858 {
+00859         H_AUTO(CUnifiedNetworkUpdate);
+00860         
+00861         nlassertex(_Initialised == true, ("Try to CUnifiedNetwork::update() whereas it is not initialised yet"));
+00862 
+00863         if (ThreadCreator != NLMISC::getThreadId()) nlwarning ("HNETL5: Multithread access but this class is not thread safe thread creator = %u thread used = %u", ThreadCreator, NLMISC::getThreadId());
+00864 
+00865         bool    enableRetry;    // true every 5 seconds to reconnect if necessary
+00866 
+00867         // Compute the real timeout based on the next update timeout
+00868         TTime t0 = CTime::getLocalTime ();
+00869 
+00870         if (timeout > 0)
+00871         {
+00872                 if (_NextUpdateTime == 0)
+00873                 {
+00874                         _NextUpdateTime = t0 + timeout;
+00875                 }
+00876                 else
+00877                 {
+00878                         TTime err = t0 - _NextUpdateTime;
+00879                         _NextUpdateTime += timeout;
+00880 
+00881                         // if we are too late, resync to the next value
+00882                         while (err > timeout)
+00883                         {
+00884                                 err -= timeout;
+00885                                 _NextUpdateTime += timeout;
+00886                         }
+00887                         
+00888                         timeout -= err;
+00889                         if (timeout < 0) timeout = 0;
+00890                 }
+00891         }
+00892 
+00893         // check if we need to retry to connect to the client
+00894         if ((enableRetry = (t0-_LastRetry > 5000)))
+00895                 _LastRetry = t0;
+00896 
+00897         // Try to reconnect to the naming service if connection lost
+00898         if (_NamingServiceAddr.isValid ())
+00899         {
+00900                 if (CNamingClient::connected ())
+00901                 {
+00902                         CNamingClient::update ();
+00903                 }
+00904                 else if (enableRetry)
+00905                 {
+00906                         H_AUTO(L5NSReconnect);
+00907                         try
+00908                         {
+00909                                 vector<CInetAddress> laddr = CInetAddress::localAddresses();
+00910                                 CNamingClient::connect (_NamingServiceAddr, _RecordingState, laddr);
+00911                                 // re-register the service
+00912                                 for (uint i = 0; i < laddr.size(); i++)
+00913                                         laddr[i].setPort(_ServerPort);
+00914                                 CNamingClient::resendRegisteration (_Name, laddr, _SId);
+00915                         }
+00916                         catch (ESocketConnectionFailed &)
+00917                         {
+00918                                 nlwarning ("HNETL5: Could not connect to the Naming Service (%s). Retrying in a few seconds...", _NamingServiceAddr.asString().c_str());
+00919                         }
+00920                 }
+00921         }
+00922 
+00923         while (true)
+00924         {
+00925                 // update all server connections
+00926                 if (_CbServer)
+00927                 {
+00928                         _CbServer->update(0);
+00929                 }
+00930                 
+00931                 // update all client connections
+00932                 for (uint k = 0; k<_UsedConnection.size(); ++k)
+00933                 {
+00934                         CUnifiedConnection &uc = _IdCnx[_UsedConnection[k]];
+00935                         nlassert (uc.State == CUnifiedNetwork::CUnifiedConnection::Ready);
+00936                         for (uint j = 0; j < uc.Connection.size (); j++)
+00937                         {
+00938                                 if (!uc.Connection[j].valid())
+00939                                         continue;
+00940 
+00941                                 if (uc.Connection[j].IsServerConnection)
+00942                                         continue;
+00943 
+00944                                 if (uc.Connection[j].CbNetBase->connected ())
+00945                                 {
+00946                                         uc.Connection[j].CbNetBase->update(0);
+00947                                 }
+00948                                 else if (enableRetry && uc.AutoRetry)
+00949                                 {
+00950                                         H_AUTO(L5AutoReconnect);
+00951                                         try
+00952                                         {
+00953                                                 CCallbackClient *cbc = (CCallbackClient *)uc.Connection[j].CbNetBase;
+00954                                                 cbc->connect(uc.ExtAddress[j]);
+00955                                                 uc.Connection[j].CbNetBase->getSockId()->setAppId(uc.ServiceId);
+00956                                                 nlinfo ("HNETL5: reconnection to %s-%hu success", uc.ServiceName.c_str(), uc.ServiceId);
+00957 
+00958 
+00959                                                 // add the name only if at least one connection is ok
+00960                                                 if (!haveNamedCnx (uc.ServiceName, uc.ServiceId))
+00961                                                         addNamedCnx (uc.ServiceName, uc.ServiceId);
+00962 
+00963                                                 // resend the identification is necessary
+00964                                                 if (uc.SendId)
+00965                                                 {
+00966                                                         // send identification to the service
+00967                                                         CMessage        msg("UN_SIDENT");
+00968                                                         msg.serial(_Name);
+00969 
+00970                                                         uint16          ssid = _SId;
+00971                                                         if (uc.IsExternal)
+00972                                                         {
+00973                                                                 // in the case that the service is external, we can't send our sid because the external service can
+00974                                                                 // have other connection with the same sid (for example, LS can have 2 WS with same sid => sid = 0 and leave
+00975                                                                 // the other side to find a good number
+00976                                                                 ssid = 0;
+00977                                                         }
+00978                                                         msg.serial(ssid);       // serializes a 16 bits service id
+00979                                                         uint8 pos = j;
+00980                                                         msg.serial(pos);        // send the position in the connection table
+00981                                                         msg.serial (uc.IsExternal);
+00982                                                         uc.Connection[j].CbNetBase->send (msg, uc.Connection[j].HostId);
+00983                                                 }
+00984 
+00985                                                 // call the user callback
+00986                                                 callServiceUpCallback (uc.ServiceName, uc.ServiceId);
+00987                                                 /*
+00988                                                 CUnifiedNetwork::TNameMappedCallback::iterator  it = _UpCallbacks.find(uc.ServiceName);
+00989                                                 if (it != _UpCallbacks.end())
+00990                                                 {
+00991                                                         // call it
+00992                                                         for (list<TCallbackArgItem> it2 = (*it).second.begin(); it2 != (*it).second.end(); it2++)
+00993                                                         {
+00994                                                                 TUnifiedNetCallback     cb = (*it2).first;
+00995                                                                 if (cb) cb(uc.ServiceName, uc.ServiceId, (*it2).second);
+00996                                                         }
+00997                                                 }
+00998 
+00999                                                 for (uint c = 0; c < _UpUniCallback.size (); c++)
+01000                                                 {
+01001                                                         if (_UpUniCallback[c].first != NULL)
+01002                                                                 _UpUniCallback[c].first (uc.ServiceName, uc.ServiceId, _UpUniCallback[c].second);
+01003                                                 }
+01004                                                 */
+01005                                         }
+01006                                         catch (ESocketConnectionFailed &e)
+01007                                         {
+01008                                                 nlinfo ("HNETL5: can't connect to %s-%hu now (%s)", uc.ServiceName.c_str(), uc.ServiceId, e.what ());
+01009                                         }
+01010                                 }
+01011                         }
+01012                 }
+01013 
+01014                 enableRetry = false;
+01015 
+01016                 // If it's the end, don't nlSleep()
+01017                 if (CTime::getLocalTime() - t0 > timeout)
+01018                         break;
+01019                 
+01020                 // Enable windows multithreading before rescanning all connections
+01021                 H_TIME(L5UpdateSleep, nlSleep(1););
+01022         }
+01023 
+01024         autoCheck();
+01025 }
+
+


Friends And Related Function Documentation

+

+ + + + +
+ + +
friend struct isServiceLocalClass [friend] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 510 of file unified_network.h.

+

+ + + + +
+ + +
friend struct l5CallbackClass [friend] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 511 of file unified_network.h.

+

+ + + + +
+ + +
friend struct l5QueuesStatsClass [friend] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 512 of file unified_network.h.

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void uncbConnection TSockId  from,
void *  arg
[friend]
+
+ + + + + +
+   + + +

+ +

+Definition at line 172 of file unified_network.cpp. +

+

00173 {
+00174         nlinfo ("HNETL5: + connec '%s'", from->asString().c_str());
+00175 
+00176         from->setAppId (AppIdDeadConnection);
+00177 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void uncbDisconnection TSockId  from,
void *  arg
[friend]
+
+ + + + + +
+   + + +

+ +

+Definition at line 179 of file unified_network.cpp. +

+

00180 {
+00181         if(from->appId () == AppIdDeadConnection)
+00182         {
+00183                 nlinfo ("HNETL5: - connec '%s'", from->asString().c_str());
+00184                 test.displayNL ("-connect dead conenction");
+00185         }
+00186         else
+00187         {
+00188                 CUnifiedNetwork *uni = CUnifiedNetwork::getInstance();
+00189                 uint16                  sid = (uint16)from->appId();
+00190                 CUnifiedNetwork::CUnifiedConnection *uc = uni->getUnifiedConnection (sid);
+00191                 if (uc == 0)
+00192                 {
+00193                         nlinfo ("HNETL5: - connec '%s' sid %hu", from->asString().c_str(), sid);
+00194                         test.displayNL ("-connect '%s' %hu", from->asString ().c_str (), sid);
+00195                 }
+00196                 else
+00197                 {
+00198                         nlinfo ("HNETL5: - connec '%s' %s-%hu", from->asString().c_str(), uc->ServiceName.c_str (), sid);
+00199                         allstuffs += "-connect "+uc->ServiceName+"-"+toString(sid)+"\n";
+00200                         test.displayNL ("-connect %s-%hu", uc->ServiceName.c_str (), (uint16)(uc->ServiceId));
+00201 
+00202                         if (uc->IsExternal)
+00203                         {
+00204                                 if (!uc->AutoRetry)
+00205                                 {
+00206                                         // If it s a external service with no auto retry, remove the connection
+00207                                         
+00208                                         // call the user callback
+00209                                         uni->callServiceDownCallback(uc->ServiceName, uc->ServiceId);
+00210                                         
+00211                                         /*CUnifiedNetwork::TNameMappedCallback::iterator        it2 = uni->_DownCallbacks.find(uc->ServiceName);
+00212 
+00213                                         if (it2 != uni->_DownCallbacks.end())
+00214                                         {
+00215                                                 // call it
+00216                                                 TUnifiedNetCallback     cb = (*it2).second.first;
+00217                                                 cb(uc->ServiceName, uc->ServiceId, (*it2).second.second);
+00218                                         }
+00219 
+00220                                         for (uint c = 0; c < uni->_DownUniCallback.size (); c++)
+00221                                         {
+00222                                                 if (uni->_DownUniCallback[c].first != NULL)
+00223                                                         uni->_DownUniCallback[c].first(uc->ServiceName, uc->ServiceId, uni->_DownUniCallback[c].second);
+00224                                         }*/
+00225 
+00226                                         uni->removeNamedCnx (uc->ServiceName, uc->ServiceId);
+00227         
+00228                                         // remove the _UsedConnection
+00229                                         bool found = false;
+00230                                         for (vector<uint16>::iterator it = uni->_UsedConnection.begin (); it != uni->_UsedConnection.end(); it++)
+00231                                         {
+00232                                                 if (*it == uc->ServiceId)
+00233                                                 {
+00234                                                         found = true;
+00235                                                         uni->_UsedConnection.erase (it);
+00236                                                         break;
+00237                                                 }
+00238                                         }
+00239                                         if (!found) AUTOCHECK_DISPLAY ("HNETL5: can't find the sid %hu in the _UsedConnection", uc->ServiceId);
+00240 
+00241                                         uc->reset ();
+00242                                 }
+00243                         }
+00244                         else
+00245                         {
+00246                                 // reset the connection
+00247                                 uint i;
+00248                                 for (i = 0; i < uc->Connection.size (); i++)
+00249                                 {
+00250                                         if (uc->Connection[i].valid() && uc->Connection[i].CbNetBase->getSockId(uc->Connection[i].HostId) == from)
+00251                                         {
+00252                                                 if (uc->Connection[i].IsServerConnection)
+00253                                                 {
+00254                                                         // we have to remove the stuffs now because HostId will not be accessible later
+00255                                                         uc->Connection[i].reset();
+00256                                                 }
+00257                                                 else
+00258                                                 {
+00259                                                         // if it s a client, we can't delete now because the callback client is currently in use
+00260                                                         // only disconnect
+00261                                                         if(uc->Connection[i].CbNetBase->connected ())
+00262                                                         {
+00263                                                                 uc->Connection[i].CbNetBase->disconnect (uc->Connection[i].HostId);
+00264                                                         }
+00265                                                 }
+00266                                                 break;
+00267                                         }
+00268                                 }
+00269                                 if (i == uc->Connection.size ())
+00270                                 {
+00271                                         AUTOCHECK_DISPLAY ("HNETL5: received a disconnection from a service but the connection is not in my list!");
+00272                                 }
+00273                         }
+00274                 }
+00275 
+00276                 from->setAppId (AppIdDeadConnection);
+00277         }
+00278 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void uncbMsgProcessing CMessage msgin,
TSockId  from,
CCallbackNetBase netbase
[friend]
+
+ + + + + +
+   + + +

+ +

+Definition at line 406 of file unified_network.cpp. +

+

00407 {
+00408         if (from->appId() == AppIdDeadConnection)
+00409         {
+00410                 AUTOCHECK_DISPLAY ("HNETL5: Receive a message from a dead connection");
+00411                 return;
+00412         }
+00413 
+00414         CUnifiedNetwork                                                                 *uni = CUnifiedNetwork::getInstance();
+00415         uint16                                                                                  sid = (uint16)from->appId();
+00416         CUnifiedNetwork::TMsgMappedCallback::iterator   itcb;
+00417 
+00418         itcb = uni->_Callbacks.find(msgin.getName());
+00419         if (itcb == uni->_Callbacks.end())
+00420         {
+00421                 // the callback doesn't exist
+00422                 nlwarning ("HNETL5: Can't find callback '%s' called by service %hu", msgin.getName().c_str(), sid);
+00423         }
+00424         else
+00425         {
+00426                 CUnifiedNetwork::CUnifiedConnection *uc = uni->getUnifiedConnection (sid);
+00427 
+00428                 if (uc == 0)
+00429                 {
+00430                         nlwarning ("HNETL5: Received a message from a service %hu that is not ready (bad appid? 0x%"NL_I64"X)", sid, from->appId ());
+00431                         return;
+00432                 }
+00433                 if((*itcb).second == 0)
+00434                 {
+00435                         nlwarning ("HNETL5: Received message %s from a service %hu but the associated callback is NULL", msgin.getName ().c_str(), sid);
+00436                         return;
+00437                 }
+00438 
+00439                 {
+00440                         static map<string, CHTimer> timers;
+00441                         map<string, CHTimer>::iterator it;
+00442                         
+00443                         {
+00444                                 H_AUTO(L5UCHTimerOverhead);
+00445                                 string callbackName = "USRCB_" + msgin.getName();
+00446                                 it = timers.find(callbackName);
+00447                                 if(it == timers.end())
+00448                                 {
+00449                                         it = timers.insert(make_pair(callbackName, CHTimer(NULL))).first;
+00450                                         (*it).second.setName((*it).first.c_str());
+00451                                 }
+00452                         }
+00453 
+00454                         {
+00455                                 H_AUTO(L5UserCallback);
+00456                                 
+00457                                 (*it).second.before();
+00458                                 (*itcb).second (msgin, uc->ServiceName, sid);
+00459                                 (*it).second.after();
+00460                         }
+00461                 }
+00462 
+00463                 uc->TotalCallbackCalled++;
+00464                 TotalCallbackCalled++;
+00465         }
+00466 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void uncbServiceIdentification CMessage msgin,
TSockId  from,
CCallbackNetBase netbase
[friend]
+
+ + + + + +
+   + + +

+ +

+Definition at line 284 of file unified_network.cpp. +

+

00285 {
+00286         string          inSName;
+00287         uint16          inSid;
+00288 
+00289         if (from->appId () != AppIdDeadConnection)
+00290                 AUTOCHECK_DISPLAY ("HNETL5: received a connec ident from an unknown connection 0x%"NL_I64"X", from->appId ());
+00291 
+00292         // recover the service name and id
+00293         msgin.serial(inSName);
+00294         msgin.serial(inSid);
+00295         uint8 pos;
+00296         msgin.serial (pos);
+00297         bool isExternal;
+00298         msgin.serial (isExternal);
+00299 
+00300         nlinfo ("HNETL5: + connec ident '%s' %s-%hu pos %hu ext %d", from->asString().c_str(), inSName.c_str(), inSid, (uint16)pos, (uint8)isExternal);
+00301         
+00302         allstuffs += "+rconnect "+inSName+"-"+toString(inSid)+" pos "+toString((uint16)pos)+"\n";
+00303         test.displayNL ("+rconnect %s-%hu pos %hu", inSName.c_str (), (uint16)inSid, (uint16)pos);
+00304 
+00305         if(isExternal)
+00306         {
+00307                 nlassert (pos == 0);
+00308         }
+00309 
+00310         if (inSid == 0)
+00311         {
+00312                 if (isExternal)
+00313                 {
+00314                         inSid = CUnifiedNetwork::getInstance ()->_ExtSId++;
+00315                         nlwarning ("HNETL5: Received a connection from a service with a SId 0, we give him the SId %d", inSid);
+00316                 }
+00317                 else
+00318                 {
+00319                         nlwarning ("HNETL5: Received a connection from a service with a SId 0 and wasn't external, disconnecting it");
+00320                         netbase.disconnect();
+00321                         return;
+00322                 }
+00323         }
+00324 
+00325         from->setAppId(inSid);
+00326 
+00327         // add a new connection to the list
+00328         CUnifiedNetwork         *uni= CUnifiedNetwork::getInstance();
+00329 
+00330         if(inSid >= uni->_IdCnx.size ())
+00331         {
+00332                 uni->_IdCnx.resize (inSid+1);
+00333         }
+00334 
+00335         switch(uni->_IdCnx[inSid].State)
+00336         {
+00337         case CUnifiedNetwork::CUnifiedConnection::NotUsed:              // add the new unified connection
+00338                 uni->_IdCnx[inSid] = CUnifiedNetwork::CUnifiedConnection(inSName, inSid, isExternal);
+00339                 uni->_UsedConnection.push_back (inSid);
+00340                 break;
+00341         default:
+00342                 break;
+00343         }
+00344 
+00345         if (uni->_IdCnx[inSid].IsExternal != isExternal)
+00346         {
+00347                 AUTOCHECK_DISPLAY ("HNETL5: Receive a connection that is not totally external %d %d", uni->_IdCnx[inSid].IsExternal, isExternal);
+00348                 return;
+00349         }
+00350 
+00351         bool FirstConnection = (uni->_IdCnx[inSid].Connection.size () == 0);
+00352 
+00353         // add the connection to the already inserted unified connection
+00354         if (pos >= uni->_IdCnx[inSid].Connection.size ())
+00355                 uni->_IdCnx[inSid].Connection.resize(pos+1);
+00356         uni->_IdCnx[inSid].Connection[pos] = CUnifiedNetwork::CUnifiedConnection::TConnection(&netbase, from);
+00357 
+00358         // If the connection is external, we'll never receive the ExtAddress by the naming service, so add it manually
+00359         if (isExternal)
+00360         {
+00361                 uni->_IdCnx[inSid].ExtAddress.push_back (netbase.hostAddress (from));
+00362                 uni->_IdCnx[inSid].setupNetworkAssociation (uni->_NetworkAssociations, uni->_DefaultNetwork);
+00363         }
+00364 
+00365 
+00366         // todo ace temp to savoir comment c est possible ce cas la
+00367         if (uni->_IdCnx[inSid].Connection.size() == 3)
+00368         {
+00369                 CUnifiedNetwork::CUnifiedConnection *uc = &uni->_IdCnx[inSid];
+00370                 nlstop;
+00371                 nlinfo ("HNETL5: ext addr %s", vectorCInetAddressToString (uc->ExtAddress).c_str ());
+00372                 for(uint i = 0; i < uc->Connection.size(); i++)
+00373                         nlinfo ("HNETL5: cnx %s", uc->Connection[i].HostId->asString ().c_str ());
+00374                 nlinfo ("HNETL5: %s", allstuffs.c_str ());
+00375         }
+00376 
+00377         // send the callback to the user with the first connection
+00378         if (FirstConnection)
+00379         {
+00380                 // insert the name in the map to be able to send message with the name
+00381                 uni->addNamedCnx (inSName, inSid);
+00382 
+00383                 uni->callServiceUpCallback (inSName, inSid);
+00384 /*
+00385                 // now we warn the user
+00386                 CUnifiedNetwork::TNameMappedCallback::iterator  it = uni->_UpCallbacks.find(inSName);
+00387                 if (it != uni->_UpCallbacks.end())
+00388                 {
+00389                         // call it
+00390                         for (list<TCallbackArgItem> it2 = (*it).second.begin(); it2 != (*it).second.end(); it2++)
+00391                         {
+00392                                 TUnifiedNetCallback     cb = (*it2).first;
+00393                                 if (cb) cb(inSName, inSid, (*it2).second);
+00394                         }
+00395                 }
+00396 
+00397                 for (uint c = 0; c < uni->_UpUniCallback.size (); c++)
+00398                 {
+00399                         if (uni->_UpUniCallback[c].first != NULL)
+00400                                 uni->_UpUniCallback[c].first (inSName, inSid, uni->_UpUniCallback[c].second);
+00401                 }*/
+00402         }
+00403 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void uNetRegistrationBroadcast const std::string &  name,
TServiceId  sid,
const std::vector< CInetAddress > &  addr
[friend]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void uNetUnregistrationBroadcast const std::string &  name,
TServiceId  sid,
const std::vector< CInetAddress > &  addr
[friend]
+
+ + + + + +
+   + + +

+

+


Field Documentation

+

+ + + + +
+ + +
TMsgMappedCallback NLNET::CUnifiedNetwork::_Callbacks [private] +
+
+ + + + + +
+   + + +

+Map of callbacks. +

+ +

+Definition at line 454 of file unified_network.h. +

+Referenced by addCallbackArray(), findCallback(), NLNET::NLMISC_COMMAND(), release(), and NLNET::uncbMsgProcessing().

+

+ + + + +
+ + +
CCallbackServer* NLNET::CUnifiedNetwork::_CbServer [private] +
+
+ + + + + +
+   + + +

+The callback server. +

+ +

+Definition at line 433 of file unified_network.h. +

+Referenced by CUnifiedNetwork(), getBytesReceived(), getBytesSent(), getReceiveQueueSize(), getSendQueueSize(), init(), release(), and update().

+

+ + + + +
+ + +
std::vector<std::string> NLNET::CUnifiedNetwork::_DefaultNetwork [private] +
+
+ + + + + +
+   + + +

+for each services, which network to take +

+ +

+Definition at line 478 of file unified_network.h. +

+Referenced by addDefaultNetwork(), addService(), clearDefaultNetwork(), NLNET::uncbServiceIdentification(), and NLNET::uNetRegistrationBroadcast().

+

+ + + + +
+ + +
TNameMappedCallback NLNET::CUnifiedNetwork::_DownCallbacks [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 441 of file unified_network.h. +

+Referenced by callServiceDownCallback(), release(), and setServiceDownCallback().

+

+ + + + +
+ + +
std::vector<TCallbackArgItem> NLNET::CUnifiedNetwork::_DownUniCallback [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 442 of file unified_network.h. +

+Referenced by callServiceDownCallback(), and setServiceDownCallback().

+

+ + + + +
+ + +
uint16 NLNET::CUnifiedNetwork::_ExtSId [private] +
+
+ + + + + +
+   + + +

+Used for external service. +

+ +

+Definition at line 457 of file unified_network.h. +

+Referenced by addService(), and CUnifiedNetwork().

+

+ + + + +
+ + +
std::vector<CUnifiedConnection> NLNET::CUnifiedNetwork::_IdCnx [private] +
+
+ + + + + +
+   + + +

+Vector of connections by service id (sid is the entry in this array, it means that there s some hole). +

+ +

+Definition at line 424 of file unified_network.h. +

+Referenced by addService(), autoCheck(), displayInternalTables(), findConnectionId(), getBytesReceived(), getBytesSent(), getNetBase(), getReceiveQueueSize(), getSendQueueSize(), getUnifiedConnection(), isServiceLocal(), NLNET::NLMISC_COMMAND(), release(), send(), sendAll(), NLNET::uncbServiceIdentification(), NLNET::uNetRegistrationBroadcast(), and update().

+

+ + + + +
+ + +
bool NLNET::CUnifiedNetwork::_Initialised [private] +
+
+ + + + + +
+   + + +

+true if initialisation function called +

+ +

+Definition at line 472 of file unified_network.h.

+

+ + + + +
+ + +
CUnifiedNetwork * NLNET::CUnifiedNetwork::_Instance = NULL [static, private] +
+
+ + + + + +
+   + + +

+The main instance. +

+ +

+Definition at line 1479 of file unified_network.cpp.

+

+ + + + +
+ + +
NLMISC::TTime NLNET::CUnifiedNetwork::_LastRetry [private] +
+
+ + + + + +
+   + + +

+Last time of retry. +

+ +

+Definition at line 460 of file unified_network.h. +

+Referenced by CUnifiedNetwork(), and update().

+

+ + + + +
+ + +
std::string NLNET::CUnifiedNetwork::_Name [private] +
+
+ + + + + +
+   + + +

+Service name. +

+ +

+Definition at line 451 of file unified_network.h.

+

+ + + + +
+ + +
TNameMappedConnection NLNET::CUnifiedNetwork::_NamedCnx [private] +
+
+ + + + + +
+   + + +

+Map of connections by service name. +

+ +

+Definition at line 430 of file unified_network.h. +

+Referenced by addNamedCnx(), autoCheck(), displayInternalTables(), getNetBase(), haveNamedCnx(), isServiceLocal(), release(), removeNamedCnx(), and send().

+

+ + + + +
+ + +
NLNET::CInetAddress NLNET::CUnifiedNetwork::_NamingServiceAddr [private] +
+
+ + + + + +
+   + + +

+Naming service. +

+ +

+Definition at line 469 of file unified_network.h. +

+Referenced by init(), and update().

+

+ + + + +
+ + +
std::vector<uint32> NLNET::CUnifiedNetwork::_NetworkAssociations [private] +
+
+ + + + + +
+   + + +

+for each nid, which network address +

+ +

+Definition at line 475 of file unified_network.h. +

+Referenced by addNetworkAssociation(), addService(), autoCheck(), clearNetworkAssociation(), displayInternalTables(), NLNET::uncbServiceIdentification(), and NLNET::uNetRegistrationBroadcast().

+

+ + + + +
+ + +
NLMISC::TTime NLNET::CUnifiedNetwork::_NextUpdateTime [private] +
+
+ + + + + +
+   + + +

+Time of the theorical next update. +

+ +

+Definition at line 463 of file unified_network.h.

+

+ + + + +
+ + +
CCallbackNetBase::TRecordingState NLNET::CUnifiedNetwork::_RecordingState [private] +
+
+ + + + + +
+   + + +

+Recording state. +

+ +

+Definition at line 445 of file unified_network.h.

+

+ + + + +
+ + +
uint16 NLNET::CUnifiedNetwork::_ServerPort [private] +
+
+ + + + + +
+   + + +

+The server port. +

+ +

+Definition at line 436 of file unified_network.h. +

+Referenced by init(), and update().

+

+ + + + +
+ + +
TServiceId NLNET::CUnifiedNetwork::_SId [private] +
+
+ + + + + +
+   + + +

+Service id of the running service. +

+ +

+Definition at line 448 of file unified_network.h. +

+Referenced by NLNET::NLMISC_COMMAND(), and NLNET::uNetRegistrationBroadcast().

+

+ + + + +
+ + +
TNameMappedCallback NLNET::CUnifiedNetwork::_UpCallbacks [private] +
+
+ + + + + +
+   + + +

+Map of the up/down service callbacks. +

+ +

+Definition at line 439 of file unified_network.h. +

+Referenced by callServiceUpCallback(), release(), and setServiceUpCallback().

+

+ + + + +
+ + +
std::vector<TCallbackArgItem> NLNET::CUnifiedNetwork::_UpUniCallback [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 440 of file unified_network.h. +

+Referenced by callServiceUpCallback(), and setServiceUpCallback().

+

+ + + + +
+ + +
std::vector<uint16> NLNET::CUnifiedNetwork::_UsedConnection [private] +
+
+ + + + + +
+   + + +

+This vector contains only an index to the unified connection. It is used to have quick access on the available connections. +

+ +

+Definition at line 427 of file unified_network.h. +

+Referenced by addService(), autoCheck(), displayInternalTables(), getBytesReceived(), getBytesSent(), getConnectionList(), getReceiveQueueSize(), getSendQueueSize(), release(), NLNET::uncbDisconnection(), NLNET::uncbServiceIdentification(), NLNET::uNetRegistrationBroadcast(), NLNET::uNetUnregistrationBroadcast(), and update().

+


The documentation for this class was generated from the following files: +
Generated on Tue Mar 16 14:06:55 2004 for NeL by + +doxygen +1.3.6
+ + -- cgit v1.2.1