Program Listing for File HsmEventDispatcherQt.hpp
↰ Return to documentation for file (include/hsmcpp/HsmEventDispatcherQt.hpp
)
// Copyright (C) 2021 Igor Krechetov
// Distributed under MIT license. See file LICENSE for details
#ifndef HSMCPP_HSMEVENTDISPATCHERQT_HPP
#define HSMCPP_HSMEVENTDISPATCHERQT_HPP
#include "HsmEventDispatcherBase.hpp"
#include <QObject>
#include <QEvent>
#include <QTimer>
namespace hsmcpp
{
class HsmEventDispatcherQt: public QObject
, public HsmEventDispatcherBase
{
Q_OBJECT
public:
// cppcheck-suppress misra-c2012-17.8 ; false positive. setting default parameter value is not parameter modification
static std::shared_ptr<HsmEventDispatcherQt> create(const size_t eventsCacheSize = DISPATCHER_DEFAULT_EVENTS_CACHESIZE);
bool start() override;
void stop() override;
void emitEvent(const HandlerID_t handlerID) override;
// Timers
protected:
void unregisterAllTimerHandlers();
void startTimerImpl(const TimerID_t timerID, const unsigned int intervalMs, const bool isSingleShot) override;
void stopTimerImpl(const TimerID_t timerID) override;
private slots:
void onTimerEvent();
protected:
explicit HsmEventDispatcherQt(const size_t eventsCacheSize);
virtual ~HsmEventDispatcherQt();
bool deleteSafe() override;
void notifyDispatcherAboutEvent() override;
void customEvent(QEvent* ev) override;
private:
static QEvent::Type mQtDispatchEventType;
std::map<TimerID_t, QTimer*> mNativeTimerHandlers; // protected by mRunningTimersSync
};
} // namespace hsmcpp
#endif // HSMCPP_HSMEVENTDISPATCHERQT_HPP