mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-06 18:10:40 +02:00
started receiver start on a separate thread and returns, whereas stop receiver will end udp, tcp socket and exit thread
This commit is contained in:
parent
567501c6f7
commit
90f5fb39db
@ -5,6 +5,7 @@
|
||||
#include "slsReceiverUsers.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
using namespace std;
|
||||
|
||||
|
||||
@ -13,15 +14,15 @@ using namespace std;
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int ret = slsReceiverDefs::OK;
|
||||
|
||||
slsReceiverUsers *user = new slsReceiverUsers(argc, argv, ret);
|
||||
|
||||
if(ret==slsReceiverDefs::FAIL)
|
||||
return -1;
|
||||
|
||||
int ret = slsReceiverDefs::OK;
|
||||
|
||||
//register callbacks
|
||||
slsReceiverUsers *user = new slsReceiverUsers(argc, argv, ret);
|
||||
|
||||
if(ret==slsReceiverDefs::FAIL)
|
||||
return -1;
|
||||
|
||||
|
||||
//register callbacks
|
||||
|
||||
|
||||
/**
|
||||
@ -30,7 +31,7 @@ int main(int argc, char *argv[]) {
|
||||
filename
|
||||
fileindex
|
||||
datasize
|
||||
|
||||
|
||||
return value is
|
||||
0 raw data ready callback takes care of open,close,write file
|
||||
1 callback writes file, we have to open, close it
|
||||
@ -38,8 +39,8 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
|
||||
registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg);
|
||||
*/
|
||||
|
||||
*/
|
||||
|
||||
//receiver->registerCallBackStartAcquisition(func,arg);
|
||||
|
||||
|
||||
@ -47,11 +48,11 @@ int main(int argc, char *argv[]) {
|
||||
callback argument is
|
||||
total farmes caught
|
||||
registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg);
|
||||
*/
|
||||
|
||||
*/
|
||||
|
||||
|
||||
//receiver->registerCallBackAcquisitionFinished(func,arg);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@ -60,22 +61,30 @@ int main(int argc, char *argv[]) {
|
||||
datapointer
|
||||
file descriptor
|
||||
guidatapointer (NULL, no data required)
|
||||
|
||||
|
||||
NEVER DELETE THE DATA POINTER
|
||||
REMEMBER THAT THE CALLBACK IS BLOCKING
|
||||
|
||||
registerCallBackRawDataReady(void (*func)(int, char*, FILE*, char*, void*),void *arg);
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
//receiver->registerCallBackRawDataReady(func,arg);
|
||||
|
||||
|
||||
|
||||
//start tcp server thread
|
||||
if(user->start() == slsReceiverDefs::OK){
|
||||
string str;
|
||||
cin>>str;
|
||||
//wait and look for an exit keyword
|
||||
while(str.find("exit") == string::npos)
|
||||
cin>>str;
|
||||
//stop tcp server thread, stop udp socket
|
||||
user->stop();
|
||||
}
|
||||
|
||||
user->start();
|
||||
|
||||
|
||||
return 0;
|
||||
cout << "Goodbye!" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,6 @@
|
||||
using namespace std;
|
||||
|
||||
|
||||
int slsReceiverTCPIPInterface::file_des(-1);
|
||||
int slsReceiverTCPIPInterface::socketDescriptor(-1);
|
||||
|
||||
|
||||
slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() {
|
||||
@ -36,7 +34,8 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int argc, char *argv[], int
|
||||
lockStatus(0),
|
||||
shortFrame(-1),
|
||||
packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME),
|
||||
socket(NULL){
|
||||
socket(NULL),
|
||||
killTCPServerThread(0){
|
||||
|
||||
int port_no = DEFAULT_PORTNO+2;
|
||||
ifstream infile;
|
||||
@ -169,21 +168,64 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int argc, char *argv[], int
|
||||
//Catch signal SIGINT to close files properly
|
||||
signal(SIGINT,staticCloseFile);
|
||||
|
||||
file_des=socket->getFileDes();
|
||||
socketDescriptor=socket->getsocketDescriptor();
|
||||
|
||||
//success = OK;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void slsReceiverTCPIPInterface::start(){
|
||||
int slsReceiverTCPIPInterface::start(){
|
||||
cout << "Creating TCP Server Thread" << endl;
|
||||
killTCPServerThread = 0;
|
||||
if(pthread_create(&TCPServer_thread, NULL,startTCPServerThread, (void*) this)){
|
||||
cout << "Could not create TCP Server thread" << endl;
|
||||
return FAIL;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
cout << "TCP Server thread created successfully." << endl;
|
||||
#endif
|
||||
return OK;
|
||||
}
|
||||
|
||||
int v=slsReceiverDefs::OK;
|
||||
|
||||
while(v!=GOODBYE) {
|
||||
void slsReceiverTCPIPInterface::stop(){
|
||||
|
||||
cout << "Shutting down UDP Socket" << endl;
|
||||
if(slsReceiverFunctions)
|
||||
slsReceiverFunctions->shutDownUDPSocket();
|
||||
|
||||
cout << "Closing Files... " << endl;
|
||||
slsReceiverFunctions->closeFile();
|
||||
|
||||
|
||||
cout<<"Shutting down TCP Socket and TCP thread"<<endl;
|
||||
killTCPServerThread = 1;
|
||||
socket->ShutDownSocket();
|
||||
void* status;
|
||||
pthread_join(TCPServer_thread, &status);
|
||||
killTCPServerThread = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void* slsReceiverTCPIPInterface::startTCPServerThread(void *this_pointer){
|
||||
((slsReceiverTCPIPInterface*)this_pointer)->startTCPServer();
|
||||
return this_pointer;
|
||||
}
|
||||
|
||||
|
||||
void slsReceiverTCPIPInterface::startTCPServer(){
|
||||
|
||||
|
||||
#ifdef VERYVERBOSE
|
||||
cout << "Starting Receiver TCP Server" << endl;
|
||||
#endif
|
||||
int v=slsReceiverDefs::OK;
|
||||
|
||||
while(1) {
|
||||
#ifdef VERBOSE
|
||||
cout<< endl;
|
||||
#endif
|
||||
@ -192,31 +234,39 @@ void slsReceiverTCPIPInterface::start(){
|
||||
#endif
|
||||
if(socket->Connect()>=0){
|
||||
#ifdef VERY_VERBOSE
|
||||
cout << "Conenction accepted" << endl;
|
||||
cout << "Conenction accepted" << endl;
|
||||
#endif
|
||||
v = decode_function();
|
||||
v = decode_function();
|
||||
#ifdef VERY_VERBOSE
|
||||
cout << "function executed" << endl;
|
||||
cout << "function executed" << endl;
|
||||
#endif
|
||||
socket->Disconnect();
|
||||
socket->Disconnect();
|
||||
#ifdef VERY_VERBOSE
|
||||
cout << "connection closed" << endl;
|
||||
cout << "connection closed" << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
//if tcp command was to exit server
|
||||
if(v==GOODBYE){
|
||||
cout << "Shutting down UDP Socket" << endl;
|
||||
if(slsReceiverFunctions)
|
||||
slsReceiverFunctions->shutDownUDPSocket();
|
||||
|
||||
cout << "Closing Files... " << endl;
|
||||
slsReceiverFunctions->closeFile();
|
||||
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
//if user entered exit
|
||||
if(killTCPServerThread)
|
||||
pthread_exit(NULL);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int slsReceiverTCPIPInterface::function_table(){
|
||||
@ -330,8 +380,7 @@ int slsReceiverTCPIPInterface::M_nofunc(){
|
||||
|
||||
|
||||
void slsReceiverTCPIPInterface::closeFile(int p){
|
||||
cout<<"Closing Files... "<<endl;
|
||||
slsReceiverFunctions->closeFile();
|
||||
stop();
|
||||
cout << "Goodbye!" << endl;
|
||||
exit(-1);
|
||||
}
|
||||
@ -1850,7 +1899,6 @@ int slsReceiverTCPIPInterface::set_port() {
|
||||
socket->Disconnect();
|
||||
delete socket;
|
||||
socket = mySocket;
|
||||
file_des=socket->getFileDes();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,10 +29,13 @@ public:
|
||||
*/
|
||||
slsReceiverTCPIPInterface(int argc, char *argv[], int &success);
|
||||
|
||||
/** starts listening on the TCP port for client comminication */
|
||||
void start();
|
||||
/**
|
||||
* Starts listening on the TCP port for client comminication
|
||||
\returns OK or FAIL
|
||||
*/
|
||||
int start();
|
||||
|
||||
/** stop listening on the TCP & UDP port for client comminication and exit receiver */
|
||||
/** stop listening on the TCP & UDP port for client comminication */
|
||||
void stop();
|
||||
|
||||
/** Destructor */
|
||||
@ -88,6 +91,20 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Static function - Thread started which is a TCP server
|
||||
* Called by start()
|
||||
* @param this_pointer pointer to this object
|
||||
*/
|
||||
static void* startTCPServerThread(void *this_pointer);
|
||||
|
||||
/**
|
||||
* Thread started which is a TCP server
|
||||
* Called by start()
|
||||
*/
|
||||
void startTCPServer();
|
||||
|
||||
/** assigns functions to the fnum enum */
|
||||
int function_table();
|
||||
|
||||
@ -226,10 +243,12 @@ private:
|
||||
/** Packets per frame */
|
||||
int packetsPerFrame;
|
||||
|
||||
static int file_des;
|
||||
static int socketDescriptor;
|
||||
/** kill tcp server thread */
|
||||
int killTCPServerThread;
|
||||
|
||||
/** thread for TCP server */
|
||||
pthread_t TCPServer_thread;
|
||||
|
||||
//private:
|
||||
protected:
|
||||
/** Socket */
|
||||
MySocketTCP* socket;
|
||||
|
@ -11,8 +11,8 @@ slsReceiverUsers::~slsReceiverUsers() {
|
||||
delete slsReceiverUsers::receiver;
|
||||
}
|
||||
|
||||
void slsReceiverUsers::start() {
|
||||
slsReceiverUsers::receiver->start();
|
||||
int slsReceiverUsers::start() {
|
||||
return slsReceiverUsers::receiver->start();
|
||||
}
|
||||
|
||||
void slsReceiverUsers::stop() {
|
||||
|
@ -37,8 +37,11 @@ public:
|
||||
/** Close File and exits receiver server */
|
||||
void closeFile(int p);
|
||||
|
||||
/** starts listening on the TCP port for client comminication */
|
||||
void start();
|
||||
/**
|
||||
* starts listening on the TCP port for client comminication
|
||||
\return 0 for success or 1 for FAIL in creating TCP server
|
||||
*/
|
||||
int start();
|
||||
|
||||
/** stops listening to the TCP & UDP port and exit receiver program*/
|
||||
void stop();
|
||||
|
Loading…
x
Reference in New Issue
Block a user