blob: fdd301c8eb4f091d15a050fe65e7d335b10491c2 [file] [log] [blame]
Jayanth Othayoth1756c062017-05-23 22:48:11 -05001#pragma once
2
Jayanth Othayoth1756c062017-05-23 22:48:11 -05003#include <systemd/sd-event.h>
4#include <unistd.h>
Jayanth Othayotha320c7c2017-06-14 07:17:21 -05005#include "dump_utils.hpp"
Jayanth Othayoth1756c062017-05-23 22:48:11 -05006
7namespace phosphor
8{
9namespace dump
10{
Jayanth Othayoth1756c062017-05-23 22:48:11 -050011namespace inotify
12{
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050013
Jayanth Othayoth1756c062017-05-23 22:48:11 -050014/** @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 */
21class 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