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):
myDetectorType(GOTTHARD),
slsReceiverFunctions(NULL),
ret(OK),
lockStatus(0),
shortFrame(-1),
@ -168,7 +169,6 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int argc, char *argv[], int
//Catch signal SIGINT to close files properly
signal(SIGINT,staticCloseFile);
file_des=socket->getFileDes();
socketDescriptor=socket->getsocketDescriptor();
@ -178,6 +178,7 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int argc, char *argv[], int
}
void slsReceiverTCPIPInterface::start(){
int v=slsReceiverDefs::OK;
@ -203,9 +204,18 @@ void slsReceiverTCPIPInterface::start(){
#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
* @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 {
@ -27,13 +27,14 @@ public:
* @param argv from command line
* @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();
/** stop listening on the TCP & UDP port for client comminication and exit receiver */
void stop();
/** Destructor */
virtual ~slsReceiverTCPIPInterface();
@ -52,14 +53,14 @@ public:
filename
fileindex
data size
return value is
0 callback takes care of open,close,wrie file
1 callback writes file, we have to open, close it
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);};;
@ -67,11 +68,11 @@ public:
callback argument is
toatal farmes caught
*/
*/
void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){slsReceiverFunctions->registerCallBackAcquisitionFinished(func,arg);};
/**
@ -81,12 +82,12 @@ public:
datasize in bytes
file descriptor
guidatapointer (NULL, no data required)
*/
*/
void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){slsReceiverFunctions->registerCallBackRawDataReady(func,arg);};
private:
private:
/** assigns functions to the fnum enum */
int function_table();
@ -228,8 +229,8 @@ public:
static int file_des;
static int socketDescriptor;
//private:
protected:
//private:
protected:
/** Socket */
MySocketTCP* socket;
};

View File

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

View File

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

View File

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

View File

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