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
00034
00035
00036
00037
00038
00039 #include "StartupWrapper.h"
00040
00041 namespace ariba {
00042 namespace utility {
00043
00044 StartupWrapper::ConfigurationList StartupWrapper::configurations;
00045 #ifdef UNDERLAY_OMNET
00046 StartupWrapper::ModuleList StartupWrapper::modules;
00047 #endif
00048
00049 SystemEventType StartupWrapperEventType("StartupWrapperEventType");
00050
00051 StartupWrapper::StartupWrapper(StartupInterface* _service, bool _block)
00052 : blocking( _block ), service( _service ){
00053 }
00054
00055 StartupWrapper::~StartupWrapper(){
00056 }
00057
00058 #ifdef UNDERLAY_OMNET
00059 void StartupWrapper::insertCurrentModule(AribaOmnetModule* mod){
00060 modules.push( mod );
00061 }
00062 #endif
00063
00064 #ifdef UNDERLAY_OMNET
00065 AribaOmnetModule* StartupWrapper::getCurrentModule(){
00066 assert( modules.size() > 0 );
00067
00068 AribaOmnetModule* ret = modules.front();
00069 modules.pop();
00070
00071 return ret;
00072 }
00073 #endif
00074
00075 void StartupWrapper::initSystem(){
00076
00077 static bool initialized = false;
00078 if( initialized ) return;
00079 initialized = true;
00080
00081
00082
00083
00084
00085 srand( time(NULL) );
00086
00087
00088
00089
00090
00091 if( ! SystemQueue::instance().isRunning() )
00092 SystemQueue::instance().run();
00093
00094
00095
00096
00097
00098
00099
00100 log4cxx::BasicConfigurator::configure();
00101
00102
00103 {
00104 log4cxx::LoggerPtr logger(log4cxx::Logger::getRootLogger());
00105 logger->setLevel(log4cxx::Level::getInfo());
00106 }
00107
00108
00109 {
00110
00111
00112 }
00113 {
00114
00115
00116 }
00117
00118
00119
00120
00121 }
00122
00123 void StartupWrapper::initConfig(string filename){
00124 configurations.push( filename );
00125 Configuration::setConfigFilename( filename );
00126 }
00127
00128 void StartupWrapper::startup(StartupInterface* service, bool block){
00129
00130 StartupWrapper* startup = new StartupWrapper(service, block);
00131
00132 #ifdef UNDERLAY_OMNET
00133 SystemQueue::instance().scheduleEvent(
00134 SystemEvent( startup, StartupWrapperEventType, NULL), 0 );
00135 #else
00136 SystemQueue::instance().scheduleEvent(
00137 SystemEvent( startup, StartupWrapperEventType, NULL), 0 );
00138
00139 if( block ) getchar();
00140 #endif
00141 }
00142
00143 void StartupWrapper::handleSystemEvent(const SystemEvent& event){
00144
00145 string config = configurations.front();
00146 configurations.pop();
00147 Configuration::setConfigFilename( config );
00148
00149
00150
00151
00152
00153
00154
00155
00156 service->startup();
00157 }
00158
00159 void StartupWrapper::shutdown(StartupInterface* service){
00160 #ifdef UNDERLAY_OMNET
00161
00162 #endif
00163
00164 service->shutdown();
00165 SystemQueue::instance().cancel();
00166 }
00167
00168 }}