blob: f7eb695368a51fb6274f02f91ba746568546beef [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{
22 public:
23 /** @brief ctor - hook inotify watch with sd-event
24 *
25 * @param[in] loop - sd-event object
Gunnar Mills3027bba2017-04-27 15:49:03 -050026 * @param[in] imageCallback - The callback function for processing
27 * the image
Deepak Kodihalli059e2332017-04-12 06:40:53 -050028 */
Gunnar Mills3027bba2017-04-27 15:49:03 -050029 Watch(sd_event* loop,
30 std::function<int(std::string&)> imageCallback);
Deepak Kodihalli059e2332017-04-12 06:40:53 -050031
32 Watch(const Watch&) = delete;
33 Watch& operator=(const Watch&) = delete;
Gunnar Mills9953e692017-10-15 11:37:16 -050034 Watch(Watch&&) = delete;
35 Watch& operator=(Watch&&) = delete;
Deepak Kodihalli059e2332017-04-12 06:40:53 -050036
37 /** @brief dtor - remove inotify watch and close fd's
38 */
39 ~Watch();
40
41 private:
42 /** @brief sd-event callback
43 *
44 * @param[in] s - event source, floating (unused) in our case
45 * @param[in] fd - inotify fd
46 * @param[in] revents - events that matched for fd
47 * @param[in] userdata - pointer to Watch object
48 * @returns 0 on success, -1 on fail
49 */
50 static int callback(sd_event_source* s,
51 int fd,
52 uint32_t revents,
53 void* userdata);
54
55 /** @brief image upload directory watch descriptor */
56 int wd = -1;
57
58 /** @brief inotify file descriptor */
59 int fd = -1;
Gunnar Mills3027bba2017-04-27 15:49:03 -050060
61 /** @brief The callback function for processing the image. */
62 std::function<int(std::string&)> imageCallback;
Deepak Kodihalli059e2332017-04-12 06:40:53 -050063};
64
65} // namespace manager
66} // namespace software
67} // namespace phosphor