can set zmqport from receiver, ensured proper destructors, and ctrl c should kill it

This commit is contained in:
Dhanya Maliakal 2017-07-13 12:17:49 +02:00
parent 672c42a20e
commit 39560969f4
22 changed files with 217 additions and 119 deletions

View File

@ -24,6 +24,7 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
/** /**
* Constructor * Constructor
* Calls Base Class CreateThread(), sets ErrorMask if error and increments NumberofDataProcessors * Calls Base Class CreateThread(), sets ErrorMask if error and increments NumberofDataProcessors
* @param ind self index
* @param f address of Fifo pointer * @param f address of Fifo pointer
* @param ftype pointer to file format type * @param ftype pointer to file format type
* @param fwenable pointer to file writer enable * @param fwenable pointer to file writer enable
@ -31,7 +32,7 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
* @param dataReadycb pointer to data ready call back function * @param dataReadycb pointer to data ready call back function
* @param pDataReadycb pointer to arguments of data ready call back function * @param pDataReadycb pointer to arguments of data ready call back function
*/ */
DataProcessor(Fifo*& f, fileFormat* ftype, bool* fwenable, bool* dsEnable, DataProcessor(int ind, Fifo*& f, fileFormat* ftype, bool* fwenable, bool* dsEnable,
void (*dataReadycb)(uint64_t, uint32_t, uint32_t, uint64_t, uint64_t, uint16_t, uint16_t, uint16_t, uint16_t, uint32_t, uint16_t, uint8_t, uint8_t, void (*dataReadycb)(uint64_t, uint32_t, uint32_t, uint64_t, uint64_t, uint16_t, uint16_t, uint16_t, uint16_t, uint32_t, uint16_t, uint8_t, uint8_t,
char*, uint32_t, void*), char*, uint32_t, void*),
void *pDataReadycb); void *pDataReadycb);

View File

