artdaq_mfextensions  v1_03_03a
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 { SDEBUG, SINFO, SWARNING, SERROR };
26 
30 class qt_mf_msg {
31  public:
40  qt_mf_msg(std::string hostname, std::string category, std::string application, pid_t pid, timeval time);
41 
43  qt_mf_msg() {}
45  qt_mf_msg(const qt_mf_msg&) = default;
46 
47  virtual ~qt_mf_msg() = default;
48 
49  // get method
55  QString const& text(bool mode) const { return mode ? shortText_ : text_; }
60  QColor const& color() const { return color_; }
65  sev_code_t sev() const { return sev_; }
70  QString const& host() const { return host_; }
75  QString const& cat() const { return cat_; }
80  QString const& app() const { return app_; }
85  timeval time() const { return time_; }
90  size_t seq() const { return seq_; }
91 
96  void setSeverity(mf::ELseverityLevel sev);
101  void setSeverityLevel(sev_code_t sev) { sev_ = sev; }
108  void setMessage(std::string prefix, int iteration, std::string msg);
113  void setHostAddr(std::string hostaddr) { hostaddr_ = QString(hostaddr.c_str()).toHtmlEscaped(); }
118  void setFileName(std::string file) { file_ = QString(file.c_str()).toHtmlEscaped(); }
123  void setLineNumber(std::string line) { line_ = QString(line.c_str()).toHtmlEscaped(); }
128  void setModule(std::string module) { module_ = QString(module.c_str()).toHtmlEscaped(); }
133  void setEventID(std::string eventID) { eventID_ = QString(eventID.c_str()).toHtmlEscaped(); }
134 
138  void updateText();
139 
140  private:
141  QString text_;
142  QString shortText_;
143  QColor color_;
144  sev_code_t sev_;
145  QString host_;
146  QString cat_;
147  QString app_;
148  timeval time_;
149  size_t seq_;
150  static size_t sequence;
151 
152  QString msg_;
153  QString application_;
154  QString pid_;
155  QString hostaddr_;
156  QString file_;
157  QString line_;
158  QString module_;
159  QString eventID_;
160  QString sourceType_;
161  int sourceSequence_;
162 };
163 
167 typedef std::list<qt_mf_msg> msgs_t;
168 
172 class msg_iter_t {
173  public:
178  msg_iter_t(msgs_t::iterator it) {
179  iter_ = it;
180  seq_ = it->seq();
181  }
182 
188  bool operator==(msg_iter_t const& other) const { return seq_ == other.seq_; }
189 
195  bool operator<(msg_iter_t const& other) const { return seq_ < other.seq_; }
196 
201  msgs_t::iterator get() const { return iter_; };
202 
203  private:
204  msgs_t::iterator iter_;
205  size_t seq_;
206 };
207 
211 typedef std::list<msg_iter_t> msg_iters_t;
215 typedef std::map<QString, msg_iters_t> msg_iters_map_t;
216 
217 #endif
QString const & app() const
Get the application of the message
Definition: qt_mf_msg.hh:80
void updateText()
Parse fields and create HTML string representing message
Definition: qt_mf_msg.cc:59
void setEventID(std::string eventID)
Set the Event ID of the message
Definition: qt_mf_msg.hh:133
timeval time() const
Get the message timestamp
Definition: qt_mf_msg.hh:85
size_t seq() const
Get the sequence number of the message
Definition: qt_mf_msg.hh:90
void setFileName(std::string file)
Set the file name field
Definition: qt_mf_msg.hh:118
Qt wrapper around MessageFacility message
Definition: qt_mf_msg.hh:30
sev_code_t sev() const
Get the severity of the message
Definition: qt_mf_msg.hh:65
void setSeverityLevel(sev_code_t sev)
Set the severity code of the message (Viewer levels)
Definition: qt_mf_msg.hh:101
msg_iter_t(msgs_t::iterator it)
Construct a msg_iter_t
Definition: qt_mf_msg.hh:178
QString const & host() const
Get the host from which the message came
Definition: qt_mf_msg.hh:70
void setMessage(std::string prefix, int iteration, std::string msg)
Set the message
Definition: qt_mf_msg.cc:53
bool operator<(msg_iter_t const &other) const
Comparison operator, based on message sequence number
Definition: qt_mf_msg.hh:195
Iterator for the msgs_t type
Definition: qt_mf_msg.hh:172
qt_mf_msg()
Default message constructor.
Definition: qt_mf_msg.hh:43
void setSeverity(mf::ELseverityLevel sev)
Set the Severity of the message (MF levels)
Definition: qt_mf_msg.cc:24
void setHostAddr(std::string hostaddr)
Set the hostaddr field
Definition: qt_mf_msg.hh:113
QString const & text(bool mode) const
Get the text of the message
Definition: qt_mf_msg.hh:55
void setLineNumber(std::string line)
Set the line number field
Definition: qt_mf_msg.hh:123
QString const & cat() const
Get the category of the message
Definition: qt_mf_msg.hh:75
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:188
void setModule(std::string module)
Set the module name
Definition: qt_mf_msg.hh:128
QColor const & color() const
Get the severity-based color of the message
Definition: qt_mf_msg.hh:60