FACT++  1.0
DimLoggerCheck.h
Go to the documentation of this file.
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 
13 {
14  //typedef std::function<int(const EventImp &)> callback;
15  typedef std::function<int(const std::map<const std::string, const int> &)> callback;
16 
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 
50 public:
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
void SetCallback(const callback &cb)
static const std::set< std::string > & GetServices()
A general base-class describing events issues in a state machine.
Definition: EventImp.h:11
Base class for a state machine implementation.
STL namespace.
std::string GetString() const
Definition: EventImp.cc:194
std::function< int(const std::map< const std::string, const int > &)> callback
callback fCallback
std::map< const std::string, const int > list
virtual ~DimLoggerCheck()
const std::map< const std::string, const int > & GetList() const
DimLoggerCheck(const std::string &n)
std::map< std::string, std::string > Split(std::string &, bool=false)
Definition: tools.cc:230
const std::string name
EventImp & Subscribe(const std::string &name)
virtual void Subscribe(StateMachineImp &imp)
virtual int Handler(const EventImp &evt)
std::function< int(const EventImp &)> Wrap(const std::function< int(const EventImp &)> &func)