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