Removed dependency to TriggerManager
introduces Messanger class which allows to send messages directly to
subscribed targets, which allows to break dependencies between classes.
Testes:
- All unit tests are passing
- Links are correctly updated
- Report is correctly updated by Trigger Action
Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
Change-Id: I32d3aaba22f9ec07e611f53fe553bd27e1c04c6d
diff --git a/src/utils/messanger_service.hpp b/src/utils/messanger_service.hpp
new file mode 100644
index 0000000..86dd2ff
--- /dev/null
+++ b/src/utils/messanger_service.hpp
@@ -0,0 +1,53 @@
+#pragma once
+
+#include <boost/asio.hpp>
+
+#include <any>
+
+namespace utils
+{
+
+class MessangerService : public boost::asio::execution_context::service
+{
+ public:
+ using key_type = MessangerService;
+
+ struct Context
+ {
+ std::vector<std::any> handlers;
+ };
+
+ MessangerService(boost::asio::execution_context& execution_context);
+ ~MessangerService() = default;
+
+ void shutdown()
+ {}
+
+ Context& create();
+ void destroy(Context& context);
+
+ template <class T>
+ void send(const T& event)
+ {
+ using HandlerType = std::function<void(const T&)>;
+
+ for (const auto& context : contexts_)
+ {
+ for (const auto& any : context->handlers)
+ {
+ if (const HandlerType* handler =
+ std::any_cast<HandlerType>(&any))
+ {
+ (*handler)(event);
+ }
+ }
+ }
+ }
+
+ static boost::asio::execution_context::id id;
+
+ private:
+ std::vector<std::unique_ptr<Context>> contexts_;
+};
+
+} // namespace utils