Implemented sensor class
Sensor class was introduced, it monitors
xyz.openbmc_project.Sensor.Value, for change and notifies all
listeners.
Tested:
- Unit tested with service stub that provides dbus interface
xyz.openbmc_project.Sensor.Value
- All changes are delivered to listeners
- All other unit tests are passing
Change-Id: I8c9d58cc986c1fe2a4d2386815d559814016efa6
Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
diff --git a/src/utils/detached_timer.hpp b/src/utils/detached_timer.hpp
new file mode 100644
index 0000000..21343f9
--- /dev/null
+++ b/src/utils/detached_timer.hpp
@@ -0,0 +1,28 @@
+#pragma once
+
+#include <boost/asio/io_context.hpp>
+#include <boost/asio/spawn.hpp>
+#include <boost/asio/steady_timer.hpp>
+
+#include <chrono>
+
+namespace utils
+{
+
+template <class F>
+void makeDetachedTimer(boost::asio::io_context& ioc,
+ std::chrono::milliseconds delay, F&& fun)
+{
+ auto timer = std::make_unique<boost::asio::steady_timer>(ioc);
+ timer->expires_after(delay);
+ timer->async_wait([timer = std::move(timer),
+ fun = std::move(fun)](boost::system::error_code ec) {
+ if (ec)
+ {
+ return;
+ }
+ fun();
+ });
+}
+
+} // namespace utils
diff --git a/src/utils/unique_call.hpp b/src/utils/unique_call.hpp
new file mode 100644
index 0000000..db10786
--- /dev/null
+++ b/src/utils/unique_call.hpp
@@ -0,0 +1,30 @@
+#pragma once
+
+#include <memory>
+#include <utility>
+
+namespace utils
+{
+
+class UniqueCall
+{
+ public:
+ struct Lock
+ {};
+
+ template <class Functor, class... Args>
+ void operator()(Functor&& functor, Args&&... args)
+ {
+ if (lock.expired())
+ {
+ auto l = std::make_shared<Lock>();
+ lock = l;
+ functor(std::move(l), std::forward<Args>(args)...);
+ }
+ }
+
+ private:
+ std::weak_ptr<Lock> lock;
+};
+
+} // namespace utils