blob: 2cf34aadab5b00ed64200c5d40b7f4fe67308011 [file] [log] [blame]
Marri Devender Raoffad1ef2019-06-03 04:54:12 -05001#pragma once
William A. Kennington IIIebd1d8a2021-02-23 19:34:47 -08002#include <functional>
Marri Devender Raoffad1ef2019-06-03 04:54:12 -05003#include <memory>
4#include <sdeventplus/source/event.hpp>
5#include <sdeventplus/source/io.hpp>
William A. Kennington IIIebd1d8a2021-02-23 19:34:47 -08006#include <string>
7
Nan Zhoue1289ad2021-12-28 11:02:56 -08008namespace phosphor::certs
Marri Devender Raoffad1ef2019-06-03 04:54:12 -05009{
10/** @class Watch
11 *
12 * @brief Adds inotify watch on certificate directory
13 *
14 * The inotify watch is hooked up with sd-event, so that on call back,
15 * appropriate actions related to a certificate upload can be taken.
16 */
17class Watch
18{
19 public:
20 using Callback = std::function<void()>;
21 /** @brief ctor - hook inotify watch with sd-event
22 *
23 * @param[in] loop - sd-event object
24 * @param[in] cb - The callback function for processing
25 * certificate upload
26 */
27 Watch(sdeventplus::Event& event, std::string& certFile, Callback cb);
28 Watch(const Watch&) = delete;
29 Watch& operator=(const Watch&) = delete;
30 Watch(Watch&&) = delete;
31 Watch& operator=(Watch&&) = delete;
32
33 /** @brief dtor - remove inotify watch and close fd's
34 */
35 ~Watch();
36
37 /** @brief start watch on the specified path
38 */
39 void startWatch();
40
41 /** @brief stop watch on the specified path
42 */
43 void stopWatch();
44
45 private:
46 /** @brief certificate upload directory watch descriptor */
47 int wd = -1;
48
49 /** @brief inotify file descriptor */
50 int fd = -1;
51
52 /** @brief SDEventPlus IO pointer added to event loop */
53 std::unique_ptr<sdeventplus::source::IO> ioPtr = nullptr;
54
55 /** @brief sd-event object */
56 sdeventplus::Event& event;
57
58 /** @brief callback method to be called */
59 Callback callback;
60
61 /** @brief Certificate directory to watch */
62 std::string watchDir;
63
64 /** @brief Certificate file to watch */
65 std::string watchFile;
66
67 /** @brief Certificate file with path */
68 std::string certFile;
69};
Nan Zhoue1289ad2021-12-28 11:02:56 -080070} // namespace phosphor::certs