Marri Devender Rao | ffad1ef | 2019-06-03 04:54:12 -0500 | [diff] [blame] | 1 | #pragma once |
William A. Kennington III | ebd1d8a | 2021-02-23 19:34:47 -0800 | [diff] [blame] | 2 | #include <functional> |
Marri Devender Rao | ffad1ef | 2019-06-03 04:54:12 -0500 | [diff] [blame] | 3 | #include <memory> |
| 4 | #include <sdeventplus/source/event.hpp> |
| 5 | #include <sdeventplus/source/io.hpp> |
William A. Kennington III | ebd1d8a | 2021-02-23 19:34:47 -0800 | [diff] [blame] | 6 | #include <string> |
| 7 | |
Marri Devender Rao | ffad1ef | 2019-06-03 04:54:12 -0500 | [diff] [blame] | 8 | namespace phosphor |
| 9 | { |
| 10 | namespace 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 | */ |
| 19 | class 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 |