BESBaseApp.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <iostream>
00034
00035 using std::cerr ;
00036 using std::endl ;
00037
00038 #include "BESBaseApp.h"
00039 #include "BESGlobalIQ.h"
00040 #include "BESInternalError.h"
00041
00042 BESApp *BESApp::_theApplication = 0;
00043
00049 BESBaseApp::BESBaseApp(void)
00050 {
00051 BESApp::_theApplication = this;
00052 }
00053
00059 BESBaseApp::~BESBaseApp(void)
00060 {
00061 BESApp::_theApplication = 0;
00062 }
00063
00074 int
00075 BESBaseApp::main(int argC, char **argV)
00076 {
00077 _appName = argV[0] ;
00078 int retVal = initialize( argC, argV ) ;
00079 if( retVal != 0 )
00080 {
00081 cerr << "BESBaseApp::initialize - failed" << endl;
00082 }
00083 else
00084 {
00085 retVal = run() ;
00086 retVal = terminate( retVal ) ;
00087 }
00088 return retVal ;
00089 }
00090
00102 int
00103 BESBaseApp::initialize(int argC, char **argV)
00104 {
00105 int retVal = 0;
00106
00107
00108 try
00109 {
00110 if( !_isInitialized )
00111 BESGlobalIQ::BESGlobalInit( argC, argV ) ;
00112 _isInitialized = true ;
00113 }
00114 catch( BESError &e )
00115 {
00116 string newerr = "Error initializing application: " ;
00117 newerr += e.get_message() ;
00118 cerr << newerr << endl ;
00119 retVal = 1 ;
00120 }
00121 catch( ... )
00122 {
00123 string newerr = "Error initializing application: " ;
00124 newerr += "caught unknown exception" ;
00125 cerr << newerr << endl ;
00126 retVal = 1 ;
00127 }
00128
00129 return retVal ;
00130 }
00131
00140 int
00141 BESBaseApp::run(void)
00142 {
00143 throw BESInternalError( "BESBaseApp::run - run method not implemented",
00144 __FILE__, __LINE__ ) ;
00145 return 0;
00146 }
00147
00157 int
00158 BESBaseApp::terminate( int sig )
00159 {
00160 BESGlobalIQ::BESGlobalQuit() ;
00161 _isInitialized = false ;
00162 return sig ;
00163 }
00164
00172 void
00173 BESBaseApp::dump( ostream &strm ) const
00174 {
00175 strm << BESIndent::LMarg << "BESBaseApp::dump - (" << (void *)this << ")" << endl ;
00176 BESIndent::Indent() ;
00177 strm << BESIndent::LMarg << "appName: " << appName() << endl ;
00178 strm << BESIndent::LMarg << "is initialized: " << _isInitialized << endl ;
00179 BESIndent::UnIndent() ;
00180 }
00181