blob: b0b8b4296e2502b912c2c1475689e4426c1a4888 [file] [log] [blame]
Marri Devender Rao0dabe592018-04-12 09:18:43 -05001/**
2 * @file PathWatch.hpp
3 * @brief Add watch for the object path for interfaces added/removed signal
4 *
5 * In general class users should include pathwatchimpl.hpp instead to avoid
6 * link failures.
7 */
8#pragma once
9
10#include "data_types.hpp"
11#include "watch.hpp"
12
13namespace phosphor
14{
15namespace dbus
16{
17namespace monitoring
18{
19
20class Callback;
21
22/** @class PathWatch
23 * @brief Watch on object path for interfaceadded/interfaceremoved signals
24 */
Patrick Venture3d6d3182018-08-31 09:33:09 -070025template <typename DBusInterfaceType>
26class PathWatch : public Watch
Marri Devender Rao0dabe592018-04-12 09:18:43 -050027{
28 public:
29 PathWatch() = delete;
30 PathWatch(const PathWatch&) = delete;
31 PathWatch(PathWatch&&) = default;
32 PathWatch& operator=(const PathWatch&) = delete;
33 PathWatch& operator=(PathWatch&&) = default;
34 virtual ~PathWatch() = default;
35 PathWatch(const std::string& path, Callback& callback) :
36 Watch(), objectPath(path), cb(callback), alreadyRan(false)
37 {
38 }
39
40 /** @brief Start the watch.
41 *
42 * Watch start interface implementation for PathWatch.
43 */
44 void start() override;
45
46 /** @brief Run the watch callback method.
47 *
48 * Watch callback interface implementation for PathWatch.
49 */
50 void callback(Context ctx) override;
51
52 /** @brief Run the watch callback method.
53 *
54 * Watch callback interface implementation for PathWatch.
55 */
56 void callback(Context ctx, sdbusplus::message::message& msg) override;
57
58 protected:
59 /** @brief Path of the D-Bus object to watch for. */
60 const std::string& objectPath;
61
62 /** @brief Optional callback method. */
63 Callback& cb;
64
65 /** @brief The start method should only be invoked once. */
66 bool alreadyRan;
67};
68
69} // namespace monitoring
70} // namespace dbus
71} // namespace phosphor