Commit 5445b525 authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Adding signal interrupt handler foo clean finalize on termination, e.g. from...

Adding signal interrupt handler foo clean finalize on termination, e.g. from Matlab killtask command
parent 66555f51
......@@ -19,6 +19,7 @@
#endif
#include <iostream>
#include <signal.h>
// ITA includes
#include <ITAException.h>
......@@ -30,12 +31,59 @@
#include <VA.h>
#include <VACore.h>
#include <VANet.h>
#include <Windows.h>
using namespace std;
int main( int argc, char* argv[] )
// Core
IVAInterface* pCore = NULL;
IVANetServer* pServer = NULL;
void SignalHandler( int iSignum )
{
try
{
delete pServer;
if( pCore )
pCore->Finalize();
delete pCore;
}
catch( CVAException& e )
{
cerr << "[ VAServer ][ Error ] " << e << endl;
delete pServer;
if( pCore )
pCore->Finalize();
delete pCore;
exit( 255 );
}
catch( ... )
{
delete pServer;
if( pCore )
pCore->Finalize();
delete pCore;
cerr << "[ VAServer ][ Error ] An unknown error occured" << endl;
exit( 255 );
}
exit( iSignum );
}
int main( int argc, char* argv[] )
{
// Register interrupt signal handler
signal( SIGABRT, SignalHandler );
signal( SIGBREAK, SignalHandler ); // closing window
signal( SIGTERM, SignalHandler );
signal( SIGINT, SignalHandler ); // CTRL+C etc.
// Arguments
bool bVersionInfoRequest = false;
......@@ -68,12 +116,6 @@ int main( int argc, char* argv[] )
}
// Core
IVAInterface* pCore = NULL;
IVANetServer* pServer = NULL;
try
{
int ec;
......@@ -159,12 +201,17 @@ int main( int argc, char* argv[] )
"[ VAServer ] s List search paths" << endl <<
"[ VAServer ] q Quit" << endl << endl;
while( true )
{
const int CTRL_D = 4;
int c = getch();
if( c == CTRL_D || c == 'q' ) break;
if( c == CTRL_D || c == 'q' )
{
raise( SIGINT );
break;
}
if( ( char ) c == 'm' )
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment