1 /** 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 13 namespace phosphor 14 { 15 namespace dbus 16 { 17 namespace monitoring 18 { 19 20 class Callback; 21 22 /** @class PathWatch 23 * @brief Watch on object path for interfaceadded/interfaceremoved signals 24 */ 25 template <typename DBusInterfaceType> 26 class PathWatch : public Watch 27 { 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 72