| 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 | #include "StartupWrapper.h"
|
---|
| 40 | #include "ariba/config.h"
|
---|
| 41 |
|
---|
| 42 | namespace ariba {
|
---|
| 43 | namespace utility {
|
---|
| 44 |
|
---|
| 45 | StartupWrapper::ConfigurationList StartupWrapper::configurations;
|
---|
| 46 | #ifdef UNDERLAY_OMNET
|
---|
| 47 | StartupWrapper::ModuleList StartupWrapper::modules;
|
---|
| 48 | #endif
|
---|
| 49 |
|
---|
| 50 | SystemEventType StartupWrapperEventStartup("StartupWrapperEventStartup");
|
---|
| 51 |
|
---|
| 52 | StartupWrapper::StartupWrapper(StartupInterface* _service) : 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::startSystem(){
|
---|
| 76 |
|
---|
| 77 | //
|
---|
| 78 | // having seeded the pseudo rng is always good
|
---|
| 79 | //
|
---|
| 80 |
|
---|
| 81 | srand( time(NULL) );
|
---|
| 82 |
|
---|
| 83 | //
|
---|
| 84 | // init the system queue
|
---|
| 85 | //
|
---|
| 86 |
|
---|
| 87 | if( ! SystemQueue::instance().isRunning() )
|
---|
| 88 | SystemQueue::instance().run();
|
---|
| 89 |
|
---|
| 90 | //
|
---|
| 91 | // init the logging system
|
---|
| 92 | //
|
---|
| 93 | // configure the logging
|
---|
| 94 | //
|
---|
| 95 |
|
---|
| 96 | log4cxx::BasicConfigurator::configure();
|
---|
| 97 |
|
---|
| 98 | // set the global log level
|
---|
| 99 | {
|
---|
| 100 | log4cxx::LoggerPtr logger(log4cxx::Logger::getRootLogger());
|
---|
| 101 | logger->setLevel(log4cxx::Level::getWarn());
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | // set up again an individual level if you like
|
---|
| 105 |
|
---|
| 106 | {
|
---|
| 107 | log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("MCPO"));
|
---|
| 108 | logger->setLevel(log4cxx::Level::getDebug());
|
---|
| 109 | }/*
|
---|
| 110 | {
|
---|
| 111 | log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("BaseCommunication"));
|
---|
| 112 | logger->setLevel(log4cxx::Level::getDebug());
|
---|
| 113 | }
|
---|
| 114 | {
|
---|
| 115 | log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("OverlayBootstrap"));
|
---|
| 116 | logger->setLevel(log4cxx::Level::getDebug());
|
---|
| 117 | }
|
---|
| 118 | {
|
---|
| 119 | log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("BootstrapManager"));
|
---|
| 120 | logger->setLevel(log4cxx::Level::getDebug());
|
---|
| 121 | }
|
---|
| 122 | {
|
---|
| 123 | log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("BluetoothSdp"));
|
---|
| 124 | logger->setLevel(log4cxx::Level::getDebug());
|
---|
| 125 | }
|
---|
| 126 | {
|
---|
| 127 | log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("Chord"));
|
---|
| 128 | logger->setLevel(log4cxx::Level::getInfo());
|
---|
| 129 | }
|
---|
| 130 | {
|
---|
| 131 | log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("BaseOverlay"));
|
---|
| 132 | logger->setLevel(log4cxx::Level::getInfo());
|
---|
| 133 | }
|
---|
| 134 | */
|
---|
| 135 | //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
|
---|
| 136 | // DON'T SVN COMMIT YOUR CHANGED LOGGING! THE ABOVE CODE MUST REMAIN AS IS!
|
---|
| 137 | //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
|
---|
| 138 |
|
---|
| 139 | #ifdef HAVE_MAEMO
|
---|
| 140 | log4cxx::LoggerPtr logger(log4cxx::Logger::getRootLogger());
|
---|
| 141 | logger->setLevel(log4cxx::Level::getWarn());
|
---|
| 142 | #endif
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | void StartupWrapper::stopSystem(){
|
---|
| 146 | SystemQueue::instance().cancel();
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | void StartupWrapper::initConfig(string filename){
|
---|
| 150 | configurations.push( filename );
|
---|
| 151 | Configuration::setConfigFilename( filename );
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | void StartupWrapper::handleSystemEvent(const SystemEvent& event){
|
---|
| 155 |
|
---|
| 156 | if( event.getType() == StartupWrapperEventStartup ){
|
---|
| 157 |
|
---|
| 158 | string config = configurations.front();
|
---|
| 159 | configurations.pop();
|
---|
| 160 | Configuration::setConfigFilename( config );
|
---|
| 161 |
|
---|
| 162 | //
|
---|
| 163 | // start the actual application
|
---|
| 164 | //
|
---|
| 165 |
|
---|
| 166 | // TODO: im falle von omnet ist service = null, da von SpoVNetOmnetModule so ÃŒbergeben
|
---|
| 167 | // wie wird im Falle von omnet die anwendung erstellt?
|
---|
| 168 |
|
---|
| 169 | service->startup();
|
---|
| 170 |
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | void StartupWrapper::startup(StartupInterface* service, bool block){
|
---|
| 176 |
|
---|
| 177 | StartupWrapper* startup = new StartupWrapper(service);
|
---|
| 178 | service->wrapper = startup;
|
---|
| 179 |
|
---|
| 180 | SystemQueue::instance().scheduleEvent(
|
---|
| 181 | SystemEvent( startup, StartupWrapperEventStartup, NULL), 0 );
|
---|
| 182 |
|
---|
| 183 | #ifndef UNDERLAY_OMNET
|
---|
| 184 | if( block ) getchar();
|
---|
| 185 | #endif
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | void StartupWrapper::shutdown(StartupInterface* service, bool block){
|
---|
| 189 |
|
---|
| 190 | if( service == NULL || service->wrapper == NULL ) return;
|
---|
| 191 |
|
---|
| 192 | #ifdef UNDERLAY_OMNET
|
---|
| 193 | //TODO: service->shutdown();
|
---|
| 194 | #endif
|
---|
| 195 |
|
---|
| 196 | if(block){
|
---|
| 197 | // call directly
|
---|
| 198 | service->shutdown();
|
---|
| 199 | }else{
|
---|
| 200 | // call async, but not using systemqueue! // TODO: mem leak
|
---|
| 201 | AsyncShutdown* async = new AsyncShutdown(service);
|
---|
| 202 | async->runBlockingMethod();
|
---|
| 203 | }
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | StartupWrapper::AsyncShutdown::AsyncShutdown(StartupInterface* _service)
|
---|
| 207 | : service(_service){
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | void StartupWrapper::AsyncShutdown::blockingFunction(){
|
---|
| 211 | service->shutdown();
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | void StartupWrapper::AsyncShutdown::dispatchFunction(){
|
---|
| 215 | //unused
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | }} // namespace ariba, utility
|
---|