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