blob: e1e8f979673781e929d77bde8b8ea0134a04765c [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*
36 { (this->cb)(Context::SIGNAL, msg); });
37 // *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,
50 sdbusplus::message::message& msg)
51{
52 (this->cb)(ctx, msg);
53}
54} // namespace monitoring
55} // namespace dbus
56} // namespace phosphor