#pragma once #include "ddkit/base/Thread.hpp" #include "ddkit/access/ConfigLoaderDds.hpp" #include "ddkit/access/DdsWrap.hpp" #include "ddkit/access/System.hpp" #include "ddkit/access/ICleanup.hpp" #include "ddkit/utils/Logger.hpp" #include namespace ddkit { namespace access { class Dispatcher : public base::Thread { public: explicit Dispatcher(const std::string& threadName); Dispatcher(const std::string& threadName, std::shared_ptr cleanup); ~Dispatcher(); void addReadCondition(const dds::sub::cond::ReadCondition& readCondition); void removeReadCondition(const dds::sub::cond::ReadCondition& readCondition); void requestCleanup(); // Thread void run() override; void onStop() override; private: // System has to be referenced because System::instance() call (and therefore instantiation of the singleton) // has to happen before the waitset is initialized. Otherwise the waitset would access the policy first and // the manipulation by System later will throw an exception because the policy is already immutable. std::shared_ptr m_configLoaderDds; // contains System std::shared_ptr m_cleanup; std::recursive_mutex m_addRemoveMutex; dds::core::cond::WaitSet m_waitset; dds::core::cond::GuardCondition m_guardCondition; void callCleanupIf(); Dispatcher(Dispatcher const&) = delete; void operator=(Dispatcher const&) = delete; }; } // namespace access } // namespace ddkit