From 80a1a3d796c6597ed1fab9944ef9903647f2d729 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Wed, 16 Jan 2019 15:10:24 +0100 Subject: [PATCH] moved ClientInterface to src --- slsDetectorSoftware/CMakeLists.txt | 4 +- slsReceiverSoftware/CMakeLists.txt | 4 +- slsSupportLib/include/ClientInterface.cpp | 148 ---------------------- slsSupportLib/include/ClientInterface.h | 2 +- slsSupportLib/include/utilities.cpp | 148 ---------------------- 5 files changed, 5 insertions(+), 301 deletions(-) delete mode 100644 slsSupportLib/include/ClientInterface.cpp delete mode 100644 slsSupportLib/include/utilities.cpp diff --git a/slsDetectorSoftware/CMakeLists.txt b/slsDetectorSoftware/CMakeLists.txt index 1e93cbb45..5ac91741f 100644 --- a/slsDetectorSoftware/CMakeLists.txt +++ b/slsDetectorSoftware/CMakeLists.txt @@ -4,8 +4,8 @@ set(SOURCES slsDetector/slsDetectorUsers.cpp slsDetector/slsDetectorCommand.cpp slsDetector/slsDetector.cpp - ${PROJECT_SOURCE_DIR}/slsSupportLib/include/ClientInterface.cpp - ${PROJECT_SOURCE_DIR}/slsSupportLib/include/utilities.cpp + ${PROJECT_SOURCE_DIR}/slsSupportLib/src/ClientInterface.cpp + ${PROJECT_SOURCE_DIR}/slsSupportLib/src/utilities.cpp ${PROJECT_SOURCE_DIR}/slsSupportLib/src/string_utils.cpp ) diff --git a/slsReceiverSoftware/CMakeLists.txt b/slsReceiverSoftware/CMakeLists.txt index f342c44df..fe518e585 100644 --- a/slsReceiverSoftware/CMakeLists.txt +++ b/slsReceiverSoftware/CMakeLists.txt @@ -10,8 +10,8 @@ set(SOURCES src/DataProcessor.cpp src/DataStreamer.cpp src/Fifo.cpp - ../slsSupportLib/include/utilities.cpp - ../slsSupportLib/include/ClientInterface.cpp + ../slsSupportLib/src/utilities.cpp + ../slsSupportLib/src/ClientInterface.cpp ) diff --git a/slsSupportLib/include/ClientInterface.cpp b/slsSupportLib/include/ClientInterface.cpp deleted file mode 100644 index cb427c980..000000000 --- a/slsSupportLib/include/ClientInterface.cpp +++ /dev/null @@ -1,148 +0,0 @@ -#include "ClientInterface.h" - - -ClientInterface::ClientInterface(MySocketTCP *socket, int n, std::string t): -mySocket(socket), -index(n), -type(t){} - -ClientInterface::~ClientInterface(){} - - -void ClientInterface::SetSocket(MySocketTCP *socket) { - mySocket = socket; -} - - -void ClientInterface::Client_Receive(int& ret, char* mess, void* retval, int sizeOfRetval) { - // get result of operation - mySocket->ReceiveDataOnly(&ret,sizeof(ret)); - - bool unrecognizedFunction = false; - if (ret == FAIL) { - bool created = false; - // allocate mess if null - if (!mess){ - created = true; - mess = new char[MAX_STR_LENGTH]; - memset(mess, 0, MAX_STR_LENGTH); - } - // get error message - mySocket->ReceiveDataOnly(mess,MAX_STR_LENGTH); - cprintf(RED, "%s %d returned error: %s", type.c_str(), index, mess); - - // unrecognized function, do not ask for retval - if(strstr(mess,"Unrecognized Function") != NULL) - unrecognizedFunction = true; - // delete allocated mess - if (created) - delete [] mess; - } - // get retval - if (!unrecognizedFunction) - mySocket->ReceiveDataOnly(retval, sizeOfRetval); -} - - -int ClientInterface::Client_Send(int fnum, - void* args, int sizeOfArgs, - void* retval, int sizeOfRetval, - char* mess) { - int ret = FAIL; - mySocket->SendDataOnly(&fnum,sizeof(fnum)); - mySocket->SendDataOnly(args, sizeOfArgs); - Client_Receive(ret, mess, retval, sizeOfRetval); - return ret; -} - - -int ClientInterface::Server_SendResult(bool update, int ret, - void* retval, int retvalSize, char* mess) { - - // update if different clients - if (update && ret == OK && 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); - - return ret; -} - - -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(); - - // 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) { - 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,"Receiver locked by %s\n", 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 receiver is not idle\n", - getFunctionNameFromEnum((enum detFuncs)fnum)); - FILE_LOG(logERROR) << mess; - return ret; -} - - - - diff --git a/slsSupportLib/include/ClientInterface.h b/slsSupportLib/include/ClientInterface.h index ddc823167..ace0e9717 100644 --- a/slsSupportLib/include/ClientInterface.h +++ b/slsSupportLib/include/ClientInterface.h @@ -25,7 +25,7 @@ public: /** * destructor */ - virtual ~ClientInterface(); + virtual ~ClientInterface() = default; /** * Set the datasocket diff --git a/slsSupportLib/include/utilities.cpp b/slsSupportLib/include/utilities.cpp deleted file mode 100644 index d3ebe74b2..000000000 --- a/slsSupportLib/include/utilities.cpp +++ /dev/null @@ -1,148 +0,0 @@ -#include "utilities.h" -#include "logger.h" - -#include -#include - - - - -int read_config_file(std::string fname, int *tcpip_port_no, - std::map * configuration_map) { - - std::ifstream infile; - std::string sLine,sargname, sargvalue; - int iline = 0; - int success = slsDetectorDefs::OK; - - - FILE_LOG(logINFO) << "config file name " << fname; - try { - infile.open(fname.c_str(), std::ios_base::in); - } catch(...) { - FILE_LOG(logERROR) << "Could not open configuration file " << fname ; - success = slsDetectorDefs::FAIL; - } - - if (success == slsDetectorDefs::OK && infile.is_open()) { - while(infile.good()){ - getline(infile,sLine); - iline++; - - //VERBOSE_PRINT(sLine); - - if(sLine.find('#') != std::string::npos) - continue; - - else if(sLine.length()<2) - continue; - - else{ - std::istringstream sstr(sLine); - - //parameter name - if(sstr.good()){ - sstr >> sargname; - - if (! sstr.good()) - continue; - - sstr >> sargvalue; - (*configuration_map)[sargname] = sargvalue; - } - //tcp port - if(sargname=="rx_tcpport"){ - if(sstr.good()) { - sstr >> sargname; - if(sscanf(sargname.c_str(),"%d",tcpip_port_no)) - cprintf(RESET, "dataport: %d\n" , *tcpip_port_no); - else{ - cprintf(RED, "could not decode port in config file. Exiting.\n"); - success = slsDetectorDefs::FAIL; - } - } - } - } - } - infile.close(); - } - - return success; -} - - - -int readDataFile(std::ifstream &infile, short int *data, int nch, int offset) { - int ichan, iline=0; - short int idata; - int interrupt=0; - std::string str; - while (infile.good() and interrupt==0) { - getline(infile,str); - std::istringstream ssstr(str); - ssstr >> ichan >> idata; - if (ssstr.fail() || ssstr.bad()) { - interrupt=1; - break; - } - if (iline=offset) { - data[iline]=idata; - iline++; - } - } else { - interrupt=1; - break; - } - return iline; - }; - return iline; -} - - - -int readDataFile(std::string fname, short int *data, int nch) { - std::ifstream infile; - int iline=0; - std::string str; - infile.open(fname.c_str(), std::ios_base::in); - if (infile.is_open()) { - iline=readDataFile(infile, data, nch, 0); - infile.close(); - } else { - FILE_LOG(logERROR) << "Could not read file " << fname; - return -1; - } - return iline; -} - - - -int writeDataFile(std::ofstream &outfile,int nch, short int *data, int offset) { - if (data==NULL) - return slsDetectorDefs::FAIL; - for (int ichan=0; ichan