Line data Source code
1 : #ifndef ERROR_HANDLER_QT_RULE_ENGINE_H
2 : #define ERROR_HANDLER_QT_RULE_ENGINE_H
3 :
4 : #include "ErrorHandler/MessageAnalyzer/ma_rule_engine.h"
5 :
6 : #include <QtCore/QObject>
7 : #include <QtCore/QVector>
8 :
9 : namespace fhicl {
10 : class ParameterSet;
11 : }
12 :
13 : namespace novadaq {
14 : namespace errorhandler {
15 :
16 : class qt_rule_engine : public QObject
17 : {
18 : Q_OBJECT
19 :
20 : public:
21 : // c'tor
22 : qt_rule_engine(fhicl::ParameterSet const &pset, QObject *parent = 0);
23 :
24 : // d'tor
25 : ~qt_rule_engine();
26 :
27 : // rule_engine accessor
28 0 : size_t cond_size() const { return engine.cond_size(); }
29 0 : size_t rule_size() const { return engine.rule_size(); }
30 :
31 : QVector<QString> cond_names() const;
32 : QVector<QString> rule_names() const;
33 :
34 : bool is_EHS() const { return engine.is_EHS(); }
35 :
36 : // raw configuration
37 : fhicl::ParameterSet get_configuration() const
38 : {
39 : return engine.get_configuration();
40 : }
41 :
42 : // condition fields
43 0 : QString cond_description(QString const &name) const
44 : {
45 0 : return QString(engine.cond_description(name.toUtf8().constData()).c_str());
46 : }
47 :
48 0 : QString cond_sources(QString const &name) const
49 : {
50 0 : return QString(engine.cond_sources(name.toUtf8().constData()).c_str());
51 : }
52 :
53 0 : QString cond_regex(QString const &name) const
54 : {
55 0 : return QString(engine.cond_regex(name.toUtf8().constData()).c_str());
56 : }
57 :
58 0 : int cond_msg_count(QString const &name) const
59 : {
60 0 : return engine.cond_msg_count(name.toUtf8().constData());
61 : }
62 :
63 : // rule fields
64 0 : QString rule_description(QString const &name) const
65 : {
66 0 : return QString(engine.rule_description(name.toUtf8().constData()).c_str());
67 : }
68 :
69 0 : QString rule_expr(QString const &name) const
70 : {
71 0 : return QString(engine.rule_expr(name.toUtf8().constData()).c_str());
72 : }
73 :
74 0 : int rule_alarm_count(QString const &name) const
75 : {
76 0 : return engine.rule_alarm_count(name.toUtf8().constData());
77 : }
78 :
79 : // name list of conditions associated with a rule
80 : QVector<QString> rule_cond_names(QString const &name) const;
81 :
82 : // enable/disable the rule with given name
83 0 : void enable_rule(QString const &name, bool flag)
84 : {
85 0 : engine.enable_rule(name.toUtf8().constData(), flag);
86 0 : }
87 :
88 : // enable/disable action
89 : void enable_EHS(bool flag)
90 : {
91 : engine.enable_EHS(flag);
92 : }
93 :
94 : // reset named rule
95 0 : void reset_rule(QString const &name)
96 : {
97 0 : engine.reset_rule(name.toUtf8().constData());
98 0 : }
99 :
100 : // reset all rules
101 : void reset_rules()
102 : {
103 : engine.reset_rules();
104 : }
105 :
106 : // reset named cond
107 : void reset_cond(QString const &name)
108 : {
109 : engine.reset_cond(name.toUtf8().constData());
110 : }
111 :
112 : // reset all conds
113 : void reset_conds()
114 : {
115 : engine.reset_conds();
116 : }
117 :
118 : // reset everything
119 0 : void reset()
120 : {
121 0 : engine.reset();
122 0 : }
123 :
124 : // participants
125 : void add_participant_group(std::string const &group)
126 : {
127 : engine.add_participant_group(group);
128 : }
129 :
130 : void add_participant_group(std::string const &group, size_t size)
131 : {
132 : engine.add_participant_group(group, size);
133 : }
134 :
135 : void add_participant(std::string const &group, std::string const &app)
136 : {
137 : engine.add_participant(group, app);
138 : }
139 :
140 : void add_participant(std::string const &app)
141 : {
142 : engine.add_participant(app);
143 : }
144 :
145 : size_t get_group_participant_count(std::string const &group) const
146 : {
147 : return engine.get_group_participant_count(group);
148 : }
149 :
150 : size_t get_participant_count() const
151 : {
152 : return engine.get_participant_count();
153 : }
154 :
155 : public slots:
156 :
157 : // receiving a new message
158 0 : void feed(qt_mf_msg const &msg) { engine.feed(msg); }
159 :
160 : signals:
161 :
162 : // emits when alarms triggered
163 : void alarm(QString const & /*rule name*/
164 : ,
165 : QString const & /*message body*/);
166 :
167 : void match(QString const &);
168 :
169 : private:
170 : void new_alarm(std::string const &rule_name, std::string const &msg);
171 : void cond_match(std::string const &cond_name);
172 :
173 : private:
174 : ma_rule_engine engine;
175 : };
176 :
177 : } // namespace errorhandler
178 : } // namespace novadaq
179 :
180 : #endif
|