Marri Devender Rao | 0dabe59 | 2018-04-12 09:18:43 -0500 | [diff] [blame] | 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 | |
Andrew Geissler | ae4c95c | 2020-05-16 13:58:53 -0500 | [diff] [blame] | 13 | #include <string> |
| 14 | |
Marri Devender Rao | 0dabe59 | 2018-04-12 09:18:43 -0500 | [diff] [blame] | 15 | namespace phosphor |
| 16 | { |
| 17 | namespace dbus |
| 18 | { |
| 19 | namespace monitoring |
| 20 | { |
| 21 | |
| 22 | class Callback; |
| 23 | |
| 24 | /** @class PathWatch |
| 25 | * @brief Watch on object path for interfaceadded/interfaceremoved signals |
| 26 | */ |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 27 | template <typename DBusInterfaceType> |
| 28 | class PathWatch : public Watch |
Marri Devender Rao | 0dabe59 | 2018-04-12 09:18:43 -0500 | [diff] [blame] | 29 | { |
| 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) |
George Liu | 3fe976c | 2022-06-21 09:37:04 +0800 | [diff] [blame] | 39 | {} |
Marri Devender Rao | 0dabe59 | 2018-04-12 09:18:43 -0500 | [diff] [blame] | 40 | |
| 41 | /** @brief Start the watch. |
| 42 | * |
| 43 | * Watch start interface implementation for PathWatch. |
| 44 | */ |
| 45 | void start() override; |
| 46 | |
| 47 | /** @brief Run the watch callback method. |
| 48 | * |
| 49 | * Watch callback interface implementation for PathWatch. |
| 50 | */ |
| 51 | void callback(Context ctx) override; |
| 52 | |
| 53 | /** @brief Run the watch callback method. |
| 54 | * |
| 55 | * Watch callback interface implementation for PathWatch. |
| 56 | */ |
| 57 | void callback(Context ctx, sdbusplus::message::message& msg) override; |
| 58 | |
| 59 | protected: |
| 60 | /** @brief Path of the D-Bus object to watch for. */ |
| 61 | const std::string& objectPath; |
| 62 | |
| 63 | /** @brief Optional callback method. */ |
| 64 | Callback& cb; |
| 65 | |
| 66 | /** @brief The start method should only be invoked once. */ |
| 67 | bool alreadyRan; |
| 68 | }; |
| 69 | |
| 70 | } // namespace monitoring |
| 71 | } // namespace dbus |
| 72 | } // namespace phosphor |