source: source/ariba/utility/system/StartupWrapper.cpp@ 7500

Last change on this file since 7500 was 5993, checked in by Christoph Mayer, 15 years ago

sigcomm release

File size: 4.8 KB
Line 
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
42namespace ariba {
43namespace utility {
44
45StartupWrapper::ConfigurationList StartupWrapper::configurations;
46#ifdef UNDERLAY_OMNET
47StartupWrapper::ModuleList StartupWrapper::modules;
48#endif
49
50SystemEventType StartupWrapperEventStartup("StartupWrapperEventStartup");
51
52StartupWrapper::StartupWrapper(StartupInterface* _service) : service( _service ){
53}
54
55StartupWrapper::~StartupWrapper(){
56}
57
58#ifdef UNDERLAY_OMNET
59void StartupWrapper::insertCurrentModule(AribaOmnetModule* mod){
60 modules.push( mod );
61}
62#endif
63
64#ifdef UNDERLAY_OMNET
65AribaOmnetModule* StartupWrapper::getCurrentModule(){
66 assert( modules.size() > 0 );
67
68 AribaOmnetModule* ret = modules.front();
69 modules.pop();
70
71 return ret;
72}
73#endif
74
75void 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 to warning
99 {
100 log4cxx::LoggerPtr logger(log4cxx::Logger::getRootLogger());
101 logger->setLevel(log4cxx::Level::getInfo());
102 }
103
104 // set up again an individual level if you like
105#ifndef HAVE_MAEMO
106 {
107 //log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("MCPO"));
108 //logger->setLevel(log4cxx::Level::getDebug());
109 }
110#endif //HAVE_MAEMO
111}
112
113void StartupWrapper::stopSystem(){
114 SystemQueue::instance().cancel();
115}
116
117void StartupWrapper::initConfig(string filename){
118 configurations.push( filename );
119 Configuration::setConfigFilename( filename );
120}
121
122void StartupWrapper::handleSystemEvent(const SystemEvent& event){
123
124 if( event.getType() == StartupWrapperEventStartup ){
125
126 string config = configurations.front();
127 configurations.pop();
128 Configuration::setConfigFilename( config );
129
130 //
131 // start the actual application
132 //
133
134 // TODO: im falle von omnet ist service = null, da von SpoVNetOmnetModule so ÃŒbergeben
135 // wie wird im Falle von omnet die anwendung erstellt?
136
137 service->startup();
138
139 }
140
141}
142
143void StartupWrapper::startup(StartupInterface* service, bool block){
144
145 StartupWrapper* startup = new StartupWrapper(service);
146 service->wrapper = startup;
147
148 SystemQueue::instance().scheduleEvent(
149 SystemEvent( startup, StartupWrapperEventStartup, NULL), 0 );
150
151#ifndef UNDERLAY_OMNET
152 if( block ) getchar();
153#endif
154}
155
156void StartupWrapper::shutdown(StartupInterface* service, bool block){
157
158 if( service == NULL || service->wrapper == NULL ) return;
159
160#ifdef UNDERLAY_OMNET
161 //TODO: service->shutdown();
162#endif
163
164 if(block){
165 // call directly
166 service->shutdown();
167 }else{
168 // call async, but not using systemqueue! // TODO: mem leak
169 AsyncShutdown* async = new AsyncShutdown(service);
170 async->runBlockingMethod();
171 }
172}
173
174StartupWrapper::AsyncShutdown::AsyncShutdown(StartupInterface* _service)
175 : service(_service){
176}
177
178void StartupWrapper::AsyncShutdown::blockingFunction(){
179 service->shutdown();
180}
181
182void StartupWrapper::AsyncShutdown::dispatchFunction(){
183 //unused
184}
185
186}} // namespace ariba, utility
Note: See TracBrowser for help on using the repository browser.