43 m_bBuildConfig(
false),
45 m_bContraintChecking(
false),
46 m_OutputDirectory(
"./")
49 const char*
const pOptions(
":absvc:o:h");
54 if (iNumberArguments > 0)
58 m_BinaryName = ppArguements[0];
62 if (iNumberArguments == 1)
68 m_ErrorMessage <<
"at least the XML model file is required as argument" << ::std::endl;
77 iOption = getopt(iNumberArguments, ppArguements, pOptions);
84 m_bBuildConfig =
true;
102 m_bBuildConfig =
true;
110 m_bContraintChecking =
true;
113 m_ContraintFile = optarg;
119 m_OutputDirectory = optarg;
134 m_ErrorMessage <<
"option -" << char(optopt) <<
" needs an operand" << ::std::endl;
143 m_ErrorMessage <<
"unknown option -" << char(optopt) << ::std::endl;
149 while (iOption != -1);
152 if (iOption == -1 && (optind == (iNumberArguments - 1) || iNumberArguments > 2))
155 m_XMLFile = ppArguements[iNumberArguments - 1];
161 m_ErrorMessage <<
"XML model file must always passed as argument" << ::std::endl;
194 ::std::fstream SourceFile;
195 ::std::fstream CMakeFile;
196 ::std::fstream PIMFile;
197 ::std::fstream PSMFile;
198 ::std::fstream ReportFile;
199 ::std::string FileNamePrefix;
200 ::std::string SourceFileName;
201 ::std::string CMakeFileName;
202 ::std::string PIMFileName;
203 ::std::string PSMFileName;
204 ::std::string ReportFileName;
227 ::std::cout <<
"Parsing XML model file...";
234 ::std::cout <<
"done" << ::std::endl;
240 FileNamePrefix = pRootGraph->
m_ID;
243 while (FileNamePrefix.find(
" ") != std::string::npos)
246 FileNamePrefix.replace(FileNamePrefix.find(
" "), 1,
"_");
253 if (FileNamePrefix.empty())
256 FileNamePrefix =
"openETCS";
267 SourceFileName += FileNamePrefix;
268 SourceFileName +=
".cpp";
271 SourceFile.open(SourceFileName, ::std::ios_base::out);
274 if (not SourceFile.is_open())
277 ::std::cout <<
"Could not open " << SourceFileName <<
" for source generation!" << ::std::endl;
285 ::std::cout <<
"generating C++ source file " << SourceFileName <<
"...";
292 ::std::cout <<
"done" << ::std::endl;
295 catch (const ::std::exception& Exception)
298 ::std::cout <<
"abort" << ::std::endl;
299 ::std::cerr << Exception.what() << ::std::endl;
319 CMakeFileName +=
"CMakeLists.txt";
322 CMakeFile.open(CMakeFileName, ::std::ios_base::out);
325 if (not CMakeFile.is_open())
328 ::std::cout <<
"Could not create " << CMakeFileName <<
" for build configuration generation!" << ::std::endl;
336 ::std::cout <<
"generating CMake build configuration file " << CMakeFileName <<
"...";
343 ::std::cout <<
"done" << ::std::endl;
346 catch (const ::std::exception& Exception)
349 ::std::cout <<
"abort" << ::std::endl;
350 ::std::cerr << Exception.what() << ::std::endl;
370 PIMFileName += FileNamePrefix;
371 PIMFileName +=
"_PIM";
372 PIMFileName +=
".cfg";
375 PIMFile.open(PIMFileName, ::std::ios_base::out);
378 if (not PIMFile.is_open())
381 ::std::cout <<
"Could not open " << PIMFileName <<
" for hypervisor configuration generation!" << ::std::endl;
389 ::std::cout <<
"generating Xen PIM config file " << PIMFileName <<
"...";
396 ::std::cout <<
"done" << ::std::endl;
399 catch (const ::std::exception& Exception)
402 ::std::cout <<
"abort" << ::std::endl;
403 ::std::cerr << Exception.what() << ::std::endl;
420 PSMFileName += FileNamePrefix;
421 PSMFileName +=
"_PSM";
422 PSMFileName +=
".cfg";
425 PSMFile.open(PSMFileName, ::std::ios_base::out);
428 if (not PSMFile.is_open())
431 ::std::cout <<
"Could not open " << PSMFileName <<
" for hypervisor configuration generation!" << ::std::endl;
439 ::std::cout <<
"generating Xen PSM config file " << PSMFileName <<
"...";
446 ::std::cout <<
"done" << ::std::endl;
449 catch (const ::std::exception& Exception)
452 ::std::cout <<
"abort" << ::std::endl;
453 ::std::cerr << Exception.what() << ::std::endl;
476 ReportFileName += FileNamePrefix;
477 ReportFileName +=
".log";
480 ReportFile.open(ReportFileName, ::std::ios_base::out);
483 if (not ReportFile.is_open())
486 ::std::cout <<
"Could not create " << ReportFileName <<
" for static semantics report generation!" << ::std::endl;
494 ::std::cout <<
"WARNING: OCL usage currently not supported! Using static constraint implementation!" << ::std::endl;
495 ::std::cout <<
"generating report for static semantics / model constraints " << ReportFileName <<
"...";
502 ::std::cout <<
"done" << ::std::endl;
505 catch (const ::std::exception& Exception)
508 ::std::cout <<
"abort" << ::std::endl;
509 ::std::cerr << Exception.what() << ::std::endl;
527 catch (const ::DSM::Error::CException& Exception)
530 ::std::cout <<
"abort" << ::std::endl;
531 ::std::cerr << Exception.what() << ::std::endl;
537 catch (const ::std::exception& Exception)
540 ::std::cerr << Exception.what() << ::std::endl;
549 ::std::cerr <<
"unhandled and unknown exception" << ::std::endl;
573 ::std::cout <<
"Usage: " <<
m_BinaryName <<
" -a | [ -b ] [ -s ] [ -v ] [ -c <constraints file> ] [-o <output directory> ] [ -h ] <XML model file>" << ::std::endl;
574 ::std::cout <<
" -b generate build configuration" << ::std::endl;
575 ::std::cout <<
" -s generate C++ source file" << ::std::endl;
576 ::std::cout <<
" -v generate Xen configuration file(s)" << ::std::endl;
577 ::std::cout <<
" -a generates all output files" << ::std::endl;
578 ::std::cout <<
" -c check static semantics for <constraints file>" << ::std::endl;
579 ::std::cout <<
" -o sets the output directory to <output directory> instead of current one" << ::std::endl;
580 ::std::cout <<
" -h prints this short help" << ::std::endl;
581 ::std::cout <<
" The model file <XML model file> must always be set" << ::std::endl;
596 int main(
int argc,
char* argv[])