rxr: removed char array memebers in rxrimplementation

This commit is contained in:
2019-11-18 14:29:01 +01:00
parent 32cf46a8a3
commit f2c0ff7f98
23 changed files with 99 additions and 116 deletions

View File

@ -14,7 +14,7 @@
FILE* BinaryFile::masterfd = nullptr;
BinaryFile::BinaryFile(int ind, uint32_t* maxf,
int* nd, char* fname, char* fpath, uint64_t* findex, bool* owenable,
int* nd, std::string* fname, std::string* 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),
@ -46,7 +46,7 @@ int BinaryFile::CreateFile() {
numFramesInFile = 0;
numActualPacketsInFile = 0;
currentFileName = BinaryFileStatic::CreateFileName(filePath, fileNamePrefix, *fileIndex,
currentFileName = BinaryFileStatic::CreateFileName(*filePath, *fileNamePrefix, *fileIndex,
subFileIndex, *detIndex, *numUnitsPerDetector, index);
if (BinaryFileStatic::CreateDataFile(filefd, *overWriteEnable, currentFileName, FILE_BUFFER_SIZE) == FAIL)
@ -120,8 +120,8 @@ int BinaryFile::CreateMasterFile(bool mfwenable, masterAttributes& attr) {
numActualPacketsInFile = 0;
if (mfwenable && master && (*detIndex==0)) {
masterFileName = BinaryFileStatic::CreateMasterFileName(filePath,
fileNamePrefix, *fileIndex);
masterFileName = BinaryFileStatic::CreateMasterFileName(*filePath,
*fileNamePrefix, *fileIndex);
if(!(*silentMode)) {
FILE_LOG(logINFO) << "Master File: " << masterFileName;
}

View File

@ -173,7 +173,7 @@ void DataProcessor::SetFileFormat(const fileFormat f) {
//remember the pointer values before they are destroyed
int nd[MAX_DIMENSIONS];nd[0] = 0; nd[1] = 0;
uint32_t* maxf = nullptr;
char* fname=nullptr; char* fpath=nullptr; uint64_t* findex=nullptr;
std::string* fname=nullptr; std::string* 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,
@ -186,7 +186,7 @@ void DataProcessor::SetFileFormat(const fileFormat f) {
void DataProcessor::SetupFileWriter(bool fwe, int* nd, uint32_t* maxf,
char* fname, char* fpath, uint64_t* findex,
std::string* fname, std::string* fpath, uint64_t* findex,
bool* owenable, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr,
uint32_t* portno,
GeneralData* g)

View File

@ -17,7 +17,7 @@ const std::string DataStreamer::TypeName = "DataStreamer";
DataStreamer::DataStreamer(int ind, Fifo* f, uint32_t* dr, ROI* r,
uint64_t* fi, int fd, char* ajh, int* nd, bool* gpEnable, bool* qe) :
uint64_t* fi, int fd, std::string* ajh, int* nd, bool* gpEnable, bool* qe) :
ThreadObject(ind),
runningFlag(0),
generalData(nullptr),

View File

@ -10,7 +10,7 @@
File::File(int ind, uint32_t* maxf,
int* nd, char* fname, char* fpath, uint64_t* findex, bool* owenable,
int* nd, std::string* fname, std::string* fpath, uint64_t* findex, bool* owenable,
int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, uint32_t* portno,
bool* smode):
index(ind),
@ -64,7 +64,7 @@ void File::PrintMembers(TLogLevel level) {
}
void File::GetMemberPointerValues(int* nd, uint32_t*& maxf, char*& fname, char*& fpath, uint64_t*& findex, bool*& owenable,
void File::GetMemberPointerValues(int* nd, uint32_t*& maxf, std::string*& fname, std::string*& fpath, uint64_t*& findex, bool*& owenable,
int*& dindex, int*& nunits, uint64_t*& nf, uint32_t*& dr, uint32_t*& portno)
{
nd[0] = numDetX;

View File

@ -20,7 +20,7 @@ hid_t HDF5File::virtualfd = 0;
HDF5File::HDF5File(int ind, uint32_t* maxf,
int* nd, char* fname, char* fpath, uint64_t* findex, bool* owenable,
int* nd, std::string* fname, std::string* fpath, uint64_t* findex, bool* owenable,
int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, uint32_t* portno,
uint32_t nx, uint32_t ny,
bool* smode):
@ -132,7 +132,7 @@ int HDF5File::CreateFile() {
numFilesinAcquisition++;
numFramesInFile = 0;
numActualPacketsInFile = 0;
currentFileName = HDF5FileStatic::CreateFileName(filePath, fileNamePrefix, *fileIndex,
currentFileName = HDF5FileStatic::CreateFileName(*filePath, *fileNamePrefix, *fileIndex,
subFileIndex, *detIndex, *numUnitsPerDetector, index);
//first time
@ -249,8 +249,8 @@ int HDF5File::CreateMasterFile(bool mfwenable, masterAttributes& attr) {
if (mfwenable && master && (*detIndex==0)) {
virtualfd = 0;
masterFileName = HDF5FileStatic::CreateMasterFileName(filePath,
fileNamePrefix, *fileIndex);
masterFileName = HDF5FileStatic::CreateMasterFileName(*filePath,
*fileNamePrefix, *fileIndex);
if(!(*silentMode)) {
FILE_LOG(logINFO) << "Master File: " << masterFileName;
}
@ -289,14 +289,14 @@ void HDF5File::EndofAcquisition(bool anyPacketsCaught, uint64_t numf) {
int HDF5File::CreateVirtualFile(uint64_t numf) {
pthread_mutex_lock(&Mutex);
std::string vname = HDF5FileStatic::CreateVirtualFileName(filePath, fileNamePrefix, *fileIndex);
std::string vname = HDF5FileStatic::CreateVirtualFileName(*filePath, *fileNamePrefix, *fileIndex);
if(!(*silentMode)) {
FILE_LOG(logINFO) << "Virtual File: " << vname;
}
int ret = HDF5FileStatic::CreateVirtualDataFile(vname,
virtualfd, masterFileName,
filePath, fileNamePrefix, *fileIndex, (*numImages > 1),
*filePath, *fileNamePrefix, *fileIndex, (*numImages > 1),
*detIndex, *numUnitsPerDetector,
// infinite images in 1 file, then maxfrperfile = numf
((*maxFramesPerFile == 0) ? numf+1 : *maxFramesPerFile),

View File

@ -25,7 +25,7 @@ void sigInterruptHandler(int p){
/*
#define PRINT_IN_COLOR(c,f, ...) printf ("\033[%dm" f RESET, 30 + c+1, ##__VA_ARGS__)
int StartAcq(char* filepath, char* filename, uint64_t fileindex, uint32_t datasize, void*p){
int StartAcq(std::string filepath, std::string filename, uint64_t fileindex, uint32_t datasize, void*p){
FILE_LOG(logINFO) << "#### StartAcq: "
"filepath: " << filepath << "filename: " << filename <<
"fileindex: " << fileindex << "datasize: " << datasize << " ####";
@ -112,7 +112,7 @@ int main(int argc, char *argv[]) {
1 callback writes file, we have to open, close it
2 we open, close, write file, callback does not do anything
registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg);
registerCallBackStartAcquisition(int (*func)(std::string, std::string, int, int, void*),void *arg);
*/
//receiver->registerCallBackStartAcquisition(startAcquisitionCallBack,NULL);

View File

@ -69,11 +69,8 @@ void printHelp() {
* @param p pointer to object
* \returns ignored
*/
int StartAcq(char* filepath, char* filename, uint64_t fileindex, uint32_t datasize, void*p){
cprintf(BLUE, "#### StartAcq: filepath:%s filename:%s fileindex:%llu datasize:%u ####\n",
filepath, filename, (long long unsigned int)fileindex, datasize);
cprintf(BLUE, "--StartAcq: returning 0\n");
int StartAcq(std::string filepath, std::string filename, uint64_t fileindex, uint32_t datasize, void*p){
FILE_LOG(logINFOBLUE) << "#### StartAcq: filepath:" << filepath << " filename:" << filename << " fileindex:" << fileindex << " datasize:" << datasize << " ####";
return 0;
}
@ -83,7 +80,7 @@ int StartAcq(char* filepath, char* filename, uint64_t fileindex, uint32_t datasi
* @param p pointer to object
*/
void AcquisitionFinished(uint64_t frames, void*p){
cprintf(BLUE, "#### AcquisitionFinished: frames:%llu ####\n",(long long unsigned int)frames);
FILE_LOG(logINFOBLUE) << "#### AcquisitionFinished: frames:" << frames << " ####";
}

View File

@ -104,7 +104,7 @@ int64_t slsReceiver::getReceiverVersion(){
void slsReceiver::registerCallBackStartAcquisition(int (*func)(
char*, char*, uint64_t, uint32_t, void*),void *arg){
std::string, std::string, uint64_t, uint32_t, void*),void *arg){
tcpipInterface->registerCallBackStartAcquisition(func,arg);
}

View File

@ -1,11 +1,3 @@
/********************************************/ /**
* @file
*slsReceiverImplementation.cpp
* @short does all the functions
*for a receiver, set/get
*parameters, start/stop etc.
***********************************************/
#include "slsReceiverImplementation.h"
#include "DataProcessor.h"
#include "DataStreamer.h"
@ -57,7 +49,6 @@ void slsReceiverImplementation::InitializeMembers() {
for (int i = 0; i < MAX_DIMENSIONS; ++i)
numDet[i] = 0;
detID = 0;
strcpy(detHostname, "");
acquisitionPeriod = SAMPLE_TIME_IN_NS;
acquisitionTime = 0;
subExpTime = 0;
@ -96,8 +87,7 @@ void slsReceiverImplementation::InitializeMembers() {
//***file parameters***
fileFormatType = BINARY;
strcpy(fileName, "run");
strcpy(filePath, "");
fileName = "run";
fileIndex = 0;
framesPerFile = 0;
fileWriteEnable = true;
@ -113,7 +103,6 @@ void slsReceiverImplementation::InitializeMembers() {
dataStreamEnable = false;
streamingPort = 0;
streamingSrcIP = 0u;
memset(additionalJsonHeader, 0, sizeof(additionalJsonHeader));
//** class objects ***
generalData = nullptr;
@ -146,7 +135,7 @@ int slsReceiverImplementation::getDetectorPositionId() const {
std::string slsReceiverImplementation::getDetectorHostname() const {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return std::string(detHostname);
return detHostname;
}
int slsReceiverImplementation::getFlippedDataX() const {
@ -183,12 +172,12 @@ slsDetectorDefs::fileFormat slsReceiverImplementation::getFileFormat() const {
std::string slsReceiverImplementation::getFileName() const {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return std::string(fileName);
return fileName;
}
std::string slsReceiverImplementation::getFilePath() const {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return std::string(filePath);
return filePath;
}
uint64_t slsReceiverImplementation::getFileIndex() const {
@ -405,7 +394,7 @@ sls::IpAddr slsReceiverImplementation::getStreamingSourceIP() const {
std::string slsReceiverImplementation::getAdditionalJsonHeader() const {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return std::string(additionalJsonHeader);
return additionalJsonHeader;
}
int64_t slsReceiverImplementation::getUDPSocketBufferSize() const {
@ -425,11 +414,11 @@ int64_t slsReceiverImplementation::getActualUDPSocketBufferSize() const {
/**initial parameters***/
void slsReceiverImplementation::setDetectorHostname(const char *c) {
void slsReceiverImplementation::setDetectorHostname(const std::string& c) {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
if (strlen(c))
strcpy(detHostname, c);
if (!c.empty())
detHostname = c;
FILE_LOG(logINFO) << "Detector Hostname: " << detHostname;
}
@ -572,20 +561,20 @@ void slsReceiverImplementation::setFileFormat(const fileFormat f) {
FILE_LOG(logINFO) << "File Format: " << sls::ToString(fileFormatType);
}
void slsReceiverImplementation::setFileName(const char c[]) {
void slsReceiverImplementation::setFileName(const std::string& c) {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
if (strlen(c))
strcpy(fileName, c);
if (!c.empty())
fileName = c;
FILE_LOG(logINFO) << "File name: " << fileName;
}
void slsReceiverImplementation::setFilePath(const char c[]) {
void slsReceiverImplementation::setFilePath(const std::string& c) {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
if (strlen(c)) {
if (!c.empty()) {
mkdir_p(c); //throws if it can't create
strcpy(filePath, c);
filePath = c;
}
FILE_LOG(logINFO) << "File path: " << filePath;
}
@ -627,8 +616,8 @@ void slsReceiverImplementation::setFileWriteEnable(const bool b) {
fileWriteEnable = b;
for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
dataProcessor[i]->SetupFileWriter(
fileWriteEnable, (int *)numDet, &framesPerFile, fileName,
filePath, &fileIndex, &overwriteEnable, &detID, &numThreads,
fileWriteEnable, (int *)numDet, &framesPerFile, &fileName,
&filePath, &fileIndex, &overwriteEnable, &detID, &numThreads,
&numberOfFrames, &dynamicRange, &udpPortNum[i], generalData);
}
}
@ -747,7 +736,7 @@ int slsReceiverImplementation::setNumberofUDPInterfaces(const int n) {
}
dataStreamer.push_back(sls::make_unique<DataStreamer>(
i, fifo[i].get(), &dynamicRange, &roi, &fileIndex,
fd, additionalJsonHeader, (int*)nd, &gapPixelsEnable, &quadEnable));
fd, &additionalJsonHeader, (int*)nd, &gapPixelsEnable, &quadEnable));
dataStreamer[i]->SetGeneralData(generalData);
dataStreamer[i]->CreateZmqSockets(
&numThreads, streamingPort, streamingSrcIP);
@ -889,7 +878,7 @@ int slsReceiverImplementation::setDataStreamEnable(const bool enable) {
}
dataStreamer.push_back(sls::make_unique<DataStreamer>(
i, fifo[i].get(), &dynamicRange, &roi, &fileIndex,
fd, additionalJsonHeader, (int*)nd, &gapPixelsEnable, &quadEnable));
fd, &additionalJsonHeader, (int*)nd, &gapPixelsEnable, &quadEnable));
dataStreamer[i]->SetGeneralData(generalData);
dataStreamer[i]->CreateZmqSockets(
&numThreads, streamingPort, streamingSrcIP);
@ -918,9 +907,9 @@ void slsReceiverImplementation::setStreamingSourceIP(const sls::IpAddr ip) {
FILE_LOG(logINFO) << "Streaming Source IP: " << streamingSrcIP;
}
void slsReceiverImplementation::setAdditionalJsonHeader(const char c[]) {
void slsReceiverImplementation::setAdditionalJsonHeader(const std::string& c) {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
strcpy(additionalJsonHeader, c);
additionalJsonHeader = c;
FILE_LOG(logINFO) << "Additional JSON Header: " << additionalJsonHeader;
}
@ -1194,7 +1183,7 @@ void slsReceiverImplementation::setDetectorPositionId(const int id) {
FILE_LOG(logINFO) << "Detector Position Id:" << detID;
for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
dataProcessor[i]->SetupFileWriter(
fileWriteEnable, (int *)numDet, &framesPerFile, fileName, filePath,
fileWriteEnable, (int *)numDet, &framesPerFile, &fileName, &filePath,
&fileIndex, &overwriteEnable, &detID, &numThreads, &numberOfFrames,
&dynamicRange, &udpPortNum[i], generalData);
}
@ -1209,15 +1198,15 @@ void slsReceiverImplementation::setDetectorPositionId(const int id) {
}
int slsReceiverImplementation::startReceiver(char *c) {
int slsReceiverImplementation::startReceiver(std::string& err) {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
FILE_LOG(logINFO) << "Starting Receiver";
ResetParametersforNewAcquisition();
// listener
if (CreateUDPSockets() == FAIL) {
strcpy(c, "Could not create UDP Socket(s).");
FILE_LOG(logERROR) << c;
err.assign("Could not create UDP Socket(s).");
FILE_LOG(logERROR) << err;
return FAIL;
}
@ -1235,8 +1224,8 @@ int slsReceiverImplementation::startReceiver(char *c) {
// processor->writer
if (fileWriteEnable) {
if (SetupWriter() == FAIL) {
strcpy(c, "Could not create file.\n");
FILE_LOG(logERROR) << c;
err.assign("Could not create file.\n");
FILE_LOG(logERROR) << err;
return FAIL;
}
} else
@ -1417,7 +1406,7 @@ int slsReceiverImplementation::restreamStop() {
/***callback functions***/
void slsReceiverImplementation::registerCallBackStartAcquisition(
int (*func)(char *, char *, uint64_t, uint32_t, void *), void *arg) {
int (*func)(std::string, std::string, uint64_t, uint32_t, void *), void *arg) {
startAcquisitionCallBack = func;
pStartAcquisition = arg;
}
@ -1537,9 +1526,9 @@ void slsReceiverImplementation::ResetParametersforNewAcquisition() {
it->ResetParametersforNewAcquisition();
if (dataStreamEnable) {
char fnametostream[MAX_STR_LENGTH * 2];
snprintf(fnametostream, MAX_STR_LENGTH * 2, "%s/%s", filePath,
fileName);
std::ostringstream os;
os << filePath << '/' << fileName;
std::string fnametostream = os.str();
for (const auto &it : dataStreamer)
it->ResetParametersforNewAcquisition(fnametostream);
}

View File

@ -69,7 +69,7 @@ int64_t slsReceiverTCPIPInterface::getReceiverVersion() { return APIRECEIVER; }
/***callback functions***/
void slsReceiverTCPIPInterface::registerCallBackStartAcquisition(
int (*func)(char *, char *, uint64_t, uint32_t, void *), void *arg) {
int (*func)(std::string, std::string, uint64_t, uint32_t, void *), void *arg) {
startAcquisitionCallBack = func;
pStartAcquisition = arg;
}
@ -112,6 +112,7 @@ void slsReceiverTCPIPInterface::startTCPServer() {
ret = decode_function(socket);
} catch (const RuntimeError &e) {
// We had an error needs to be sent to client
char mess[MAX_STR_LENGTH]{};
sls::strcpy_safe(mess, e.what());
socket.Send(FAIL);
socket.Send(mess);
@ -274,9 +275,10 @@ void slsReceiverTCPIPInterface::VerifyLock() {
void slsReceiverTCPIPInterface::VerifyIdle(Interface &socket) {
if (impl()->getStatus() != IDLE) {
// sprintf(mess, "Can not execute %s when receiver is not idle\n",
// getFunctionNameFromEnum((enum detFuncs)fnum));
throw sls::SocketError(mess);
std::ostringstream oss;
oss << "Can not execute " << getFunctionNameFromEnum((enum detFuncs)fnum)
<< " when receiver is not idle";
throw sls::SocketError(oss.str());
}
}
@ -656,9 +658,10 @@ int slsReceiverTCPIPInterface::get_status(Interface &socket) {
int slsReceiverTCPIPInterface::start_receiver(Interface &socket) {
if (impl()->getStatus() == IDLE) {
FILE_LOG(logDEBUG1) << "Starting Receiver";
ret = impl()->startReceiver(mess);
std::string err;
ret = impl()->startReceiver(err);
if (ret == FAIL) {
throw RuntimeError(mess);
throw RuntimeError(err);
}
}
return socket.Send(OK);
@ -852,8 +855,6 @@ int slsReceiverTCPIPInterface::set_streaming_timer(Interface &socket) {
}
int slsReceiverTCPIPInterface::set_flipped_data(Interface &socket) {
// TODO! Why 2 args?
memset(mess, 0, sizeof(mess));
auto arg = socket.Receive<int>();
if (myDetectorType != EIGER)
@ -983,7 +984,6 @@ int slsReceiverTCPIPInterface::restream_stop(Interface &socket) {
}
int slsReceiverTCPIPInterface::set_additional_json_header(Interface &socket) {
memset(mess, 0, sizeof(mess));
char arg[MAX_STR_LENGTH]{};
char retval[MAX_STR_LENGTH]{};
socket.Receive(arg);

View File

@ -28,7 +28,7 @@ int64_t slsReceiverUsers::getReceiverVersion(){
return receiver->getReceiverVersion();
}
void slsReceiverUsers::registerCallBackStartAcquisition(int (*func)(char*, char*, uint64_t, uint32_t, void*),void *arg){
void slsReceiverUsers::registerCallBackStartAcquisition(int (*func)(std::string, std::string, uint64_t, uint32_t, void*),void *arg){
receiver->registerCallBackStartAcquisition(func,arg);
}