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