SEvMgr Logo  1.00.8
C++ Simulation-Oriented Discrete Event Management Library
Loading...
Searching...
No Matches
pysevmgr.cpp
Go to the documentation of this file.
1// STL
2#include <cassert>
3#include <stdexcept>
4#include <fstream>
5#include <sstream>
6#include <string>
7#include <list>
8#include <vector>
9// Boost String
10#include <boost/python.hpp>
11// StdAir
12#include <stdair/stdair_basic_types.hpp>
13#include <stdair/stdair_exceptions.hpp>
14#include <stdair/basic/BasFileMgr.hpp>
15#include <stdair/basic/BasLogParams.hpp>
16#include <stdair/basic/BasDBParams.hpp>
17// SEvMgr
19
20namespace SEVMGR {
21
23 public:
25 std::string sevmgr() {
26 std::ostringstream oStream;
27
28 // Sanity check
29 if (_logOutputStream == NULL) {
30 oStream << "The log filepath is not valid." << std::endl;
31 return oStream.str();
32 }
33 assert (_logOutputStream != NULL);
34
35 try {
36
37 // DEBUG
38 *_logOutputStream << "Default service" << std::endl;
39
40 if (_sevmgrService == NULL) {
41 oStream << "The Sevmgr service has not been initialised, "
42 << "i.e., the init() method has not been called "
43 << "correctly on the PYEventQueueManager object. Please "
44 << "check that all the parameters are not empty and "
45 << "point to actual files.";
46 *_logOutputStream << oStream.str();
47 return oStream.str();
48 }
49 assert (_sevmgrService != NULL);
50
51 // Do the sevmgr
52 _sevmgrService->buildSampleBom();
53
54 // DEBUG
55 *_logOutputStream << "Default service returned" << std::endl;
56
57 // DEBUG
58 *_logOutputStream << "Sevmgr output: " << oStream.str() << std::endl;
59
60 } catch (const stdair::RootException& eSevmgrError) {
61 *_logOutputStream << "Sevmgr error: " << eSevmgrError.what()
62 << std::endl;
63
64 } catch (const std::exception& eStdError) {
65 *_logOutputStream << "Error: " << eStdError.what() << std::endl;
66
67 } catch (...) {
68 *_logOutputStream << "Unknown error" << std::endl;
69 }
70
71 return oStream.str();
72 }
73
74 public:
76 PYEventQueueManager() : _sevmgrService (NULL), _logOutputStream (NULL) {
77 }
78
80 PYEventQueueManager (const PYEventQueueManager& iPYEventQueueManager)
81 : _sevmgrService (iPYEventQueueManager._sevmgrService),
82 _logOutputStream (iPYEventQueueManager._logOutputStream) {
83 }
84
87 _sevmgrService = NULL;
88 _logOutputStream = NULL;
89 }
90
92 bool init (const std::string& iLogFilepath,
93 const std::string& iDBUser, const std::string& iDBPasswd,
94 const std::string& iDBHost, const std::string& iDBPort,
95 const std::string& iDBDBName) {
96 bool isEverythingOK = true;
97
98 try {
99
100 // Check that the file path given as input corresponds to an actual file
101 const bool isWriteable = (iLogFilepath.empty() == false);
102 // stdair::BasFileMgr::isWriteable (iLogFilepath);
103 if (isWriteable == false) {
104 isEverythingOK = false;
105 return isEverythingOK;
106 }
107
108 // Set the log parameters
109 _logOutputStream = new std::ofstream;
110 assert (_logOutputStream != NULL);
111
112 // Open and clean the log outputfile
113 _logOutputStream->open (iLogFilepath.c_str());
114 _logOutputStream->clear();
115
116 // DEBUG
117 *_logOutputStream << "Python wrapper initialisation" << std::endl;
118 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG,
119 *_logOutputStream);
120
121 // Initialise the context
122 stdair::BasDBParams lDBParams (iDBUser, iDBPasswd, iDBHost, iDBPort,
123 iDBDBName);
124 _sevmgrService = new SEVMGR_Service (lLogParams, lDBParams);
125
126 // DEBUG
127 *_logOutputStream << "Python wrapper initialised" << std::endl;
128
129 } catch (const stdair::RootException& eSevmgrError) {
130 *_logOutputStream << "Sevmgr error: " << eSevmgrError.what()
131 << std::endl;
132
133 } catch (const std::exception& eStdError) {
134 *_logOutputStream << "Error: " << eStdError.what() << std::endl;
135
136 } catch (...) {
137 *_logOutputStream << "Unknown error" << std::endl;
138 }
139
140 return isEverythingOK;
141 }
142
143 private:
145 SEVMGR_Service* _sevmgrService;
146 std::ofstream* _logOutputStream;
147 };
148
149}
150
151// /////////////////////////////////////////////////////////////
153 boost::python::class_<SEVMGR::PYEventQueueManager> ("PYEventQueueManager")
155 .def ("init", &SEVMGR::PYEventQueueManager::init);
156}
class holding the services related to Travel Demand Generation.
BOOST_PYTHON_MODULE(libpysevmgr)
Definition pysevmgr.cpp:152
bool init(const std::string &iLogFilepath, const std::string &iDBUser, const std::string &iDBPasswd, const std::string &iDBHost, const std::string &iDBPort, const std::string &iDBDBName)
Definition pysevmgr.cpp:92
PYEventQueueManager(const PYEventQueueManager &iPYEventQueueManager)
Definition pysevmgr.cpp:80