$treeview $search $mathjax
00001 // ////////////////////////////////////////////////////////////////////// 00002 // Import section 00003 // ////////////////////////////////////////////////////////////////////// 00004 // STL 00005 #include <cassert> 00006 #include <sstream> 00007 #include <fstream> 00008 #include <vector> 00009 #include <list> 00010 #include <string> 00011 // //// Boost (Extended STL) //// 00012 // Boost Program Options 00013 #include <boost/program_options.hpp> 00014 // StdAir 00015 #include <stdair/stdair_basic_types.hpp> 00016 #include <stdair/basic/ProgressStatusSet.hpp> 00017 #include <stdair/bom/EventStruct.hpp> 00018 #include <stdair/bom/BomDisplay.hpp> 00019 #include <stdair/service/Logger.hpp> 00020 #include <stdair/bom/BookingRequestStruct.hpp> 00021 #include <stdair/bom/BookingRequestTypes.hpp> 00022 #include <stdair/bom/EventStruct.hpp> 00023 // SEvMgr 00024 #include <sevmgr/SEVMGR_Service.hpp> 00025 #include <sevmgr/config/sevmgr-paths.hpp> 00026 00027 // //////// Constants ////// 00029 const stdair::Filename_T K_SEVMGR_DEFAULT_LOG_FILENAME ("sevmgr_demo.log"); 00030 00032 const int K_SEVMGR_EARLY_RETURN_STATUS = 99; 00033 00034 00035 // ///////// Parsing of Options & Configuration ///////// 00037 int readConfiguration (int argc, char* argv[], 00038 stdair::Filename_T& ioLogFilename) { 00039 00040 // Declare a group of options that will be allowed only on command line 00041 boost::program_options::options_description generic ("Generic options"); 00042 generic.add_options() 00043 ("prefix", "print installation prefix") 00044 ("version,v", "print version string") 00045 ("help,h", "produce help message"); 00046 00047 // Declare a group of options that will be allowed both on command 00048 // line and in config file 00049 boost::program_options::options_description config ("Configuration"); 00050 config.add_options() 00051 ("log,l", 00052 boost::program_options::value< std::string >(&ioLogFilename)->default_value(K_SEVMGR_DEFAULT_LOG_FILENAME), 00053 "Filepath for the logs") 00054 ; 00055 00056 // Hidden options, will be allowed both on command line and 00057 // in config file, but will not be shown to the user. 00058 boost::program_options::options_description hidden ("Hidden options"); 00059 hidden.add_options() 00060 ("copyright", 00061 boost::program_options::value< std::vector<std::string> >(), 00062 "Show the copyright (license)"); 00063 00064 boost::program_options::options_description cmdline_options; 00065 cmdline_options.add(generic).add(config).add(hidden); 00066 00067 boost::program_options::options_description config_file_options; 00068 config_file_options.add(config).add(hidden); 00069 00070 boost::program_options::options_description visible ("Allowed options"); 00071 visible.add(generic).add(config); 00072 00073 boost::program_options::positional_options_description p; 00074 p.add ("copyright", -1); 00075 00076 boost::program_options::variables_map vm; 00077 boost::program_options:: 00078 store (boost::program_options::command_line_parser (argc, argv). 00079 options (cmdline_options).positional(p).run(), vm); 00080 00081 std::ifstream ifs ("sevmgr.cfg"); 00082 boost::program_options::store (parse_config_file (ifs, config_file_options), 00083 vm); 00084 boost::program_options::notify (vm); 00085 00086 if (vm.count ("help")) { 00087 std::cout << visible << std::endl; 00088 return K_SEVMGR_EARLY_RETURN_STATUS; 00089 } 00090 00091 if (vm.count ("version")) { 00092 std::cout << PACKAGE_NAME << ", version " << PACKAGE_VERSION << std::endl; 00093 return K_SEVMGR_EARLY_RETURN_STATUS; 00094 } 00095 00096 if (vm.count ("prefix")) { 00097 std::cout << "Installation prefix: " << PREFIXDIR << std::endl; 00098 return K_SEVMGR_EARLY_RETURN_STATUS; 00099 } 00100 00101 if (vm.count ("log")) { 00102 ioLogFilename = vm["log"].as< std::string >(); 00103 std::cout << "Log filename is: " << ioLogFilename << std::endl; 00104 } 00105 00106 return 0; 00107 } 00108 00109 00110 // /////////////// M A I N ///////////////// 00111 int main (int argc, char* argv[]) { 00112 00113 // Output log File 00114 stdair::Filename_T lLogFilename; 00115 00116 // Call the command-line option parser 00117 const int lOptionParserStatus = readConfiguration (argc, argv, lLogFilename); 00118 00119 if (lOptionParserStatus == K_SEVMGR_EARLY_RETURN_STATUS) { 00120 return 0; 00121 } 00122 00123 // Set the log parameters 00124 std::ofstream logOutputFile; 00125 // Open and clean the log outputfile 00126 logOutputFile.open (lLogFilename.c_str()); 00127 logOutputFile.clear(); 00128 00129 // Set up the log parameters 00130 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile); 00131 00135 SEVMGR::SEVMGR_Service sevmgrService (lLogParams); 00136 00137 // Build the default sample queue. 00138 STDAIR_LOG_DEBUG ("Build the default sample queue."); 00139 sevmgrService.buildSampleQueue(); 00140 00147 stdair::Count_T idx = 1; 00148 while (sevmgrService.isQueueDone() == false) { 00149 00150 // Pop the next event out of the event queue 00151 stdair::EventStruct lEventStruct; 00152 const stdair::ProgressStatusSet lPPS = 00153 sevmgrService.popEvent (lEventStruct); 00154 00155 // DEBUG 00156 STDAIR_LOG_DEBUG ("Poped event "<< idx << ": '" 00157 << lEventStruct.describe() << "'."); 00158 STDAIR_LOG_DEBUG ("Progresss status: " << lPPS.describe()); 00159 00160 // Iterate 00161 ++idx; 00162 } 00163 00164 // DEBUG 00165 STDAIR_LOG_DEBUG ("End of the simulation"); 00166 00167 // Close the Log outputFile 00168 logOutputFile.close(); 00169 00170 /* 00171 Note: as that program is not intended to be run on a server in 00172 production, it is better not to catch the exceptions. When it 00173 happens (that an exception is throwned), that way we get the 00174 call stack. 00175 */ 00176 00177 return 0; 00178 }