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.hpp b/src/utils/messanger.hpp
new file mode 100644
index 0000000..a2a2c22
--- /dev/null
+++ b/src/utils/messanger.hpp
@@ -0,0 +1,43 @@
+#pragma once
+
+#include "messanger_service.hpp"
+
+#include <boost/asio.hpp>
+
+namespace utils
+{
+
+template <class Service>
+class MessangerT
+{
+ public:
+ explicit MessangerT(boost::asio::execution_context& execution_context) :
+ service_(boost::asio::use_service<Service>(execution_context)),
+ context_(service_.create())
+ {}
+
+ ~MessangerT()
+ {
+ service_.destroy(context_);
+ }
+
+ template <class EventType>
+ void on_receive(std::function<void(const EventType&)> handler)
+ {
+ context_.handlers.emplace_back(std::move(handler));
+ }
+
+ template <class EventType>
+ void send(const EventType& event)
+ {
+ service_.send(event);
+ }
+
+ private:
+ Service& service_;
+ typename Service::Context& context_;
+};
+
+using Messanger = MessangerT<MessangerService>;
+
+} // namespace utils