| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #ifndef __PMULTITHREADPROGRESS_H__ | ||
| 8 | #define __PMULTITHREADPROGRESS_H__ | ||
| 9 | |||
| 10 | #include <string> | ||
| 11 | #include <vector> | ||
| 12 | #include <map> | ||
| 13 | #include <thread> | ||
| 14 | |||
| 15 | #include <mutex> | ||
| 16 | #include "PString.h" | ||
| 17 | |||
| 18 | ///@brief Single progress information for multithreaded progress bar | ||
| 19 | struct ProgressElement{ | ||
| 20 | ///Current progression | ||
| 21 | int progress; | ||
| 22 | ///Previous progression | ||
| 23 | int prevProgress; | ||
| 24 | ///Maximum of the progression | ||
| 25 | int progressMax; | ||
| 26 | ///Name of the progress bar | ||
| 27 | PString name; | ||
| 28 | ///True if the progress ends with an error | ||
| 29 | bool isEndError; | ||
| 30 | }; | ||
| 31 | |||
| 32 | ///Vector of ProgressElement | ||
| 33 | typedef std::vector<ProgressElement> VecProgressElement; | ||
| 34 | |||
| 35 | ///@brief Deal with Progress bar in mutlithread mode | ||
| 36 | class PMultiThreadProgress{ | ||
| 37 | public: | ||
| 38 | PMultiThreadProgress(size_t nbExpectedProgressBar = 1lu); | ||
| 39 | PMultiThreadProgress(const PMultiThreadProgress & other); | ||
| 40 | virtual ~PMultiThreadProgress(); | ||
| 41 | PMultiThreadProgress & operator = (const PMultiThreadProgress & other); | ||
| 42 | |||
| 43 | void setNbExpectedProgressBar(size_t nbExpectedProgressBar); | ||
| 44 | |||
| 45 | size_t addProgressBar(const PString & name, int progressMax = 1); | ||
| 46 | void incrementProgress(size_t index); | ||
| 47 | void setError(size_t index); | ||
| 48 | |||
| 49 | bool isFinished() const; | ||
| 50 | void print(); | ||
| 51 | void printSummary() const; | ||
| 52 | |||
| 53 | protected: | ||
| 54 | void copyPMultiThreadProgress(const PMultiThreadProgress & other); | ||
| 55 | |||
| 56 | private: | ||
| 57 | void initialisationPMultiThreadProgress(size_t nbExpectedProgressBar); | ||
| 58 | bool isModified(); | ||
| 59 | void eraseProgressBar(size_t nbColTerminal); | ||
| 60 | void printProgressBar(size_t nbColTerminal); | ||
| 61 | void printAllFinshedProgressBar(); | ||
| 62 | size_t getNbColTerminal() const; | ||
| 63 | |||
| 64 | ///Nunmber of already printed line | ||
| 65 | size_t p_alreadyPrintedLine; | ||
| 66 | ///Vector of pair (progress, between 0 and 100) and name of progress | ||
| 67 | VecProgressElement p_vecProgressElement; | ||
| 68 | ///Mutex of the class to avoid conflict manipulation between threads | ||
| 69 | std::mutex p_currentMutex; | ||
| 70 | ///Previous number of progress bars | ||
| 71 | size_t p_previousNbProgressBar; | ||
| 72 | ///Number of expected progress bars | ||
| 73 | size_t p_nbExpectedProgressBar; | ||
| 74 | }; | ||
| 75 | |||
| 76 | void phoenix_print_parallel_progress(PMultiThreadProgress & progress, int refreshSecond); | ||
| 77 | |||
| 78 | #endif | ||
| 79 | |||
| 80 |