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