25 #ifndef __BIASCScommBase__
26 #define __BIASCScommBase__
28 #include <bias_config.h>
29 #include <Base/Common/W32Compat.hh>
30 #include <Base/Common/BIASpragmaStart.hh>
32 #ifndef BIAS_HAVE_PTHREADS
33 # error BIAS_HAVE_PTHREADS not defined. But BIASNetworkComm needs pthreads (on Unix and Win32). Please enable USE_PTHREADS in CMake configure step.
37 #include <sys/types.h>
40 #include <Base/Debug/Debug.hh>
41 #include <NetworkComm/CScommClasses.hh>
45 #define D_CS_MAXCLIENTS 100
46 #define D_CS_DEFAULT_PORT 4123
48 #define D_CS_LISTENER 1<<0
49 #define D_CS_RECEIVER 1<<1
50 #define D_CS_CONNECT 1<<2
51 #define D_CS_ANALYZE 1<<3
52 #define D_CS_SEND 1<<4
53 #define D_CS_GETDATA 1<<5
56 # define mygetpid() (pthread_self()).p
58 # define mygetpid() getpid()
113 int WaitForNewMessage(std::string &msgName);
121 int GetData(
const std::string &msgName, std::vector<float> &floatData);
122 int GetData(
const std::string &msgName, std::vector<int> &intData);
123 int GetData(
const std::string &msgName,
124 std::vector<std::string> &stringData);
128 int GetData(
const std::string &msgName,
129 std::vector<char> &binaryData);
135 int SendMsg(
const std::string &msgName, std::vector<float> &floatData);
136 int SendMsg(
const std::string &msgName, std::vector<int> &intData);
137 int SendMsg(
const std::string &msgName,
138 std::vector<std::string> &stringData);
142 int SendMsg(
const std::string &msgName,
char* binaryData,
unsigned int size);
148 int SendMsg(
const std::string commPartnerName,
149 const std::string &msgName,
char* binaryData,
unsigned int size);
155 int SendMsg(
int commPartnerNr,
156 const std::string &msgName,
char* binaryData,
unsigned int size);
170 int RegisterMsg(std::string msgName,
EdataType dataType,
int amount=1);
174 int RegisterMsg(std::string commPartnerName,
175 std::string msgName,
EdataType dataType,
int amount=1);
184 std::string GetCommPartnerName(
int commPartnerNr);
190 if (time==0) timeOutFlag_=
false; timeOut_=time;}
205 void SetLog(
bool on);
210 void SetLogOut(std::ostream &outputStream);
214 void SetVerbose(
bool on);
219 void SetVerboseOut(std::ostream &outputStream);
228 void logOutPut_(
const char *data,
unsigned int size);
231 int SendMsg_(
const std::string &data);
235 int GetData_(
const std::string &msgName);
251 int AnalyzeData_(
int clientNr);
257 int CheckRegisteredMsgs_(std::string &msgName,
const CScommData &cPartner,
259 unsigned int &dataSizeToRead);
261 void receiveThread_(
int clientNr);
269 int AnalyzeFirstMsg_(
int commNr);
273 int AcceptConn_(
int fd);
305 std::map<std::string, int> indexRegMsgs_;
320 #include <Base/Common/BIASpragmaEnd.hh>
int commPartnersConnected_
std::vector< CScommMsg > registeredMsgs_
helper class for CScommBase
void SetConnectionTimeOut(unsigned int time)
set the time in ms until a commPartner is assumed to be disconnected.
int GetConnections()
returns the number of connected commPartners
pthread_mutex_t registerLock_
void SetAutomaticPortChange(bool on)
if set on, the server will take automatically the next free TCP port for connections.
std::vector< CScommData > commPartners_
this class CScomm (ClientServer communciation) handles data comunication via TCP/IP for one server an...
std::vector< CScommMsg > msgBuffer_
bool GetThreadedReceive()
void * receivethread(void *data)
these are wrapper to comply to the pthread_create() interface
void SetKeepAll(bool on)
If not threaded you can set this true to keep all received data.