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 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 22 | public: |
| 23 | /** @brief ctor - hook inotify watch with sd-event |
| 24 | * |
| 25 | * @param[in] loop - sd-event object |
| 26 | * @param[in] imageCallback - The callback function for processing |
| 27 | * the image |
| 28 | */ |
| 29 | Watch(sd_event* loop, std::function<int(std::string&)> imageCallback); |
Deepak Kodihalli | 059e233 | 2017-04-12 06:40:53 -0500 | [diff] [blame] | 30 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 31 | Watch(const Watch&) = delete; |
| 32 | Watch& operator=(const Watch&) = delete; |
| 33 | Watch(Watch&&) = delete; |
| 34 | Watch& operator=(Watch&&) = delete; |
Deepak Kodihalli | 059e233 | 2017-04-12 06:40:53 -0500 | [diff] [blame] | 35 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 36 | /** @brief dtor - remove inotify watch and close fd's |
| 37 | */ |
| 38 | ~Watch(); |
Deepak Kodihalli | 059e233 | 2017-04-12 06:40:53 -0500 | [diff] [blame] | 39 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 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, int fd, uint32_t revents, |
| 50 | void* userdata); |
Deepak Kodihalli | 059e233 | 2017-04-12 06:40:53 -0500 | [diff] [blame] | 51 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 52 | /** @brief image upload directory watch descriptor */ |
| 53 | int wd = -1; |
Deepak Kodihalli | 059e233 | 2017-04-12 06:40:53 -0500 | [diff] [blame] | 54 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 55 | /** @brief inotify file descriptor */ |
| 56 | int fd = -1; |
Gunnar Mills | 3027bba | 2017-04-27 15:49:03 -0500 | [diff] [blame] | 57 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 58 | /** @brief The callback function for processing the image. */ |
| 59 | std::function<int(std::string&)> imageCallback; |
Deepak Kodihalli | 059e233 | 2017-04-12 06:40:53 -0500 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | } // namespace manager |
| 63 | } // namespace software |
| 64 | } // namespace phosphor |