Jayanth Othayoth | 1756c06 | 2017-05-23 22:48:11 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Jayanth Othayoth | 1756c06 | 2017-05-23 22:48:11 -0500 | [diff] [blame] | 3 | #include <systemd/sd-event.h> |
| 4 | #include <unistd.h> |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame^] | 5 | #include "dump_utils.hpp" |
Jayanth Othayoth | 1756c06 | 2017-05-23 22:48:11 -0500 | [diff] [blame] | 6 | |
| 7 | namespace phosphor |
| 8 | { |
| 9 | namespace dump |
| 10 | { |
Jayanth Othayoth | 1756c06 | 2017-05-23 22:48:11 -0500 | [diff] [blame] | 11 | namespace inotify |
| 12 | { |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame^] | 13 | |
Jayanth Othayoth | 1756c06 | 2017-05-23 22:48:11 -0500 | [diff] [blame] | 14 | /** @class Watch |
| 15 | * |
| 16 | * @brief Adds inotify watch on core file directories. |
| 17 | * |
| 18 | * The inotify watch is hooked up with sd-event, so that on call back, |
| 19 | * appropriate actions are taken to collect the core files. |
| 20 | */ |
| 21 | class Watch |
| 22 | { |
| 23 | public: |
| 24 | /** @brief ctor - hook inotify watch with sd-event |
| 25 | * |
| 26 | * @param[in] loop - sd-event object |
| 27 | */ |
| 28 | Watch(sd_event* loop); |
| 29 | |
| 30 | Watch(const Watch&) = delete; |
| 31 | Watch& operator=(const Watch&) = delete; |
| 32 | Watch(Watch&&) = default; |
| 33 | Watch& operator=(Watch&&) = default; |
| 34 | |
| 35 | /* @brief dtor - remove inotify watch and close fd's */ |
| 36 | ~Watch(); |
| 37 | |
| 38 | private: |
| 39 | /** @brief sd-event callback |
| 40 | * |
| 41 | * @param[in] s - event source, floating (unused) in our case |
| 42 | * @param[in] fd - inotify fd |
| 43 | * @param[in] revents - events that matched for fd |
| 44 | * @param[in] userdata - pointer to Watch object |
| 45 | * @returns 0 on success, -1 on fail |
| 46 | */ |
| 47 | static int callback(sd_event_source* s, |
| 48 | int fd, |
| 49 | uint32_t revents, |
| 50 | void* userdata); |
| 51 | |
| 52 | /** initialize an inotify instance and returns file descriptor */ |
| 53 | int inotifyInit(); |
| 54 | |
| 55 | /** @brief core file directory watch descriptor */ |
| 56 | int wd = -1; |
| 57 | |
| 58 | /** @brief file descriptor manager */ |
| 59 | CustomFd fd; |
| 60 | }; |
| 61 | |
| 62 | } // namespace inotify |
| 63 | } // namespace dump |
| 64 | } // namespace phosphor |