mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-15 14:27:13 +02:00
receiver tcp interface updated
This commit is contained in:
@ -20,50 +20,25 @@ ClientInterface::~ClientInterface(){}
|
||||
|
||||
|
||||
void ClientInterface::SetSocket(MySocketTCP *socket) {
|
||||
mySocket=socket;
|
||||
}
|
||||
|
||||
|
||||
int ClientInterface::PrintSocketReadError() {
|
||||
FILE_LOG(logERROR) << "Reading from socket failed. Possible socket crash";
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
void ClientInterface::Server_SendResult(bool diffClients, int ret,
|
||||
void* retval, int retvalSize, char* mess) {
|
||||
|
||||
// update if different clients
|
||||
if (diffClients)
|
||||
ret = FORCE_UPDATE;
|
||||
|
||||
// send success of operation
|
||||
mySocket->SendDataOnly(&ret,sizeof(ret));
|
||||
if(ret == FAIL) {
|
||||
// send error message
|
||||
if (mess)
|
||||
mySocket->SendDataOnly(mess, MAX_STR_LENGTH);
|
||||
// debugging feature. should not happen.
|
||||
else
|
||||
FILE_LOG(logERROR) << "No error message provided for this failure. Will mess up TCP\n";
|
||||
}
|
||||
// send return value
|
||||
mySocket->SendDataOnly(retval, retvalSize);
|
||||
mySocket = socket;
|
||||
}
|
||||
|
||||
|
||||
int ClientInterface::Client_GetMesage(char* mess) {
|
||||
bool created = false;
|
||||
int ret = OK;
|
||||
if (!mess){
|
||||
char messref[MAX_STR_LENGTH];
|
||||
memset(messref, 0, MAX_STR_LENGTH);
|
||||
mess = (char*)messref;
|
||||
created = true;
|
||||
mess = new char[MAX_STR_LENGTH];
|
||||
memset(mess, 0, MAX_STR_LENGTH);
|
||||
}
|
||||
mySocket->ReceiveDataOnly(mess,MAX_STR_LENGTH);
|
||||
cprintf(RED, "%s %d returned error: %s", type.c_str(), index, mess);
|
||||
if(strstr(mess,"Unrecognized Function")!=NULL)
|
||||
ret = FAIL;
|
||||
|
||||
if (created)
|
||||
delete [] mess;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -110,6 +85,93 @@ int ClientInterface::Client_Send(int fnum,
|
||||
}
|
||||
|
||||
|
||||
void ClientInterface::Server_SendResult(bool update, int ret,
|
||||
void* retval, int retvalSize, char* mess) {
|
||||
|
||||
// update if different clients
|
||||
if (update && mySocket->differentClients)
|
||||
ret = FORCE_UPDATE;
|
||||
|
||||
// send success of operation
|
||||
mySocket->SendDataOnly(&ret,sizeof(ret));
|
||||
if(ret == FAIL) {
|
||||
// send error message
|
||||
if (mess)
|
||||
mySocket->SendDataOnly(mess, MAX_STR_LENGTH);
|
||||
// debugging feature. should not happen.
|
||||
else
|
||||
FILE_LOG(logERROR) << "No error message provided for this failure. Will mess up TCP\n";
|
||||
}
|
||||
// send return value
|
||||
mySocket->SendDataOnly(retval, retvalSize);
|
||||
}
|
||||
|
||||
|
||||
int ClientInterface::Server_ReceiveArg(int& ret, char* mess, void* arg, int sizeofArg, bool checkbase, void* base) {
|
||||
// client socket crash, cannot receive arguments
|
||||
if (sizeofArg && mySocket->ReceiveDataOnly(arg, sizeofArg) < 0)
|
||||
return Server_SocketCrash();
|
||||
|
||||
ret = OK;
|
||||
// check if server object created
|
||||
if (checkbase && base == NULL)
|
||||
Server_NullObjectError(ret, mess);
|
||||
|
||||
// no crash
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int ClientInterface::Server_VerifyLock(int& ret, char* mess, int lockstatus) {
|
||||
// server locked
|
||||
if (mySocket->differentClients && lockstatus)
|
||||
return Server_LockedError(ret, mess);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int ClientInterface::Server_VerifyLockAndIdle(int& ret, char* mess, int lockstatus, slsDetectorDefs::runStatus status, int fnum) {
|
||||
// server locked
|
||||
if (mySocket->differentClients && lockstatus)
|
||||
return Server_LockedError(ret, mess);
|
||||
|
||||
// server not idle for this command
|
||||
if (status != slsDetectorDefs::IDLE)
|
||||
return Server_NotIdleError(ret, mess, fnum);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void ClientInterface::Server_NullObjectError(int& ret, char* mess) {
|
||||
// only for receiver
|
||||
ret=FAIL;
|
||||
strcpy(mess,"Receiver not set up. Please use rx_hostname first.\n");
|
||||
FILE_LOG(logERROR) << mess;
|
||||
}
|
||||
|
||||
|
||||
int ClientInterface::Server_SocketCrash() {
|
||||
FILE_LOG(logERROR) << "Reading from socket failed. Possible socket crash";
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
int ClientInterface::Server_LockedError(int& ret, char* mess) {
|
||||
ret = FAIL;
|
||||
sprintf(mess,"%s locked by %s\n",type.c_str(), mySocket->lastClientIP);
|
||||
FILE_LOG(logERROR) << mess;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int ClientInterface::Server_NotIdleError(int& ret, char* mess, int fnum) {
|
||||
ret = FAIL;
|
||||
sprintf(mess,"Can not execute %s when %s is not idle\n",
|
||||
getFunctionNameFromEnum((enum detFuncs)fnum), type.c_str());
|
||||
FILE_LOG(logERROR) << mess;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user