Exceptions handling in constructor for genericSocket, created object to handle both socket descriptors upon throwing exception in constructor (as raw pointers wont get destructed automatically)

This commit is contained in:
2018-08-09 15:43:56 +02:00
parent ab7e63c20f
commit 1102153d2b
14 changed files with 309 additions and 357 deletions

View File

@ -18,11 +18,8 @@ using namespace std;
slsReceiver::slsReceiver(int argc, char *argv[], int &success):
tcpipInterface (NULL),
udp_interface (NULL)
{
success=OK;
slsReceiver::slsReceiver(int argc, char *argv[]):
tcpipInterface (0) {
// options
map<string, string> configuration_map;
@ -72,8 +69,7 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success):
tempval = GITREV;
tempval = (tempval <<32) | GITDATE;
cout << "SLS Receiver " << GITBRANCH << " (0x" << hex << tempval << ")" << endl;
success = FAIL; // to exit
break;
throw exception();
case 'h':
default:
@ -87,26 +83,18 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success):
+ "\t receivers\n\n";
FILE_LOG(logINFO) << help_message << endl;
break;
throw exception();
}
}
if( !fname.empty() ){
try{
FILE_LOG(logINFO) << "config file name " << fname;
success = read_config_file(fname, &tcpip_port_no, &configuration_map);
//VERBOSE_PRINT("Read configuration file of " + iline + " lines");
}
catch(...){
FILE_LOG(logERROR) << "Coult not open configuration file " << fname ;
success = FAIL;
}
if( !fname.empty() && read_config_file(fname, &tcpip_port_no, &configuration_map) == FAIL) {
throw exception();
}
if (success==OK){
tcpipInterface = new slsReceiverTCPIPInterface(success, udp_interface, tcpip_port_no);
}
// might throw an exception
tcpipInterface = new slsReceiverTCPIPInterface(tcpip_port_no);
}
@ -131,40 +119,26 @@ int64_t slsReceiver::getReceiverVersion(){
}
void slsReceiver::registerCallBackStartAcquisition(int (*func)(char*, char*, uint64_t, uint32_t, void*),void *arg){
//tcpipInterface
if(udp_interface)
udp_interface->registerCallBackStartAcquisition(func,arg);
else
tcpipInterface->registerCallBackStartAcquisition(func,arg);
void slsReceiver::registerCallBackStartAcquisition(int (*func)(
char*, char*, uint64_t, uint32_t, void*),void *arg){
tcpipInterface->registerCallBackStartAcquisition(func,arg);
}
void slsReceiver::registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg){
//tcpipInterface
if(udp_interface)
udp_interface->registerCallBackAcquisitionFinished(func,arg);
else
tcpipInterface->registerCallBackAcquisitionFinished(func,arg);
void slsReceiver::registerCallBackAcquisitionFinished(
void (*func)(uint64_t, void*),void *arg){
tcpipInterface->registerCallBackAcquisitionFinished(func,arg);
}
void slsReceiver::registerCallBackRawDataReady(void (*func)(char*,
char*, uint32_t, void*),void *arg){
//tcpipInterface
if(udp_interface)
udp_interface->registerCallBackRawDataReady(func,arg);
else
tcpipInterface->registerCallBackRawDataReady(func,arg);
tcpipInterface->registerCallBackRawDataReady(func,arg);
}
void slsReceiver::registerCallBackRawDataModifyReady(void (*func)(char*,
char*, uint32_t &, void*),void *arg){
//tcpipInterface
if(udp_interface)
udp_interface->registerCallBackRawDataModifyReady(func,arg);
else
tcpipInterface->registerCallBackRawDataModifyReady(func,arg);
tcpipInterface->registerCallBackRawDataModifyReady(func,arg);
}