blob: 282ed60ca87fb4e7646e5b7d0ea87757950a23a0 [file] [log] [blame]
Marri Devender Rao0dabe592018-04-12 09:18:43 -05001/**
2 * @file PathWatchimpl.hpp
3 * @brief Add interfaces added watch for the specified path
4 *
5 */
6#pragma once
7
Marri Devender Rao0dabe592018-04-12 09:18:43 -05008#include "callback.hpp"
9#include "data_types.hpp"
10#include "pathwatch.hpp"
11
Patrick Venture3d6d3182018-08-31 09:33:09 -070012#include <sdbusplus/bus/match.hpp>
13#include <sdbusplus/message.hpp>
George Liu3fe976c2022-06-21 09:37:04 +080014
Patrick Venture3d6d3182018-08-31 09:33:09 -070015#include <vector>
16
Marri Devender Rao0dabe592018-04-12 09:18:43 -050017namespace phosphor
18{
19namespace dbus
20{
21namespace monitoring
22{
23
Patrick Venture3d6d3182018-08-31 09:33:09 -070024template <typename DBusInterfaceType>
25void PathWatch<DBusInterfaceType>::start()
Marri Devender Rao0dabe592018-04-12 09:18:43 -050026{
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*
Patrick Williamseab4f8c2024-08-16 15:20:10 -040036 { (this->cb)(Context::SIGNAL, msg); });
Marri Devender Rao0dabe592018-04-12 09:18:43 -050037 // *INDENT-ON*
38
39 alreadyRan = true;
40}
41
42template <typename DBusInterfaceType>
43void PathWatch<DBusInterfaceType>::callback(Context ctx)
44{
45 (this->cb)(ctx);
46}
47
48template <typename DBusInterfaceType>
49void PathWatch<DBusInterfaceType>::callback(Context ctx,
Patrick Williams413a4852022-07-22 19:26:52 -050050 sdbusplus::message_t& msg)
Marri Devender Rao0dabe592018-04-12 09:18:43 -050051{
52 (this->cb)(ctx, msg);
53}
54} // namespace monitoring
55} // namespace dbus
56} // namespace phosphor