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