blob: 451f1d6def0bc5a1f0508a0f9c96ab487baafd9e [file] [log] [blame]
Deepak Kodihalli059e2332017-04-12 06:40:53 -05001#pragma once
2
Brad Bishopfd8c02d2018-02-21 12:54:07 -05003#include <functional>
Deepak Kodihalli059e2332017-04-12 06:40:53 -05004#include <systemd/sd-event.h>
5
6namespace phosphor
7{
8namespace software
9{
10namespace 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 */
20class Watch
21{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060022 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 Kodihalli059e2332017-04-12 06:40:53 -050030
Adriana Kobylak2285fe02018-02-27 15:36:59 -060031 Watch(const Watch&) = delete;
32 Watch& operator=(const Watch&) = delete;
33 Watch(Watch&&) = delete;
34 Watch& operator=(Watch&&) = delete;
Deepak Kodihalli059e2332017-04-12 06:40:53 -050035
Adriana Kobylak2285fe02018-02-27 15:36:59 -060036 /** @brief dtor - remove inotify watch and close fd's
37 */
38 ~Watch();
Deepak Kodihalli059e2332017-04-12 06:40:53 -050039
Adriana Kobylak2285fe02018-02-27 15:36:59 -060040 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 Kodihalli059e2332017-04-12 06:40:53 -050051
Adriana Kobylak2285fe02018-02-27 15:36:59 -060052 /** @brief image upload directory watch descriptor */
53 int wd = -1;
Deepak Kodihalli059e2332017-04-12 06:40:53 -050054
Adriana Kobylak2285fe02018-02-27 15:36:59 -060055 /** @brief inotify file descriptor */
56 int fd = -1;
Gunnar Mills3027bba2017-04-27 15:49:03 -050057
Adriana Kobylak2285fe02018-02-27 15:36:59 -060058 /** @brief The callback function for processing the image. */
59 std::function<int(std::string&)> imageCallback;
Deepak Kodihalli059e2332017-04-12 06:40:53 -050060};
61
62} // namespace manager
63} // namespace software
64} // namespace phosphor