Basic Image AlgorithmS Library
2.8.0
|
this class CScomm (ClientServer communciation) handles data comunication via TCP/IP for one server and multiple clients. More...
#include <NetworkComm/CScommBase.hh>
Public Member Functions | |
void | AddDebugLevel (const long int lv) |
void | AddDebugLevel (const std::string &name) |
CScommBase (bool threaded=true) | |
Set threaded to false for deactivating the receive-thread. More... | |
CScommBase (const CScommBase &arg) | |
copy ctor required due to ostream member with explicit ctor JW More... | |
bool | DebugLevelIsSet (const long int lv) const |
bool | DebugLevelIsSet (const std::string &name) const |
std::string | GetCommPartnerName (int commPartnerNr) |
returns the name of the commPartner with nr commPartnerNr or empty string in case of a number, that is to high. More... | |
int | GetConnections () |
returns the number of connected commPartners More... | |
int | GetData (const std::string &msgName, std::vector< float > &floatData) |
returns instantly:<br> 0 if new data has arrived and the data in xxxData | |
int | GetData (const std::string &msgName, std::vector< int > &intData) |
int | GetData (const std::string &msgName, std::vector< std::string > &stringData) |
int | GetData (const std::string &msgName, std::vector< char > &binaryData) |
returns the binarydata in the vector, its wise to reserve enough bytes, if the size is known. More... | |
int | GetDebugLevel () const |
std::ostream & | GetDebugStream () const |
void | GetDebugStream (std::ostream &os) const |
bool | GetThreadedReceive () |
long int | Name2DebugLevel (const std::string &name) const |
looks up a debuglevel in the internal map, returns 0 if not found More... | |
long int | NewDebugLevel (const std::string &name) |
creates a new debuglevel More... | |
CScommBase & | operator= (const CScommBase &arg) |
assignment op. required due to ostream member with explicit ctor JW More... | |
void | PrintDebugLevel (std::ostream &os=std::cout) const |
int | RegisterMsg (std::string msgName, EdataType dataType, int amount=1) |
only registered msgs are accepted by commPartners Register a msg with this functions. More... | |
int | RegisterMsg (std::string commPartnerName, std::string msgName, EdataType dataType, int amount=1) |
same as above, but the msg is only accepted from a specific commPartner More... | |
void | RemoveDebugLevel (const long int lv) |
void | RemoveDebugLevel (const std::string &name) |
int | SendMsg (const std::string &msgName, std::vector< float > &floatData) |
sends msg msgName to all connected commPartners. More... | |
int | SendMsg (const std::string &msgName, std::vector< int > &intData) |
int | SendMsg (const std::string &msgName, std::vector< std::string > &stringData) |
int | SendMsg (const std::string &msgName, char *binaryData, unsigned int size) |
maximum size for binary data is 15MB! More... | |
int | SendMsg (const std::string commPartnerName, const std::string &msgName, char *binaryData, unsigned int size) |
like above, but msg is only send to one specific commPartner given as string, which must equal the name given by the client to itself | |
int | SendMsg (int commPartnerNr, const std::string &msgName, char *binaryData, unsigned int size) |
like above, but msg is only send to one specific commPartner given as the index number of all connected partners More... | |
void | SetAutomaticPortChange (bool on) |
if set on, the server will take automatically the next free TCP port for connections. More... | |
void | SetConnectionTimeOut (unsigned int time) |
set the time in ms until a commPartner is assumed to be disconnected. More... | |
void | SetDebugLevel (const long int lv) |
void | SetDebugLevel (const std::string &name) |
void | SetDebugStream (const std::ostream &os) |
void | SetKeepAll (bool on) |
If not threaded you can set this true to keep all received data. More... | |
void | SetLog (bool on) |
gives a lot of information regarding the connections, like the exact data received and send. More... | |
void | SetLogOut (std::ostream &outputStream) |
set the output of log msgs to another stream, e.g. More... | |
void | SetVerbose (bool on) |
gives some information about establising conn, and disconnecting etc. More... | |
void | SetVerboseOut (std::ostream &outputStream) |
set the output of verbose msgs to another stream, e.g. More... | |
void | ShowDebugLevel (std::ostream &os=std::cout) const |
prints all internally known debuglevels More... | |
int | WaitForNewMessage (std::string &msgName) |
only if not threaded! <br> Blocks until any new msg arrives, or returns instantly if a new message is already in a buffer slot. More... | |
virtual | ~CScommBase () |
Static Public Member Functions | |
static long int | GetGlobalDebugLevel () |
static void | SetGlobalDebugLevel (long int lev) |
Protected Member Functions | |
int | AcceptConn_ (int fd) |
int | AnalyzeData_ (int clientNr) |
return values: 0 no error all fine More... | |
int | AnalyzeFirstMsg_ (int commNr) |
int | CheckRegisteredMsgs_ (std::string &msgName, const CScommData &cPartner, EdataType &dataTypeToRead, unsigned int &dataSizeToRead) |
long | ConsumeNextFreeDebuglevel_ () |
returns the next available debuglevel More... | |
int | GetData_ (const std::string &msgName) |
void | logOutPut_ (const char *data, unsigned int size) |
void | receiveThread_ (int clientNr) |
int | SendMsg_ (const std::string &data) |
void | syncReceive_ () |
Protected Attributes | |
long int | _liDebugLevel |
long int | _liNextDebugLevel |
new concept, debuglevel are managed here in the debug class More... | |
std::map< std::string, long int > | _String2Debuglevel |
std::vector< CScommData > | commPartners_ |
int | commPartnersConnected_ |
int | connectPort_ |
bool | isServer_ |
bool | keepAll_ |
bool | log_ |
std::ostream | logOut_ |
std::vector< CScommMsg > | msgBuffer_ |
std::string | name_ |
bool | onlyNewMsgs_ |
bool | portChange_ |
std::vector< CScommMsg > | registeredMsgs_ |
pthread_mutex_t | registerLock_ |
bool | terminateReceiver_ |
bool | threaded_ |
unsigned int | timeOut_ |
bool | timeOutFlag_ |
bool | verbose_ |
std::ostream | verboseOut_ |
Static Protected Attributes | |
static std::ostream | _zDebugStream |
static long int | GlobalDebugLevel = 0 |
Friends | |
void * | receivethread (void *data) |
these are wrapper to comply to the pthread_create() interface More... | |
this class CScomm (ClientServer communciation) handles data comunication via TCP/IP for one server and multiple clients.
It spawns threads itself for all communication. Messages can be registered by functions or within a file(not yet). See CScommClient or CScommServer for more details.
Definition at line 73 of file CScommBase.hh.
|
virtual |
Definition at line 55 of file CScommBase.cpp.
CScommBase::CScommBase | ( | bool | threaded = true | ) |
Set threaded to false for deactivating the receive-thread.
Data will be read from TCP-buffer only when GetData methods are called. Threaded receive is activated by default! Beware: if there's no msg in tcp-buffer, GetData will BLOCK until there is any new msg (this need not be the one GetData was called for, for example binary instead of int) if receive-buffer is completly filled, send blocks until msg can be delivered!
Definition at line 86 of file CScommBase.cpp.
References commPartners_, commPartnersConnected_, connectPort_, keepAll_, log_, onlyNewMsgs_, portChange_, registeredMsgs_, registerLock_, terminateReceiver_, threaded_, timeOut_, timeOutFlag_, and verbose_.
CScommBase::CScommBase | ( | const CScommBase & | arg | ) |
copy ctor required due to ostream member with explicit ctor JW
Definition at line 124 of file CScommBase.cpp.
|
protected |
create a new receivethread
Definition at line 968 of file CScommBase.cpp.
References BIAS::CSCommWithClientNr::comm, BIAS::CSCommWithClientNr::commNr, commPartners_, commPartnersConnected_, receivethread, and threaded_.
Referenced by BIAS::CScommClient::ConnectServer(), and BIAS::listenthread().
|
inlineinherited |
Definition at line 355 of file Debug.hh.
Referenced by BIAS::GLProjectionParametersBase::AddDebugLevel(), BIAS::Triangulation::CorrectCorrespondences(), BIAS::FilterBase< InputStorageType, OutputStorageType >::FilterBase(), BIAS::ShowCamWxVideoSourceFactory::OpenDevice(), and BIAS::SceneOpenSceneGraph::SceneOpenSceneGraph().
|
inlineinherited |
|
protected |
return values:
0 no error all fine
warnings: 1 not enough data to analyze (<3 bytes) 2 no data after msg name 3 more data read than registered for a msg 4 less data read than registered A warning is returned if one of the above cases was true for any one msg in the buffer.
errors: -1 only trash received
Definition at line 564 of file CScommBase.cpp.
References CheckRegisteredMsgs_(), commPartners_, BIAS::CS_BINARY, BIAS::CS_FLOAT, BIAS::CS_INT, BIAS::CS_NONE, BIAS::CS_STRING, keepAll_, BIAS::CScommData::lastProcessed, BIAS::CScommData::msgBuffer, BIAS::CScommData::name, registeredMsgs_, and threaded_.
Referenced by receiveThread_(), and syncReceive_().
|
protected |
Definition at line 763 of file CScommBase.cpp.
References commPartners_.
Referenced by receiveThread_(), and syncReceive_().
|
protected |
Definition at line 511 of file CScommBase.cpp.
References isServer_, BIAS::CScommData::name, registeredMsgs_, registerLock_, and threaded_.
Referenced by AnalyzeData_().
|
inlineprotectedinherited |
|
inlineinherited |
Definition at line 341 of file Debug.hh.
Referenced by BIAS::GenSynthMatches::_AddUniformDistributedOutliers(), BIAS::GenSynthMatches::_CreateCamMovement(), BIAS::GenSynthMatches::_CreateStatic2DPoints(), BIAS::UnscentedTransform::ComputeSigmaPoints_(), BIAS::Triangulation::CorrectCorrespondences(), BIAS::GenSynthMatches::GetGTNormalizedF(), BIAS::MonteCarloTransform::GetSamples_(), and BIAS::MonteCarloTransform::Transform().
|
inlineinherited |
std::string CScommBase::GetCommPartnerName | ( | int | commPartnerNr | ) |
returns the name of the commPartner with nr commPartnerNr or
empty string in case of a number, that is to high.
Definition at line 1027 of file CScommBase.cpp.
References commPartners_.
Referenced by SendMsg().
|
inline |
returns the number of connected commPartners
Definition at line 179 of file CScommBase.hh.
Referenced by BIAS::VideoTransmitter::Process().
int CScommBase::GetData | ( | const std::string & | msgName, |
std::vector< float > & | floatData | ||
) |
returns instantly:<br>
0 if new data has arrived and the data in xxxData
1 if no new data has arrived, the data in xxxData stays unchanged
-1 in case of errors
Definition at line 170 of file CScommBase.cpp.
References GetData_(), registeredMsgs_, syncReceive_(), and threaded_.
Referenced by BIAS::VideoSource_Net::GrabSingle(), and BIAS::VideoSource_Kinect2Net::runner().
int CScommBase::GetData | ( | const std::string & | msgName, |
std::vector< int > & | intData | ||
) |
Definition at line 197 of file CScommBase.cpp.
References GetData_(), registeredMsgs_, syncReceive_(), and threaded_.
int CScommBase::GetData | ( | const std::string & | msgName, |
std::vector< std::string > & | stringData | ||
) |
Definition at line 225 of file CScommBase.cpp.
References GetData_(), registeredMsgs_, syncReceive_(), and threaded_.
int CScommBase::GetData | ( | const std::string & | msgName, |
std::vector< char > & | binaryData | ||
) |
returns the binarydata in the vector, its wise to reserve enough
bytes, if the size is known.
Definition at line 253 of file CScommBase.cpp.
References GetData_(), registeredMsgs_, syncReceive_(), and threaded_.
|
protected |
|
inlineinherited |
Definition at line 332 of file Debug.hh.
Referenced by BIAS::listenthread(), BIAS::Image< StorageType >::operator=(), and BIAS::ImageBase::operator=().
|
inlineinherited |
|
inlineinherited |
|
inlinestaticinherited |
|
inline |
Definition at line 200 of file CScommBase.hh.
|
protected |
Definition at line 805 of file CScommBase.cpp.
Referenced by receiveThread_(), SendMsg_(), and syncReceive_().
|
inlineinherited |
|
inlineinherited |
creates a new debuglevel
Definition at line 474 of file Debug.hh.
Referenced by BIAS::COSAC< SolutionType >::COSAC(), BIAS::ProjectionParametersPerspectiveDepth::Init(), BIAS::MonteCarloTransform::MonteCarloTransform(), BIAS::PMatrixEstimation::PMatrixEstimation(), BIAS::PreemptiveRANSAC< SolutionType >::PreemptiveRANSAC(), BIAS::RANSACPreKnowledge< SolutionType >::RANSACPreKnowledge(), BIAS::ROI::ROI(), BIAS::RotationAveraging::RotationAveraging(), BIAS::SceneOpenSceneGraph::SceneOpenSceneGraph(), BIAS::ThreeDOutOpenSceneGraph::ThreeDOutOpenSceneGraph(), BIAS::Triangulation::Triangulation(), and BIAS::UnscentedTransform::UnscentedTransform().
CScommBase & CScommBase::operator= | ( | const CScommBase & | arg | ) |
assignment op. required due to ostream member with explicit ctor JW
Definition at line 133 of file CScommBase.cpp.
|
inlineinherited |
|
protected |
Definition at line 813 of file CScommBase.cpp.
References AnalyzeData_(), AnalyzeFirstMsg_(), commPartners_, commPartnersConnected_, isServer_, log_, logOut_, logOutPut_(), terminateReceiver_, verbose_, and verboseOut_.
Referenced by BIAS::receivethread().
int CScommBase::RegisterMsg | ( | std::string | msgName, |
EdataType | dataType, | ||
int | amount = 1 |
||
) |
only registered msgs are accepted by commPartners
Register a msg with this functions.
Amount is the number of dataTypes for this msg, for binarydata this is not necessary
The msg will be bound to the first commPartner sending such a msg. And will be accepted only from him later.
All msgNames have to be unique!
return zero on success <0 on errors
Definition at line 315 of file CScommBase.cpp.
Referenced by BIAS::VideoSource_Net::OpenDevice(), and BIAS::VideoSource_Kinect2Net::runner().
int CScommBase::RegisterMsg | ( | std::string | commPartnerName, |
std::string | msgName, | ||
EdataType | dataType, | ||
int | amount = 1 |
||
) |
same as above, but the msg is only accepted from a specific commPartner
Definition at line 321 of file CScommBase.cpp.
References BIAS::CScommMsg::commName, BIAS::CS_BINARY, BIAS::CScommMsg::dataSize, BIAS::CScommMsg::dataType, isServer_, BIAS::CScommMsg::msgName, registeredMsgs_, registerLock_, BIAS::CScommMsg::server, and threaded_.
|
inlineinherited |
|
inlineinherited |
int CScommBase::SendMsg | ( | const std::string & | msgName, |
std::vector< float > & | floatData | ||
) |
sends msg msgName to all connected commPartners.
Msg doesn't have to be registered on the sender side, but must be registered on the receiver side!
Definition at line 358 of file CScommBase.cpp.
References SendMsg_().
Referenced by BIAS::VideoTransmitter::Process(), and SendMsg().
int CScommBase::SendMsg | ( | const std::string & | msgName, |
std::vector< int > & | intData | ||
) |
Definition at line 371 of file CScommBase.cpp.
References SendMsg_().
int CScommBase::SendMsg | ( | const std::string & | msgName, |
std::vector< std::string > & | stringData | ||
) |
Definition at line 384 of file CScommBase.cpp.
References SendMsg_().
int CScommBase::SendMsg | ( | const std::string & | msgName, |
char * | binaryData, | ||
unsigned int | size | ||
) |
maximum size for binary data is 15MB!
Definition at line 423 of file CScommBase.cpp.
References commPartners_, log_, and logOut_.
int CScommBase::SendMsg | ( | const std::string | commPartnerName, |
const std::string & | msgName, | ||
char * | binaryData, | ||
unsigned int | size | ||
) |
like above, but msg is only send to one specific commPartner given
as string, which must equal the name given by the client to itself
Definition at line 460 of file CScommBase.cpp.
References commPartners_, GetCommPartnerName(), and SendMsg().
int CScommBase::SendMsg | ( | int | commPartnerNr, |
const std::string & | msgName, | ||
char * | binaryData, | ||
unsigned int | size | ||
) |
like above, but msg is only send to one specific commPartner given
as the index number of all connected partners
Definition at line 472 of file CScommBase.cpp.
References commPartners_, log_, and logOut_.
|
protected |
Definition at line 395 of file CScommBase.cpp.
References commPartners_, log_, logOut_, and logOutPut_().
Referenced by SendMsg().
|
inline |
if set on, the server will take automatically the next free TCP port
for connections.
The client tries 10 consecutive different ports to conncect the server. Default is off. Useful if you don't care about port numbers and just want a connection somehow.
Definition at line 197 of file CScommBase.hh.
|
inline |
set the time in ms until a commPartner is assumed to be disconnected.
If time is zero there is no timeOut. default is no Time out
Definition at line 189 of file CScommBase.hh.
|
inlineinherited |
Definition at line 318 of file Debug.hh.
Referenced by BIAS::ShowCamWxVideoSourceFactory::CreateBumbleBee(), BIAS::ShowCamWxVideoSourceFactory::CreateDCAM(), BIAS::VideoSource_MDcam::ScanBus(), BIAS::GLProjectionParametersBase::SetDebugLevel(), BIAS::VideoSource_Disk::VideoSource_Disk(), BIAS::VideoSource_DV2::VideoSource_DV2(), BIAS::VideoSource_DV::VideoSource_DV_Internal_Init_(), and BIAS::VideoSource_V4L::VideoSource_V4L().
|
inlineinherited |
|
inlineinherited |
|
inlinestaticinherited |
|
inline |
If not threaded you can set this true to keep all received data.
Else a call of GetData() will deliver the newest msg only. Default is off. If threaded this is useless... (always off)
Definition at line 101 of file CScommBase.hh.
Referenced by BIAS::VideoTransmitter::Init(), and BIAS::VideoSource_Net::VideoSource_Net().
void CScommBase::SetLog | ( | bool | on | ) |
gives a lot of information regarding the connections, like the exact
data received and send.
Implies verbose.
Definition at line 1008 of file CScommBase.cpp.
void CScommBase::SetLogOut | ( | std::ostream & | outputStream | ) |
set the output of log msgs to another stream, e.g.
to a file. Default ist cout.
Definition at line 1013 of file CScommBase.cpp.
References logOut_.
void CScommBase::SetVerbose | ( | bool | on | ) |
gives some information about establising conn, and disconnecting etc.
Definition at line 1018 of file CScommBase.cpp.
References verbose_.
Referenced by BIAS::VideoSource_Net::OpenDevice(), and BIAS::VideoSource_Kinect2Net::runner().
void CScommBase::SetVerboseOut | ( | std::ostream & | outputStream | ) |
set the output of verbose msgs to another stream, e.g.
to a file. Default ist cout.
Definition at line 1022 of file CScommBase.cpp.
References verboseOut_.
|
inlineinherited |
|
protected |
Definition at line 885 of file CScommBase.cpp.
References AnalyzeData_(), AnalyzeFirstMsg_(), commPartners_, commPartnersConnected_, isServer_, log_, logOut_, logOutPut_(), verbose_, and verboseOut_.
Referenced by GetData(), and WaitForNewMessage().
int CScommBase::WaitForNewMessage | ( | std::string & | msgName | ) |
only if not threaded! <br>
Blocks until any new msg arrives, or returns instantly if a new message is already in a buffer slot.
The msg name is returned in msgName.
The return value indicates how many additional new msgs are in the buffer slots, e.g. if 0 the msgName is the only new message.
Definition at line 284 of file CScommBase.cpp.
References registeredMsgs_, syncReceive_(), and threaded_.
|
friend |
these are wrapper to comply to the pthread_create() interface
Referenced by AcceptConn_().
|
protectedinherited |
Definition at line 510 of file Debug.hh.
Referenced by BIAS::Debug::operator=(), and BIAS::ImageBase::operator=().
|
protectedinherited |
new concept, debuglevel are managed here in the debug class
Definition at line 516 of file Debug.hh.
Referenced by BIAS::Debug::operator=().
|
protectedinherited |
Definition at line 517 of file Debug.hh.
Referenced by BIAS::Debug::operator=().
|
staticprotectedinherited |
Definition at line 511 of file Debug.hh.
Referenced by BIAS::Debug::operator=().
|
protected |
Definition at line 275 of file CScommBase.hh.
Referenced by AcceptConn_(), AnalyzeData_(), AnalyzeFirstMsg_(), BIAS::CScommClient::ConnectServer(), CScommBase(), GetCommPartnerName(), receiveThread_(), SendMsg(), SendMsg_(), and syncReceive_().
|
protected |
Definition at line 277 of file CScommBase.hh.
Referenced by AcceptConn_(), CScommBase(), receiveThread_(), and syncReceive_().
|
protected |
Definition at line 276 of file CScommBase.hh.
Referenced by BIAS::CScommClient::ConnectServer(), BIAS::CScommServer::CreateListenThread_(), CScommBase(), BIAS::listenthread(), and BIAS::CScommServer::WaitForConnections().
|
staticprotectedinherited |
|
protected |
Definition at line 281 of file CScommBase.hh.
Referenced by CheckRegisteredMsgs_(), BIAS::CScommClient::CScommClient(), BIAS::CScommServer::CScommServer(), receiveThread_(), RegisterMsg(), and syncReceive_().
|
protected |
Definition at line 286 of file CScommBase.hh.
Referenced by AnalyzeData_(), and CScommBase().
|
protected |
Definition at line 288 of file CScommBase.hh.
Referenced by BIAS::CScommClient::ConnectServer(), CScommBase(), logOutPut_(), receiveThread_(), SendMsg(), SendMsg_(), SetLog(), and syncReceive_().
|
protected |
Definition at line 289 of file CScommBase.hh.
Referenced by BIAS::CScommClient::ConnectServer(), logOutPut_(), receiveThread_(), SendMsg(), SendMsg_(), SetLogOut(), and syncReceive_().
|
protected |
Definition at line 299 of file CScommBase.hh.
|
protected |
Definition at line 293 of file CScommBase.hh.
Referenced by BIAS::CScommClient::ConnectServer(), and BIAS::CScommClient::CScommClient().
|
protected |
Definition at line 280 of file CScommBase.hh.
Referenced by CScommBase().
|
protected |
Definition at line 284 of file CScommBase.hh.
Referenced by BIAS::CScommClient::ConnectServer(), CScommBase(), and BIAS::listenthread().
|
protected |
Definition at line 300 of file CScommBase.hh.
Referenced by AnalyzeData_(), CheckRegisteredMsgs_(), CScommBase(), GetData(), GetData_(), RegisterMsg(), and WaitForNewMessage().
|
protected |
Definition at line 297 of file CScommBase.hh.
Referenced by CheckRegisteredMsgs_(), CScommBase(), and RegisterMsg().
|
protected |
Definition at line 296 of file CScommBase.hh.
Referenced by CScommBase(), and receiveThread_().
|
protected |
Definition at line 285 of file CScommBase.hh.
Referenced by AcceptConn_(), AnalyzeData_(), CheckRegisteredMsgs_(), CScommBase(), GetData(), RegisterMsg(), and WaitForNewMessage().
|
protected |
Definition at line 294 of file CScommBase.hh.
Referenced by CScommBase().
|
protected |
Definition at line 295 of file CScommBase.hh.
Referenced by CScommBase().
|
protected |
Definition at line 290 of file CScommBase.hh.
Referenced by BIAS::CScommClient::ConnectServer(), CScommBase(), BIAS::listenthread(), receiveThread_(), SetLog(), SetVerbose(), and syncReceive_().
|
protected |
Definition at line 291 of file CScommBase.hh.
Referenced by BIAS::CScommClient::ConnectServer(), BIAS::listenthread(), receiveThread_(), SetVerboseOut(), and syncReceive_().