blob: 1e1b33e290e34a602d8303b7bf39159269bc3c6d [file] [log] [blame]
Jagpal Singh Gillca8c7e92024-11-02 16:51:48 -07001#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
11namespace notify_watch
12{
13
14class 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