blob: 8b7e8eea105336052afbabe9f1b552816137a4a3 [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>
14#include <vector>
15
Marri Devender Rao0dabe592018-04-12 09:18:43 -050016namespace phosphor
17{
18namespace dbus
19{
20namespace monitoring
21{
22
Patrick Venture3d6d3182018-08-31 09:33:09 -070023template <typename DBusInterfaceType>
24void PathWatch<DBusInterfaceType>::start()
Marri Devender Rao0dabe592018-04-12 09:18:43 -050025{
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
41template <typename DBusInterfaceType>
42void PathWatch<DBusInterfaceType>::callback(Context ctx)
43{
44 (this->cb)(ctx);
45}
46
47template <typename DBusInterfaceType>
48void 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