#ifndef FACT_DimLoggerCheck #define FACT_DimLoggerCheck #include #include #include #include "tools.h" #include "EventImp.h" #include "DimDescriptionService.h" class DimLoggerCheck { //typedef std::function callback; typedef std::function &)> callback; callback fCallback; const std::string name; std::map list; virtual int Handler(const EventImp &evt) { using namespace std; const set vserv = DimDescribedService::GetServices(); const vector ltxt = Tools::Split(evt.GetString(), "\n"); map vsubs; for (auto it=ltxt.begin(); it!=ltxt.end(); it++) { const vector col = Tools::Split(*it, ","); if (col.size()==2 && col[0].substr(0, name.size()+1)==name+"/") vsubs[col[0]] = atoi(col[1].c_str()); } list.clear(); for (auto it=vserv.begin(); it!=vserv.end(); it++) { const auto is = vsubs.find(*it); list.insert(make_pair(it->substr(name.size()+1), is==vsubs.end() ? -2 : is->second)); } list.erase("STATE_LIST"); return fCallback ? fCallback(list) : StateMachineImp::kSM_KeepState; } public: DimLoggerCheck() { } DimLoggerCheck(const std::string &n) : name(n) { } virtual ~DimLoggerCheck() { } virtual void Subscribe(StateMachineImp &imp) { imp.Subscribe("DATA_LOGGER/SUBSCRIPTIONS") (imp.Wrap(std::bind(&DimLoggerCheck::Handler, this, std::placeholders::_1))); } void SetCallback(const callback &cb) { fCallback = cb; } const std::map &GetList() const { return list; } }; #endif