| 1 | #ifndef FACT_DimWriteStatistics | 
|---|
| 2 | #define FACT_DimWriteStatistics | 
|---|
| 3 |  | 
|---|
| 4 | #include "MessageImp.h" | 
|---|
| 5 | #include "DimDescriptionService.h" | 
|---|
| 6 |  | 
|---|
| 7 | #include <boost/thread.hpp> | 
|---|
| 8 |  | 
|---|
| 9 | #include <string> | 
|---|
| 10 | #include <set> | 
|---|
| 11 |  | 
|---|
| 12 | class DimWriteStatistics | 
|---|
| 13 | { | 
|---|
| 14 | public: | 
|---|
| 15 | struct Stats | 
|---|
| 16 | { | 
|---|
| 17 | uint64_t freeSpace; | 
|---|
| 18 | uint64_t sizeWritten; | 
|---|
| 19 | uint64_t rateWritten; | 
|---|
| 20 | uint64_t timeElapsed; | 
|---|
| 21 |  | 
|---|
| 22 | Stats() : freeSpace(0), sizeWritten(0), rateWritten(0), timeElapsed(0) { } | 
|---|
| 23 | }; | 
|---|
| 24 |  | 
|---|
| 25 | private: | 
|---|
| 26 | MessageImp &fLog; | 
|---|
| 27 |  | 
|---|
| 28 | DimDescribedService   fDimService; | 
|---|
| 29 |  | 
|---|
| 30 | std::string           fCurrentFolder;   /// Current folder being watched for free space | 
|---|
| 31 | uint16_t              fUpdateInterval;  /// Duration, in millisecond between two service updates. 0 means no more updates | 
|---|
| 32 | size_t                fBaseSize;        /// Total base size of all opened files | 
|---|
| 33 | std::set<std::string> fOpenedFiles;     /// List of all opened files. set is used to easily check for entries | 
|---|
| 34 |  | 
|---|
| 35 | /// Bool indicating if debug information should be printed | 
|---|
| 36 | bool fDebug; | 
|---|
| 37 |  | 
|---|
| 38 | /// The data structure holding the stat data | 
|---|
| 39 | Stats fStats; | 
|---|
| 40 |  | 
|---|
| 41 | /// The boost thread used to update the service | 
|---|
| 42 | boost::thread fThread; | 
|---|
| 43 |  | 
|---|
| 44 | ///Main loop | 
|---|
| 45 | void UpdateService(); | 
|---|
| 46 |  | 
|---|
| 47 | ///Returns the free space on the disk of the folder being watched (fCurrentFolder) | 
|---|
| 48 | int64_t GetFreeSpace(); | 
|---|
| 49 |  | 
|---|
| 50 | ///Returns the size on disk of a given file | 
|---|
| 51 | int64_t GetFileSizeOnDisk(const std::string& file); | 
|---|
| 52 |  | 
|---|
| 53 | int Write(const Time &t, const std::string &txt, int qos); | 
|---|
| 54 |  | 
|---|
| 55 | public: | 
|---|
| 56 | ///Constructor | 
|---|
| 57 | DimWriteStatistics(const std::string& serverName, MessageImp &log); | 
|---|
| 58 | ///Default destructor | 
|---|
| 59 | ~DimWriteStatistics(); | 
|---|
| 60 |  | 
|---|
| 61 | ///Configures that current folder where files are written to | 
|---|
| 62 | bool SetCurrentFolder(const std::string& folder); | 
|---|
| 63 |  | 
|---|
| 64 | bool FileOpened(const std::string& fileName); | 
|---|
| 65 |  | 
|---|
| 66 | void SetDebugMode(bool); | 
|---|
| 67 | void SetUpdateInterval(const int16_t millisec); | 
|---|
| 68 |  | 
|---|
| 69 | const Stats &GetTotalSizeWritten() const { return fStats; } | 
|---|
| 70 | uint16_t GetUpdateInterval() const { return fUpdateInterval; } | 
|---|
| 71 | }; | 
|---|
| 72 |  | 
|---|
| 73 | #endif | 
|---|