00001 #ifndef _ots_ConsoleSupervisor_h_
00002 #define _ots_ConsoleSupervisor_h_
00003
00004
00005 #include "otsdaq-core/CoreSupervisors/CoreSupervisorBase.h"
00006
00007 #include <mutex>
00008
00009
00010 namespace ots
00011 {
00012
00013
00014
00015 class ConsoleSupervisor : public CoreSupervisorBase
00016 {
00017
00018 public:
00019
00020
00021 public:
00022
00023 XDAQ_INSTANTIATOR();
00024
00025 ConsoleSupervisor (xdaq::ApplicationStub* s);
00026 virtual ~ConsoleSupervisor (void);
00027
00028 void init (void);
00029 void destroy (void);
00030
00031 virtual void defaultPage (xgi::Input* in, xgi::Output* out) override;
00032 virtual void request (const std::string& requestType, cgicc::Cgicc& cgiIn, HttpXmlDocument& xmlOut, const WebUsers::RequestUserInfo& userInfo) override;
00033
00034 virtual void forceSupervisorPropertyValues (void) override;
00035
00036
00037 private:
00038
00039 static void messageFacilityReceiverWorkLoop (ConsoleSupervisor *cs);
00040 void insertMessageRefresh (HttpXmlDocument *xmldoc, const clock_t lastUpdateClock, const unsigned int lastUpdateIndex);
00041
00042
00043
00044
00045
00046 struct ConsoleMessageStruct
00047 {
00048 ConsoleMessageStruct()
00049 {
00050 buffer.resize(BUFFER_SZ);
00051 timeStamp = 0;
00052 countStamp = (time_t)-1;
00053
00054
00055
00056 fields[SEQID].set("SequenceID", 2, -1);
00057 fields[LEVEL].set("Level", 5, -1);
00058 fields[LABEL].set("Label", 6, -1);
00059 fields[SOURCEID].set("SourceID", 7, -1);
00060 fields[SOURCE].set("Source", 9, -1);
00061 fields[MSG].set("Msg", 10, -1);
00062
00063
00064
00065
00066
00067 }
00068
00069 void set(const std::string &msg, const time_t count)
00070 {
00071 buffer = (std::string)(msg.substr(0, BUFFER_SZ));
00072
00073 timeStamp = time(0);
00074 countStamp = count;
00075
00076
00077 int i = 0, m = 0;
00078 size_t p = 0;
00079
00080
00081 if (fields[i].markerCount == 0)
00082 fields[i++].posInString = 0;
00083
00084
00085 while ((p = buffer.find('|', p)) != std::string::npos)
00086 {
00087 ++m;
00088
00089 if (i < (int)fields.size() &&
00090 m == fields[i].markerCount)
00091 fields[i++].posInString = p + 1;
00092
00093
00094 buffer[p] = '\0';
00095
00096
00097 if(i == LABEL && p + 1 + strlen(&buffer[p+1]) != msg.length())
00098 {
00099
00100
00101 fields[i++].posInString = p + 2 + strlen(&buffer[p+1]);
00102 }
00103 }
00104
00105
00106
00107
00108
00109
00110
00111
00112 }
00113
00114 const char * getMsg() { return (char *)&buffer[fields[MSG].posInString]; }
00115 const char * getLabel() { return (char *)&buffer[fields[LABEL].posInString]; }
00116 const char * getLevel() { return (char *)&buffer[fields[LEVEL].posInString]; }
00117 const char * getSourceID() { return (char *)&buffer[fields[SOURCEID].posInString]; }
00118 const long long getSourceIDAsNumber()
00119 {
00120
00121 long long srcid;
00122 sscanf((char *)&buffer[fields[SOURCEID].posInString], "%lld", &srcid);
00123 return srcid;
00124 }
00125 const char * getSource() { return (char *)&buffer[fields[SOURCE].posInString]; }
00126 const char * getSequenceID() { return (char *)&buffer[fields[SEQID].posInString]; }
00127 const unsigned int getSequenceIDAsNumber()
00128 {
00129 unsigned long long longSeqid;
00130 sscanf((char *)&buffer[fields[SEQID].posInString], "%llu", &longSeqid);
00131
00132
00133 return (unsigned int)longSeqid;
00134 }
00135
00136 const char * getField(int i) { return (char *)&buffer[fields[i].posInString]; }
00137 const time_t getTime() { return timeStamp; }
00138 const time_t getCount() { return countStamp; }
00139
00140
00141
00142
00143 struct FieldStruct
00144 {
00145 void set(const std::string &fn, const int mc, const int ps)
00146 {
00147 fieldName = fn; markerCount = mc; posInString = ps;
00148 }
00149
00150 std::string fieldName;
00151 int markerCount;
00152 int posInString;
00153 };
00154
00155
00156 enum
00157 {
00158 SEQID,
00159 LEVEL,
00160 LABEL,
00161 SOURCEID,
00162 SOURCE,
00163 MSG,
00164 };
00165
00166 const int BUFFER_SZ = 5000;
00167 std::array<FieldStruct, 6> fields;
00168 private:
00169 std::string buffer;
00170 time_t timeStamp;
00171 time_t countStamp;
00172 };
00173
00174 std::array<ConsoleMessageStruct, 100> messages_;
00175 std::mutex messageMutex_;
00176 volatile unsigned int writePointer_;
00177 time_t messageCount_;
00178
00179
00180 unsigned int refreshReadPointer_;
00181 char refreshTempStr_[50];
00182 unsigned int refreshIndex_;
00183 xercesc::DOMElement* refreshParent_;
00184 time_t refreshCurrentLastCount_;
00185 };
00186
00187
00188 }
00189
00190 #endif