mirror of
https://github.com/UltraCoderRU/court_monitor.git
synced 2026-01-28 02:15:12 +00:00
55 lines
1.5 KiB
C++
55 lines
1.5 KiB
C++
#ifndef COURT_MONITOR_DIALOG_HELPERS_H
|
|
#define COURT_MONITOR_DIALOG_HELPERS_H
|
|
|
|
#include "Logger.h"
|
|
|
|
#include <banana/types.hpp>
|
|
|
|
#include <boost/statechart/state.hpp>
|
|
#include <boost/statechart/state_machine.hpp>
|
|
|
|
namespace statechart = boost::statechart;
|
|
|
|
template <class MostDerived, class InitialState>
|
|
struct StateMachine : public statechart::state_machine<MostDerived, InitialState>
|
|
{
|
|
explicit StateMachine(Dialog& dialog) : dialog(dialog) {}
|
|
Dialog& dialog;
|
|
};
|
|
|
|
struct BasicState
|
|
{
|
|
[[nodiscard]] virtual bool isFinal() const noexcept = 0;
|
|
};
|
|
|
|
template <class MostDerived, class Context, bool IsFinal = false>
|
|
class State : public statechart::state<MostDerived, Context>, public BasicState
|
|
{
|
|
public:
|
|
State(typename statechart::state<MostDerived, Context>::my_context ctx, const char* name)
|
|
: statechart::state<MostDerived, Context>(ctx), name_(name)
|
|
{
|
|
LOG(dialog, "entering state {}", name_);
|
|
}
|
|
|
|
~State() { LOG(dialog, "leaving state {}", name_); }
|
|
|
|
[[nodiscard]] bool isFinal() const noexcept override { return IsFinal; }
|
|
|
|
private:
|
|
const char* name_;
|
|
};
|
|
|
|
struct NewMessageEvent : statechart::event<NewMessageEvent>
|
|
{
|
|
explicit NewMessageEvent(banana::api::message_t message) : message(std::move(message)) {}
|
|
banana::api::message_t message;
|
|
};
|
|
|
|
struct NewCallbackQueryEvent : statechart::event<NewCallbackQueryEvent>
|
|
{
|
|
explicit NewCallbackQueryEvent(banana::api::callback_query_t query) : query(std::move(query)) {}
|
|
banana::api::callback_query_t query;
|
|
};
|
|
|
|
#endif // COURT_MONITOR_DIALOG_HELPERS_H
|