artdaq_mfextensions  v1_04_00
qt_mf_msg.hh
1 #ifndef MESSAGEFACILITY_EXTENSIONS_QT_MF_MSG_H
2 #define MESSAGEFACILITY_EXTENSIONS_QT_MF_MSG_H
3 
4 // Wrapped mf message type to be used by msgviewer for
5 // the purpose of fast processing
6 
7 #include <QtCore/QString>
8 #include <QtGui/QColor>
9 
10 #include <list>
11 #include <map>
12 #include <string>
13 #include <vector>
14 
15 #include <sys/time.h>
16 #include "messagefacility/Utilities/ELseverityLevel.h"
17 
18 namespace mf {
19 class ErrorObj;
20 }
21 
25 enum sev_code_t
26 {
27  SDEBUG,
28  SINFO,
29  SWARNING,
30  SERROR
31 };
32 
36 class qt_mf_msg
37 {
38 public:
47  qt_mf_msg(std::string hostname, std::string category, std::string application, pid_t pid, timeval time);
48 
50  qt_mf_msg() {}
52  qt_mf_msg(const qt_mf_msg&) = default;
53 
54  virtual ~qt_mf_msg() = default;
55 
56  // get method
62  QString const& text(bool mode) const { return mode ? shortText_ : text_; }
67  QColor const& color() const { return color_; }
72  sev_code_t sev() const { return sev_; }
77  QString const& host() const { return host_; }
82  QString const& cat() const { return cat_; }
87  QString const& app() const { return app_; }
92  timeval time() const { return time_; }
97  size_t seq() const { return seq_; }
98 
103  void setSeverity(mf::ELseverityLevel sev);
108  void setSeverityLevel(sev_code_t sev) { sev_ = sev; }
115  void setMessage(std::string prefix, int iteration, std::string msg);
120  void setHostAddr(std::string hostaddr) { hostaddr_ = QString(hostaddr.c_str()).toHtmlEscaped(); }
125  void setFileName(std::string file) { file_ = QString(file.c_str()).toHtmlEscaped(); }
130  void setLineNumber(std::string line) { line_ = QString(line.c_str()).toHtmlEscaped(); }
135  void setModule(std::string module) { module_ = QString(module.c_str()).toHtmlEscaped(); }
140  void setEventID(std::string eventID) { eventID_ = QString(eventID.c_str()).toHtmlEscaped(); }
141 
145  void updateText();
146 
147 private:
148  QString text_;
149  QString shortText_;
150  QColor color_;
151  sev_code_t sev_;
152  QString host_;
153  QString cat_;
154  QString app_;
155  timeval time_;
156  size_t seq_;
157  static size_t sequence;
158 
159  QString msg_;
160  QString application_;
161  QString pid_;
162  QString hostaddr_;
163  QString file_;
164  QString line_;
165  QString module_;
166  QString eventID_;
167  QString sourceType_;
168  int sourceSequence_;
169 };
170 
174 typedef std::list<qt_mf_msg> msgs_t;
175 
180 {
181 public:
186  msg_iter_t(msgs_t::iterator it)
187  {
188  iter_ = it;
189  seq_ = it->seq();
190  }
191 
197  bool operator==(msg_iter_t const& other) const { return seq_ == other.seq_; }
198 
204  bool operator<(msg_iter_t const& other) const { return seq_ < other.seq_; }
205 
210  msgs_t::iterator get() const { return iter_; };
211 
212 private:
213  msgs_t::iterator iter_;
214  size_t seq_;
215 };
216 
220 typedef std::list<msg_iter_t> msg_iters_t;
224 typedef std::map<QString, msg_iters_t> msg_iters_map_t;
225 
226 #endif
QString const & app() const
Get the application of the message
Definition: qt_mf_msg.hh:87
void updateText()
Parse fields and create HTML string representing message
Definition: qt_mf_msg.cc:51
void setEventID(std::string eventID)
Set the Event ID of the message
Definition: qt_mf_msg.hh:140
timeval time() const
Get the message timestamp
Definition: qt_mf_msg.hh:92
size_t seq() const
Get the sequence number of the message
Definition: qt_mf_msg.hh:97
void setFileName(std::string file)
Set the file name field
Definition: qt_mf_msg.hh:125
Qt wrapper around MessageFacility message
Definition: qt_mf_msg.hh:36
sev_code_t sev() const
Get the severity of the message
Definition: qt_mf_msg.hh:72
void setSeverityLevel(sev_code_t sev)
Set the severity code of the message (Viewer levels)
Definition: qt_mf_msg.hh:108
msg_iter_t(msgs_t::iterator it)
Construct a msg_iter_t
Definition: qt_mf_msg.hh:186
QString const & host() const
Get the host from which the message came
Definition: qt_mf_msg.hh:77
void setMessage(std::string prefix, int iteration, std::string msg)
Set the message
Definition: qt_mf_msg.cc:44
bool operator<(msg_iter_t const &other) const
Comparison operator, based on message sequence number
Definition: qt_mf_msg.hh:204
Iterator for the msgs_t type
Definition: qt_mf_msg.hh:179
qt_mf_msg()
Default message constructor.
Definition: qt_mf_msg.hh:50
void setSeverity(mf::ELseverityLevel sev)
Set the Severity of the message (MF levels)
Definition: qt_mf_msg.cc:13
void setHostAddr(std::string hostaddr)
Set the hostaddr field
Definition: qt_mf_msg.hh:120
QString const & text(bool mode) const
Get the text of the message
Definition: qt_mf_msg.hh:62
void setLineNumber(std::string line)
Set the line number field
Definition: qt_mf_msg.hh:130
QString const & cat() const
Get the category of the message
Definition: qt_mf_msg.hh:82
bool operator==(msg_iter_t const &other) const
Equality operator. Equality is based on the message&#39;s sequence number
Definition: qt_mf_msg.hh:197
void setModule(std::string module)
Set the module name
Definition: qt_mf_msg.hh:135
QColor const & color() const
Get the severity-based color of the message
Definition: qt_mf_msg.hh:67