summaryrefslogtreecommitdiffstats
path: root/src/pathwatch.hpp
blob: b0b8b4296e2502b912c2c1475689e4426c1a4888 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
 * @file PathWatch.hpp
 * @brief Add watch for the object path for interfaces added/removed signal
 *
 * In general class users should include pathwatchimpl.hpp instead to avoid
 * link failures.
 */
#pragma once

#include "data_types.hpp"
#include "watch.hpp"

namespace phosphor
{
namespace dbus
{
namespace monitoring
{

class Callback;

/** @class PathWatch
 *  @brief Watch on object path for interfaceadded/interfaceremoved signals
 */
template <typename DBusInterfaceType>
class PathWatch : public Watch
{
  public:
    PathWatch() = delete;
    PathWatch(const PathWatch&) = delete;
    PathWatch(PathWatch&&) = default;
    PathWatch& operator=(const PathWatch&) = delete;
    PathWatch& operator=(PathWatch&&) = default;
    virtual ~PathWatch() = default;
    PathWatch(const std::string& path, Callback& callback) :
        Watch(), objectPath(path), cb(callback), alreadyRan(false)
    {
    }

    /** @brief Start the watch.
     *
     *  Watch start interface implementation for PathWatch.
     */
    void start() override;

    /** @brief Run the watch callback method.
     *
     *  Watch callback interface implementation for PathWatch.
     */
    void callback(Context ctx) override;

    /** @brief Run the watch callback method.
     *
     *  Watch callback interface implementation for PathWatch.
     */
    void callback(Context ctx, sdbusplus::message::message& msg) override;

  protected:
    /** @brief Path of the D-Bus object to watch for. */
    const std::string& objectPath;

    /** @brief Optional callback method. */
    Callback& cb;

    /** @brief The start method should only be invoked once. */
    bool alreadyRan;
};

} // namespace monitoring
} // namespace dbus
} // namespace phosphor
OpenPOWER on IntegriCloud