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