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