#pragma once #include #include #include #include #include #include #include #include namespace wfr { // forward declarations class WorkflowRuntime; namespace eventsystem { // forward declarations class EventListener; class Event; class OStreamLogger; class SQLiteLogger; class EventSystem { friend class wfr::WorkflowRuntime; // Singleton instances private: static EventSystem singleton; #ifdef WFR_ENABLE_STDLOGGER static std::unique_ptr oStreamLogger; #endif #ifdef WFR_ENABLE_PERFDATABASE static std::unique_ptr sqliteLogger; #endif // Non-public parameters private: std::unordered_set eventListeners; std::queue> eventQueue; std::unique_ptr eventThread; std::mutex eventThreadMutex; std::condition_variable eventThreadCondVar; bool stopThread = false; std::atomic_bool threadStarted; bool isFinished = false; // Non-public static functions private: static void eventThreadFunc(EventSystem* eventSystem) noexcept; static void init(int argc, char** argv); static void finish() noexcept; // Non-public functions private: EventSystem() noexcept; void finishInstance() noexcept; // Public functions public: ~EventSystem() noexcept; static EventSystem& getInstance() noexcept { return singleton; } /** * Adds an event to the event queue. * * It is discouraged to use this function directly. * Use the static fireEvent function found in each Event class instead (e.g. GeneralLoggingEvent::fireEvent(....)). **/ void fireEvent(std::shared_ptr event, bool noLocking = false) noexcept; bool addListener(EventListener& listener) noexcept; bool removeListener(EventListener& listener) noexcept; }; } /* namespace eventsystem */ } /* namespace wfr */