25 typedef std::function<int(const EventImp &)>
callback;
31 const bool disconnected = evt.
GetSize()==0;
64 std::pair<Time, int32_t>
last;
65 std::pair<Time, int32_t>
cur;
80 const int32_t &
state()
const {
return cur.second; }
91 out << s.
time().
GetAsStr(
"%H:%M:%S.%f").substr(0, 12) <<
" - ";
95 return out <<
": Offline";
105 out << rc.
name <<
"[" << rc.
index <<
"]";
144 fCallbackStates = cb;
152 states.emplace_back(
kOffline,
"Offline");
162 for (
auto it=states.begin(); it!=states.end(); it++)
163 if (it->index==
state())
164 return State(it->index, it->name, it->comment,
time());
178 if (fCallbackDescriptions)
179 fCallbackDescriptions();
199 fCallbackDescriptions = cb;
205 descriptions.clear();
209 std::stringstream stream(evt.
GetString());
210 while (getline(stream, buf,
'\n'))
214 CallbackDescriptions();
241 std::ostringstream out;
242 out <<
"V" <<
state()/100 <<
'r' <<
state()%100;
265 const size_t p0 =
msg.find_first_of(
' ');
266 if (p0==std::string::npos)
270 const size_t p1 =
msg.find_first_of(
':');
271 if (p1==std::string::npos)
275 const size_t p2 =
msg.find_last_of(
'[');
276 if (p2==std::string::npos)
279 scriptdepth = atoi(
msg.c_str()+p0+1);
280 file =
msg.substr(p1+1, p2-p1-1);
282 shortmsg.insert(0,
msg.substr(p0+1, p1-p0));
283 shortmsg.erase(p1+1,p2-p0-1);
287 const auto func = fCallbacks.find(file);
288 if (func==fCallbacks.end())
292 return func->second(evt);
305 fCallbacks[script] = cb;
326 void HandlerServerImp(
const EventImp &evt);
330 if (fCallbackServerAdd)
331 fCallbackServerAdd(str);
335 if (fCallbackServerRemove)
336 fCallbackServerRemove(str);
340 if (fCallbackServerEvent)
341 fCallbackServerEvent(evt);
345 HandlerServerImp(evt);
346 CallbackServerEvent(evt);
370 fCallbackServerAdd = cb;
375 fCallbackServerRemove = cb;
380 fCallbackServerEvent = cb;
404 if (fServers.find(server)!=fServers.end())
407 fStateMachine->
Subscribe(server+
"/SERVICE_LIST")
410 fServers.insert(server);
413 void HandlerServiceListImp(
const EventImp &evt);
424 HandlerServiceListImp(evt);
433 if (fCallbackServiceAdd)
434 fCallbackServiceAdd(service);
444 fStateMachine = &imp;
450 fCallbackServiceAdd = cb;
virtual void CallbackServerEvent(const EventImp &evt)
std::vector< std::string > fServiceList
virtual State description() const
virtual void Subscribe(StateMachineImp &imp)
DimDescribedState(const std::string &n)
int HandleServiceDesc(const EventImp &evt)
A general base-class describing events issues in a state machine.
Base class for a state machine implementation.
callback_desc fCallbackStates
void CallbackServerAdd(const std::string &server)
DimDescriptions(const std::string &n)
std::string comment
Name (e.g. 'Connected')
virtual void CallbackServerRemove(const std::string &str)
int Handler(const EventImp &evt)
Adds some functionality to boost::posix_time::ptime for our needs.
std::ostream & operator<<(std::ostream &out, const DimState &s)
std::set< std::string > fServers
virtual void CallbackDescriptions()
std::vector< State > states
const int32_t & state() const
std::pair< Time, int32_t > last
std::string GetString() const
void HandlerImp(const EventImp &evt)
State description() const
virtual void CallbackServerAdd(const std::string &str)
std::map< std::string, callback > fCallbacks
std::string version() const
std::function< int(const EventImp &)> callback
void SetCallbackStates(const callback_desc &cb)
virtual int HandlerServiceList(const EventImp &evt)
void SetCallbackServerEvent(const callback_evt &cb)
void AddCallback(const std::string &script, const callback &cb)
virtual Time GetTime() const
std::function< void()> callback_desc
callback_evt fCallbackServerEvent
virtual int GetQoS() const
void SetCallbackServiceAdd(const callback_svc &cb)
virtual void CallbackStates()
static std::vector< Description > SplitDescription(const std::string &buffer)
callback_srv fCallbackServerRemove
int Handler(const EventImp &evt)
virtual void Subscribe(StateMachineImp &imp)
std::function< void(const Service &)> callback_svc
void SetCallbackServerRemove(const callback_srv &cb)
virtual int HandlerServer(const EventImp &evt)
std::vector< std::vector< Description > > descriptions
virtual ~DimDnsServerList()
callback_srv fCallbackServerAdd
virtual void Subscribe(StateMachineImp &imp)
EventImp & Subscribe(const std::string &name)
std::set< std::string > fServerList
int HandleDesc(const EventImp &evt)
callback_svc fCallbackServiceAdd
virtual int Handler(const EventImp &evt)
callback_desc fCallbackDescriptions
void SetCallbackDescriptions(const callback_desc &cb)
State description() const
std::function< void()> callback_desc
State description() const
std::string name
Index (e.g. 1)
std::pair< Time, int32_t > cur
DimState(const std::string &n, const std::string s="STATE")
std::string GetAsStr(const char *fmt="%Y-%m-%d %H:%M:%S") const
const Time & time() const
int Callback(const EventImp &evt)
virtual void Subscribe(StateMachineImp &imp)
void SetCallbackServerAdd(const callback_srv &cb)
virtual void CallbackServiceAdd(const Service &service)
void SetCallback(const callback &cb)
static std::vector< State > SplitStates(const std::string &buffer)
Time of state change.
std::function< void(const std::string &)> callback_srv
void Subscribe(StateMachineImp &imp)
std::function< int(const EventImp &)> Wrap(const std::function< int(const EventImp &)> &func)
std::function< void(const EventImp &)> callback_evt
virtual size_t GetSize() const
StateMachineImp * fStateMachine