source: trunk/FACT++/src/DimLoggerCheck.h@ 19246

Last change on this file since 19246 was 15166, checked in by tbretz, 12 years ago
A helper class to easily check the DATA_LOGGER/SUBSCRIPTIONS
File size: 1.8 KB
Line 
1#ifndef FACT_DimLoggerCheck
2#define FACT_DimLoggerCheck
3
4#include <set>
5#include <string>
6#include <functional>
7
8#include "tools.h"
9#include "EventImp.h"
10#include "DimDescriptionService.h"
11
12class DimLoggerCheck
13{
14 //typedef std::function<int(const EventImp &)> callback;
15 typedef std::function<int(const std::map<const std::string, const int> &)> callback;
16
17 callback fCallback;
18
19 const std::string name;
20 std::map<const std::string, const int> list;
21
22 virtual int Handler(const EventImp &evt)
23 {
24 using namespace std;
25
26 const set<string> vserv = DimDescribedService::GetServices();
27 const vector<string> ltxt = Tools::Split(evt.GetString(), "\n");
28
29 map<string, int> vsubs;
30 for (auto it=ltxt.begin(); it!=ltxt.end(); it++)
31 {
32 const vector<string> col = Tools::Split(*it, ",");
33
34 if (col.size()==2 && col[0].substr(0, name.size()+1)==name+"/")
35 vsubs[col[0]] = atoi(col[1].c_str());
36 }
37
38 list.clear();
39 for (auto it=vserv.begin(); it!=vserv.end(); it++)
40 {
41 const auto is = vsubs.find(*it);
42 list.insert(make_pair(it->substr(name.size()+1), is==vsubs.end() ? -2 : is->second));
43 }
44
45 list.erase("STATE_LIST");
46
47 return fCallback ? fCallback(list) : StateMachineImp::kSM_KeepState;
48 }
49
50public:
51 DimLoggerCheck() { }
52 DimLoggerCheck(const std::string &n) : name(n)
53 {
54 }
55 virtual ~DimLoggerCheck()
56 {
57 }
58
59 virtual void Subscribe(StateMachineImp &imp)
60 {
61 imp.Subscribe("DATA_LOGGER/SUBSCRIPTIONS")
62 (imp.Wrap(std::bind(&DimLoggerCheck::Handler, this, std::placeholders::_1)));
63 }
64
65 void SetCallback(const callback &cb)
66 {
67 fCallback = cb;
68 }
69
70 const std::map<const std::string, const int> &GetList() const { return list; }
71};
72
73#endif
Note: See TracBrowser for help on using the repository browser.