| 1 | // [License]
|
---|
| 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 | // [License]
|
---|
| 38 |
|
---|
| 39 | // XXX NOTE: Use this class with caution! Config support is outdated.
|
---|
| 40 |
|
---|
| 41 | #include "StartupWrapper.h"
|
---|
| 42 | #include "ariba/config.h"
|
---|
| 43 |
|
---|
| 44 | #ifdef HAVE_LOG4CXX
|
---|
| 45 | #include <log4cxx/logger.h>
|
---|
| 46 | #include <log4cxx/basicconfigurator.h>
|
---|
| 47 | #endif // HAVE_LOG4CXX
|
---|
| 48 |
|
---|
| 49 | namespace ariba {
|
---|
| 50 | namespace utility {
|
---|
| 51 |
|
---|
| 52 | StartupWrapper::ConfigurationList StartupWrapper::configurations;
|
---|
| 53 | #ifdef UNDERLAY_OMNET
|
---|
| 54 | StartupWrapper::ModuleList StartupWrapper::modules;
|
---|
| 55 | #endif
|
---|
| 56 |
|
---|
| 57 | SystemEventType StartupWrapperEventStartup("StartupWrapperEventStartup");
|
---|
| 58 |
|
---|
| 59 | StartupWrapper::StartupWrapper(StartupInterface* _service) : service( _service ){
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | StartupWrapper::~StartupWrapper(){
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | #ifdef UNDERLAY_OMNET
|
---|
| 66 | void StartupWrapper::insertCurrentModule(AribaOmnetModule* mod){
|
---|
| 67 | modules.push( mod );
|
---|
| 68 | }
|
---|
| 69 | #endif
|
---|
| 70 |
|
---|
| 71 | #ifdef UNDERLAY_OMNET
|
---|
| 72 | AribaOmnetModule* StartupWrapper::getCurrentModule(){
|
---|
| 73 | assert( modules.size() > 0 );
|
---|
| 74 |
|
---|
| 75 | AribaOmnetModule* ret = modules.front();
|
---|
| 76 | modules.pop();
|
---|
| 77 |
|
---|
| 78 | return ret;
|
---|
| 79 | }
|
---|
| 80 | #endif
|
---|
| 81 |
|
---|
| 82 | void StartupWrapper::startSystem(){
|
---|
| 83 |
|
---|
| 84 | //
|
---|
| 85 | // having seeded the pseudo rng is always good
|
---|
| 86 | //
|
---|
| 87 |
|
---|
| 88 | srand( time(NULL) );
|
---|
| 89 |
|
---|
| 90 | //
|
---|
| 91 | // init the system queue
|
---|
| 92 | //
|
---|
| 93 |
|
---|
| 94 | if( ! SystemQueue::instance().isRunning() )
|
---|
| 95 | SystemQueue::instance().run();
|
---|
| 96 |
|
---|
| 97 | //
|
---|
| 98 | // init the logging system
|
---|
| 99 | //
|
---|
| 100 |
|
---|
| 101 | #ifdef HAVE_LOG4CXX
|
---|
| 102 | log4cxx::BasicConfigurator::configure();
|
---|
| 103 | #endif //HAVE_LOG4CXX
|
---|
| 104 |
|
---|
| 105 | //
|
---|
| 106 | // configure the default logging level to info
|
---|
| 107 | //
|
---|
| 108 |
|
---|
| 109 | logging_rootlevel_info();
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | void StartupWrapper::stopSystem(){
|
---|
| 113 | SystemQueue::instance().cancel();
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | void StartupWrapper::initConfig(string filename){
|
---|
| 117 | configurations.push( filename );
|
---|
| 118 | Configuration::setConfigFilename( filename );
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | void StartupWrapper::handleSystemEvent(const SystemEvent& event){
|
---|
| 122 |
|
---|
| 123 | if( event.getType() == StartupWrapperEventStartup ){
|
---|
| 124 |
|
---|
| 125 | if(!configurations.empty()){
|
---|
| 126 | string config = configurations.front();
|
---|
| 127 | configurations.pop();
|
---|
| 128 | Configuration::setConfigFilename( config );
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | //
|
---|
| 132 | // start the actual application
|
---|
| 133 | //
|
---|
| 134 |
|
---|
| 135 | // TODO: im falle von omnet ist service = null, da von SpoVNetOmnetModule so ÃŒbergeben
|
---|
| 136 | // wie wird im Falle von omnet die anwendung erstellt?
|
---|
| 137 |
|
---|
| 138 | service->startup();
|
---|
| 139 |
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | void StartupWrapper::startup(StartupInterface* service, bool block){
|
---|
| 145 |
|
---|
| 146 | StartupWrapper* startup = new StartupWrapper(service);
|
---|
| 147 | service->wrapper = startup;
|
---|
| 148 |
|
---|
| 149 | SystemQueue::instance().scheduleEvent(
|
---|
| 150 | SystemEvent( startup, StartupWrapperEventStartup, NULL), 0 );
|
---|
| 151 |
|
---|
| 152 | #ifndef UNDERLAY_OMNET
|
---|
| 153 | if( block ) getchar();
|
---|
| 154 | #endif
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | void StartupWrapper::shutdown(StartupInterface* service, bool block){
|
---|
| 158 |
|
---|
| 159 | if( service == NULL || service->wrapper == NULL ) return;
|
---|
| 160 |
|
---|
| 161 | #ifdef UNDERLAY_OMNET
|
---|
| 162 | //TODO: service->shutdown();
|
---|
| 163 | #endif
|
---|
| 164 |
|
---|
| 165 | if(block){
|
---|
| 166 | // call directly
|
---|
| 167 | service->shutdown();
|
---|
| 168 | }else{
|
---|
| 169 | // call async, but not using systemqueue! // TODO: mem leak
|
---|
| 170 | AsyncShutdown* async = new AsyncShutdown(service);
|
---|
| 171 | async->runBlockingMethod();
|
---|
| 172 | }
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | StartupWrapper::AsyncShutdown::AsyncShutdown(StartupInterface* _service)
|
---|
| 176 | : service(_service){
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | void StartupWrapper::AsyncShutdown::blockingFunction(){
|
---|
| 180 | service->shutdown();
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | void StartupWrapper::AsyncShutdown::dispatchFunction(){
|
---|
| 184 | //unused
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | }} // namespace ariba, utility
|
---|