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