blob: 25fd6debe68f4239b9d4ab4ae64641c7c1437af0 [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
Andrew Geisslerae4c95c2020-05-16 13:58:53 -050013#include <string>
14
Marri Devender Rao0dabe592018-04-12 09:18:43 -050015namespace phosphor
16{
17namespace dbus
18{
19namespace monitoring
20{
21
22class Callback;
23
24/** @class PathWatch
25 * @brief Watch on object path for interfaceadded/interfaceremoved signals
26 */
Patrick Venture3d6d3182018-08-31 09:33:09 -070027template <typename DBusInterfaceType>
28class PathWatch : public Watch
Marri Devender Rao0dabe592018-04-12 09:18:43 -050029{
30 public:
31 PathWatch() = delete;
32 PathWatch(const PathWatch&) = delete;
33 PathWatch(PathWatch&&) = default;
34 PathWatch& operator=(const PathWatch&) = delete;
35 PathWatch& operator=(PathWatch&&) = default;
36 virtual ~PathWatch() = default;
37 PathWatch(const std::string& path, Callback& callback) :
38 Watch(), objectPath(path), cb(callback), alreadyRan(false)
39 {
40 }
41
42 /** @brief Start the watch.
43 *
44 * Watch start interface implementation for PathWatch.
45 */
46 void start() override;
47
48 /** @brief Run the watch callback method.
49 *
50 * Watch callback interface implementation for PathWatch.
51 */
52 void callback(Context ctx) override;
53
54 /** @brief Run the watch callback method.
55 *
56 * Watch callback interface implementation for PathWatch.
57 */
58 void callback(Context ctx, sdbusplus::message::message& msg) override;
59
60 protected:
61 /** @brief Path of the D-Bus object to watch for. */
62 const std::string& objectPath;
63
64 /** @brief Optional callback method. */
65 Callback& cb;
66
67 /** @brief The start method should only be invoked once. */
68 bool alreadyRan;
69};
70
71} // namespace monitoring
72} // namespace dbus
73} // namespace phosphor