Program Listing for File IHsmEventDispatcher.hpp

Return to documentation for file (include/hsmcpp/IHsmEventDispatcher.hpp)

// Copyright (C) 2021 Igor Krechetov
// Distributed under MIT license. See file LICENSE for details

#ifndef HSMCPP_IHSMEVENTDISPATCHER_HPP
#define HSMCPP_IHSMEVENTDISPATCHER_HPP

#include "HsmTypes.hpp"

namespace hsmcpp {
using EventHandlerFunc_t = std::function<bool(void)>;
using TimerHandlerFunc_t = std::function<bool(const TimerID_t)>;
using EnqueuedEventHandlerFunc_t = std::function<bool(const EventID_t)>;

using ActionHandlerFunc_t = std::function<void()>;

class IHsmEventDispatcher {
public:
    virtual ~IHsmEventDispatcher() = default;

    virtual bool start() = 0;

    virtual void stop() = 0;

    virtual HandlerID_t registerEventHandler(const EventHandlerFunc_t& handler) = 0;

    virtual void unregisterEventHandler(const HandlerID_t handlerID) = 0;

    virtual HandlerID_t registerEnqueuedEventHandler(const EnqueuedEventHandlerFunc_t& handler) = 0;

    virtual void unregisterEnqueuedEventHandler(const HandlerID_t handlerID) = 0;

    virtual void emitEvent(const HandlerID_t handlerID) = 0;

    virtual bool enqueueEvent(const HandlerID_t handlerID, const EventID_t event) = 0;

    virtual void enqueueAction(ActionHandlerFunc_t actionCallback) = 0;

    virtual HandlerID_t registerTimerHandler(const TimerHandlerFunc_t& handler) = 0;

    virtual void unregisterTimerHandler(const HandlerID_t handlerID) = 0;

    virtual void startTimer(const HandlerID_t handlerID,
                            const TimerID_t timerID,
                            const unsigned int intervalMs,
                            const bool isSingleShot) = 0;

    virtual void restartTimer(const TimerID_t timerID) = 0;

    virtual void stopTimer(const TimerID_t timerID) = 0;

    virtual bool isTimerRunning(const TimerID_t timerID) = 0;
};

}  // namespace hsmcpp

#endif  // HSMCPP_IHSMEVENTDISPATCHER_HPP