Marri Devender Rao | 0dabe59 | 2018-04-12 09:18:43 -0500 | [diff] [blame] | 1 | /** |
| 2 | * @file PathWatchimpl.hpp |
| 3 | * @brief Add interfaces added watch for the specified path |
| 4 | * |
| 5 | */ |
| 6 | #pragma once |
| 7 | |
Marri Devender Rao | 0dabe59 | 2018-04-12 09:18:43 -0500 | [diff] [blame] | 8 | #include "callback.hpp" |
| 9 | #include "data_types.hpp" |
| 10 | #include "pathwatch.hpp" |
| 11 | |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 12 | #include <sdbusplus/bus/match.hpp> |
| 13 | #include <sdbusplus/message.hpp> |
George Liu | 3fe976c | 2022-06-21 09:37:04 +0800 | [diff] [blame] | 14 | |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
Marri Devender Rao | 0dabe59 | 2018-04-12 09:18:43 -0500 | [diff] [blame] | 17 | namespace phosphor |
| 18 | { |
| 19 | namespace dbus |
| 20 | { |
| 21 | namespace monitoring |
| 22 | { |
| 23 | |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 24 | template <typename DBusInterfaceType> |
| 25 | void PathWatch<DBusInterfaceType>::start() |
Marri Devender Rao | 0dabe59 | 2018-04-12 09:18:43 -0500 | [diff] [blame] | 26 | { |
| 27 | if (alreadyRan) |
| 28 | { |
| 29 | return; |
| 30 | } |
| 31 | // Watch for new interfaces added on this path. |
| 32 | DBusInterfaceType::addMatch( |
| 33 | sdbusplus::bus::match::rules::interfacesAdded(objectPath), |
| 34 | [this](auto& msg) |
| 35 | // *INDENT-OFF* |
| 36 | { (this->cb)(Context::SIGNAL, msg); }); |
| 37 | // *INDENT-ON* |
| 38 | |
| 39 | alreadyRan = true; |
| 40 | } |
| 41 | |
| 42 | template <typename DBusInterfaceType> |
| 43 | void PathWatch<DBusInterfaceType>::callback(Context ctx) |
| 44 | { |
| 45 | (this->cb)(ctx); |
| 46 | } |
| 47 | |
| 48 | template <typename DBusInterfaceType> |
| 49 | void PathWatch<DBusInterfaceType>::callback(Context ctx, |
| 50 | sdbusplus::message::message& msg) |
| 51 | { |
| 52 | (this->cb)(ctx, msg); |
| 53 | } |
| 54 | } // namespace monitoring |
| 55 | } // namespace dbus |
| 56 | } // namespace phosphor |