[295] | 1 | #include "abstractSoftware.h" |
---|
[305] | 2 | #include "dataManager.h" |
---|
[295] | 3 | |
---|
| 4 | abstractSoftware::abstractSoftware() |
---|
| 5 | { |
---|
[316] | 6 | globParamPtr_ = NULL; |
---|
| 7 | dataManager_ = NULL; |
---|
[386] | 8 | nameOfSoftware_ = nomDeLogiciel("unknownSoftware"); |
---|
[295] | 9 | } |
---|
| 10 | |
---|
[316] | 11 | abstractSoftware::abstractSoftware(string inputFileName, globalParameters* globals, dataManager* dt) { |
---|
| 12 | inputFileName_ = inputFileName; |
---|
[295] | 13 | globParamPtr_ = globals; |
---|
[305] | 14 | dataManager_ = dt; |
---|
[386] | 15 | numeroDeb_ = 0; |
---|
| 16 | numeroFin_ = 0; |
---|
| 17 | nameOfSoftware_ = nomDeLogiciel("unknownSoftware"); |
---|
[295] | 18 | } |
---|
| 19 | |
---|
[386] | 20 | bool abstractSoftware::initComputationLimits(unsigned int numeroDeb,unsigned int numeroFin) { |
---|
| 21 | numeroDeb_ = numeroDeb; |
---|
| 22 | numeroFin_ = numeroFin; |
---|
| 23 | return ComputationLimitsOk(); |
---|
| 24 | } |
---|
[295] | 25 | |
---|
[386] | 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 | |
---|
[418] | 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 | |
---|
[295] | 61 | bool abstractSoftware::launchJob(string commandLine, string& resul) |
---|
| 62 | { |
---|
| 63 | bool ExecuteStatus = true; |
---|
[342] | 64 | |
---|
[295] | 65 | FILE* pp = popen(commandLine.c_str(), "r"); |
---|
[342] | 66 | ostringstream sortie; |
---|
[295] | 67 | if (pp == NULL) { |
---|
| 68 | sortie << " launching failed : " << commandLine << endl; |
---|
| 69 | ExecuteStatus = false; |
---|
[342] | 70 | } else { |
---|
| 71 | cout << " executing command : " << commandLine << endl; |
---|
[295] | 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 | } |
---|