blob: 60e2a51075d2f2da81270a3b29250954682c6990 [file] [log] [blame]
George Liua881c172021-06-21 18:28:11 +08001#pragma once
2
George Liub49b7d82021-02-08 14:10:17 +08003#include "../oem/ibm/host-bmc/host_lamp_test.hpp"
George Liua881c172021-06-21 18:28:11 +08004#include "../oem/ibm/libpldmresponder/file_io.hpp"
5#include "../oem/ibm/libpldmresponder/fru_oem_ibm.hpp"
6#include "../oem/ibm/libpldmresponder/oem_ibm_handler.hpp"
7#include "common/utils.hpp"
8#include "dbus_impl_requester.hpp"
9#include "host-bmc/dbus_to_event_handler.hpp"
10#include "invoker.hpp"
11#include "libpldmresponder/fru.hpp"
12#include "requester/request.hpp"
13
Andrew Jeffery41ca40d2024-06-19 16:52:21 +093014#include <libpldm/pdr.h>
15
George Liua881c172021-06-21 18:28:11 +080016namespace pldm
17{
18namespace oem_ibm
19{
20
21using namespace pldm::state_sensor;
22using namespace pldm::dbus_api;
23
24/**
25 * @class OemIBM
26 *
27 * @brief class for creating all the OEM IBM handlers
28 *
29 * Only in case of OEM_IBM this class object will be instantiated
30 */
31class OemIBM
32{
33 public:
34 OemIBM() = delete;
35 OemIBM(const Pdr&) = delete;
36 OemIBM& operator=(const OemIBM&) = delete;
37 OemIBM(OemIBM&&) = delete;
38 OemIBM& operator=(OemIBM&&) = delete;
39
40 public:
41 /** Constructs OemIBM object
42 *
43 * @param[in] dBusIntf - D-Bus handler
44 * @param[in] mctp_fd - fd of MCTP communications socket
45 * @param[in] mctp_eid - MCTP EID of remote host firmware
46 * @param[in] repo - pointer to BMC's primary PDR repo
47 * @param[in] instanceIdDb - pointer to an InstanceIdDb object
48 * @param[in] event - sd_event handler
49 * @param[in] invoker - invoker handler
50 * @param[in] hostPDRHandler - hostPDRHandler handler
51 * @param[in] platformHandler - platformHandler handler
52 * @param[in] fruHandler - fruHandler handler
53 * @param[in] baseHandler - baseHandler handler
54 * @param[in] reqHandler - reqHandler handler
55 */
56 explicit OemIBM(
57 const pldm::utils::DBusHandler* dBusIntf, int mctp_fd, uint8_t mctp_eid,
58 pldm_pdr* repo, pldm::InstanceIdDb& instanceIdDb,
59 sdeventplus::Event& event, Invoker& invoker,
60 HostPDRHandler* hostPDRHandler, platform::Handler* platformHandler,
61 fru::Handler* fruHandler, base::Handler* baseHandler,
62 pldm::requester::Handler<pldm::requester::Request>* reqHandler) :
63 dBusIntf(dBusIntf),
64 mctp_fd(mctp_fd), mctp_eid(mctp_eid), repo(repo),
65 instanceIdDb(instanceIdDb), event(event), invoker(invoker),
66 reqHandler(reqHandler)
67 {
68 createOemFruHandler();
69 fruHandler->setOemFruHandler(oemFruHandler.get());
70
71 createOemIbmFruHandler();
72 oemIbmFruHandler->setIBMFruHandler(fruHandler);
73
74 createCodeUpdate();
75 createOemPlatformHandler();
76 codeUpdate->setOemPlatformHandler(oemPlatformHandler.get());
77 hostPDRHandler->setOemPlatformHandler(oemPlatformHandler.get());
78 platformHandler->setOemPlatformHandler(oemPlatformHandler.get());
79 baseHandler->setOemPlatformHandler(oemPlatformHandler.get());
80
81 createOemIbmPlatformHandler();
82 oemIbmPlatformHandler->setPlatformHandler(platformHandler);
83
George Liub49b7d82021-02-08 14:10:17 +080084 createHostLampTestHandler();
85
George Liua881c172021-06-21 18:28:11 +080086 registerHandler();
87 }
88
89 private:
90 /** @brief Method for creating codeUpdate handler */
91 void createCodeUpdate()
92 {
93 codeUpdate = std::make_unique<pldm::responder::CodeUpdate>(dBusIntf);
94 codeUpdate->clearDirPath(LID_STAGING_DIR);
95 }
96
97 /** @brief Method for creating oemPlatformHandler
98 *
99 * This method also assigns the oemPlatformHandler to the below
100 * different handlers.
101 */
102 void createOemPlatformHandler()
103 {
104 oemPlatformHandler = std::make_unique<oem_ibm_platform::Handler>(
105 dBusIntf, codeUpdate.get(), mctp_fd, mctp_eid, instanceIdDb, event,
106 reqHandler);
107 }
108
109 /** @brief Method for creating oemIbmPlatformHandler */
110 void createOemIbmPlatformHandler()
111 {
112 oemIbmPlatformHandler =
113 dynamic_cast<pldm::responder::oem_ibm_platform::Handler*>(
114 oemPlatformHandler.get());
115 }
116
117 /** @brief Method for creating oemFruHandler */
118 void createOemFruHandler()
119 {
120 oemFruHandler = std::make_unique<oem_ibm_fru::Handler>(repo);
121 }
122
123 /** @brief Method for creating oemIbmFruHandler */
124 void createOemIbmFruHandler()
125 {
126 oemIbmFruHandler = dynamic_cast<pldm::responder::oem_ibm_fru::Handler*>(
127 oemFruHandler.get());
128 }
129
George Liub49b7d82021-02-08 14:10:17 +0800130 void createHostLampTestHandler()
131 {
132 auto& bus = pldm::utils::DBusHandler::getBus();
133 hostLampTest = std::make_unique<pldm::led::HostLampTest>(
134 bus, "/xyz/openbmc_project/led/groups/host_lamp_test", mctp_eid,
135 instanceIdDb, repo, reqHandler);
136 }
137
George Liua881c172021-06-21 18:28:11 +0800138 /** @brief Method for registering PLDM OEM handler */
139 void registerHandler()
140 {
141 invoker.registerHandler(
142 PLDM_OEM, std::make_unique<pldm::responder::oem_ibm::Handler>(
143 oemPlatformHandler.get(), mctp_fd, mctp_eid,
144 &instanceIdDb, reqHandler));
145 }
146
147 private:
148 /** @brief D-Bus handler */
149 const pldm::utils::DBusHandler* dBusIntf;
150
151 /** @brief fd of MCTP communications socket */
152 int mctp_fd;
153
154 /** @brief MCTP EID of remote host firmware */
155 uint8_t mctp_eid;
156
157 /** @brief pointer to BMC's primary PDR repo */
158 pldm_pdr* repo;
159
160 /** @brief reference to an Instance ID database object, used to obtain PLDM
161 * instance IDs
162 */
163 pldm::InstanceIdDb& instanceIdDb;
164
165 /** @brief reference of main event loop of pldmd, primarily used to schedule
166 * work
167 */
168 sdeventplus::Event& event;
169
170 /** @brief Object to the invoker class*/
171 Invoker& invoker;
172
173 /** @brief pointer to the requester class*/
174 requester::Handler<requester::Request>* reqHandler;
175
176 /** @brief pointer to the oem_ibm_handler class*/
177 std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
178
179 /** @brief pointer to the oem_ibm_fru class*/
180 std::unique_ptr<oem_fru::Handler> oemFruHandler{};
181
182 /** @brief pointer to the CodeUpdate class*/
183 std::unique_ptr<pldm::responder::CodeUpdate> codeUpdate{};
184
185 /** @brief oem IBM Platform handler*/
186 pldm::responder::oem_ibm_platform::Handler* oemIbmPlatformHandler = nullptr;
187
188 /** @brief oem IBM Fru handler*/
189 pldm::responder::oem_ibm_fru::Handler* oemIbmFruHandler = nullptr;
George Liub49b7d82021-02-08 14:10:17 +0800190
191 std::unique_ptr<pldm::led::HostLampTest> hostLampTest;
George Liua881c172021-06-21 18:28:11 +0800192};
193
194} // namespace oem_ibm
195} // namespace pldm