1 | #include "abstractSoftware.h" |
---|
2 | #include "dataManager.h" |
---|
3 | |
---|
4 | abstractSoftware::abstractSoftware() |
---|
5 | { |
---|
6 | globParamPtr_ = NULL; |
---|
7 | dataManager_ = NULL; |
---|
8 | nameOfSoftware_ = nomDeLogiciel("unknownSoftware"); |
---|
9 | } |
---|
10 | |
---|
11 | abstractSoftware::abstractSoftware(string inputFileName, globalParameters* globals, dataManager* dt) { |
---|
12 | inputFileName_ = inputFileName; |
---|
13 | globParamPtr_ = globals; |
---|
14 | dataManager_ = dt; |
---|
15 | numeroDeb_ = 0; |
---|
16 | numeroFin_ = 0; |
---|
17 | nameOfSoftware_ = nomDeLogiciel("unknownSoftware"); |
---|
18 | } |
---|
19 | |
---|
20 | bool abstractSoftware::initComputationLimits(unsigned int numeroDeb,unsigned int numeroFin) { |
---|
21 | numeroDeb_ = numeroDeb; |
---|
22 | numeroFin_ = numeroFin; |
---|
23 | return ComputationLimitsOk(); |
---|
24 | } |
---|
25 | |
---|
26 | bool abstractSoftware::ComputationLimitsOk() const { |
---|
27 | if ( numeroDeb_ < 1 || numeroFin_ < 1 || numeroDeb_ > dataManager_->getBeamLineSize() || numeroFin_ > dataManager_->getBeamLineSize() ) { |
---|
28 | dataManager_->consoleMessage(" abstractSoftware::initComputationLimit : numero of element out of limits in software " + getName() ); |
---|
29 | return false; |
---|
30 | } else { |
---|
31 | return true; |
---|
32 | } |
---|
33 | } |
---|
34 | |
---|
35 | |
---|
36 | void abstractSoftware::registerElement(nomdElements::typedElement nomdel,trivaluedBool b) { |
---|
37 | if (b == TBoolIgnore) { |
---|
38 | ignoredElements_.push_back(nomdel); |
---|
39 | } else if (b == TBoolOk) { |
---|
40 | acceptedElements_.push_back(nomdel); |
---|
41 | } |
---|
42 | } |
---|
43 | |
---|
44 | trivaluedBool abstractSoftware::doAcceptElement(nomdElements::typedElement typdel) { |
---|
45 | if (acceptedElements_.size() == 0) { |
---|
46 | return TBoolError; |
---|
47 | } |
---|
48 | if ( std::find(acceptedElements_.begin(), acceptedElements_.end(), typdel) != acceptedElements_.end()) { |
---|
49 | return TBoolOk; |
---|
50 | } |
---|
51 | if (ignoredElements_.size() == 0) { |
---|
52 | return TBoolError; |
---|
53 | } |
---|
54 | if ( std::find(ignoredElements_.begin(), ignoredElements_.end(), typdel) != ignoredElements_.end()) { |
---|
55 | return TBoolIgnore; |
---|
56 | } |
---|
57 | return TBoolOk; |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | bool abstractSoftware::launchJob(string commandLine, string& resul) |
---|
62 | { |
---|
63 | bool ExecuteStatus = true; |
---|
64 | |
---|
65 | FILE* pp = popen(commandLine.c_str(), "r"); |
---|
66 | ostringstream sortie; |
---|
67 | if (pp == NULL) { |
---|
68 | sortie << " launching failed : " << commandLine << endl; |
---|
69 | ExecuteStatus = false; |
---|
70 | } else { |
---|
71 | cout << " executing command : " << commandLine << endl; |
---|
72 | // on copie la sortie dans le fichier assigne |
---|
73 | char buf[132]; |
---|
74 | while (fgets(buf, sizeof buf, pp)) |
---|
75 | { |
---|
76 | sortie << buf; |
---|
77 | } |
---|
78 | pclose(pp); |
---|
79 | } |
---|
80 | resul = sortie.str(); |
---|
81 | return ExecuteStatus; |
---|
82 | } |
---|