blob: 99854b7c910c763615bf4e1a57f2e945bfd2e567 [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
Gunnar Mills3027bba2017-04-27 15:49:03 -050025 * @param[in] imageCallback - The callback function for processing
26 * the image
Deepak Kodihalli059e2332017-04-12 06:40:53 -050027 */
Gunnar Mills3027bba2017-04-27 15:49:03 -050028 Watch(sd_event* loop,
29 std::function<int(std::string&)> imageCallback);
Deepak Kodihalli059e2332017-04-12 06:40:53 -050030
31 Watch(const Watch&) = delete;
32 Watch& operator=(const Watch&) = delete;
Gunnar Mills9953e692017-10-15 11:37:16 -050033 Watch(Watch&&) = delete;
34 Watch& operator=(Watch&&) = delete;
Deepak Kodihalli059e2332017-04-12 06:40:53 -050035
36 /** @brief dtor - remove inotify watch and close fd's
37 */
38 ~Watch();
39
40 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,
50 int fd,
51 uint32_t revents,
52 void* userdata);
53
54 /** @brief image upload directory watch descriptor */
55 int wd = -1;
56
57 /** @brief inotify file descriptor */
58 int fd = -1;
Gunnar Mills3027bba2017-04-27 15:49:03 -050059
60 /** @brief The callback function for processing the image. */
61 std::function<int(std::string&)> imageCallback;
Deepak Kodihalli059e2332017-04-12 06:40:53 -050062};
63
64} // namespace manager
65} // namespace software
66} // namespace phosphor