57 lines
1.1 KiB
C++
57 lines
1.1 KiB
C++
#pragma once
|
|
#include <SiaCommon.h>
|
|
|
|
NS_BEGIN(Sia)
|
|
NS_BEGIN(Api)
|
|
|
|
class AFX_EXT_CLASS CEvent
|
|
{
|
|
public:
|
|
virtual ~CEvent() {}
|
|
|
|
public:
|
|
virtual String GetSingleLineMessage() const = 0;
|
|
};
|
|
|
|
typedef std::shared_ptr<CEvent> CEventPtr;
|
|
|
|
#define CreateSystemEvent(E) CEventPtr(new E)
|
|
#define CreateSystemEventConsumer(E) [=](const CEvent&) -> void { E(e); }
|
|
|
|
// Singleton
|
|
class AFX_EXT_CLASS CEventSystem
|
|
{
|
|
private:
|
|
CEventSystem();
|
|
|
|
private:
|
|
~CEventSystem();
|
|
|
|
public:
|
|
// Singleton setup
|
|
CEventSystem(const CEventSystem&) = delete;
|
|
CEventSystem(CEventSystem&&) = delete;
|
|
CEventSystem& operator=(CEventSystem&&) = delete;
|
|
CEventSystem& operator=(const CEventSystem&) = delete;
|
|
|
|
private:
|
|
HANDLE _stopEvent;
|
|
std::deque<CEventPtr> _eventQueue;
|
|
std::deque<std::function<void(const CEvent&)>> _eventConsumers;
|
|
std::mutex _eventMutex;
|
|
std::unique_ptr<std::thread> _processThread;
|
|
|
|
public:
|
|
static CEventSystem EventSystem;
|
|
|
|
private:
|
|
void ProcessEvents();
|
|
|
|
public:
|
|
void AddEventConsumer(std::function<void(const CEvent&)> consumer);
|
|
void NotifyEvent(CEventPtr eventData);
|
|
void Start();
|
|
void Stop();
|
|
};
|
|
NS_END(2)
|