1 #pragma once 2 3 #include <systemd/sd-event.h> 4 5 #include <functional> 6 #include <string> 7 8 namespace phosphor 9 { 10 namespace software 11 { 12 namespace manager 13 { 14 15 /** @class Watch 16 * 17 * @brief Adds inotify watch on software image upload directory 18 * 19 * The inotify watch is hooked up with sd-event, so that on call back, 20 * appropriate actions related to a software image upload can be taken. 21 */ 22 class Watch 23 { 24 public: 25 /** @brief ctor - hook inotify watch with sd-event 26 * 27 * @param[in] loop - sd-event object 28 * @param[in] imageCallback - The callback function for processing 29 * the image 30 */ 31 Watch(sd_event* loop, std::function<int(std::string&)> imageCallback); 32 33 Watch(const Watch&) = delete; 34 Watch& operator=(const Watch&) = delete; 35 Watch(Watch&&) = delete; 36 Watch& operator=(Watch&&) = delete; 37 38 /** @brief dtor - remove inotify watch and close fd's 39 */ 40 ~Watch(); 41 42 private: 43 /** @brief sd-event callback 44 * 45 * @param[in] s - event source, floating (unused) in our case 46 * @param[in] fd - inotify fd 47 * @param[in] revents - events that matched for fd 48 * @param[in] userdata - pointer to Watch object 49 * @returns 0 on success, -1 on fail 50 */ 51 static int callback(sd_event_source* s, int fd, uint32_t revents, 52 void* userdata); 53 54 /** @brief image upload directory watch descriptor */ 55 int wd = -1; 56 57 /** @brief inotify file descriptor */ 58 int fd = -1; 59 60 /** @brief The callback function for processing the image. */ 61 std::function<int(std::string&)> imageCallback; 62 }; 63 64 } // namespace manager 65 } // namespace software 66 } // namespace phosphor 67