blob: b82a594af4ec134425150376494fc53493ee57ba [file] [log] [blame]
Jagpal Singh Gillca8c7e92024-11-02 16:51:48 -07001#pragma once
2
3#include <sdbusplus/async.hpp>
4
Jagpal Singh Gillca8c7e92024-11-02 16:51:48 -07005#include <functional>
6#include <memory>
7#include <string>
8
9namespace notify_watch
10{
11
12class 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