| 1 | // [Licence]
|
---|
| 2 | // The Ariba-Underlay Copyright
|
---|
| 3 | //
|
---|
| 4 | // Copyright (c) 2008-2009, Institute of Telematics, UniversitÀt Karlsruhe (TH)
|
---|
| 5 | //
|
---|
| 6 | // Institute of Telematics
|
---|
| 7 | // UniversitÀt Karlsruhe (TH)
|
---|
| 8 | // Zirkel 2, 76128 Karlsruhe
|
---|
| 9 | // Germany
|
---|
| 10 | //
|
---|
| 11 | // Redistribution and use in source and binary forms, with or without
|
---|
| 12 | // modification, are permitted provided that the following conditions are
|
---|
| 13 | // met:
|
---|
| 14 | //
|
---|
| 15 | // 1. Redistributions of source code must retain the above copyright
|
---|
| 16 | // notice, this list of conditions and the following disclaimer.
|
---|
| 17 | // 2. Redistributions in binary form must reproduce the above copyright
|
---|
| 18 | // notice, this list of conditions and the following disclaimer in the
|
---|
| 19 | // documentation and/or other materials provided with the distribution.
|
---|
| 20 | //
|
---|
| 21 | // THIS SOFTWARE IS PROVIDED BY THE INSTITUTE OF TELEMATICS ``AS IS'' AND
|
---|
| 22 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
| 23 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
---|
| 24 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ARIBA PROJECT OR
|
---|
| 25 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
| 26 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
---|
| 27 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
---|
| 28 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
---|
| 29 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
---|
| 30 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
---|
| 31 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 32 | //
|
---|
| 33 | // The views and conclusions contained in the software and documentation
|
---|
| 34 | // are those of the authors and should not be interpreted as representing
|
---|
| 35 | // official policies, either expressed or implied, of the Institute of
|
---|
| 36 | // Telematics.
|
---|
| 37 | // [Licence]
|
---|
| 38 |
|
---|
| 39 | #include "StartupWrapper.h"
|
---|
| 40 |
|
---|
| 41 | namespace ariba {
|
---|
| 42 | namespace utility {
|
---|
| 43 |
|
---|
| 44 | StartupWrapper::ConfigurationList StartupWrapper::configurations;
|
---|
| 45 | #ifdef UNDERLAY_OMNET
|
---|
| 46 | StartupWrapper::ModuleList StartupWrapper::modules;
|
---|
| 47 | #endif
|
---|
| 48 |
|
---|
| 49 | SystemEventType StartupWrapperEventType("StartupWrapperEventType");
|
---|
| 50 |
|
---|
| 51 | StartupWrapper::StartupWrapper(StartupInterface* _service, bool _block)
|
---|
| 52 | : blocking( _block ), service( _service ){
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | StartupWrapper::~StartupWrapper(){
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | #ifdef UNDERLAY_OMNET
|
---|
| 59 | void StartupWrapper::insertCurrentModule(AribaOmnetModule* mod){
|
---|
| 60 | modules.push( mod );
|
---|
| 61 | }
|
---|
| 62 | #endif
|
---|
| 63 |
|
---|
| 64 | #ifdef UNDERLAY_OMNET
|
---|
| 65 | AribaOmnetModule* StartupWrapper::getCurrentModule(){
|
---|
| 66 | assert( modules.size() > 0 );
|
---|
| 67 |
|
---|
| 68 | AribaOmnetModule* ret = modules.front();
|
---|
| 69 | modules.pop();
|
---|
| 70 |
|
---|
| 71 | return ret;
|
---|
| 72 | }
|
---|
| 73 | #endif
|
---|
| 74 |
|
---|
| 75 | void StartupWrapper::initSystem(){
|
---|
| 76 |
|
---|
| 77 | static bool initialized = false;
|
---|
| 78 | if( initialized ) return;
|
---|
| 79 | initialized = true;
|
---|
| 80 |
|
---|
| 81 | //
|
---|
| 82 | // having seeded the pseudo rng is always good
|
---|
| 83 | //
|
---|
| 84 |
|
---|
| 85 | srand( time(NULL) );
|
---|
| 86 |
|
---|
| 87 | //
|
---|
| 88 | // init the system queue
|
---|
| 89 | //
|
---|
| 90 |
|
---|
| 91 | if( ! SystemQueue::instance().isRunning() )
|
---|
| 92 | SystemQueue::instance().run();
|
---|
| 93 |
|
---|
| 94 | //
|
---|
| 95 | // init the logging system
|
---|
| 96 | //
|
---|
| 97 | // configure the logging
|
---|
| 98 | //
|
---|
| 99 |
|
---|
| 100 | log4cxx::BasicConfigurator::configure();
|
---|
| 101 |
|
---|
| 102 | // set the global log level
|
---|
| 103 | {
|
---|
| 104 | log4cxx::LoggerPtr logger(log4cxx::Logger::getRootLogger());
|
---|
| 105 | logger->setLevel(log4cxx::Level::getDebug());
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | // set up again an individual level if you like
|
---|
| 109 | {
|
---|
| 110 | // log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("BaseOverlay"));
|
---|
| 111 | // logger->setLevel(log4cxx::Level::getInfo());
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
|
---|
| 115 | // DON'T SVN COMMIT YOUR CHANTED LOGGING! THE ABOVE CODE MUST REMAIN AS IS!
|
---|
| 116 | //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | void StartupWrapper::initConfig(string filename){
|
---|
| 120 | configurations.push( filename );
|
---|
| 121 | Configuration::setConfigFilename( filename );
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | void StartupWrapper::startup(StartupInterface* service, bool block){
|
---|
| 125 |
|
---|
| 126 | StartupWrapper* startup = new StartupWrapper(service, block);
|
---|
| 127 |
|
---|
| 128 | #ifdef UNDERLAY_OMNET
|
---|
| 129 | SystemQueue::instance().scheduleEvent(
|
---|
| 130 | SystemEvent( startup, StartupWrapperEventType, NULL), 0 );
|
---|
| 131 | #else
|
---|
| 132 | SystemQueue::instance().scheduleEvent(
|
---|
| 133 | SystemEvent( startup, StartupWrapperEventType, NULL), 0 );
|
---|
| 134 |
|
---|
| 135 | if( block ) getchar();
|
---|
| 136 | #endif
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | void StartupWrapper::handleSystemEvent(const SystemEvent& event){
|
---|
| 140 |
|
---|
| 141 | string config = configurations.front();
|
---|
| 142 | configurations.pop();
|
---|
| 143 | Configuration::setConfigFilename( config );
|
---|
| 144 |
|
---|
| 145 | //
|
---|
| 146 | // start the actual application
|
---|
| 147 | //
|
---|
| 148 |
|
---|
| 149 | // TODO: im falle von omnet ist service = null, da von SpoVNetOmnetModule so ÃŒbergeben
|
---|
| 150 | // wie wird im Falle von omnet die anwendung erstellt?
|
---|
| 151 |
|
---|
| 152 | service->startup();
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | void StartupWrapper::shutdown(StartupInterface* service){
|
---|
| 156 | #ifdef UNDERLAY_OMNET
|
---|
| 157 | //TODO: service->shutdown();
|
---|
| 158 | #endif
|
---|
| 159 |
|
---|
| 160 | service->shutdown();
|
---|
| 161 | SystemQueue::instance().cancel();
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | }} // namespace ariba, utility
|
---|