SEvMgr Logo  0.2.0
C++ Simulation-Oriented Discrete Event Management Library
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
SEVMGR_Service.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <sstream>
7 // Boost
8 #include <boost/make_shared.hpp>
9 // StdAir
10 #include <stdair/basic/BasChronometer.hpp>
11 #include <stdair/basic/BasConst_General.hpp>
12 #include <stdair/bom/BomRoot.hpp>
13 #include <stdair/bom/BomDisplay.hpp>
14 #include <stdair/bom/EventStruct.hpp>
15 #include <stdair/bom/EventQueue.hpp>
16 #include <stdair/service/Logger.hpp>
17 #include <stdair/STDAIR_Service.hpp>
18 // Sevmgr
24 
25 namespace SEVMGR {
26 
27  // //////////////////////////////////////////////////////////////////////
28  SEVMGR_Service::SEVMGR_Service() : _sevmgrServiceContext (NULL) {
29  assert (false);
30  }
31 
32  // //////////////////////////////////////////////////////////////////////
33  SEVMGR_Service::SEVMGR_Service (const SEVMGR_Service& iService)
34  : _sevmgrServiceContext (NULL) {
35  assert (false);
36  }
37 
38  // //////////////////////////////////////////////////////////////////////
39  SEVMGR_Service::SEVMGR_Service (const stdair::BasLogParams& iLogParams,
40  const stdair::BasDBParams& iDBParams)
41  : _sevmgrServiceContext (NULL) {
42 
43  // Initialise the STDAIR service handler
44  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
45  initStdAirService (iLogParams, iDBParams);
46 
47  // Initialise the service context
48  initServiceContext();
49 
50  // Add the StdAir service context to the SEVMGR service context
51  // \note SEVMGR owns the STDAIR service resources here.
52  const bool ownStdairService = true;
53  addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
54 
55  // Initialise the (remaining of the) context
56  initSevmgrService();
57  }
58 
59  // //////////////////////////////////////////////////////////////////////
60  SEVMGR_Service::SEVMGR_Service (const stdair::BasLogParams& iLogParams)
61  : _sevmgrServiceContext (NULL) {
62 
63  // Initialise the STDAIR service handler
64  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
65  initStdAirService (iLogParams);
66 
67  // Initialise the service context
68  initServiceContext();
69 
70  // Add the StdAir service context to the SEVMGR service context
71  // \note SEVMGR owns the STDAIR service resources here.
72  const bool ownStdairService = true;
73  addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
74 
75  // Initialise the (remaining of the) context
76  initSevmgrService();
77  }
78 
79  // ////////////////////////////////////////////////////////////////////
80  SEVMGR_Service::
81  SEVMGR_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr)
82  : _sevmgrServiceContext (NULL) {
83 
84  // Initialise the service context
85  initServiceContext();
86 
87  // Add the StdAir service context to the SEVMGR service context
88  // \note Sevmgr does not own the STDAIR service resources here.
89  const bool doesNotOwnStdairService = false;
90  addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
91 
92  // Initialise the context
93  initSevmgrService();
94  }
95 
96  // //////////////////////////////////////////////////////////////////////
98  // Delete/Clean all the objects from memory
99  finalise();
100  }
101 
102  // ////////////////////////////////////////////////////////////////////
103  void SEVMGR_Service::finalise() {
104  assert (_sevmgrServiceContext != NULL);
105  // Reset the (Boost.)Smart pointer pointing on the STDAIR_Service object.
106  _sevmgrServiceContext->reset();
107  }
108 
109  // //////////////////////////////////////////////////////////////////////
110  void SEVMGR_Service::initServiceContext() {
111  // Initialise the service context
112  SEVMGR_ServiceContext& lSEVMGR_ServiceContext =
114  _sevmgrServiceContext = &lSEVMGR_ServiceContext;
115  }
116 
117  // ////////////////////////////////////////////////////////////////////
118  void SEVMGR_Service::
119  addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
120  const bool iOwnStdairService) {
121  // Retrieve the Sevmgr service context
122  assert (_sevmgrServiceContext != NULL);
123  SEVMGR_ServiceContext& lSEVMGR_ServiceContext =
124  *_sevmgrServiceContext;
125 
126  // Store the STDAIR service object within the (SEVMGR) service context
127  lSEVMGR_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
128  iOwnStdairService);
129  }
130 
131  // //////////////////////////////////////////////////////////////////////
132  stdair::STDAIR_ServicePtr_T SEVMGR_Service::
133  initStdAirService (const stdair::BasLogParams& iLogParams,
134  const stdair::BasDBParams& iDBParams) {
135 
141  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
142  boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
143  assert (lSTDAIR_Service_ptr != NULL);
144 
145  return lSTDAIR_Service_ptr;
146  }
147 
148  // //////////////////////////////////////////////////////////////////////
149  stdair::STDAIR_ServicePtr_T SEVMGR_Service::
150  initStdAirService (const stdair::BasLogParams& iLogParams) {
151 
157  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
158  boost::make_shared<stdair::STDAIR_Service> (iLogParams);
159  assert (lSTDAIR_Service_ptr != NULL);
160 
161  return lSTDAIR_Service_ptr;
162  }
163 
164  // //////////////////////////////////////////////////////////////////////
165  void SEVMGR_Service::initSevmgrService() {
166  // Do nothing at this stage. A sample BOM tree may be built by
167  // calling the buildSampleBom() method
168  }
169 
170  // ////////////////////////////////////////////////////////////////////
172 
173  // Retrieve the Sevmgr service context
174  if (_sevmgrServiceContext == NULL) {
175  throw stdair::NonInitialisedServiceException ("The Sevmgr service has "
176  "not been initialised");
177  }
178  assert (_sevmgrServiceContext != NULL);
179 
180  //SEVMGR_ServiceContext& lSEVMGR_ServiceContext = *_sevmgrServiceContext;
181 
182  // Retrieve the STDAIR service object from the (Sevmgr) service context
183  //stdair::STDAIR_Service& lSTDAIR_Service =
184  // lSEVMGR_ServiceContext.getSTDAIR_Service();
185 
186  // Retrieve the event queue
187  //stdair::EventQueue& lEventQueue = lSTDAIR_Service.getEventQueue();
188  }
189 
190  // //////////////////////////////////////////////////////////////////////
191  std::string SEVMGR_Service::csvDisplay() const {
192 
193  // Retrieve the Sevmgr service context
194  if (_sevmgrServiceContext == NULL) {
195  throw stdair::NonInitialisedServiceException ("The Sevmgr service has "
196  "not been initialised");
197  }
198  assert (_sevmgrServiceContext != NULL);
199 
200  SEVMGR_ServiceContext& lSEVMGR_ServiceContext = *_sevmgrServiceContext;
201 
202  // Retrieve the STDAIR service object from the (Sevmgr) service context
203  stdair::STDAIR_Service& lSTDAIR_Service =
204  lSEVMGR_ServiceContext.getSTDAIR_Service();
205 
206  // Retrieve the event queue
207  stdair::EventQueue& lEventQueue = lSTDAIR_Service.getEventQueue();
208 
209  // Delegate the BOM building to the dedicated service
210  return stdair::BomDisplay::csvDisplay (lEventQueue);
211  }
212 
213  // ////////////////////////////////////////////////////////////////////
214  stdair::ProgressStatusSet SEVMGR_Service::
215  popEvent (stdair::EventStruct& ioEventStruct) const {
216 
217  // Retrieve the Sevmgr service context
218  assert (_sevmgrServiceContext != NULL);
219  SEVMGR_ServiceContext& lSEVMGR_ServiceContext = *_sevmgrServiceContext;
220 
221  // Retrieve the StdAir service context
222  stdair::STDAIR_Service& lSTDAIR_Service =
223  lSEVMGR_ServiceContext.getSTDAIR_Service();
224 
225  // Retrieve the event queue object instance
226  stdair::EventQueue& lQueue = lSTDAIR_Service.getEventQueue();
227 
228  // Extract the next event from the queue
229  return lQueue.popEvent (ioEventStruct);
230  }
231 
232  // ////////////////////////////////////////////////////////////////////
234 
235  // Retrieve the Sevmgr service context
236  assert (_sevmgrServiceContext != NULL);
237  SEVMGR_ServiceContext& lSEVMGR_ServiceContext =
238  *_sevmgrServiceContext;
239 
240  // Retrieve the StdAir service context
241  stdair::STDAIR_Service& lSTDAIR_Service =
242  lSEVMGR_ServiceContext.getSTDAIR_Service();
243 
244  // Retrieve the event queue object instance
245  const stdair::EventQueue& lQueue = lSTDAIR_Service.getEventQueue();
246 
247  // Calculates whether the event queue has been fully emptied
248  const bool isQueueDone = lQueue.isQueueDone();
249 
250  //
251  return isQueueDone;
252  }
253 
254  // ////////////////////////////////////////////////////////////////////
255  void SEVMGR_Service::reset() const {
256 
257  // Retrieve the Sevmgr service context
258  assert (_sevmgrServiceContext != NULL);
259  SEVMGR_ServiceContext& lSEVMGR_ServiceContext =
260  *_sevmgrServiceContext;
261 
262  // Retrieve the StdAir service context
263  stdair::STDAIR_Service& lSTDAIR_Service =
264  lSEVMGR_ServiceContext.getSTDAIR_Service();
265  // Retrieve the event queue object instance
266  stdair::EventQueue& lQueue = lSTDAIR_Service.getEventQueue();
267 
268  // Delegate the call to the dedicated command
269  EventQueueManager::reset (lQueue);
270  }
271 }