@ -20,13 +20,14 @@ class DataStreamer : private virtual slsReceiverDefs, public ThreadObject {
/** /**
* Constructor * Constructor
* Calls Base Class CreateThread(), sets ErrorMask if error and increments NumberofDataStreamers * Calls Base Class CreateThread(), sets ErrorMask if error and increments NumberofDataStreamers
* @param ind self index
* @param f address of Fifo pointer * @param f address of Fifo pointer
* @param dr pointer to dynamic range * @param dr pointer to dynamic range
* @param freq pointer to streaming frequency * @param freq pointer to streaming frequency
* @param timer pointer to timer if streaming frequency is random * @param timer pointer to timer if streaming frequency is random
* @param sEnable pointer to short frame enable * @param sEnable pointer to short frame enable
*/ */
DataStreamer(Fifo*& f, uint32_t* dr, uint32_t* freq, uint32_t* timer, int* sEnable); DataStreamer(int ind, Fifo*& f, uint32_t* dr, uint32_t* freq, uint32_t* timer, int* sEnable);
/** /**
* Destructor * Destructor
@ -100,11 +101,11 @@ class DataStreamer : private virtual slsReceiverDefs, public ThreadObject {
/** /**
* Creates Zmq Sockets * Creates Zmq Sockets
* @param dindex pointer to detector index
* @param nunits pointer to number of theads/ units per detector * @param nunits pointer to number of theads/ units per detector
* @param port streaming port start index
* @return OK or FAIL * @return OK or FAIL
*/ */
int CreateZmqSockets(int* dindex, int* nunits); int CreateZmqSockets(int* nunits, uint32_t port);
/** /**
* Shuts down and deletes Zmq Sockets * Shuts down and deletes Zmq Sockets

View File

@ -20,11 +20,12 @@ class Fifo : private virtual slsReceiverDefs {
/** /**
* Constructor * Constructor
* Calls CreateFifos that creates fifos and allocates memory * Calls CreateFifos that creates fifos and allocates memory
* @param ind self index
* @param fifoItemSize size of each fifo item * @param fifoItemSize size of each fifo item
* @param fifoDepth fifo depth * @param fifoDepth fifo depth
* @param success true if successful, else false * @param success true if successful, else false
*/ */
Fifo(uint32_t fifoItemSize, uint32_t fifoDepth, bool &success); Fifo(int ind, uint32_t fifoItemSize, uint32_t fifoDepth, bool &success);
/** /**
* Destructor * Destructor

View File

@ -21,6 +21,7 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
/** /**
* Constructor * Constructor
* Calls Base Class CreateThread(), sets ErrorMask if error and increments NumberofListerners * Calls Base Class CreateThread(), sets ErrorMask if error and increments NumberofListerners
* @param ind self index
* @param dtype detector type * @param dtype detector type
* @param f address of Fifo pointer * @param f address of Fifo pointer
* @param s pointer to receiver status * @param s pointer to receiver status
@ -30,7 +31,7 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
* @param nf pointer to number of images to catch * @param nf pointer to number of images to catch
* @param dr pointer to dynamic range * @param dr pointer to dynamic range
*/ */
Listener(detectorType dtype, Fifo*& f, runStatus* s, uint32_t* portno, char* e, int* act, uint64_t* nf, uint32_t* dr); Listener(int ind, detectorType dtype, Fifo*& f, runStatus* s, uint32_t* portno, char* e, int* act, uint64_t* nf, uint32_t* dr);
/** /**
* Destructor * Destructor

View File

@ -19,9 +19,8 @@ class ThreadObject : private virtual slsReceiverDefs {
public: public:
/** /**
* Constructor * Constructor
* @param ind self index
*/ */
ThreadObject(int ind); ThreadObject();
/** /**
* Destructor * Destructor

View File

@ -241,6 +241,12 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
*/ */
int getActivate() const; int getActivate() const;
/**
* Get Streaming Port
* @return streaming port
*/
uint32_t getStreamingPort() const;
/************************************************************************* /*************************************************************************
@ -497,11 +503,6 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
*/ */
void abort(); //FIXME: needed, isn't stopReceiver enough? void abort(); //FIXME: needed, isn't stopReceiver enough?
/**
* Closes all files
*/
void closeFiles();
/** /**
* Activate / Deactivate Receiver * Activate / Deactivate Receiver
* If deactivated, receiver will write dummy packets 0xFF * If deactivated, receiver will write dummy packets 0xFF
@ -509,6 +510,12 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
*/ */
int setActivate(int enable = -1); int setActivate(int enable = -1);
/**
* Set streaming port
* @param i streaming port
*/
void setStreamingPort(const uint32_t i);
//***callback functions*** //***callback functions***
/** /**
* Call back for start acquisition * Call back for start acquisition
@ -629,6 +636,8 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
/** Data Stream Enable from Receiver */ /** Data Stream Enable from Receiver */
bool dataStreamEnable; bool dataStreamEnable;
static const int DEFAULT_STREAMING_TIMER = 500; static const int DEFAULT_STREAMING_TIMER = 500;
/** streaming port */
uint32_t streamingPort;
//***callback parameters*** //***callback parameters***

View File

@ -20,7 +20,6 @@
class UDPInterface { class UDPInterface {
/* abstract class that defines the UDP interface of an sls detector data receiver. /* abstract class that defines the UDP interface of an sls detector data receiver.
* *
@ -302,6 +301,12 @@ class UDPInterface {
*/ */
virtual int getActivate() const = 0; virtual int getActivate() const = 0;
/**
* Get Streaming Port
* @return streaming port
*/
virtual uint32_t getStreamingPort() const = 0;
/************************************************************************* /*************************************************************************
* Setters *************************************************************** * Setters ***************************************************************
@ -555,11 +560,6 @@ class UDPInterface {
*/ */
virtual void abort() = 0; //FIXME: needed, isnt stopReceiver enough? virtual void abort() = 0; //FIXME: needed, isnt stopReceiver enough?
/**
* Closes all files
*/
virtual void closeFiles() = 0;
/** /**
* Activate / Deactivate Receiver * Activate / Deactivate Receiver
* If deactivated, receiver will write dummy packets 0xFF * If deactivated, receiver will write dummy packets 0xFF
@ -567,6 +567,12 @@ class UDPInterface {
*/ */
virtual int setActivate(int enable = -1) = 0; virtual int setActivate(int enable = -1) = 0;
/**
* Set streaming port
* @param i streaming port
*/
virtual void setStreamingPort(const uint32_t i) = 0;
//***callback functions*** //***callback functions***
/** /**

View File

@ -46,11 +46,6 @@ class slsReceiver : private virtual slsReceiverDefs {
*/ */
void stop(); void stop();
/**
* Close File and exits receiver server
*/
void closeFile(int p);
/** /**
* get get Receiver Version * get get Receiver Version
\returns id \returns id

View File

@ -51,10 +51,6 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs {
void stop(); void stop();
/** Close all threaded Files and exit */
void closeFile(int p);
/** gets version */ /** gets version */
int64_t getReceiverVersion(); int64_t getReceiverVersion();
@ -265,6 +261,9 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs {
/** set multi detector size */ /** set multi detector size */
int set_multi_detector_size(); int set_multi_detector_size();
/** set streaming port */
int set_streaming_port();
/** detector type */ /** detector type */

View File

@ -29,9 +29,6 @@ public:
/** Destructor */ /** Destructor */
~slsReceiverUsers(); ~slsReceiverUsers();
/** Close File and exits receiver server */
void closeFile(int p);
/** /**
* starts listening on the TCP port for client comminication * starts listening on the TCP port for client comminication
\return 0 for success or 1 for FAIL in creating TCP server \return 0 for success or 1 for FAIL in creating TCP server

View File

@ -60,6 +60,7 @@ enum recFuncs{
F_SEND_RECEIVER_DETPOSID, /** < sets the detector position id in the reveiver */ F_SEND_RECEIVER_DETPOSID, /** < sets the detector position id in the reveiver */
F_SEND_RECEIVER_MULTIDETSIZE, /** < sets the multi detector size to the receiver */ F_SEND_RECEIVER_MULTIDETSIZE, /** < sets the multi detector size to the receiver */
F_SET_RECEIVER_STREAMING_PORT, /** < sets the receiver streaming port */
/* Always append functions hereafter!!! */ /* Always append functions hereafter!!! */

View File

@ -31,12 +31,12 @@ uint64_t DataProcessor::RunningMask(0x0);
pthread_mutex_t DataProcessor::Mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t DataProcessor::Mutex = PTHREAD_MUTEX_INITIALIZER;
DataProcessor::DataProcessor(Fifo*& f, fileFormat* ftype, bool* fwenable, bool* dsEnable, DataProcessor::DataProcessor(int ind, Fifo*& f, fileFormat* ftype, bool* fwenable, bool* dsEnable,
void (*dataReadycb)(uint64_t, uint32_t, uint32_t, uint64_t, uint64_t, uint16_t, uint16_t, uint16_t, uint16_t, uint32_t, uint16_t, uint8_t, uint8_t, void (*dataReadycb)(uint64_t, uint32_t, uint32_t, uint64_t, uint64_t, uint16_t, uint16_t, uint16_t, uint16_t, uint32_t, uint16_t, uint8_t, uint8_t,
char*, uint32_t, void*), char*, uint32_t, void*),
void *pDataReadycb) : void *pDataReadycb) :
ThreadObject(NumberofDataProcessors), ThreadObject(),
generalData(0), generalData(0),
fifo(f), fifo(f),
file(0), file(0),
@ -53,6 +53,8 @@ DataProcessor::DataProcessor(Fifo*& f, fileFormat* ftype, bool* fwenable, bool*
rawDataReadyCallBack(dataReadycb), rawDataReadyCallBack(dataReadycb),
pRawDataReady(pDataReadycb) pRawDataReady(pDataReadycb)
{ {
index = ind;
if(ThreadObject::CreateThread()){ if(ThreadObject::CreateThread()){
pthread_mutex_lock(&Mutex); pthread_mutex_lock(&Mutex);
ErrorMask ^= (1<<index); ErrorMask ^= (1<<index);

View File

@ -24,8 +24,8 @@ uint64_t DataStreamer::RunningMask(0x0);
pthread_mutex_t DataStreamer::Mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t DataStreamer::Mutex = PTHREAD_MUTEX_INITIALIZER;
DataStreamer::DataStreamer(Fifo*& f, uint32_t* dr, uint32_t* freq, uint32_t* timer, int* sEnable) : DataStreamer::DataStreamer(int ind, Fifo*& f, uint32_t* dr, uint32_t* freq, uint32_t* timer, int* sEnable) :
ThreadObject(NumberofDataStreamers), ThreadObject(),
generalData(0), generalData(0),
fifo(f), fifo(f),
zmqSocket(0), zmqSocket(0),
@ -40,6 +40,10 @@ DataStreamer::DataStreamer(Fifo*& f, uint32_t* dr, uint32_t* freq, uint32_t* tim
firstMeasurementIndex(0), firstMeasurementIndex(0),
completeBuffer(0) completeBuffer(0)
{ {
index = NumberofDataStreamers;
cprintf(RED, "%d: Number of DataStreamers: %d\n", index, NumberofDataStreamers);
//index = ind;
if(ThreadObject::CreateThread()){ if(ThreadObject::CreateThread()){
pthread_mutex_lock(&Mutex); pthread_mutex_lock(&Mutex);
ErrorMask ^= (1<<index); ErrorMask ^= (1<<index);
@ -158,11 +162,8 @@ int DataStreamer::SetThreadPriority(int priority) {
} }
int DataStreamer::CreateZmqSockets(int* dindex, int* nunits) { int DataStreamer::CreateZmqSockets(int* nunits, uint32_t port) {
uint32_t portnum = DEFAULT_ZMQ_PORTNO + ((*dindex) * (*nunits) + index); uint32_t portnum = port + index;
//using userReceiver where all receivers in one program (numberofstreamers>*nunits)
if(index >= *nunits)
portnum = DEFAULT_ZMQ_PORTNO + index;
zmqSocket = new ZmqSocket(portnum); zmqSocket = new ZmqSocket(portnum);
if (zmqSocket->IsError()) { if (zmqSocket->IsError()) {

View File

@ -14,14 +14,15 @@ using namespace std;
int Fifo::NumberofFifoClassObjects(0); int Fifo::NumberofFifoClassObjects(0);
Fifo::Fifo(uint32_t fifoItemSize, uint32_t fifoDepth, bool &success): Fifo::Fifo(int ind, uint32_t fifoItemSize, uint32_t fifoDepth, bool &success):
index(ind),
memory(0), memory(0),
fifoBound(0), fifoBound(0),
fifoFree(0), fifoFree(0),
fifoStream(0), fifoStream(0),
status_fifoBound(0){ status_fifoBound(0){
FILE_LOG (logDEBUG) << __AT__ << " called"; FILE_LOG (logDEBUG) << __AT__ << " called";
index = NumberofFifoClassObjects++; NumberofFifoClassObjects++;
if(CreateFifos(fifoItemSize, fifoDepth) == FAIL) if(CreateFifos(fifoItemSize, fifoDepth) == FAIL)
success = false; success = false;
} }

View File

@ -27,8 +27,8 @@ uint64_t Listener::RunningMask(0x0);
pthread_mutex_t Listener::Mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t Listener::Mutex = PTHREAD_MUTEX_INITIALIZER;
Listener::Listener(detectorType dtype, Fifo*& f, runStatus* s, uint32_t* portno, char* e, int* act, uint64_t* nf, uint32_t* dr) : Listener::Listener(int ind, detectorType dtype, Fifo*& f, runStatus* s, uint32_t* portno, char* e, int* act, uint64_t* nf, uint32_t* dr) :
ThreadObject(NumberofListeners), ThreadObject(),
generalData(0), generalData(0),
fifo(f), fifo(f),
myDetectorType(dtype), myDetectorType(dtype),
@ -50,6 +50,7 @@ Listener::Listener(detectorType dtype, Fifo*& f, runStatus* s, uint32_t* portno,
carryOverPacket(0), carryOverPacket(0),
listeningPacket(0) listeningPacket(0)
{ {
index = ind;
if(ThreadObject::CreateThread()){ if(ThreadObject::CreateThread()){
pthread_mutex_lock(&Mutex); pthread_mutex_lock(&Mutex);

View File

@ -12,8 +12,8 @@ using namespace std;
ThreadObject::ThreadObject(int ind): ThreadObject::ThreadObject():
index(ind), index(0),
alive(false), alive(false),
killThread(false), killThread(false),
thread(0) thread(0)

View File

@ -6,6 +6,7 @@
#include "UDPBaseImplementation.h" #include "UDPBaseImplementation.h"
#include "genericSocket.h" #include "genericSocket.h"
#include "ZmqSocket.h"
#include <sys/stat.h> // stat #include <sys/stat.h> // stat
#include <iostream> #include <iostream>
@ -77,6 +78,7 @@ void UDPBaseImplementation::initializeMembers(){
frameToGuiFrequency = 0; frameToGuiFrequency = 0;
frameToGuiTimerinMS = DEFAULT_STREAMING_TIMER; frameToGuiTimerinMS = DEFAULT_STREAMING_TIMER;
dataStreamEnable = false; dataStreamEnable = false;
streamingPort = 0;
} }
UDPBaseImplementation::~UDPBaseImplementation(){} UDPBaseImplementation::~UDPBaseImplementation(){}
@ -203,6 +205,7 @@ slsReceiverDefs::runStatus UDPBaseImplementation::getStatus() const{ FILE_LOG(lo
int UDPBaseImplementation::getActivate() const{FILE_LOG(logDEBUG) << __AT__ << " starting"; return activated;} int UDPBaseImplementation::getActivate() const{FILE_LOG(logDEBUG) << __AT__ << " starting"; return activated;}
uint32_t UDPBaseImplementation::getStreamingPort() const{FILE_LOG(logDEBUG) << __AT__ << " starting"; return streamingPort;}
/************************************************************************* /*************************************************************************
* Setters *************************************************************** * Setters ***************************************************************
@ -523,11 +526,6 @@ void UDPBaseImplementation::abort(){
FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes";
} }
void UDPBaseImplementation::closeFiles(){
FILE_LOG(logWARNING) << __AT__ << " doing nothing...";
FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes";
}
int UDPBaseImplementation::setActivate(int enable){ int UDPBaseImplementation::setActivate(int enable){
FILE_LOG(logDEBUG) << __AT__ << " starting"; FILE_LOG(logDEBUG) << __AT__ << " starting";
@ -540,6 +538,17 @@ int UDPBaseImplementation::setActivate(int enable){
return activated; return activated;
} }
void UDPBaseImplementation::setStreamingPort(const uint32_t i) {
if (streamingPort == 0)
streamingPort = DEFAULT_ZMQ_PORTNO + (detID * ((myDetectorType == EIGER) ? 2 : 1) ); // multiplied by 2 as eiger has 2 ports
else
streamingPort = i;
FILE_LOG(logINFO) << "Streaming Port: " << streamingPort;
}
/***callback functions***/ /***callback functions***/
void UDPBaseImplementation::registerCallBackStartAcquisition(int (*func)(char*, char*, uint64_t, uint32_t, void*),void *arg){ void UDPBaseImplementation::registerCallBackStartAcquisition(int (*func)(char*, char*, uint64_t, uint32_t, void*),void *arg){
startAcquisitionCallBack=func; startAcquisitionCallBack=func;

View File

@ -10,6 +10,7 @@
#include "DataProcessor.h" #include "DataProcessor.h"
#include "DataStreamer.h" #include "DataStreamer.h"
#include "Fifo.h" #include "Fifo.h"
#include "ZmqSocket.h" //just for the zmq port define
#include <cstdlib> //system #include <cstdlib> //system
#include <cstring> //strcpy #include <cstring> //strcpy
@ -182,7 +183,8 @@ int UDPStandardImplementation::setFrameToGuiFrequency(const uint32_t freq) {
} }
int UDPStandardImplementation::setDataStreamEnable(const bool enable) { int UDPStandardImplementation::setDataStreamEnable(const bool enable) {\
if (dataStreamEnable != enable) { if (dataStreamEnable != enable) {
dataStreamEnable = enable; dataStreamEnable = enable;
@ -194,9 +196,12 @@ int UDPStandardImplementation::setDataStreamEnable(const bool enable) {
if (enable) { if (enable) {
bool error = false; bool error = false;
for ( int i = 0; i < numThreads; ++i ) { for ( int i = 0; i < numThreads; ++i ) {
dataStreamer.push_back(new DataStreamer(fifo[i], &dynamicRange, &frameToGuiFrequency, &frameToGuiTimerinMS, &shortFrameEnable)); dataStreamer.push_back(new DataStreamer(i, fifo[i], &dynamicRange, &frameToGuiFrequency, &frameToGuiTimerinMS, &shortFrameEnable));
dataStreamer[i]->SetGeneralData(generalData); dataStreamer[i]->SetGeneralData(generalData);
if (dataStreamer[i]->CreateZmqSockets(&detID, &numThreads) == FAIL) { // check again
if (streamingPort == 0)
streamingPort = DEFAULT_ZMQ_PORTNO + (detID * ((myDetectorType == EIGER) ? 2 : 1) ); // multiplied by 2 as eiger has 2 ports
if (dataStreamer[i]->CreateZmqSockets(&numThreads, streamingPort) == FAIL) {
error = true; error = true;
break; break;
} }
@ -370,8 +375,8 @@ int UDPStandardImplementation::setDetectorType(const detectorType d) {
//create threads //create threads
for ( int i=0; i < numThreads; ++i ) { for ( int i=0; i < numThreads; ++i ) {
listener.push_back(new Listener(myDetectorType, fifo[i], &status, &udpPortNum[i], eth, &activated, &numberOfFrames, &dynamicRange)); listener.push_back(new Listener(i, myDetectorType, fifo[i], &status, &udpPortNum[i], eth, &activated, &numberOfFrames, &dynamicRange));
dataProcessor.push_back(new DataProcessor(fifo[i], &fileFormatType, &fileWriteEnable, &dataStreamEnable, dataProcessor.push_back(new DataProcessor(i, fifo[i], &fileFormatType, &fileWriteEnable, &dataStreamEnable,
rawDataReadyCallBack,pRawDataReady)); rawDataReadyCallBack,pRawDataReady));
if (Listener::GetErrorMask() || DataProcessor::GetErrorMask()) { if (Listener::GetErrorMask() || DataProcessor::GetErrorMask()) {
FILE_LOG (logERROR) << "Error: Could not creates listener/dataprocessor threads (index:" << i << ")"; FILE_LOG (logERROR) << "Error: Could not creates listener/dataprocessor threads (index:" << i << ")";
@ -727,7 +732,7 @@ int UDPStandardImplementation::SetupFifoStructure() {
for ( int i = 0; i < numThreads; i++ ) { for ( int i = 0; i < numThreads; i++ ) {
//create fifo structure //create fifo structure
bool success = true; bool success = true;
fifo.push_back( new Fifo ( fifo.push_back( new Fifo (i,
(generalData->imageSize) * numberofJobs + (generalData->fifoBufferHeaderSize), (generalData->imageSize) * numberofJobs + (generalData->fifoBufferHeaderSize),
fifoDepth, success)); fifoDepth, success));
if (!success) { if (!success) {

View File

@ -6,62 +6,85 @@
#include <iostream> #include <iostream>
#include <string.h> #include <string.h>
#include <signal.h> //SIGINT #include <signal.h> //SIGINT
#include <cstdlib> //system #include <cstdlib> //system
#include "utilities.h" #include "utilities.h"
#include "logger.h" #include "logger.h"
#include <sys/types.h> //wait
#include <sys/wait.h> //wait
using namespace std; using namespace std;
slsReceiverUsers *receiver;
void deleteReceiver(slsReceiverUsers* r){ bool keeprunning;
if(r){delete r;r=0;}
}
void closeFile(int p){ void sigInterruptHandler(int p){
deleteReceiver(receiver); keeprunning = false;
} }
/* /*
int startAcquisitionCallBack(char* filePath, char* fileName, int fileIndex, int bufferSize, void* context) { int StartAcq(char* filepath, char* filename, uint64_t fileindex, uint32_t datasize, void*p){
FILE_LOG(logINFO) << "#### startAcquisitionCallBack ####"; printf("#### StartAcq: filepath:%s filename:%s fileindex:%llu datasize:%u ####\n",
FILE_LOG(logINFO) << "* filePath: " << filePath; filepath, filename, fileindex, datasize);
FILE_LOG(logINFO) << "* fileName: " << fileName;
FILE_LOG(logINFO) << "* fileIndex: " << fileIndex; cprintf(BLUE, "--StartAcq: returning 0\n");
FILE_LOG(logINFO) << "* bufferSize: " << bufferSize; return 0;
return 1;
} }
void acquisitionFinishedCallBack(int totalFramesCaught, void* context) {
FILE_LOG(logINFO) << "#### acquisitionFinishedCallBack ####"; void AcquisitionFinished(uint64_t frames, void*p){
FILE_LOG(logINFO) << "* totalFramesCaught: " << totalFramesCaught; cprintf(BLUE, "#### AcquisitionFinished: frames:%llu ####\n",frames);
} }
void rawDataReadyCallBack(int currFrameNum, char* dataPointer, int dataSize, FILE* file, char* guiDataPointer, void* context) {
FILE_LOG(logINFO) << "#### rawDataReadyCallBack ####"; void GetData(uint64_t frameNumber, uint32_t expLength, uint32_t packetNumber, uint64_t bunchId, uint64_t timestamp,
FILE_LOG(logINFO) << "* currFrameNum: " << currFrameNum; uint16_t modId, uint16_t xCoord, uint16_t yCoord, uint16_t zCoord, uint32_t debug, uint16_t roundRNumber, uint8_t detType, uint8_t version,
FILE_LOG(logINFO) << "* dataSize: " << dataSize; char* datapointer, uint32_t datasize, void* p){
PRINT_IN_COLOR (xCoord,
"#### %d GetData: ####\n"
"frameNumber: %llu\t\texpLength: %u\t\tpacketNumber: %u\t\tbunchId: %llu\t\ttimestamp: %llu\t\tmodId: %u\t\t"
"xCoord: %u\t\tyCoord: %u\t\tzCoord: %u\t\tdebug: %u\t\troundRNumber: %u\t\tdetType: %u\t\t"
"version: %u\t\tfirstbytedata: 0x%x\t\tdatsize: %u\n\n",
xCoord, frameNumber, expLength, packetNumber, bunchId, timestamp, modId,
xCoord, yCoord, zCoord, debug, roundRNumber, detType, version,
((uint8_t)(*((uint8_t*)(datapointer)))), datasize);
} }
*/ */
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
//Catch signal SIGINT to close files properly keeprunning = true;
signal(SIGINT,closeFile);
// Catch signal SIGINT to close files and call destructors properly
struct sigaction sa;
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) {
bprintf(RED, "Could not set handler function for SIGINT\n");
}
// if socket crash, ignores SISPIPE, prevents global signal handler // if socket crash, ignores SISPIPE, prevents global signal handler
// subsequent read/write to socket gives error - must handle locally // subsequent read/write to socket gives error - must handle locally
signal(SIGPIPE, SIG_IGN); struct sigaction asa;
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) {
bprintf(RED, "Could not set handler function for SIGCHILD\n");
}
//system("setterm -linux term -background white -clear");
int ret = slsReceiverDefs::OK; int ret = slsReceiverDefs::OK;
receiver = new slsReceiverUsers(argc, argv, ret); slsReceiverUsers *receiver = new slsReceiverUsers(argc, argv, ret);
if(ret==slsReceiverDefs::FAIL){ if(ret==slsReceiverDefs::FAIL){
deleteReceiver(receiver); delete receiver;
return -1; exit(EXIT_FAILURE);
} }
@ -107,18 +130,16 @@ int main(int argc, char *argv[]) {
//start tcp server thread //start tcp server thread
if(receiver->start() == slsReceiverDefs::OK){ if (receiver->start() == slsReceiverDefs::FAIL){
FILE_LOG(logDEBUG1) << "DONE!"; delete receiver;
string str; exit(EXIT_FAILURE);
cin>>str;
//wait and look for an exit keyword
while(str.find("exit") == string::npos)
cin>>str;
//stop tcp server thread, stop udp socket
receiver->stop();
} }
deleteReceiver(receiver); FILE_LOG(logINFO) << "Ready ... ";
bprintf(GRAY, "\n[ Press \'Ctrl+c\' to exit ]\n");
while(keeprunning);
delete receiver;
FILE_LOG(logINFO) << "Goodbye!"; FILE_LOG(logINFO) << "Goodbye!";
return 0; return 0;
} }

View File

@ -135,9 +135,7 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success) {
slsReceiver::~slsReceiver() { slsReceiver::~slsReceiver() {
if(udp_interface) if(tcpipInterface)
delete udp_interface;
if(tcpipInterface)
delete tcpipInterface; delete tcpipInterface;
} }
@ -152,11 +150,6 @@ void slsReceiver::stop() {
} }
void slsReceiver::closeFile(int p) {
tcpipInterface->closeFile(p);
}
int64_t slsReceiver::getReceiverVersion(){ int64_t slsReceiver::getReceiverVersion(){
return tcpipInterface->getReceiverVersion(); return tcpipInterface->getReceiverVersion();
} }

View File

@ -25,6 +25,8 @@ slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() {
delete mySock; delete mySock;
mySock=NULL; mySock=NULL;
} }
if(receiverBase)
delete receiverBase;
} }
slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* rbase, int pn): slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* rbase, int pn):
@ -137,7 +139,7 @@ int slsReceiverTCPIPInterface::start(){
void slsReceiverTCPIPInterface::stop(){ void slsReceiverTCPIPInterface::stop(){
FILE_LOG(logINFO) << "Shutting down UDP Socket"; FILE_LOG(logINFO) << "Shutting down TCP Socket";
killTCPServerThread = 1; killTCPServerThread = 1;
if(mySock) mySock->ShutDownSocket(); if(mySock) mySock->ShutDownSocket();
FILE_LOG(logDEBUG) << "Socket closed"; FILE_LOG(logDEBUG) << "Socket closed";
@ -147,11 +149,6 @@ void slsReceiverTCPIPInterface::stop(){
void slsReceiverTCPIPInterface::closeFile(int p){
receiverBase->closeFiles();
}
int64_t slsReceiverTCPIPInterface::getReceiverVersion(){ int64_t slsReceiverTCPIPInterface::getReceiverVersion(){
int64_t retval = SVNREV; int64_t retval = SVNREV;
retval= (retval <<32) | SVNDATE; retval= (retval <<32) | SVNDATE;
@ -220,9 +217,6 @@ void slsReceiverTCPIPInterface::startTCPServer(){
FILE_LOG(logINFO) << "Shutting down UDP Socket"; FILE_LOG(logINFO) << "Shutting down UDP Socket";
if(receiverBase){ if(receiverBase){
receiverBase->shutDownUDPSockets(); receiverBase->shutDownUDPSockets();
FILE_LOG(logINFO) << "Closing Files... ";
receiverBase->closeFiles();
} }
mySock->exitServer(); mySock->exitServer();
@ -230,8 +224,14 @@ void slsReceiverTCPIPInterface::startTCPServer(){
} }
//if user entered exit //if user entered exit
if(killTCPServerThread) if(killTCPServerThread) {
if (v != GOODBYE) {
if(receiverBase){
receiverBase->shutDownUDPSockets();
}
}
pthread_exit(NULL); pthread_exit(NULL);
}
} }
} }
@ -277,6 +277,7 @@ const char* slsReceiverTCPIPInterface::getFunctionName(enum recFuncs func) {
case F_SET_RECEIVER_FILE_FORMAT: return "F_SET_RECEIVER_FILE_FORMAT"; case F_SET_RECEIVER_FILE_FORMAT: return "F_SET_RECEIVER_FILE_FORMAT";
case F_SEND_RECEIVER_DETPOSID: return "F_SEND_RECEIVER_DETPOSID"; case F_SEND_RECEIVER_DETPOSID: return "F_SEND_RECEIVER_DETPOSID";
case F_SEND_RECEIVER_MULTIDETSIZE: return "F_SEND_RECEIVER_MULTIDETSIZE"; case F_SEND_RECEIVER_MULTIDETSIZE: return "F_SEND_RECEIVER_MULTIDETSIZE";
case F_SET_RECEIVER_STREAMING_PORT: return "F_SET_RECEIVER_STREAMING_PORT";
default: return "Unknown Function"; default: return "Unknown Function";
} }
} }
@ -322,7 +323,7 @@ int slsReceiverTCPIPInterface::function_table(){
flist[F_SET_RECEIVER_FILE_FORMAT] = &slsReceiverTCPIPInterface::set_file_format; flist[F_SET_RECEIVER_FILE_FORMAT] = &slsReceiverTCPIPInterface::set_file_format;
flist[F_SEND_RECEIVER_DETPOSID] = &slsReceiverTCPIPInterface::set_detector_posid; flist[F_SEND_RECEIVER_DETPOSID] = &slsReceiverTCPIPInterface::set_detector_posid;
flist[F_SEND_RECEIVER_MULTIDETSIZE] = &slsReceiverTCPIPInterface::set_multi_detector_size; flist[F_SEND_RECEIVER_MULTIDETSIZE] = &slsReceiverTCPIPInterface::set_multi_detector_size;
flist[F_SET_RECEIVER_STREAMING_PORT] = &slsReceiverTCPIPInterface::set_streaming_port;
#ifdef VERYVERBOSE #ifdef VERYVERBOSE
for (int i = 0; i < NUM_REC_FUNCTIONS ; i++) { for (int i = 0; i < NUM_REC_FUNCTIONS ; i++) {
FILE_LOG(logINFO) << "function fnum: " << i << " (" << getFunctionName((enum recFuncs)i) << ") located at " << (unsigned int)flist[i]; FILE_LOG(logINFO) << "function fnum: " << i << " (" << getFunctionName((enum recFuncs)i) << ") located at " << (unsigned int)flist[i];
@ -670,6 +671,12 @@ int slsReceiverTCPIPInterface::send_update() {
#endif #endif
mySock->SendDataOnly(&ind,sizeof(ind)); mySock->SendDataOnly(&ind,sizeof(ind));
// streaming port
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
ind=(int)receiverBase->getStreamingPort();
#endif
mySock->SendDataOnly(&ind,sizeof(ind));
if (!lockStatus) if (!lockStatus)
strcpy(mySock->lastClientIP,mySock->thisClientIP); strcpy(mySock->lastClientIP,mySock->thisClientIP);
@ -2305,3 +2312,55 @@ int slsReceiverTCPIPInterface::set_multi_detector_size() {
} }
int slsReceiverTCPIPInterface::set_streaming_port() {
ret = OK;
memset(mess, 0, sizeof(mess));
int port = -1;
int retval = -1;
// receive arguments
if (mySock->ReceiveDataOnly(&port,sizeof(port)) < 0 )
return printSocketReadError();
// execute action
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
if (receiverBase == NULL)
invalidReceiverObject();
else {
// set
if(port >= 0) {
if (mySock->differentClients && lockStatus)
receiverlocked();
else if (receiverBase->getStatus() != IDLE)
receiverNotIdle();
else {
receiverBase->setStreamingPort(port);
}
}
//get
retval=receiverBase->getStreamingPort();
if(port > 0 && retval != port) { //if port = 0, its actual value calculated
ret = FAIL;
strcpy(mess, "Could not set streaming port\n");
FILE_LOG(logERROR) << "Warning: " << mess;
}
}
#endif
#ifdef VERYVERBOSE
FILE_LOG(logDEBUG1) << "streaming port:" << retval;
#endif
if (ret == OK && mySock->differentClients)
ret = FORCE_UPDATE;
// send answer
mySock->SendDataOnly(&ret,sizeof(ret));
if (ret == FAIL)
mySock->SendDataOnly(mess,sizeof(mess));
mySock->SendDataOnly(&retval,sizeof(retval));
// return ok/fail
return ret;
}

View File

@ -17,10 +17,6 @@ void slsReceiverUsers::stop() {
receiver->stop(); receiver->stop();
} }
void slsReceiverUsers::closeFile(int p) {
receiver->closeFile(p);
}
int64_t slsReceiverUsers::getReceiverVersion(){ int64_t slsReceiverUsers::getReceiverVersion(){
return receiver->getReceiverVersion(); return receiver->getReceiverVersion();
} }