blob: c125ef2785bd07bd3ff1d24292127a292bb6d35b [file] [log] [blame]
Deepak Kodihalli059e2332017-04-12 06:40:53 -05001#pragma once
2
3#include <systemd/sd-event.h>
4
5namespace phosphor
6{
7namespace software
8{
9namespace manager
10{
11
12/** @class Watch
13 *
14 * @brief Adds inotify watch on software image upload directory
15 *
16 * The inotify watch is hooked up with sd-event, so that on call back,
17 * appropriate actions related to a software image upload can be taken.
18 */
19class Watch
20{
21 public:
22 /** @brief ctor - hook inotify watch with sd-event
23 *
24 * @param[in] loop - sd-event object
25 */
26 Watch(sd_event* loop);
27
28 Watch(const Watch&) = delete;
29 Watch& operator=(const Watch&) = delete;
30 Watch(Watch&&) = default;
31 Watch& operator=(Watch&&) = default;
32
33 /** @brief dtor - remove inotify watch and close fd's
34 */
35 ~Watch();
36
37 private:
38 /** @brief sd-event callback
39 *
40 * @param[in] s - event source, floating (unused) in our case
41 * @param[in] fd - inotify fd
42 * @param[in] revents - events that matched for fd
43 * @param[in] userdata - pointer to Watch object
44 * @returns 0 on success, -1 on fail
45 */
46 static int callback(sd_event_source* s,
47 int fd,
48 uint32_t revents,
49 void* userdata);
50
51 /** @brief image upload directory watch descriptor */
52 int wd = -1;
53
54 /** @brief inotify file descriptor */
55 int fd = -1;
56};
57
58} // namespace manager
59} // namespace software
60} // namespace phosphor