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> |
Andrew Geissler | 9155b71 | 2020-05-16 13:04:44 -0500 | [diff] [blame] | 6 | #include <string> |
Gunnar Mills | b0ce996 | 2018-09-07 13:39:10 -0500 | [diff] [blame] | 7 | |
Deepak Kodihalli | 059e233 | 2017-04-12 06:40:53 -0500 | [diff] [blame] | 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 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 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); |
Deepak Kodihalli | 059e233 | 2017-04-12 06:40:53 -0500 | [diff] [blame] | 32 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 33 | Watch(const Watch&) = delete; |
| 34 | Watch& operator=(const Watch&) = delete; |
| 35 | Watch(Watch&&) = delete; |
| 36 | Watch& operator=(Watch&&) = delete; |
Deepak Kodihalli | 059e233 | 2017-04-12 06:40:53 -0500 | [diff] [blame] | 37 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 38 | /** @brief dtor - remove inotify watch and close fd's |
| 39 | */ |
| 40 | ~Watch(); |
Deepak Kodihalli | 059e233 | 2017-04-12 06:40:53 -0500 | [diff] [blame] | 41 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 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); |
Deepak Kodihalli | 059e233 | 2017-04-12 06:40:53 -0500 | [diff] [blame] | 53 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 54 | /** @brief image upload directory watch descriptor */ |
| 55 | int wd = -1; |
Deepak Kodihalli | 059e233 | 2017-04-12 06:40:53 -0500 | [diff] [blame] | 56 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 57 | /** @brief inotify file descriptor */ |
| 58 | int fd = -1; |
Gunnar Mills | 3027bba | 2017-04-27 15:49:03 -0500 | [diff] [blame] | 59 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 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 |