xref: /openbmc/dbus-sensors/src/NotifyWatch.hpp (revision ca8c7e98687da407fbab5dcd20cfe892928928ae)
1 #pragma once
2 
3 #include <sdbusplus/async.hpp>
4 
5 #include <cerrno>
6 #include <cstring>
7 #include <functional>
8 #include <memory>
9 #include <string>
10 
11 namespace notify_watch
12 {
13 
14 class NotifyWatch
15 {
16   public:
17     using Callback_t = std::function<sdbusplus::async::task<>(std::string)>;
18 
19     NotifyWatch() = delete;
20     explicit NotifyWatch(sdbusplus::async::context& ctx, const std::string& dir,
21                          Callback_t callback);
22     ~NotifyWatch();
23 
24     /** @brief Asynchronously watch and notify for any changes to dir */
25     auto readNotifyAsync() -> sdbusplus::async::task<>;
26 
27   private:
28     sdbusplus::async::context& ctx;
29     Callback_t callback;
30     int wd = -1;
31     int fd = -1;
32     std::unique_ptr<sdbusplus::async::fdio> fdioInstance;
33 };
34 
35 } // namespace notify_watch
36