artdaq_mfextensions  v1_05_00
ma_utils.h
1 #ifndef ERROR_HANDLER_UTILS_H
2 #define ERROR_HANDLER_UTILS_H
3 
4 #include "ErrorHandler/MessageAnalyzer/ma_types.h"
5 #include "messagefacility/Utilities/ELseverityLevel.h"
6 
7 namespace novadaq {
8 namespace errorhandler {
9 
10  inline std::string
11  trim_hostname(std::string const & host);
12 
13  inline node_type_t
14  get_source_from_msg(std::string & src, qt_mf_msg const & msg);
15 
16  inline std::string
17  get_message_type_str(message_type_t type);
18 
19  inline sev_code_t get_sev_from_string(std::string const& sev);
20 
21 } // end of namespace errorhandler
22 } // end of namespace novadaq
23 
24 // ------------------------------------------------------------------
25 // misc. utilities
26 
27 std::string
28  novadaq::errorhandler::trim_hostname(std::string const & host)
29 {
30  size_t pos = host.find('.');
31  if (pos==std::string::npos) return host;
32  else return host.substr(0, pos);
33 }
34 
41 novadaq::errorhandler::node_type_t
42 novadaq::errorhandler::get_source_from_msg(std::string& src, qt_mf_msg const& msg)
43 {
44  src = msg.app().toStdString();
45  return Framework;
46 }
47 
48 
49 std::string
50  novadaq::errorhandler::get_message_type_str(message_type_t type)
51 {
52  switch(type)
53  {
54  case MSG_SYSTEM: return "SYSTEM";
55  case MSG_ERROR: return "ERROR";
56  case MSG_WARNING: return "WARNING";
57  case MSG_INFO: return "INFO";
58  case MSG_DEBUG: return "DEBUG";
59  default: return "UNKNOWN";
60  }
61 }
62 
63 sev_code_t novadaq::errorhandler::get_sev_from_string(std::string const& sev) {
64  mf::ELseverityLevel elss(sev);
65 
66  int sevid = elss.getLevel();
67 
68  switch (sevid)
69  {
70  case mf::ELseverityLevel::ELsev_success:
71  case mf::ELseverityLevel::ELsev_zeroSeverity:
72  case mf::ELseverityLevel::ELsev_unspecified:
73  return SDEBUG;
74 
75  case mf::ELseverityLevel::ELsev_info:
76  return SINFO;
77 
78  case mf::ELseverityLevel::ELsev_warning:
79  return SWARNING;
80 
81  case mf::ELseverityLevel::ELsev_error:
82  case mf::ELseverityLevel::ELsev_severe:
83  case mf::ELseverityLevel::ELsev_highestSeverity:
84  default:
85  return SERROR;
86  }
87 }
88 
89 #endif
90 
91 
92 
93 
94 
95 
96 
97 
98 
QString const & app() const
Get the application of the message
Definition: qt_mf_msg.hh:91
Qt wrapper around MessageFacility message
Definition: qt_mf_msg.hh:37