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> |
| 14 | #include <vector> |
| 15 | |
Marri Devender Rao | 0dabe59 | 2018-04-12 09:18:43 -0500 | [diff] [blame] | 16 | namespace phosphor |
| 17 | { |
| 18 | namespace dbus |
| 19 | { |
| 20 | namespace monitoring |
| 21 | { |
| 22 | |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 23 | template <typename DBusInterfaceType> |
| 24 | void PathWatch<DBusInterfaceType>::start() |
Marri Devender Rao | 0dabe59 | 2018-04-12 09:18:43 -0500 | [diff] [blame] | 25 | { |
| 26 | if (alreadyRan) |
| 27 | { |
| 28 | return; |
| 29 | } |
| 30 | // Watch for new interfaces added on this path. |
| 31 | DBusInterfaceType::addMatch( |
| 32 | sdbusplus::bus::match::rules::interfacesAdded(objectPath), |
| 33 | [this](auto& msg) |
| 34 | // *INDENT-OFF* |
| 35 | { (this->cb)(Context::SIGNAL, msg); }); |
| 36 | // *INDENT-ON* |
| 37 | |
| 38 | alreadyRan = true; |
| 39 | } |
| 40 | |
| 41 | template <typename DBusInterfaceType> |
| 42 | void PathWatch<DBusInterfaceType>::callback(Context ctx) |
| 43 | { |
| 44 | (this->cb)(ctx); |
| 45 | } |
| 46 | |
| 47 | template <typename DBusInterfaceType> |
| 48 | void PathWatch<DBusInterfaceType>::callback(Context ctx, |
| 49 | sdbusplus::message::message& msg) |
| 50 | { |
| 51 | (this->cb)(ctx, msg); |
| 52 | } |
| 53 | } // namespace monitoring |
| 54 | } // namespace dbus |
| 55 | } // namespace phosphor |