Skip to content

Commit 25e6316

Browse files
committed
notify-service : Framework to initiate DBus notifications
- This change introduces framework APIs to initiate D-Bus notification calls when the configured notification Mode is set to DBus. - Applications that need to receive notifications are expected to implement the corresponding D-Bus interface and method. - The full implementation is not included in this change, as the PDI interface and methods are still under discussion. Change-Id: I574a297bc850ef4fd797ae8b5f4c1533fc19bbc5 Signed-off-by: Arya K Padman <[email protected]>
1 parent 2885e4e commit 25e6316

File tree

2 files changed

+133
-1
lines changed

2 files changed

+133
-1
lines changed

src/notify_service.cpp

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,86 @@ NotifyService::NotifyService(sdbusplus::async::context& ctx,
3131
ctx.spawn(init(ctx, notifyFilePath));
3232
}
3333

34+
sdbusplus::async::task<std::string>
35+
// NOLINTNEXTLINE
36+
NotifyService::getDbusObjectPath(sdbusplus::async::context& ctx,
37+
const std::string& service,
38+
const std::string& interface)
39+
{
40+
std::string objectPath{};
41+
42+
constexpr auto objMapper =
43+
sdbusplus::async::proxy()
44+
.service("xyz.openbmc_project.ObjectMapper")
45+
.path("/xyz/openbmc_project/object_mapper")
46+
.interface("xyz.openbmc_project.ObjectMapper");
47+
48+
using services = std::map<std::string, std::vector<std::string>>;
49+
using paths = std::map<std::string, services>;
50+
paths subTreesInfo = co_await objMapper.call<paths>(
51+
ctx, "GetSubTree", "/", 0, std::vector<std::string>{interface});
52+
53+
// TODO : Change the logic with std::views
54+
bool objPathFound{false};
55+
for (const auto& [objPath, serviceInterfaceMap] : subTreesInfo)
56+
{
57+
for (const auto& [serviceName, interfaces] : serviceInterfaceMap)
58+
{
59+
if (serviceName == service)
60+
{
61+
objectPath = objPath;
62+
objPathFound = true;
63+
break;
64+
}
65+
}
66+
if (objPathFound)
67+
{
68+
break;
69+
}
70+
}
71+
if (!objPathFound)
72+
{
73+
lg2::error(
74+
"Unable to find the object path which hosts the interface[{INTERFACE}],"
75+
" of the service {SERVICE}",
76+
"INTERFACE", interface, "SERVICE", service);
77+
throw std::runtime_error("Unable to find the DBus object path");
78+
}
79+
80+
co_return objectPath;
81+
}
82+
83+
// NOLINTNEXTLINE
84+
sdbusplus::async::task<> NotifyService::invokeNotifyDBusMethod(
85+
[[maybe_unused]] sdbusplus::async::context& ctx,
86+
[[maybe_unused]] const std::string& service,
87+
[[maybe_unused]] const fs::path& modifiedDataPath)
88+
{
89+
// TODO : Complete DBus notification method once INTERFACE and method name
90+
// finalized
91+
// Step 1 : Invoke getDbusObjectPath()
92+
// Step 2 : Using the object path,interface and service, frame the DBus
93+
// :method call
94+
lg2::warning("DBus notification support is not available currently");
95+
96+
co_return;
97+
}
98+
99+
sdbusplus::async::task<>
100+
// NOLINTNEXTLINE
101+
NotifyService::sendDBusNotification(sdbusplus::async::context& ctx,
102+
std::vector<std::string> services,
103+
fs::path modifiedDataPath)
104+
{
105+
for (const auto& service : services)
106+
{
107+
// NOLINTNEXTLINE
108+
co_await invokeNotifyDBusMethod(ctx, service, modifiedDataPath);
109+
}
110+
111+
co_return;
112+
}
113+
34114
sdbusplus::async::task<>
35115
// NOLINTNEXTLINE
36116
NotifyService::sendSystemDNotification(sdbusplus::async::context& ctx,
@@ -80,7 +160,13 @@ sdbusplus::async::task<> NotifyService::init(sdbusplus::async::context& ctx,
80160
file_operations::readfromFile(notifyFilePath);
81161
if (notifyfileData["NotifyInfo"]["Mode"] == "DBus")
82162
{
83-
// TODO : Send DBUS notification
163+
// Send DBUS notification
164+
// NOLINTNEXTLINE
165+
co_await sendDBusNotification(
166+
ctx,
167+
notifyfileData["NotifyInfo"]["NotifyServices"]
168+
.get<std::vector<std::string>>(),
169+
notifyfileData["ModifiedDataPath"]);
84170
}
85171
else if ((notifyfileData["NotifyInfo"]["Mode"] == "Systemd"))
86172
{

src/notify_service.hpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,52 @@ class NotifyService
3333
const fs::path& notifyFilePath);
3434

3535
private:
36+
/**
37+
* @brief Get the Dbus Object Path object associated with the service
38+
* which implements the given interface.
39+
*
40+
* @param[in] ctx - The async context object
41+
* @param[in] service - The DBus service name
42+
* @param[in] interface - The DBus Interface name
43+
*
44+
* @return DBus Object path as sdbusplus::async::task<std::string>
45+
*/
46+
static sdbusplus::async::task<std::string>
47+
getDbusObjectPath(sdbusplus::async::context& ctx,
48+
const std::string& service,
49+
const std::string& interface);
50+
51+
/**
52+
* @brief API to notify the requested services by triggering the DBus method
53+
* implemented at the service to be notified.
54+
*
55+
* @param[in] ctx - The async context object.
56+
* @param[in] service - The DBus service name which need to be notified
57+
*
58+
* @return void
59+
*/
60+
sdbusplus::async::task<>
61+
invokeNotifyDBusMethod(sdbusplus::async::context& ctx,
62+
const std::string& service,
63+
const fs::path& modifiedDataPath);
64+
65+
/**
66+
* @brief API to the initiate the DBus notification to all the
67+
*. configured services if the mode of notification is DBus.
68+
*
69+
* @param[in] ctx - The async context object.
70+
* @param[in] services - The vector of DBus service name which need to be
71+
* notified
72+
* @param[in] modifiedDataPath - The root path of the modified path given in
73+
*the request
74+
*
75+
* @return void
76+
*/
77+
sdbusplus::async::task<>
78+
sendDBusNotification(sdbusplus::async::context& ctx,
79+
std::vector<std::string> services,
80+
fs::path modifiedDataPath);
81+
3682
/**
3783
* @brief API to initiate the systemd notification to all the configured
3884
* services if the mode of notification is systemd. It will trigger

0 commit comments

Comments
 (0)