00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef XRDMONCTRWRITER_HH
00014 #define XRDMONCTRWRITER_HH
00015
00016 #include "XrdMon/XrdMonTypes.hh"
00017 #include <fstream>
00018 #include <string>
00019 using std::fstream;
00020 using std::ostream;
00021 using std::string;
00022
00023 class XrdMonHeader;
00024
00025
00026
00027
00028
00029
00030 class XrdMonCtrWriter {
00031 public:
00032 XrdMonCtrWriter(senderid_t senderId, kXR_int32 stod);
00033 ~XrdMonCtrWriter();
00034 void operator()(const char* packet,
00035 const XrdMonHeader& header,
00036 long currentTime);
00037
00038 kXR_int32 prevStod() const { return _prevStod; }
00039
00040 void forceClose();
00041 long lastActivity() const { return _lastActivity; }
00042
00043 static void setBaseDir(const char* dir) { _baseDir = dir; }
00044 static void setMaxLogSize(kXR_int64 size) { _maxLogSize = size;}
00045 static void setBufferSize(int size) { _bufferSize = size;}
00046
00047 private:
00048 enum LogType { ACTIVE, PERMANENT };
00049
00050 bool logIsOpen() { return _file.is_open(); }
00051 bool logIsFull() { return (kXR_int64) _file.tellp() >= _maxLogSize; }
00052 bool bufferIsFull(packetlen_t x) { return _bPos + x > _bufferSize; }
00053
00054 string logName(LogType t) const;
00055 void mkActiveLogNameDirs() const;
00056
00057 void flushBuffer();
00058 void openLog();
00059 void closeLog();
00060 void publish();
00061
00062 private:
00063 static string _baseDir;
00064 static kXR_int64 _maxLogSize;
00065 static int _bufferSize;
00066 static long _totalArchived;
00067
00068 kXR_int32 _prevStod;
00069
00070 string _timestamp;
00071 hp_t _sender;
00072 char* _buffer;
00073 kXR_int32 _bPos;
00074 fstream _file;
00075
00076 long _lastActivity;
00077
00078 friend ostream& operator<<(ostream& o, const XrdMonCtrWriter& w);
00079 };
00080
00081 #endif