blob: 54b90fdaefbfe6447cc0496baa746a4b5f0cc9fb [file] [log] [blame]
Sagar Srinivas11ce8d22022-07-28 11:32:34 -05001#include "bios_oem_ibm.hpp"
2
3namespace pldm
4{
5namespace responder
6{
7namespace oem::ibm::bios
8{
9/** @brief Method to get the system type information
10 *
11 * @return - the system type information
12 */
13std::optional<std::string>
14 pldm::responder::oem::ibm::bios::Handler::getPlatformName()
15{
16 if (!systemType.empty())
17 {
18 return systemType;
19 }
20
21 static constexpr auto searchpath = "/xyz/openbmc_project/";
22 int depth = 0;
23 std::vector<std::string> ibmCompatible = {compatibleInterface};
24 pldm::utils::GetSubTreeResponse response;
25 try
26 {
27 response = pldm::utils::DBusHandler().getSubtree(searchpath, depth,
28 ibmCompatible);
29 }
30 catch (const sdbusplus::exception_t& e)
31 {
32 error(
33 " getSubtree call failed with, ERROR={ERROR} PATH={PATH} INTERFACE={INTERFACE}",
34 "ERROR", e.what(), "PATH", searchpath, "INTERFACE",
35 ibmCompatible[0]);
36 return std::nullopt;
37 }
38
39 for (const auto& [objectPath, serviceMap] : response)
40 {
41 try
42 {
43 auto value = pldm::utils::DBusHandler()
44 .getDbusProperty<std::vector<std::string>>(
45 objectPath.c_str(), namesProperty,
46 ibmCompatible[0].c_str());
47 return value[0];
48 }
49 catch (const sdbusplus::exception_t& e)
50 {
51 error(
52 " Error getting Names property, ERROR={ERROR} PATH={PATH} INTERFACE={INTERFACE}",
53 "ERROR", e.what(), "PATH", searchpath, "INTERFACE",
54 ibmCompatible[0]);
55 }
56 }
57 return std::nullopt;
58}
59
60/** @brief callback function invoked when interfaces get added from
61 * Entity manager
62 *
63 * @param[in] msg - Data associated with subscribed signal
64 */
65void pldm::responder::oem::ibm::bios::Handler::ibmCompatibleAddedCallback(
Patrick Williams98e703f2023-08-15 02:34:38 -050066 sdbusplus::message_t& msg)
Sagar Srinivas11ce8d22022-07-28 11:32:34 -050067{
68 sdbusplus::message::object_path path;
69
70 pldm::utils::InterfaceMap interfaceMap;
71
72 msg.read(path, interfaceMap);
73
74 if (!interfaceMap.contains(compatibleInterface))
75 {
76 return;
77 }
78 // Get the "Name" property value of the
79 // "xyz.openbmc_project.Configuration.IBMCompatibleSystem" interface
80 const auto& properties = interfaceMap.at(compatibleInterface);
81
82 if (!properties.contains(namesProperty))
83 {
84 return;
85 }
86 auto names =
87 std::get<pldm::utils::Interfaces>(properties.at(namesProperty));
88
89 // get only the first system type
90 if (!names.empty())
91 {
92 systemType = names.front();
93 }
94
95 if (!systemType.empty())
96 {
97 ibmCompatibleMatchConfig.reset();
98 }
99}
100
101} // namespace oem::ibm::bios
102} // namespace responder
103} // namespace pldm