|
|
|
|
Documentation |
|
Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages Search
NLNET::CUnifiedNetwork Class ReferenceLayer 5.
More...
#include <unified_network.h>
List of all members.
Public Methods |
void | init (const CInetAddress *addr, CCallbackNetBase::TRecordingState rec, const std::string &shortName, uint16 port, TServiceId &sid) |
| Creates the connection to the Naming Service. More...
|
void | connect () |
| Registers to the Naming Service, and connects to the present services. More...
|
void | release () |
| Closes the connection to the naming service, every other connection and free. More...
|
void | 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. More...
|
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 | addCallbackArray (const TUnifiedCallbackItem *callbackarray, NLMISC::CStringIdArray::TStringId arraysize) |
| Adds a callback array in the system. More...
|
void | update (NLMISC::TTime timeout=0) |
| Call it evenly. More...
|
bool | send (const std::string &serviceName, const CMessage &msg, uint8 nid=0xFF) |
| Sends a message to a specific serviceName. More...
|
bool | send (uint16 serviceId, const CMessage &msg, uint8 nid=0xFF) |
| Sends a message to a specific serviceId. More...
|
void | send (const CMessage &msg, uint8 nid=0xFF) |
| Broadcasts a message to all connected services. More...
|
void | setServiceUpCallback (const std::string &serviceName, TUnifiedNetCallback cb, void *arg=0, bool back=true) |
| Sets callback for incoming connections. More...
|
void | setServiceDownCallback (const std::string &serviceName, TUnifiedNetCallback cb, void *arg=0, bool back=true) |
| Sets callback for disconnections. More...
|
void | 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. More...
|
void | clearNetworkAssociation () |
| Clear all network association. More...
|
void | addDefaultNetwork (const std::string &defnet) |
| This array says to wich network we need to send the message for the default nid. More...
|
void | clearDefaultNetwork () |
| Clear all default network. More...
|
bool | isServiceLocal (uint16 sid) |
| Returns true if the sid service is on the same computer than this service. More...
|
bool | isServiceLocal (const std::string &serviceName) |
| Returns true if the serviceName service is on the same computer than this service. More...
|
CCallbackNetBase * | getNetBase (const std::string &name, TSockId &host, uint8 nid=0xFF) |
| -
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 Gets the CCallbackNetBase of the service.
More...
|
CCallbackNetBase * | getNetBase (uint16 sid, TSockId &host, uint8 nid=0xFF) |
| Gets the CCallbackNetBase of the service. More...
|
uint64 | getBytesSent () |
| Gets the total number of bytes sent. More...
|
uint64 | getBytesReceived () |
| Gets the total number of bytes received. More...
|
uint64 | getSendQueueSize () |
| Gets the total number of bytes queued for sending. More...
|
uint64 | getReceiveQueueSize () |
| Gets the total number of bytes queued after receiving. More...
|
TUnifiedMsgCallback | findCallback (const std::string &callbackName) |
| Find a callback in the array. More...
|
void | displayInternalTables (NLMISC::CLog *log=NLMISC::InfoLog) |
Static Public Methods |
CUnifiedNetwork * | getInstance () |
| Returns the singleton instance of the CUnifiedNetwork class. More...
|
bool | isUsed () |
| Returns true if the application called getInstance(). More...
|
Private Types |
typedef std::map< std::string,
TUnifiedMsgCallback > | TMsgMappedCallback |
| A map of callbacks, refered by message name. More...
|
typedef std::pair< TUnifiedNetCallback,
void * > | TCallbackArgItem |
| A callback and its user data. More...
|
typedef std::hash_multimap<
std::string, TCallbackArgItem > | TNameMappedCallback |
| A map of service up/down callbacks with their user data. More...
|
Private Methods |
| CUnifiedNetwork () |
| ~CUnifiedNetwork () |
void | autoCheck () |
CUnifiedConnection * | getUnifiedConnection (uint16 sid) |
bool | haveNamedCnx (const std::string &name, uint16 sid) |
void | addNamedCnx (const std::string &name, uint16 sid) |
void | removeNamedCnx (const std::string &name, uint16 sid) |
uint8 | findConnectionId (uint16 sid, uint8 nid) |
Private Attributes |
std::vector< CUnifiedConnection > | _IdCnx |
| Vector of connections by service id (sid is the entry in this array, it means that there s some hole). More...
|
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. More...
|
TNameMappedConnection | _NamedCnx |
| Map of connections by service name. More...
|
CCallbackServer * | _CbServer |
| The callback server. More...
|
uint16 | _ServerPort |
| The server port. More...
|
TNameMappedCallback | _UpCallbacks |
| Map of the up/down service callbacks. More...
|
std::vector< TCallbackArgItem > | _UpUniCallback |
TNameMappedCallback | _DownCallbacks |
std::vector< TCallbackArgItem > | _DownUniCallback |
CCallbackNetBase::TRecordingState | _RecordingState |
| Recording state. More...
|
TServiceId | _SId |
| Service id of the running service. More...
|
std::string | _Name |
| Service name. More...
|
TMsgMappedCallback | _Callbacks |
| Map of callbacks. More...
|
uint16 | _ExtSId |
| Used for external service. More...
|
NLMISC::TTime | _LastRetry |
| Last time of retry. More...
|
NLMISC::TTime | _NextUpdateTime |
| Time of the theorical next update. More...
|
NLNET::CInetAddress | _NamingServiceAddr |
| Naming service. More...
|
bool | _Initialised |
| true if initialisation function called. More...
|
std::vector< uint32 > | _NetworkAssociations |
| for each nid, which network address. More...
|
std::vector< std::string > | _DefaultNetwork |
| for each services, which network to take. More...
|
Static Private Attributes |
CUnifiedNetwork * | _Instance = NULL |
| The main instance. More...
|
Friends |
struct | isServiceLocalClass |
void | uncbConnection (TSockId from, void *arg) |
void | uncbDisconnection (TSockId from, void *arg) |
void | uncbServiceIdentification (CMessage &msgin, TSockId from, CCallbackNetBase &netbase) |
void | uncbMsgProcessing (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) |
Detailed Description
Layer 5.
-
Author:
-
Vianney Lecroart, Benjamin Legros , Nevrax France
-
Date:
-
2002
Definition at line 71 of file unified_network.h.
Member Typedef Documentation
typedef std::pair<TUnifiedNetCallback, void *> NLNET::CUnifiedNetwork::TCallbackArgItem [private]
|
|
typedef std::map<std::string, TUnifiedMsgCallback> NLNET::CUnifiedNetwork::TMsgMappedCallback [private]
|
|
typedef std::hash_multimap<std::string, TCallbackArgItem> NLNET::CUnifiedNetwork::TNameMappedCallback [private]
|
|
|
A map of service up/down callbacks with their user data.
Definition at line 235 of file unified_network.h. |
Constructor & Destructor Documentation
NLNET::CUnifiedNetwork::CUnifiedNetwork |
( |
|
) |
[inline, private] |
|
NLNET::CUnifiedNetwork::~CUnifiedNetwork |
( |
|
) |
[inline, private] |
|
Member Function Documentation
|
Adds a callback array in the system.
You can add callback only *after* adding the server, the client or the group.
Definition at line 1117 of file unified_network.cpp.
References _Callbacks. |
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 185 of file unified_network.h.
References _DefaultNetwork, and nlinfo. |
void NLNET::CUnifiedNetwork::addNamedCnx |
( |
const std::string & |
name, |
|
|
uint16 |
sid |
|
) |
[private] |
|
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. |
|
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 |
|
) |
|
|
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.
Referenced by connect. |
void NLNET::CUnifiedNetwork::autoCheck |
( |
|
) |
[private] |
|
void NLNET::CUnifiedNetwork::clearDefaultNetwork |
( |
|
) |
[inline] |
|
void NLNET::CUnifiedNetwork::clearNetworkAssociation |
( |
|
) |
[inline] |
|
void NLNET::CUnifiedNetwork::connect |
( |
|
) |
|
|
uint8 NLNET::CUnifiedNetwork::findConnectionId |
( |
uint16 |
sid, |
|
|
uint8 |
nid |
|
) |
[private] |
|
uint64 NLNET::CUnifiedNetwork::getBytesReceived |
( |
|
) |
|
|
uint64 NLNET::CUnifiedNetwork::getBytesSent |
( |
|
) |
|
|
CUnifiedNetwork * NLNET::CUnifiedNetwork::getInstance |
( |
|
) |
[static] |
|
uint64 NLNET::CUnifiedNetwork::getReceiveQueueSize |
( |
|
) |
|
|
uint64 NLNET::CUnifiedNetwork::getSendQueueSize |
( |
|
) |
|
|
bool NLNET::CUnifiedNetwork::haveNamedCnx |
( |
const std::string & |
name, |
|
|
uint16 |
sid |
|
) |
[private] |
|
|
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 |
recorging state to know if we have to record or replay messages |
|
bool NLNET::CUnifiedNetwork::isServiceLocal |
( |
const std::string & |
serviceName |
) |
|
|
bool NLNET::CUnifiedNetwork::isServiceLocal |
( |
uint16 |
sid |
) |
|
|
bool NLNET::CUnifiedNetwork::isUsed |
( |
|
) |
[static] |
|
void NLNET::CUnifiedNetwork::release |
( |
|
) |
|
|
|
Closes the connection to the naming service, every other connection and free.
Definition at line 552 of file unified_network.cpp.
References _Callbacks, _CbServer, _DownCallbacks, _IdCnx, _Initialised, _NamedCnx, _UpCallbacks, _UsedConnection, NLMISC::getThreadId, nlwarning, and NLNET::ThreadCreator. |
void NLNET::CUnifiedNetwork::removeNamedCnx |
( |
const std::string & |
name, |
|
|
uint16 |
sid |
|
) |
[private] |
|
void NLNET::CUnifiedNetwork::send |
( |
const CMessage & |
msg, |
|
|
uint8 |
nid = 0xFF |
|
) |
|
|
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)
|
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.
If the serviceName is "*", you can set more than one callback, each one will be called one after one. Otherwise only the last setCallback will be called (and you can set cb to 0 to remove the callback). 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 |
|
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
If the serviceName is "*", you can set more than one callback, each one will be called one after one. Otherwise only the last setCallback will be called (and you can set cb to 0 to remove the callback). 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 |
|
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 804 of file unified_network.cpp.
References _CbServer, _IdCnx, _Initialised, _LastRetry, _Name, _NamingServiceAddr, _NextUpdateTime, _RecordingState, _ServerPort, _SId, _UpCallbacks, _UpUniCallback, _UsedConnection, addNamedCnx, NLNET::CInetAddress::asString, autoCheck, NLMISC::getThreadId, haveNamedCnx, NLNET::CInetAddress::isValid, nlassert, nlassertex, nlinfo, NLMISC::nlSleep, nlwarning, NLNET::ThreadCreator, NLMISC::TTime, and NLNET::TUnifiedNetCallback. |
Friends And Related Function Documentation
friend struct isServiceLocalClass [friend]
|
|
void uncbConnection |
( |
TSockId |
from, |
|
|
void * |
arg |
|
) |
[friend] |
|
void uncbDisconnection |
( |
TSockId |
from, |
|
|
void * |
arg |
|
) |
[friend] |
|
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] |
|
Member Data Documentation
std::vector<std::string> NLNET::CUnifiedNetwork::_DefaultNetwork [private]
|
|
std::vector<TCallbackArgItem> NLNET::CUnifiedNetwork::_DownUniCallback [private]
|
|
uint16 NLNET::CUnifiedNetwork::_ExtSId [private]
|
|
|
Vector of connections by service id (sid is the entry in this array, it means that there s some hole).
Definition at line 404 of file unified_network.h.
Referenced by autoCheck, displayInternalTables, findConnectionId, getBytesReceived, getBytesSent, getNetBase, getReceiveQueueSize, getSendQueueSize, getUnifiedConnection, isServiceLocal, release, send, and update. |
bool NLNET::CUnifiedNetwork::_Initialised [private]
|
|
CUnifiedNetwork * NLNET::CUnifiedNetwork::_Instance = NULL [static, private]
|
|
std::string NLNET::CUnifiedNetwork::_Name [private]
|
|
std::vector<uint32> NLNET::CUnifiedNetwork::_NetworkAssociations [private]
|
|
uint16 NLNET::CUnifiedNetwork::_ServerPort [private]
|
|
std::vector<uint16> NLNET::CUnifiedNetwork::_UsedConnection [private]
|
|
The documentation for this class was generated from the following files:
|
|