included the stop receiver function for the users

This commit is contained in:
Maliakal Dhanya 2014-05-23 14:50:11 +02:00
parent af89269c0c
commit 567501c6f7
6 changed files with 64 additions and 33 deletions

View File

@ -31,6 +31,7 @@ slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() {
slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int argc, char *argv[], int &success): slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int argc, char *argv[], int &success):
myDetectorType(GOTTHARD), myDetectorType(GOTTHARD),
slsReceiverFunctions(NULL),
ret(OK), ret(OK),
lockStatus(0), lockStatus(0),
shortFrame(-1), shortFrame(-1),
@ -168,7 +169,6 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int argc, char *argv[], int
//Catch signal SIGINT to close files properly //Catch signal SIGINT to close files properly
signal(SIGINT,staticCloseFile); signal(SIGINT,staticCloseFile);
file_des=socket->getFileDes(); file_des=socket->getFileDes();
socketDescriptor=socket->getsocketDescriptor(); socketDescriptor=socket->getsocketDescriptor();
@ -178,6 +178,7 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int argc, char *argv[], int
} }
void slsReceiverTCPIPInterface::start(){ void slsReceiverTCPIPInterface::start(){
int v=slsReceiverDefs::OK; int v=slsReceiverDefs::OK;
@ -203,9 +204,18 @@ void slsReceiverTCPIPInterface::start(){
#endif #endif
} }
} }
}
void slsReceiverTCPIPInterface::stop(){
//shut down udp socket
if(slsReceiverFunctions)
slsReceiverFunctions->shutDownUDPSocket();
//disconnect and delete socket
socket->Disconnect();
delete socket;
//close file and exit
closeFile(0);
} }

View File

@ -1,4 +1,4 @@
/********************************************//** /********************************************//**
* @file slsReceiverTCPIPInterface.h * @file slsReceiverTCPIPInterface.h
* @short interface between receiver and client * @short interface between receiver and client
***********************************************/ ***********************************************/
@ -14,8 +14,8 @@
/** /**
*@short interface between receiver and client *@short interface between receiver and client
*/ */
class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { class slsReceiverTCPIPInterface : private virtual slsReceiverDefs {
@ -27,13 +27,14 @@ public:
* @param argv from command line * @param argv from command line
* @param succecc socket creation was successfull * @param succecc socket creation was successfull
*/ */
slsReceiverTCPIPInterface(int argc, char *argv[], int &success); slsReceiverTCPIPInterface(int argc, char *argv[], int &success);
/** starts listening on the TCP port for client comminication */
/** starts listening on the TCP port for client comminication */
void start(); void start();
/** stop listening on the TCP & UDP port for client comminication and exit receiver */
void stop();
/** Destructor */ /** Destructor */
virtual ~slsReceiverTCPIPInterface(); virtual ~slsReceiverTCPIPInterface();
@ -58,7 +59,7 @@ public:
1 callback writes file, we have to open, close it 1 callback writes file, we have to open, close it
2 we open, close, write file, callback does not do anything 2 we open, close, write file, callback does not do anything
*/ */
void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){slsReceiverFunctions->registerCallBackStartAcquisition(func,arg);};; void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){slsReceiverFunctions->registerCallBackStartAcquisition(func,arg);};;
@ -67,7 +68,7 @@ public:
callback argument is callback argument is
toatal farmes caught toatal farmes caught
*/ */
void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){slsReceiverFunctions->registerCallBackAcquisitionFinished(func,arg);}; void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){slsReceiverFunctions->registerCallBackAcquisitionFinished(func,arg);};
@ -81,12 +82,12 @@ public:
datasize in bytes datasize in bytes
file descriptor file descriptor
guidatapointer (NULL, no data required) guidatapointer (NULL, no data required)
*/ */
void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){slsReceiverFunctions->registerCallBackRawDataReady(func,arg);}; void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){slsReceiverFunctions->registerCallBackRawDataReady(func,arg);};
private: private:
/** assigns functions to the fnum enum */ /** assigns functions to the fnum enum */
int function_table(); int function_table();
@ -228,8 +229,8 @@ public:
static int file_des; static int file_des;
static int socketDescriptor; static int socketDescriptor;
//private: //private:
protected: protected:
/** Socket */ /** Socket */
MySocketTCP* socket; MySocketTCP* socket;
}; };

