1 /**
2  * @file PathWatchimpl.hpp
3  * @brief Add interfaces added watch for the specified path
4  *
5  */
6 #pragma once
7 
8 #include "callback.hpp"
9 #include "data_types.hpp"
10 #include "pathwatch.hpp"
11 
12 #include <sdbusplus/bus/match.hpp>
13 #include <sdbusplus/message.hpp>
14 #include <vector>
15 
16 namespace phosphor
17 {
18 namespace dbus
19 {
20 namespace monitoring
21 {
22 
23 template <typename DBusInterfaceType>
24 void PathWatch<DBusInterfaceType>::start()
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
56