blob: 6be0f50a4b2062810f6564564291e0388fae2d9e [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
8#include <sdbusplus/message.hpp>
9#include <sdbusplus/bus/match.hpp>
10#include <vector>
11#include "callback.hpp"
12#include "data_types.hpp"
13#include "pathwatch.hpp"
14
15namespace phosphor
16{
17namespace dbus
18{
19namespace monitoring
20{
21
22template <typename DBusInterfaceType> void PathWatch<DBusInterfaceType>::start()
23{
24 if (alreadyRan)
25 {
26 return;
27 }
28 // Watch for new interfaces added on this path.
29 DBusInterfaceType::addMatch(
30 sdbusplus::bus::match::rules::interfacesAdded(objectPath),
31 [this](auto& msg)
32 // *INDENT-OFF*
33 { (this->cb)(Context::SIGNAL, msg); });
34 // *INDENT-ON*
35
36 alreadyRan = true;
37}
38
39template <typename DBusInterfaceType>
40void PathWatch<DBusInterfaceType>::callback(Context ctx)
41{
42 (this->cb)(ctx);
43}
44
45template <typename DBusInterfaceType>
46void PathWatch<DBusInterfaceType>::callback(Context ctx,
47 sdbusplus::message::message& msg)
48{
49 (this->cb)(ctx, msg);
50}
51} // namespace monitoring
52} // namespace dbus
53} // namespace phosphor