Line data Source code
1 :
2 : #include "ErrorHandler/MessageAnalyzer/ma_function_is_syncd.h"
3 : #include "ErrorHandler/MessageAnalyzer/ma_condition.h"
4 :
5 : #include <boost/lexical_cast.hpp>
6 :
7 : using namespace novadaq::errorhandler;
8 :
9 : // class registeration
10 0 : REG_MA_FUNCTION(is_syncd /*function name*/, ma_func_is_syncd /*class name*/)
11 :
12 0 : bool ma_func_is_syncd::grouped_alarm()
13 : {
14 0 : return false;
15 : }
16 :
17 : boost::any
18 0 : ma_func_is_syncd::evaluate(ma_condition const& cond, ma_cond_domain)
19 : {
20 0 : std::string time_str = cond.get_msg_group(1);
21 0 : std::string source = cond.get_msg_source();
22 :
23 0 : uint64_t time = 0;
24 :
25 : try
26 : {
27 0 : time = boost::lexical_cast<uint64_t>(time_str);
28 : }
29 0 : catch (boost::bad_lexical_cast&)
30 : {
31 0 : return boost::any(true);
32 0 : }
33 :
34 : // std::map<std::string, uint64_t>::const_iterator it = sync_time.find(source);
35 :
36 0 : if (sync_time.empty() || sync_time.find(source) != sync_time.end())
37 : {
38 : // a new round if the table is empty, or the key already exists
39 0 : sync_time.clear();
40 0 : min = time;
41 0 : max = time;
42 :
43 0 : sync_time.insert(std::make_pair(source, time));
44 0 : return boost::any(false);
45 : }
46 : else
47 : {
48 : // check if in-sync
49 0 : sync_time.insert(std::make_pair(source, time));
50 :
51 0 : if (time < min) min = time;
52 0 : if (time > max) max = time;
53 :
54 0 : if (max - min > 5)
55 0 : return boost::any(true);
56 : else
57 0 : return boost::any(false);
58 : }
59 0 : }
|