mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-26 08:10:02 +02:00
project wide nullptr fix
This commit is contained in:
parent
80a1a3d796
commit
49f71ffca7
@ -187,7 +187,7 @@ int main(int argc, char *argv[]) {
|
||||
sa.sa_flags=0; // no flags
|
||||
sa.sa_handler=sigInterruptHandler; // handler function
|
||||
sigemptyset(&sa.sa_mask); // dont block additional signals during invocation of handler
|
||||
if (sigaction(SIGINT, &sa, NULL) == -1) {
|
||||
if (sigaction(SIGINT, &sa, nullptr) == -1) {
|
||||
cprintf(RED, "Could not set handler function for SIGINT\n");
|
||||
}
|
||||
|
||||
@ -197,7 +197,7 @@ int main(int argc, char *argv[]) {
|
||||
asa.sa_flags=0; // no flags
|
||||
asa.sa_handler=SIG_IGN; // handler function
|
||||
sigemptyset(&asa.sa_mask); // dont block additional signals during invocation of handler
|
||||
if (sigaction(SIGPIPE, &asa, NULL) == -1) {
|
||||
if (sigaction(SIGPIPE, &asa, nullptr) == -1) {
|
||||
cprintf(RED, "Could not set handler function for SIGPIPE\n");
|
||||
}
|
||||
|
||||
@ -236,16 +236,16 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
/** - Call back for start acquisition */
|
||||
cprintf(BLUE, "Registering StartAcq()\n");
|
||||
receiver->registerCallBackStartAcquisition(StartAcq, NULL);
|
||||
receiver->registerCallBackStartAcquisition(StartAcq, nullptr);
|
||||
|
||||
/** - Call back for acquisition finished */
|
||||
cprintf(BLUE, "Registering AcquisitionFinished()\n");
|
||||
receiver->registerCallBackAcquisitionFinished(AcquisitionFinished, NULL);
|
||||
receiver->registerCallBackAcquisitionFinished(AcquisitionFinished, nullptr);
|
||||
|
||||
/* - Call back for raw data */
|
||||
cprintf(BLUE, "Registering GetData() \n");
|
||||
if (withCallback == 1) receiver->registerCallBackRawDataReady(GetData,NULL);
|
||||
else if (withCallback == 2) receiver->registerCallBackRawDataModifyReady(GetData,NULL);
|
||||
if (withCallback == 1) receiver->registerCallBackRawDataReady(GetData,nullptr);
|
||||
else if (withCallback == 2) receiver->registerCallBackRawDataModifyReady(GetData,nullptr);
|
||||
}
|
||||
|
||||
|
||||
@ -272,7 +272,7 @@ int main(int argc, char *argv[]) {
|
||||
sa.sa_flags=0; // no flags
|
||||
sa.sa_handler=SIG_IGN; // handler function
|
||||
sigemptyset(&sa.sa_mask); // dont block additional signals during invocation of handler
|
||||
if (sigaction(SIGINT, &sa, NULL) == -1) {
|
||||
if (sigaction(SIGINT, &sa, nullptr) == -1) {
|
||||
cprintf(RED, "Could not set handler function for SIGINT\n");
|
||||
}
|
||||
|
||||
@ -283,7 +283,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
/** - Parent process waits for all child processes to exit */
|
||||
for(;;) {
|
||||
pid_t childPid = waitpid (-1, NULL, 0);
|
||||
pid_t childPid = waitpid (-1, nullptr, 0);
|
||||
|
||||
// no child closed
|
||||
if (childPid == -1) {
|
||||
|
@ -103,7 +103,7 @@ void SharedMemory::RemoveSharedMemory() {
|
||||
|
||||
|
||||
void* SharedMemory::MapSharedMemory(size_t sz) {
|
||||
void* addr = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
void* addr = mmap(nullptr, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (addr == MAP_FAILED) {
|
||||
FILE_LOG(logERROR) << "Mapping shared memory " << name << " failed: " << strerror(errno);
|
||||
close(fd);
|
||||
@ -120,7 +120,7 @@ std::string SharedMemory::ConstructSharedMemoryName(int multiId, int slsId) {
|
||||
// using environment path
|
||||
std::string sEnvPath = "";
|
||||
char* envpath = getenv(SHM_ENV_NAME);
|
||||
if (envpath != NULL) {
|
||||
if (envpath != nullptr) {
|
||||
sEnvPath.assign(envpath);
|
||||
sEnvPath.insert(0,"_");
|
||||
}
|
||||
|
@ -2389,7 +2389,7 @@ std::string slsDetectorCommand::cmdTrimEn(int narg, char *args[], int action, in
|
||||
myDet->setTrimEn(ip, pos, detPos);
|
||||
}
|
||||
}
|
||||
int npos = myDet->getTrimEn(NULL, detPos);
|
||||
int npos = myDet->getTrimEn(nullptr, detPos);
|
||||
if (npos != -1) {
|
||||
sprintf(answer, "%d", npos);
|
||||
int opos[npos];
|
||||
@ -4601,7 +4601,7 @@ std::string slsDetectorCommand::cmdAdvanced(int narg, char *args[], int action,
|
||||
} else if (cmd == "programfpga") {
|
||||
if (action == GET_ACTION)
|
||||
return std::string("cannot get");
|
||||
if (strstr(args[1], ".pof") == NULL)
|
||||
if (strstr(args[1], ".pof") == nullptr)
|
||||
return std::string("wrong usage: programming file should have .pof extension");
|
||||
std::string sval = std::string(args[1]);
|
||||
#ifdef VERBOSE
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
slsDetectorUsers::slsDetectorUsers(int& ret, int id) : myDetector(0), myCmd(0){
|
||||
slsDetectorUsers::slsDetectorUsers(int& ret, int id) : myDetector(nullptr), myCmd(nullptr){
|
||||
try {
|
||||
myDetector=new multiSlsDetector(id);
|
||||
} catch(...) {
|
||||
|
@ -11,14 +11,14 @@
|
||||
#include <iostream>
|
||||
|
||||
|
||||
FILE* BinaryFile::masterfd = 0;
|
||||
FILE* BinaryFile::masterfd = nullptr;
|
||||
|
||||
BinaryFile::BinaryFile(int ind, uint32_t* maxf,
|
||||
int* nd, char* fname, char* fpath, uint64_t* findex, bool* owenable,
|
||||
int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, uint32_t* portno,
|
||||
bool* smode):
|
||||
File(ind, maxf, nd, fname, fpath, findex, owenable, dindex, nunits, nf, dr, portno, smode),
|
||||
filefd(0),
|
||||
filefd(nullptr),
|
||||
numFramesInFile(0),
|
||||
numActualPacketsInFile(0)
|
||||
{
|
||||
|
@ -33,10 +33,10 @@ DataProcessor::DataProcessor(int ind, detectorType dtype, Fifo* f,
|
||||
|
||||
ThreadObject(ind),
|
||||
runningFlag(0),
|
||||
generalData(0),
|
||||
generalData(nullptr),
|
||||
fifo(f),
|
||||
myDetectorType(dtype),
|
||||
file(0),
|
||||
file(nullptr),
|
||||
dataStreamEnable(dsEnable),
|
||||
fileFormatType(ftype),
|
||||
fileWriteEnable(fwenable),
|
||||
@ -45,7 +45,7 @@ DataProcessor::DataProcessor(int ind, detectorType dtype, Fifo* f,
|
||||
streamingFrequency(freq),
|
||||
streamingTimerInMs(timer),
|
||||
currentFreqCount(0),
|
||||
tempBuffer(0),
|
||||
tempBuffer(nullptr),
|
||||
activated(act),
|
||||
deactivatedPaddingEnable(depaden),
|
||||
silentMode(sm),
|
||||
@ -144,7 +144,7 @@ void DataProcessor::ResetParametersforNewMeasurement(){
|
||||
|
||||
if (tempBuffer) {
|
||||
delete [] tempBuffer;
|
||||
tempBuffer = 0;
|
||||
tempBuffer = nullptr;
|
||||
}
|
||||
if (*gapPixelsEnable) {
|
||||
tempBuffer = new char[generalData->imageSize];
|
||||
@ -196,10 +196,10 @@ void DataProcessor::SetFileFormat(const fileFormat f) {
|
||||
if (file && file->GetFileType() != f) {
|
||||
//remember the pointer values before they are destroyed
|
||||
int nd[MAX_DIMENSIONS];nd[0] = 0; nd[1] = 0;
|
||||
uint32_t* maxf = 0;
|
||||
char* fname=0; char* fpath=0; uint64_t* findex=0;
|
||||
bool* owenable=0; int* dindex=0; int* nunits=0; uint64_t* nf = 0;
|
||||
uint32_t* dr = 0; uint32_t* port = 0;
|
||||
uint32_t* maxf = nullptr;
|
||||
char* fname=nullptr; char* fpath=nullptr; uint64_t* findex=nullptr;
|
||||
bool* owenable=nullptr; int* dindex=nullptr; int* nunits=nullptr; uint64_t* nf = nullptr;
|
||||
uint32_t* dr = nullptr; uint32_t* port = nullptr;
|
||||
file->GetMemberPointerValues(nd, maxf, fname, fpath, findex,
|
||||
owenable, dindex, nunits, nf, dr, port);
|
||||
//create file writer with same pointers
|
||||
@ -221,7 +221,7 @@ void DataProcessor::SetupFileWriter(bool fwe, int* nd, uint32_t* maxf,
|
||||
|
||||
|
||||
if (file) {
|
||||
delete file; file = 0;
|
||||
delete file; file = nullptr;
|
||||
}
|
||||
|
||||
if (fileWriteEnable) {
|
||||
@ -246,7 +246,7 @@ void DataProcessor::SetupFileWriter(bool fwe, int* nd, uint32_t* maxf,
|
||||
// only the first file
|
||||
int DataProcessor::CreateNewFile(bool en, uint64_t nf, uint64_t at, uint64_t st,
|
||||
uint64_t sp, uint64_t ap) {
|
||||
if (file == NULL)
|
||||
if (file == nullptr)
|
||||
return FAIL;
|
||||
file->CloseAllFiles();
|
||||
if (file->CreateMasterFile(en, generalData->imageSize,
|
||||
@ -272,7 +272,7 @@ void DataProcessor::EndofAcquisition(bool anyPacketsCaught, uint64_t numf) {
|
||||
|
||||
|
||||
void DataProcessor::ThreadExecution() {
|
||||
char* buffer=0;
|
||||
char* buffer=nullptr;
|
||||
fifo->PopAddress(buffer);
|
||||
FILE_LOG(logDEBUG5) << "DataProcessor " << index << ", "
|
||||
"pop 0x" << std::hex << (void*)(buffer) << std::dec << ":" << buffer;
|
||||
@ -492,8 +492,8 @@ void DataProcessor::InsertGapPixels(char* buf, uint32_t dr) {
|
||||
const uint32_t ny = generalData->nPixelsY;
|
||||
const uint32_t npx = nx * ny;
|
||||
|
||||
char* srcptr = 0;
|
||||
char* dstptr = 0;
|
||||
char* srcptr = nullptr;
|
||||
char* dstptr = nullptr;
|
||||
|
||||
const uint32_t b1px = generalData->imageSize / (npx); // not double as not dealing with 4 bit mode
|
||||
const uint32_t b2px = 2 * b1px;
|
||||
@ -515,8 +515,8 @@ void DataProcessor::InsertGapPixels(char* buf, uint32_t dr) {
|
||||
|
||||
// vertical filling of values
|
||||
{
|
||||
char* srcgp1 = 0; char* srcgp2 = 0; char* srcgp3 = 0;
|
||||
char* dstgp1 = 0; char* dstgp2 = 0; char* dstgp3 = 0;
|
||||
char* srcgp1 = nullptr; char* srcgp2 = nullptr; char* srcgp3 = nullptr;
|
||||
char* dstgp1 = nullptr; char* dstgp2 = nullptr; char* dstgp3 = nullptr;
|
||||
const uint32_t b3px = 3 * b1px;
|
||||
|
||||
srcptr = tempBuffer + b1line;
|
||||
|
@ -19,9 +19,9 @@ DataStreamer::DataStreamer(int ind, Fifo* f, uint32_t* dr, std::vector<ROI>* r,
|
||||
uint64_t* fi, int* fd, char* ajh) :
|
||||
ThreadObject(ind),
|
||||
runningFlag(0),
|
||||
generalData(0),
|
||||
generalData(nullptr),
|
||||
fifo(f),
|
||||
zmqSocket(0),
|
||||
zmqSocket(nullptr),
|
||||
dynamicRange(dr),
|
||||
roi(r),
|
||||
adcConfigured(-1),
|
||||
@ -32,7 +32,7 @@ DataStreamer::DataStreamer(int ind, Fifo* f, uint32_t* dr, std::vector<ROI>* r,
|
||||
measurementStartedFlag(false),
|
||||
firstAcquisitionIndex(0),
|
||||
firstMeasurementIndex(0),
|
||||
completeBuffer(0)
|
||||
completeBuffer(nullptr)
|
||||
{
|
||||
if(ThreadObject::CreateThread() == FAIL)
|
||||
throw std::exception();
|
||||
@ -85,7 +85,7 @@ void DataStreamer::ResetParametersforNewMeasurement(char* fname){
|
||||
strcpy(fileNametoStream, fname);
|
||||
if (completeBuffer) {
|
||||
delete [] completeBuffer;
|
||||
completeBuffer = 0;
|
||||
completeBuffer = nullptr;
|
||||
}
|
||||
if (roi->size()) {
|
||||
if (generalData->myDetectorType == GOTTHARD) {
|
||||
@ -131,7 +131,7 @@ void DataStreamer::CreateZmqSockets(int* nunits, uint32_t port, const char* srci
|
||||
uint32_t portnum = port + index;
|
||||
|
||||
try {
|
||||
zmqSocket = new ZmqSocket(portnum, (strlen(srcip)?srcip:NULL));
|
||||
zmqSocket = new ZmqSocket(portnum, (strlen(srcip)?srcip:nullptr));
|
||||
} catch (...) {
|
||||
FILE_LOG(logERROR) << "Could not create Zmq socket on port " << portnum << " for Streamer " << index;
|
||||
throw;
|
||||
@ -143,13 +143,13 @@ void DataStreamer::CreateZmqSockets(int* nunits, uint32_t port, const char* srci
|
||||
void DataStreamer::CloseZmqSocket() {
|
||||
if (zmqSocket) {
|
||||
delete zmqSocket;
|
||||
zmqSocket = 0;
|
||||
zmqSocket = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DataStreamer::ThreadExecution() {
|
||||
char* buffer=0;
|
||||
char* buffer=nullptr;
|
||||
fifo->PopAddressToStream(buffer);
|
||||
FILE_LOG(logDEBUG5) << "DataStreamer " << index << ", "
|
||||
"pop 0x" << std::hex << (void*)(buffer) << std::dec << ":" << buffer;
|
||||
|
@ -14,10 +14,10 @@
|
||||
|
||||
Fifo::Fifo(int ind, uint32_t fifoItemSize, uint32_t depth):
|
||||
index(ind),
|
||||
memory(0),
|
||||
fifoBound(0),
|
||||
fifoFree(0),
|
||||
fifoStream(0),
|
||||
memory(nullptr),
|
||||
fifoBound(nullptr),
|
||||
fifoFree(nullptr),
|
||||
fifoStream(nullptr),
|
||||
fifoDepth(depth),
|
||||
status_fifoBound(0),
|
||||
status_fifoFree(depth){
|
||||
@ -47,7 +47,7 @@ int Fifo::CreateFifos(uint32_t fifoItemSize) {
|
||||
//allocate memory
|
||||
size_t mem_len = fifoItemSize * fifoDepth * sizeof(char);
|
||||
memory = (char*) malloc (mem_len);
|
||||
if (memory == NULL){
|
||||
if (memory == nullptr){
|
||||
FILE_LOG(logERROR) << "Could not allocate memory for fifos";
|
||||
return FAIL;
|
||||
}
|
||||
@ -72,19 +72,19 @@ void Fifo::DestroyFifos(){
|
||||
|
||||
if(memory) {
|
||||
free(memory);
|
||||
memory = 0;
|
||||
memory = nullptr;
|
||||
}
|
||||
if (fifoBound) {
|
||||
delete fifoBound;
|
||||
fifoBound = 0;
|
||||
fifoBound = nullptr;
|
||||
}
|
||||
if (fifoFree) {
|
||||
delete fifoFree;
|
||||
fifoFree = 0;
|
||||
fifoFree = nullptr;
|
||||
}
|
||||
if (fifoStream) {
|
||||
delete fifoStream;
|
||||
fifoStream = 0;
|
||||
fifoStream = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,11 +24,11 @@ Listener::Listener(int ind, detectorType dtype, Fifo* f, runStatus* s,
|
||||
frameDiscardPolicy* fdp, bool* act, bool* depaden, bool* sm) :
|
||||
ThreadObject(ind),
|
||||
runningFlag(0),
|
||||
generalData(0),
|
||||
generalData(nullptr),
|
||||
fifo(f),
|
||||
myDetectorType(dtype),
|
||||
status(s),
|
||||
udpSocket(0),
|
||||
udpSocket(nullptr),
|
||||
udpPortNumber(portno),
|
||||
eth(e),
|
||||
numImages(nf),
|
||||
@ -50,8 +50,8 @@ Listener::Listener(int ind, detectorType dtype, Fifo* f, runStatus* s,
|
||||
lastCaughtFrameIndex(0),
|
||||
currentFrameIndex(0),
|
||||
carryOverFlag(0),
|
||||
carryOverPacket(0),
|
||||
listeningPacket(0),
|
||||
carryOverPacket(nullptr),
|
||||
listeningPacket(nullptr),
|
||||
udpSocketAlive(0),
|
||||
numPacketsStatistic(0),
|
||||
numFramesStatistic(0)
|
||||
@ -193,7 +193,7 @@ int Listener::CreateUDPSockets() {
|
||||
}
|
||||
|
||||
//if eth is mistaken with ip address
|
||||
if (strchr(eth,'.') != NULL){
|
||||
if (strchr(eth,'.') != nullptr){
|
||||
memset(eth, 0, MAX_STR_LENGTH);
|
||||
}
|
||||
if(!strlen(eth)){
|
||||
@ -204,7 +204,7 @@ int Listener::CreateUDPSockets() {
|
||||
|
||||
try{
|
||||
genericSocket* g = new genericSocket(*udpPortNumber, genericSocket::UDP,
|
||||
generalData->packetSize, (strlen(eth)?eth:NULL), generalData->headerPacketSize,
|
||||
generalData->packetSize, (strlen(eth)?eth:nullptr), generalData->headerPacketSize,
|
||||
*udpSocketBufferSize);
|
||||
udpSocket = g;
|
||||
FILE_LOG(logINFO) << index << ": UDP port opened at port " << *udpPortNumber;
|
||||
@ -235,7 +235,7 @@ void Listener::ShutDownUDPSocket() {
|
||||
if (runningFlag)
|
||||
sem_wait(&semaphore_socket);
|
||||
delete udpSocket;
|
||||
udpSocket = 0;
|
||||
udpSocket = nullptr;
|
||||
sem_destroy(&semaphore_socket);
|
||||
}
|
||||
}
|
||||
@ -253,7 +253,7 @@ int Listener::CreateDummySocketForUDPSocketBufferSize(uint32_t s) {
|
||||
*udpSocketBufferSize = s;
|
||||
|
||||
//if eth is mistaken with ip address
|
||||
if (strchr(eth,'.') != NULL){
|
||||
if (strchr(eth,'.') != nullptr){
|
||||
memset(eth, 0, MAX_STR_LENGTH);
|
||||
}
|
||||
|
||||
@ -261,13 +261,13 @@ int Listener::CreateDummySocketForUDPSocketBufferSize(uint32_t s) {
|
||||
if(udpSocket){
|
||||
udpSocket->ShutDownSocket();
|
||||
delete udpSocket;
|
||||
udpSocket = 0;
|
||||
udpSocket = nullptr;
|
||||
}
|
||||
|
||||
//create dummy socket
|
||||
try {
|
||||
udpSocket = new genericSocket(*udpPortNumber, genericSocket::UDP,
|
||||
generalData->packetSize, (strlen(eth)?eth:NULL), generalData->headerPacketSize,
|
||||
generalData->packetSize, (strlen(eth)?eth:nullptr), generalData->headerPacketSize,
|
||||
*udpSocketBufferSize);
|
||||
} catch (...) {
|
||||
FILE_LOG(logERROR) << "Could not create a test UDP socket on port " << *udpPortNumber;
|
||||
@ -287,7 +287,7 @@ int Listener::CreateDummySocketForUDPSocketBufferSize(uint32_t s) {
|
||||
udpSocketAlive = false;
|
||||
udpSocket->ShutDownSocket();
|
||||
delete udpSocket;
|
||||
udpSocket = 0;
|
||||
udpSocket = nullptr;
|
||||
}
|
||||
|
||||
return OK;
|
||||
@ -381,8 +381,8 @@ uint32_t Listener::ListenToAnImage(char* buf) {
|
||||
uint32_t fifohsize = generalData->fifoBufferHeaderSize;
|
||||
uint32_t pperFrame = generalData->packetsPerFrame;
|
||||
bool isHeaderEmpty = true;
|
||||
sls_detector_header* old_header = 0;
|
||||
sls_receiver_header* new_header = 0;
|
||||
sls_detector_header* old_header = nullptr;
|
||||
sls_receiver_header* new_header = nullptr;
|
||||
bool standardheader = generalData->standardheader;
|
||||
uint32_t corrected_dsize = dsize - ((pperFrame * dsize) - generalData->imageSize);
|
||||
|
||||
|
@ -39,7 +39,7 @@ void ThreadObject::DestroyThread() {
|
||||
if(alive){
|
||||
killThread = true;
|
||||
sem_post(&semaphore);
|
||||
pthread_join(thread,NULL);
|
||||
pthread_join(thread,nullptr);
|
||||
sem_destroy(&semaphore);
|
||||
killThread = false;
|
||||
alive = false;
|
||||
@ -56,7 +56,7 @@ int ThreadObject::CreateThread() {
|
||||
sem_init(&semaphore,1,0);
|
||||
killThread = false;
|
||||
|
||||
if(pthread_create(&thread, NULL,StartThread, (void*) this)){
|
||||
if(pthread_create(&thread, nullptr,StartThread, (void*) this)){
|
||||
FILE_LOG(logERROR) << "Could not create " << GetType() << " thread with index " << index;
|
||||
return FAIL;
|
||||
}
|
||||
@ -91,7 +91,7 @@ void ThreadObject::RunningThread() {
|
||||
if(killThread) {
|
||||
FILE_LOG(logINFOBLUE) << "Exiting [ " << GetType() <<
|
||||
" Thread " << index << ", Tid: " << syscall(SYS_gettid) << "]";
|
||||
pthread_exit(NULL);
|
||||
pthread_exit(nullptr);
|
||||
}
|
||||
|
||||
}//end of outer loop
|
||||
|
@ -76,7 +76,7 @@ int main(int argc, char *argv[]) {
|
||||
sa.sa_flags=0; // no flags
|
||||
sa.sa_handler=sigInterruptHandler; // handler function
|
||||
sigemptyset(&sa.sa_mask); // dont block additional signals during invocation of handler
|
||||
if (sigaction(SIGINT, &sa, NULL) == -1) {
|
||||
if (sigaction(SIGINT, &sa, nullptr) == -1) {
|
||||
FILE_LOG(logERROR) << "Could not set handler function for SIGINT";
|
||||
}
|
||||
|
||||
@ -87,7 +87,7 @@ int main(int argc, char *argv[]) {
|
||||
asa.sa_flags=0; // no flags
|
||||
asa.sa_handler=SIG_IGN; // handler function
|
||||
sigemptyset(&asa.sa_mask); // dont block additional signals during invocation of handler
|
||||
if (sigaction(SIGPIPE, &asa, NULL) == -1) {
|
||||
if (sigaction(SIGPIPE, &asa, nullptr) == -1) {
|
||||
FILE_LOG(logERROR) << "Could not set handler function for SIGPIPE";
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include "utilities.h"
|
||||
|
||||
slsReceiver::slsReceiver(int argc, char *argv[]):
|
||||
tcpipInterface (0) {
|
||||
tcpipInterface (nullptr) {
|
||||
|
||||
// options
|
||||
std::map<std::string, std::string> configuration_map;
|
||||
@ -32,11 +32,11 @@ slsReceiver::slsReceiver(int argc, char *argv[]):
|
||||
// These options set a flag.
|
||||
//{"verbose", no_argument, &verbose_flag, 1},
|
||||
// These options don’t set a flag. We distinguish them by their indices.
|
||||
{"config", required_argument, 0, 'f'},
|
||||
{"rx_tcpport", required_argument, 0, 't'},
|
||||
{"version", no_argument, 0, 'v'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{0, 0, 0, 0}
|
||||
{"config", required_argument, nullptr, 'f'},
|
||||
{"rx_tcpport", required_argument, nullptr, 't'},
|
||||
{"version", no_argument, nullptr, 'v'},
|
||||
{"help", no_argument, nullptr, 'h'},
|
||||
{nullptr, 0, nullptr, 0}
|
||||
};
|
||||
|
||||
//initialize global optind variable (required when instantiating multiple receivers in the same process)
|
||||
|
@ -39,7 +39,7 @@ void slsReceiverImplementation::DeleteMembers() {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
if (generalData) {
|
||||
delete generalData;
|
||||
generalData=0;
|
||||
generalData=nullptr;
|
||||
}
|
||||
|
||||
listener.clear();
|
||||
@ -107,16 +107,16 @@ void slsReceiverImplementation::InitializeMembers() {
|
||||
memset(additionalJsonHeader, 0, sizeof(additionalJsonHeader));
|
||||
|
||||
//** class objects ***
|
||||
generalData = 0;
|
||||
generalData = nullptr;
|
||||
|
||||
//***callback parameters***
|
||||
startAcquisitionCallBack = NULL;
|
||||
pStartAcquisition = NULL;
|
||||
acquisitionFinishedCallBack = NULL;
|
||||
pAcquisitionFinished = NULL;
|
||||
rawDataReadyCallBack = NULL;
|
||||
rawDataModifyReadyCallBack = NULL;
|
||||
pRawDataReady = NULL;
|
||||
startAcquisitionCallBack = nullptr;
|
||||
pStartAcquisition = nullptr;
|
||||
acquisitionFinishedCallBack = nullptr;
|
||||
pAcquisitionFinished = nullptr;
|
||||
rawDataReadyCallBack = nullptr;
|
||||
rawDataModifyReadyCallBack = nullptr;
|
||||
pRawDataReady = nullptr;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
@ -953,7 +953,7 @@ int slsReceiverImplementation::startReceiver(char *c) {
|
||||
if (startAcquisitionCallBack) {
|
||||
startAcquisitionCallBack(filePath, fileName, fileIndex,
|
||||
(generalData->imageSize) + (generalData->fifoBufferHeaderSize), pStartAcquisition);
|
||||
if (rawDataReadyCallBack != NULL) {
|
||||
if (rawDataReadyCallBack != nullptr) {
|
||||
FILE_LOG(logINFO) << "Data Write has been defined externally";
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() {
|
||||
stop();
|
||||
if(mySock) {
|
||||
delete mySock;
|
||||
mySock=NULL;
|
||||
mySock=nullptr;
|
||||
}
|
||||
if (interface)
|
||||
delete interface;
|
||||
@ -37,24 +37,24 @@ slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() {
|
||||
|
||||
slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int pn):
|
||||
myDetectorType(GOTTHARD),
|
||||
receiver(0),
|
||||
receiver(nullptr),
|
||||
ret(OK),
|
||||
fnum(-1),
|
||||
lockStatus(0),
|
||||
killTCPServerThread(0),
|
||||
tcpThreadCreated(false),
|
||||
portNumber(DEFAULT_PORTNO+2),
|
||||
mySock(0),
|
||||
interface(0)
|
||||
mySock(nullptr),
|
||||
interface(nullptr)
|
||||
{
|
||||
//***callback parameters***
|
||||
startAcquisitionCallBack = NULL;
|
||||
pStartAcquisition = NULL;
|
||||
acquisitionFinishedCallBack = NULL;
|
||||
pAcquisitionFinished = NULL;
|
||||
rawDataReadyCallBack = NULL;
|
||||
rawDataModifyReadyCallBack = NULL;
|
||||
pRawDataReady = NULL;
|
||||
startAcquisitionCallBack = nullptr;
|
||||
pStartAcquisition = nullptr;
|
||||
acquisitionFinishedCallBack = nullptr;
|
||||
pAcquisitionFinished = nullptr;
|
||||
rawDataReadyCallBack = nullptr;
|
||||
rawDataModifyReadyCallBack = nullptr;
|
||||
pRawDataReady = nullptr;
|
||||
|
||||
// create socket
|
||||
portNumber = (pn > 0 ? pn : DEFAULT_PORTNO + 2);
|
||||
@ -75,7 +75,7 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int pn):
|
||||
int slsReceiverTCPIPInterface::start(){
|
||||
FILE_LOG(logDEBUG) << "Creating TCP Server Thread";
|
||||
killTCPServerThread = 0;
|
||||
if(pthread_create(&TCPServer_thread, NULL,startTCPServerThread, (void*) this)){
|
||||
if(pthread_create(&TCPServer_thread, nullptr,startTCPServerThread, (void*) this)){
|
||||
FILE_LOG(logERROR) << "Could not create TCP Server thread";
|
||||
return FAIL;
|
||||
}
|
||||
@ -93,7 +93,7 @@ void slsReceiverTCPIPInterface::stop(){
|
||||
killTCPServerThread = 1;
|
||||
if(mySock) mySock->ShutDownSocket();
|
||||
FILE_LOG(logDEBUG) << "TCP Socket closed on port " << portNumber;
|
||||
pthread_join(TCPServer_thread, NULL);
|
||||
pthread_join(TCPServer_thread, nullptr);
|
||||
tcpThreadCreated = false;
|
||||
killTCPServerThread = 0;
|
||||
FILE_LOG(logDEBUG) << "Exiting TCP Server Thread on port " << portNumber;
|
||||
@ -160,7 +160,7 @@ void slsReceiverTCPIPInterface::startTCPServer(){
|
||||
|
||||
mySock->exitServer();
|
||||
FILE_LOG(logINFOBLUE) << "Exiting [ TCP server Tid: " << syscall(SYS_gettid) <<"]";
|
||||
pthread_exit(NULL);
|
||||
pthread_exit(nullptr);
|
||||
}
|
||||
|
||||
//if user entered exit
|
||||
@ -171,7 +171,7 @@ void slsReceiverTCPIPInterface::startTCPServer(){
|
||||
}
|
||||
}
|
||||
FILE_LOG(logINFOBLUE) << "Exiting [ TCP server Tid: " << syscall(SYS_gettid) <<"]";
|
||||
pthread_exit(NULL);
|
||||
pthread_exit(nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -309,7 +309,7 @@ int slsReceiverTCPIPInterface::M_nofunc(){
|
||||
|
||||
sprintf(mess,"Unrecognized Function enum %d. Please do not proceed.\n", fnum);
|
||||
FILE_LOG(logERROR) << mess;
|
||||
return interface->Server_SendResult(false, ret, NULL, 0, mess);
|
||||
return interface->Server_SendResult(false, ret, nullptr, 0, mess);
|
||||
}
|
||||
|
||||
|
||||
@ -339,7 +339,7 @@ int slsReceiverTCPIPInterface::exec_command() {
|
||||
FILE_LOG(logERROR) << mess;
|
||||
} else {
|
||||
while (!feof(pipe.get())) {
|
||||
if (fgets(temp.data(), tempsize, pipe.get()) != NULL)
|
||||
if (fgets(temp.data(), tempsize, pipe.get()) != nullptr)
|
||||
sresult += temp.data();
|
||||
}
|
||||
strncpy(retval, sresult.c_str(), MAX_STR_LENGTH);
|
||||
@ -356,7 +356,7 @@ int slsReceiverTCPIPInterface::exit_server() {
|
||||
FILE_LOG(logINFO) << "Closing server";
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
interface->Server_SendResult(false, ret, NULL, 0);
|
||||
interface->Server_SendResult(false, ret, nullptr, 0);
|
||||
return GOODBYE;
|
||||
}
|
||||
|
||||
@ -400,7 +400,7 @@ int slsReceiverTCPIPInterface::set_port() {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
int p_number = -1;
|
||||
MySocketTCP* mySocket = 0;
|
||||
MySocketTCP* mySocket = nullptr;
|
||||
char oldLastClientIP[INET_ADDRSTRLEN] = {0};
|
||||
|
||||
// get args, return if socket crashed
|
||||
@ -451,9 +451,9 @@ int slsReceiverTCPIPInterface::update_client() {
|
||||
memset(mess, 0, sizeof(mess));
|
||||
|
||||
// no arg, check receiver is null
|
||||
interface->Server_ReceiveArg(ret, mess, NULL, 0, true, receiver);
|
||||
interface->Server_ReceiveArg(ret, mess, nullptr, 0, true, receiver);
|
||||
|
||||
interface->Server_SendResult(false, ret, NULL, 0, mess);
|
||||
interface->Server_SendResult(false, ret, nullptr, 0, mess);
|
||||
|
||||
if (ret == FAIL)
|
||||
return ret;
|
||||
@ -574,7 +574,7 @@ int slsReceiverTCPIPInterface::set_detector_type(){
|
||||
// set
|
||||
if (arg >= 0) {
|
||||
// if object exists, verify unlocked and idle, else only verify lock (connecting first time)
|
||||
if (receiver == NULL)
|
||||
if (receiver == nullptr)
|
||||
interface->Server_VerifyLock(ret, mess, lockStatus);
|
||||
else
|
||||
interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum);
|
||||
@ -592,7 +592,7 @@ int slsReceiverTCPIPInterface::set_detector_type(){
|
||||
break;
|
||||
}
|
||||
if(ret == OK) {
|
||||
if(receiver == NULL){
|
||||
if(receiver == nullptr){
|
||||
receiver = new slsReceiverImplementation();
|
||||
if(startAcquisitionCallBack)
|
||||
receiver->registerCallBackStartAcquisition(startAcquisitionCallBack,pStartAcquisition);
|
||||
@ -688,7 +688,7 @@ int slsReceiverTCPIPInterface::set_roi() {
|
||||
functionNotImplemented();
|
||||
|
||||
// base object not null
|
||||
else if (receiver == NULL)
|
||||
else if (receiver == nullptr)
|
||||
interface->Server_NullObjectError(ret, mess);
|
||||
else {
|
||||
// only set
|
||||
@ -697,7 +697,7 @@ int slsReceiverTCPIPInterface::set_roi() {
|
||||
ret = receiver->setROI(arg);
|
||||
}
|
||||
arg.clear();
|
||||
return interface->Server_SendResult(true, ret, NULL, 0, mess);
|
||||
return interface->Server_SendResult(true, ret, nullptr, 0, mess);
|
||||
}
|
||||
|
||||
|
||||
@ -738,7 +738,7 @@ int slsReceiverTCPIPInterface::setup_udp(){
|
||||
char eth[MAX_STR_LENGTH];
|
||||
memset(eth,0,sizeof(eth));
|
||||
strcpy(eth,temp.c_str());
|
||||
if (strchr(eth,'.') != NULL) {
|
||||
if (strchr(eth,'.') != nullptr) {
|
||||
strcpy(eth,"");
|
||||
ret = FAIL;
|
||||
strcpy(mess, "Failed to get ethernet interface\n");
|
||||
@ -950,7 +950,7 @@ int slsReceiverTCPIPInterface::get_status(){
|
||||
enum runStatus retval = ERROR;
|
||||
|
||||
// no arg, check receiver is null
|
||||
interface->Server_ReceiveArg(ret, mess, NULL, 0, true, receiver);
|
||||
interface->Server_ReceiveArg(ret, mess, nullptr, 0, true, receiver);
|
||||
|
||||
if (ret == OK) {
|
||||
FILE_LOG(logDEBUG1) << "Getting Status";
|
||||
@ -967,7 +967,7 @@ int slsReceiverTCPIPInterface::start_receiver(){
|
||||
memset(mess, 0, sizeof(mess));
|
||||
|
||||
// no arg, and check receiver is null
|
||||
interface->Server_ReceiveArg(ret, mess, NULL, 0, true, receiver);
|
||||
interface->Server_ReceiveArg(ret, mess, nullptr, 0, true, receiver);
|
||||
|
||||
// receiver is not null
|
||||
if (ret == OK) {
|
||||
@ -989,7 +989,7 @@ int slsReceiverTCPIPInterface::start_receiver(){
|
||||
}
|
||||
}
|
||||
}
|
||||
return interface->Server_SendResult(true, ret, NULL, 0, mess);
|
||||
return interface->Server_SendResult(true, ret, nullptr, 0, mess);
|
||||
}
|
||||
|
||||
|
||||
@ -999,7 +999,7 @@ int slsReceiverTCPIPInterface::stop_receiver(){
|
||||
memset(mess, 0, sizeof(mess));
|
||||
|
||||
// no arg, and check receiver is null
|
||||
interface->Server_ReceiveArg(ret, mess, NULL, 0, true, receiver);
|
||||
interface->Server_ReceiveArg(ret, mess, nullptr, 0, true, receiver);
|
||||
|
||||
// receiver is not null
|
||||
if (ret == OK) {
|
||||
@ -1020,7 +1020,7 @@ int slsReceiverTCPIPInterface::stop_receiver(){
|
||||
}
|
||||
}
|
||||
}
|
||||
return interface->Server_SendResult(true, ret, NULL, 0, mess);
|
||||
return interface->Server_SendResult(true, ret, nullptr, 0, mess);
|
||||
}
|
||||
|
||||
|
||||
@ -1125,7 +1125,7 @@ int slsReceiverTCPIPInterface::get_frame_index(){
|
||||
int retval = -1;
|
||||
|
||||
// no arg, check receiver is null
|
||||
interface->Server_ReceiveArg(ret, mess, NULL, 0, true, receiver);
|
||||
interface->Server_ReceiveArg(ret, mess, nullptr, 0, true, receiver);
|
||||
|
||||
if (ret == OK) {
|
||||
FILE_LOG(logDEBUG1) << "Getting frame index";
|
||||
@ -1143,7 +1143,7 @@ int slsReceiverTCPIPInterface::get_frames_caught(){
|
||||
int retval = -1;
|
||||
|
||||
// no arg, check receiver is null
|
||||
interface->Server_ReceiveArg(ret, mess, NULL, 0, true, receiver);
|
||||
interface->Server_ReceiveArg(ret, mess, nullptr, 0, true, receiver);
|
||||
|
||||
if (ret == OK) {
|
||||
FILE_LOG(logDEBUG1) << "Getting frames caught";
|
||||
@ -1160,7 +1160,7 @@ int slsReceiverTCPIPInterface::reset_frames_caught(){
|
||||
memset(mess, 0, sizeof(mess));
|
||||
|
||||
// no arg, and check receiver is null
|
||||
interface->Server_ReceiveArg(ret, mess, NULL, 0, true, receiver);
|
||||
interface->Server_ReceiveArg(ret, mess, nullptr, 0, true, receiver);
|
||||
|
||||
// receiver is not null
|
||||
if (ret == OK) {
|
||||
@ -1171,7 +1171,7 @@ int slsReceiverTCPIPInterface::reset_frames_caught(){
|
||||
receiver->resetAcquisitionCount();
|
||||
}
|
||||
}
|
||||
return interface->Server_SendResult(true, ret, NULL, 0, mess);
|
||||
return interface->Server_SendResult(true, ret, nullptr, 0, mess);
|
||||
}
|
||||
|
||||
|
||||
@ -1649,7 +1649,7 @@ int slsReceiverTCPIPInterface::restream_stop(){
|
||||
memset(mess, 0, sizeof(mess));
|
||||
|
||||
// no arg, and check receiver is null
|
||||
interface->Server_ReceiveArg(ret, mess, NULL, 0, true, receiver);
|
||||
interface->Server_ReceiveArg(ret, mess, nullptr, 0, true, receiver);
|
||||
|
||||
// receiver is not null
|
||||
if (ret == OK) {
|
||||
@ -1670,7 +1670,7 @@ int slsReceiverTCPIPInterface::restream_stop(){
|
||||
}
|
||||
}
|
||||
}
|
||||
return interface->Server_SendResult(true, ret, NULL, 0, mess);
|
||||
return interface->Server_SendResult(true, ret, nullptr, 0, mess);
|
||||
}
|
||||
|
||||
|
||||
@ -1742,7 +1742,7 @@ int slsReceiverTCPIPInterface::get_real_udp_socket_buffer_size(){
|
||||
int retval = -1;
|
||||
|
||||
// no arg, check receiver is null
|
||||
interface->Server_ReceiveArg(ret, mess, NULL, 0, true, receiver);
|
||||
interface->Server_ReceiveArg(ret, mess, nullptr, 0, true, receiver);
|
||||
|
||||
if (ret == OK) {
|
||||
FILE_LOG(logDEBUG1) << "Getting actual UDP buffer size";
|
||||
@ -1818,7 +1818,7 @@ int slsReceiverTCPIPInterface::check_version_compatibility() {
|
||||
FILE_LOG(logERROR) << mess;
|
||||
}
|
||||
else FILE_LOG(logINFO) << "Compatibility with Client: Successful";
|
||||
return interface->Server_SendResult(true, ret, NULL, 0, mess);
|
||||
return interface->Server_SendResult(true, ret, nullptr, 0, mess);
|
||||
}
|
||||
|
||||
|
||||
|
144
slsSupportLib/src/ClientInterface.cpp
Normal file
144
slsSupportLib/src/ClientInterface.cpp
Normal file
@ -0,0 +1,144 @@
|
||||
#include "ClientInterface.h"
|
||||
|
||||
ClientInterface::ClientInterface(MySocketTCP *socket, int n, std::string t):
|
||||
mySocket(socket),
|
||||
index(n),
|
||||
type(t){}
|
||||
|
||||
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") != nullptr)
|
||||
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 == nullptr)
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
148
slsSupportLib/src/utilities.cpp
Normal file
148
slsSupportLib/src/utilities.cpp
Normal file
@ -0,0 +1,148 @@
|
||||
#include "utilities.h"
|
||||
#include "logger.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
|
||||
|
||||
int read_config_file(std::string fname, int *tcpip_port_no,
|
||||
std::map<std::string, std::string> * 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<nch) {
|
||||
if (ichan>=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==nullptr)
|
||||
return slsDetectorDefs::FAIL;
|
||||
for (int ichan=0; ichan<nch; ichan++)
|
||||
outfile << ichan+offset << " " << *(data+ichan) << std::endl;
|
||||
return slsDetectorDefs::OK;
|
||||
}
|
||||
|
||||
|
||||
int writeDataFile(std::string fname,int nch, short int *data) {
|
||||
std::ofstream outfile;
|
||||
if (data==nullptr)
|
||||
return slsDetectorDefs::FAIL;
|
||||
outfile.open (fname.c_str(),std::ios_base::out);
|
||||
if (outfile.is_open()) {
|
||||
writeDataFile(outfile, nch, data, 0);
|
||||
outfile.close();
|
||||
return slsDetectorDefs::OK;
|
||||
} else {
|
||||
FILE_LOG(logERROR) << "Could not open file " << fname << "for writing";
|
||||
return slsDetectorDefs::FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user