View File

@ -105,7 +105,7 @@ void slsReceiverUDPFunctions::deleteMembers(){
receiverdata[i] = NULL; receiverdata[i] = NULL;
} }
} }
if(udpSocket) {delete udpSocket; udpSocket = NULL;} shutDownUDPSocket();
if(eth) {delete [] eth; eth = NULL;} if(eth) {delete [] eth; eth = NULL;}
if(latestData) {delete [] latestData; latestData = NULL;} if(latestData) {delete [] latestData; latestData = NULL;}
if(guiFileName) {delete [] guiFileName; guiFileName = NULL;} if(guiFileName) {delete [] guiFileName; guiFileName = NULL;}
@ -802,14 +802,11 @@ void slsReceiverUDPFunctions::copyFrameToGui(char* startbuf){
int slsReceiverUDPFunctions::createUDPSocket(){ int slsReceiverUDPFunctions::createUDPSocket(){
if(udpSocket)
udpSocket->ShutDownSocket();
//if eth is mistaken with ip address //if eth is mistaken with ip address
if (strchr(eth,'.')!=NULL) if (strchr(eth,'.')!=NULL)
strcpy(eth,""); strcpy(eth,"");
if(udpSocket){delete udpSocket; udpSocket = NULL;} shutDownUDPSocket();
//if no eth, listen to all //if no eth, listen to all
if(!strlen(eth)){ if(!strlen(eth)){
@ -838,6 +835,22 @@ int slsReceiverUDPFunctions::createUDPSocket(){
int slsReceiverUDPFunctions::shutDownUDPSocket(){
if(udpSocket){
udpSocket->ShutDownSocket();
delete udpSocket;
udpSocket = NULL;
}
return OK;
}
int slsReceiverUDPFunctions::createListeningThreads(bool destroy){ int slsReceiverUDPFunctions::createListeningThreads(bool destroy){
void* status; void* status;
@ -1224,8 +1237,7 @@ int slsReceiverUDPFunctions::startReceiver(char message[]){
if(setupWriter() == FAIL){ if(setupWriter() == FAIL){
//stop udp socket //stop udp socket
if(udpSocket) shutDownUDPSocket();
udpSocket->ShutDownSocket();
sprintf(message,"Could not create file %s.\n",savefilename); sprintf(message,"Could not create file %s.\n",savefilename);
return FAIL; return FAIL;
@ -1312,11 +1324,7 @@ void slsReceiverUDPFunctions::startReadout(){
cout << "Status: Transmitting" << endl; cout << "Status: Transmitting" << endl;
//kill udp socket to tell the listening thread to push last packet //kill udp socket to tell the listening thread to push last packet
if(udpSocket){ shutDownUDPSocket();
udpSocket->ShutDownSocket();
delete udpSocket;
udpSocket = NULL;
}
} }

View File

@ -266,6 +266,11 @@ public:
*/ */
void startReadout(); void startReadout();
/**
* shuts down the udp socket
* \returns if success or fail
*/
int shutDownUDPSocket();
private: private:
/** /**

View File

@ -15,6 +15,10 @@ void slsReceiverUsers::start() {
slsReceiverUsers::receiver->start(); slsReceiverUsers::receiver->start();
} }
void slsReceiverUsers::stop() {
slsReceiverUsers::receiver->stop();
}
void slsReceiverUsers::closeFile(int p) { void slsReceiverUsers::closeFile(int p) {
slsReceiverUsers::receiver->closeFile(p); slsReceiverUsers::receiver->closeFile(p);

View File

@ -40,6 +40,9 @@ public:
/** starts listening on the TCP port for client comminication */ /** starts listening on the TCP port for client comminication */
void start(); void start();
/** stops listening to the TCP & UDP port and exit receiver program*/
void stop();
/** /**
get get Receiver Version get get Receiver Version
\returns id \returns id