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