00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "init.h"
00020
00021 #include "global.h"
00022 #include "log.h"
00023 #include "pluginRegistry.h"
00024 #include "rng.h"
00025 #include "thread.h"
00026
00027 #include <fstream>
00028
00029 namespace eq
00030 {
00031 namespace base
00032 {
00033
00034 namespace
00035 {
00036 static std::ofstream* _logFile = 0;
00037 }
00038
00039 EQ_EXPORT bool init( const int argc, char** argv )
00040 {
00041 for( int i=1; i<argc; ++i )
00042 {
00043 if( strcmp( "--eq-logfile", argv[i] ) == 0 )
00044 {
00045 ++i;
00046 if( i<argc )
00047 {
00048 EQASSERT( !_logFile );
00049 _logFile = new std::ofstream( argv[i] );
00050 if( _logFile->is_open( ))
00051 Log::setOutput( *_logFile );
00052 else
00053 {
00054 EQWARN << "Can't open log file " << argv[i] << ": "
00055 << base::sysError << std::endl;
00056 delete _logFile;
00057 _logFile = 0;
00058 return false;
00059 }
00060 }
00061 }
00062 }
00063
00064 if( !RNG::_init( ))
00065 {
00066 EQERROR << "Failed to initialize random number generator" << std::endl;
00067 return false;
00068 }
00069
00070
00071 PluginRegistry& pluginRegistry = Global::getPluginRegistry();
00072 pluginRegistry.init();
00073 Thread::pinCurrentThread();
00074 return true;
00075 }
00076
00077 EQ_EXPORT bool exit()
00078 {
00079
00080 PluginRegistry& pluginRegistry = Global::getPluginRegistry();
00081 pluginRegistry.exit();
00082 eq::base::Thread::removeAllListeners();
00083 eq::base::Log::exit();
00084
00085 const bool ret = RNG::_exit();
00086 if( _logFile )
00087 {
00088 #ifdef NDEBUG
00089 Log::setOutput( std::cout );
00090 #else
00091 Log::setOutput( std::cerr );
00092 #endif
00093 _logFile->close();
00094 delete _logFile;
00095 _logFile = 0;
00096 }
00097 return ret;
00098 }
00099
00100 }
00101 }
00102