Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Andrew Jeffery | 2abbce7 | 2023-10-18 10:17:35 +1030 | [diff] [blame] | 3 | #include "common/instance_id.hpp" |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 4 | #include "common/transport.hpp" |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 5 | #include "common/types.hpp" |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 6 | #include "request.hpp" |
| 7 | |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 8 | #include <libpldm/base.h> |
Manojkiran Eda | 9fffea2 | 2021-10-27 16:03:27 +0530 | [diff] [blame] | 9 | #include <sys/socket.h> |
| 10 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 11 | #include <phosphor-logging/lg2.hpp> |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 12 | #include <sdbusplus/timer.hpp> |
| 13 | #include <sdeventplus/event.hpp> |
| 14 | #include <sdeventplus/source/event.hpp> |
| 15 | |
| 16 | #include <cassert> |
| 17 | #include <chrono> |
Thu Nguyen | 4ddee3a | 2023-08-03 08:20:03 +0700 | [diff] [blame] | 18 | #include <deque> |
Patrick Williams | cdbb9e2 | 2023-07-13 18:05:40 -0500 | [diff] [blame] | 19 | #include <functional> |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 20 | #include <memory> |
Thu Nguyen | 4ddee3a | 2023-08-03 08:20:03 +0700 | [diff] [blame] | 21 | #include <mutex> |
| 22 | #include <queue> |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 23 | #include <tuple> |
| 24 | #include <unordered_map> |
| 25 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 26 | PHOSPHOR_LOG2_USING; |
| 27 | |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 28 | namespace pldm |
| 29 | { |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 30 | namespace requester |
| 31 | { |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 32 | /** @struct RequestKey |
| 33 | * |
| 34 | * RequestKey uniquely identifies the PLDM request message to match it with the |
| 35 | * response and a combination of MCTP endpoint ID, PLDM instance ID, PLDM type |
| 36 | * and PLDM command is the key. |
| 37 | */ |
| 38 | struct RequestKey |
| 39 | { |
| 40 | mctp_eid_t eid; //!< MCTP endpoint ID |
| 41 | uint8_t instanceId; //!< PLDM instance ID |
| 42 | uint8_t type; //!< PLDM type |
| 43 | uint8_t command; //!< PLDM command |
| 44 | |
| 45 | bool operator==(const RequestKey& e) const |
| 46 | { |
| 47 | return ((eid == e.eid) && (instanceId == e.instanceId) && |
| 48 | (type == e.type) && (command == e.command)); |
| 49 | } |
| 50 | }; |
| 51 | |
| 52 | /** @struct RequestKeyHasher |
| 53 | * |
| 54 | * This is a simple hash function, since the instance ID generator API |
| 55 | * generates unique instance IDs for MCTP endpoint ID. |
| 56 | */ |
| 57 | struct RequestKeyHasher |
| 58 | { |
| 59 | std::size_t operator()(const RequestKey& key) const |
| 60 | { |
| 61 | return (key.eid << 24 | key.instanceId << 16 | key.type << 8 | |
| 62 | key.command); |
| 63 | } |
| 64 | }; |
| 65 | |
Thu Nguyen | 4ddee3a | 2023-08-03 08:20:03 +0700 | [diff] [blame] | 66 | using ResponseHandler = std::function<void( |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 67 | mctp_eid_t eid, const pldm_msg* response, size_t respMsgLen)>; |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 68 | |
Thu Nguyen | 4ddee3a | 2023-08-03 08:20:03 +0700 | [diff] [blame] | 69 | /** @struct RegisteredRequest |
| 70 | * |
| 71 | * This struct is used to store the registered request to one endpoint. |
| 72 | */ |
| 73 | struct RegisteredRequest |
| 74 | { |
| 75 | RequestKey key; //!< Responder MCTP endpoint ID |
| 76 | std::vector<uint8_t> reqMsg; //!< Request messages queue |
| 77 | ResponseHandler responseHandler; //!< Waiting for response flag |
| 78 | }; |
| 79 | |
| 80 | /** @struct EndpointMessageQueue |
| 81 | * |
| 82 | * This struct is used to save the list of request messages of one endpoint and |
| 83 | * the existing of the request message to the endpoint with its' EID. |
| 84 | */ |
| 85 | struct EndpointMessageQueue |
| 86 | { |
| 87 | mctp_eid_t eid; //!< Responder MCTP endpoint ID |
| 88 | std::deque<std::shared_ptr<RegisteredRequest>> requestQueue; //!< Queue |
| 89 | bool activeRequest; //!< Waiting for response flag |
| 90 | |
| 91 | bool operator==(const mctp_eid_t& mctpEid) const |
| 92 | { |
| 93 | return (eid == mctpEid); |
| 94 | } |
| 95 | }; |
| 96 | |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 97 | /** @class Handler |
| 98 | * |
| 99 | * This class handles the lifecycle of the PLDM request message based on the |
| 100 | * instance ID expiration interval, number of request retries and the timeout |
| 101 | * waiting for a response. The registered response handlers are invoked with |
| 102 | * response once the PLDM responder sends the response. If no response is |
| 103 | * received within the instance ID expiration interval or any other failure the |
| 104 | * response handler is invoked with the empty response. |
| 105 | * |
| 106 | * @tparam RequestInterface - Request class type |
| 107 | */ |
| 108 | template <class RequestInterface> |
| 109 | class Handler |
| 110 | { |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 111 | public: |
| 112 | Handler() = delete; |
| 113 | Handler(const Handler&) = delete; |
| 114 | Handler(Handler&&) = delete; |
| 115 | Handler& operator=(const Handler&) = delete; |
| 116 | Handler& operator=(Handler&&) = delete; |
| 117 | ~Handler() = default; |
| 118 | |
| 119 | /** @brief Constructor |
| 120 | * |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 121 | * @param[in] pldm_transport - PLDM requester |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 122 | * @param[in] event - reference to PLDM daemon's main event loop |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 123 | * @param[in] instanceIdDb - reference to an InstanceIdDb |
Tom Joseph | e5268cd | 2021-09-07 13:04:03 +0530 | [diff] [blame] | 124 | * @param[in] verbose - verbose tracing flag |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 125 | * @param[in] instanceIdExpiryInterval - instance ID expiration interval |
| 126 | * @param[in] numRetries - number of request retries |
| 127 | * @param[in] responseTimeOut - time to wait between each retry |
| 128 | */ |
| 129 | explicit Handler( |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 130 | PldmTransport* pldmTransport, sdeventplus::Event& event, |
| 131 | pldm::InstanceIdDb& instanceIdDb, bool verbose, |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 132 | std::chrono::seconds instanceIdExpiryInterval = |
| 133 | std::chrono::seconds(INSTANCE_ID_EXPIRATION_INTERVAL), |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 134 | uint8_t numRetries = static_cast<uint8_t>(NUMBER_OF_REQUEST_RETRIES), |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 135 | std::chrono::milliseconds responseTimeOut = |
| 136 | std::chrono::milliseconds(RESPONSE_TIME_OUT)) : |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 137 | pldmTransport(pldmTransport), |
| 138 | event(event), instanceIdDb(instanceIdDb), verbose(verbose), |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 139 | instanceIdExpiryInterval(instanceIdExpiryInterval), |
| 140 | numRetries(numRetries), responseTimeOut(responseTimeOut) |
| 141 | {} |
| 142 | |
Thu Nguyen | 4ddee3a | 2023-08-03 08:20:03 +0700 | [diff] [blame] | 143 | void instanceIdExpiryCallBack(RequestKey key) |
| 144 | { |
| 145 | auto eid = key.eid; |
| 146 | if (this->handlers.contains(key)) |
| 147 | { |
Riya Dixit | 087a751 | 2024-04-06 14:28:08 -0500 | [diff] [blame^] | 148 | info( |
| 149 | "Instance ID expiry for EID '{EID}' using InstanceID '{INSTANCEID}'", |
| 150 | "EID", (unsigned)key.eid, "INSTANCEID", |
| 151 | (unsigned)key.instanceId); |
Thu Nguyen | 4ddee3a | 2023-08-03 08:20:03 +0700 | [diff] [blame] | 152 | auto& [request, responseHandler, |
| 153 | timerInstance] = this->handlers[key]; |
| 154 | request->stop(); |
| 155 | auto rc = timerInstance->stop(); |
| 156 | if (rc) |
| 157 | { |
Riya Dixit | 087a751 | 2024-04-06 14:28:08 -0500 | [diff] [blame^] | 158 | error( |
| 159 | "Failed to stop the instance ID expiry timer, response code '{RC}'", |
| 160 | "RC", static_cast<int>(rc)); |
Thu Nguyen | 4ddee3a | 2023-08-03 08:20:03 +0700 | [diff] [blame] | 161 | } |
| 162 | // Call response handler with an empty response to indicate no |
| 163 | // response |
| 164 | responseHandler(eid, nullptr, 0); |
| 165 | this->removeRequestContainer.emplace( |
| 166 | key, |
| 167 | std::make_unique<sdeventplus::source::Defer>( |
| 168 | event, std::bind(&Handler::removeRequestEntry, this, key))); |
| 169 | endpointMessageQueues[eid]->activeRequest = false; |
| 170 | |
| 171 | /* try to send new request if the endpoint is free */ |
| 172 | pollEndpointQueue(eid); |
| 173 | } |
| 174 | else |
| 175 | { |
| 176 | // This condition is not possible, if a response is received |
| 177 | // before the instance ID expiry, then the response handler |
| 178 | // is executed and the entry will be removed. |
| 179 | assert(false); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | /** @brief Send the remaining PLDM request messages in endpoint queue |
| 184 | * |
| 185 | * @param[in] eid - endpoint ID of the remote MCTP endpoint |
| 186 | */ |
| 187 | int pollEndpointQueue(mctp_eid_t eid) |
| 188 | { |
| 189 | if (endpointMessageQueues[eid]->activeRequest || |
| 190 | endpointMessageQueues[eid]->requestQueue.empty()) |
| 191 | { |
| 192 | return PLDM_SUCCESS; |
| 193 | } |
| 194 | |
| 195 | endpointMessageQueues[eid]->activeRequest = true; |
| 196 | auto requestMsg = endpointMessageQueues[eid]->requestQueue.front(); |
| 197 | endpointMessageQueues[eid]->requestQueue.pop_front(); |
| 198 | |
| 199 | auto request = std::make_unique<RequestInterface>( |
| 200 | pldmTransport, requestMsg->key.eid, event, |
| 201 | std::move(requestMsg->reqMsg), numRetries, responseTimeOut, |
| 202 | verbose); |
Patrick Williams | 35535cf | 2023-12-05 12:45:02 -0600 | [diff] [blame] | 203 | auto timer = std::make_unique<sdbusplus::Timer>( |
Thu Nguyen | 4ddee3a | 2023-08-03 08:20:03 +0700 | [diff] [blame] | 204 | event.get(), std::bind(&Handler::instanceIdExpiryCallBack, this, |
| 205 | requestMsg->key)); |
| 206 | |
| 207 | auto rc = request->start(); |
| 208 | if (rc) |
| 209 | { |
| 210 | instanceIdDb.free(requestMsg->key.eid, requestMsg->key.instanceId); |
Riya Dixit | 087a751 | 2024-04-06 14:28:08 -0500 | [diff] [blame^] | 211 | error( |
| 212 | "Failure to send the PLDM request message for polling endpoint queue, response code '{RC}'", |
| 213 | "RC", rc); |
Thu Nguyen | 4ddee3a | 2023-08-03 08:20:03 +0700 | [diff] [blame] | 214 | endpointMessageQueues[eid]->activeRequest = false; |
| 215 | return rc; |
| 216 | } |
| 217 | |
| 218 | try |
| 219 | { |
| 220 | timer->start(duration_cast<std::chrono::microseconds>( |
| 221 | instanceIdExpiryInterval)); |
| 222 | } |
| 223 | catch (const std::runtime_error& e) |
| 224 | { |
| 225 | instanceIdDb.free(requestMsg->key.eid, requestMsg->key.instanceId); |
| 226 | error( |
Riya Dixit | 087a751 | 2024-04-06 14:28:08 -0500 | [diff] [blame^] | 227 | "Failed to start the instance ID expiry timer, error - {ERROR}", |
| 228 | "ERROR", e); |
Thu Nguyen | 4ddee3a | 2023-08-03 08:20:03 +0700 | [diff] [blame] | 229 | endpointMessageQueues[eid]->activeRequest = false; |
| 230 | return PLDM_ERROR; |
| 231 | } |
| 232 | |
| 233 | handlers.emplace(requestMsg->key, |
| 234 | std::make_tuple(std::move(request), |
| 235 | std::move(requestMsg->responseHandler), |
| 236 | std::move(timer))); |
| 237 | return PLDM_SUCCESS; |
| 238 | } |
| 239 | |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 240 | /** @brief Register a PLDM request message |
| 241 | * |
| 242 | * @param[in] eid - endpoint ID of the remote MCTP endpoint |
| 243 | * @param[in] instanceId - instance ID to match request and response |
| 244 | * @param[in] type - PLDM type |
| 245 | * @param[in] command - PLDM command |
| 246 | * @param[in] requestMsg - PLDM request message |
| 247 | * @param[in] responseHandler - Response handler for this request |
| 248 | * |
| 249 | * @return return PLDM_SUCCESS on success and PLDM_ERROR otherwise |
| 250 | */ |
| 251 | int registerRequest(mctp_eid_t eid, uint8_t instanceId, uint8_t type, |
| 252 | uint8_t command, pldm::Request&& requestMsg, |
| 253 | ResponseHandler&& responseHandler) |
| 254 | { |
| 255 | RequestKey key{eid, instanceId, type, command}; |
| 256 | |
Thu Nguyen | b4e8cfd | 2023-03-23 15:06:44 +0700 | [diff] [blame] | 257 | if (handlers.contains(key)) |
| 258 | { |
Riya Dixit | 087a751 | 2024-04-06 14:28:08 -0500 | [diff] [blame^] | 259 | error( |
| 260 | "Register request for EID '{EID}' is using InstanceID '{INSTANCEID}'", |
| 261 | "EID", (unsigned)eid, "INSTANCEID", (unsigned)instanceId); |
Thu Nguyen | b4e8cfd | 2023-03-23 15:06:44 +0700 | [diff] [blame] | 262 | return PLDM_ERROR; |
| 263 | } |
| 264 | |
Thu Nguyen | 4ddee3a | 2023-08-03 08:20:03 +0700 | [diff] [blame] | 265 | auto inputRequest = std::make_shared<RegisteredRequest>( |
| 266 | key, std::move(requestMsg), std::move(responseHandler)); |
| 267 | if (endpointMessageQueues.contains(eid)) |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 268 | { |
Thu Nguyen | 4ddee3a | 2023-08-03 08:20:03 +0700 | [diff] [blame] | 269 | endpointMessageQueues[eid]->requestQueue.push_back(inputRequest); |
| 270 | } |
| 271 | else |
| 272 | { |
| 273 | std::deque<std::shared_ptr<RegisteredRequest>> reqQueue; |
| 274 | reqQueue.push_back(inputRequest); |
| 275 | endpointMessageQueues[eid] = |
| 276 | std::make_shared<EndpointMessageQueue>(eid, reqQueue, false); |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Thu Nguyen | 4ddee3a | 2023-08-03 08:20:03 +0700 | [diff] [blame] | 279 | /* try to send new request if the endpoint is free */ |
| 280 | pollEndpointQueue(eid); |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 281 | |
Thu Nguyen | 4ddee3a | 2023-08-03 08:20:03 +0700 | [diff] [blame] | 282 | return PLDM_SUCCESS; |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | /** @brief Handle PLDM response message |
| 286 | * |
| 287 | * @param[in] eid - endpoint ID of the remote MCTP endpoint |
| 288 | * @param[in] instanceId - instance ID to match request and response |
| 289 | * @param[in] type - PLDM type |
| 290 | * @param[in] command - PLDM command |
| 291 | * @param[in] response - PLDM response message |
| 292 | * @param[in] respMsgLen - length of the response message |
| 293 | */ |
| 294 | void handleResponse(mctp_eid_t eid, uint8_t instanceId, uint8_t type, |
| 295 | uint8_t command, const pldm_msg* response, |
| 296 | size_t respMsgLen) |
| 297 | { |
| 298 | RequestKey key{eid, instanceId, type, command}; |
| 299 | if (handlers.contains(key)) |
| 300 | { |
| 301 | auto& [request, responseHandler, timerInstance] = handlers[key]; |
| 302 | request->stop(); |
| 303 | auto rc = timerInstance->stop(); |
| 304 | if (rc) |
| 305 | { |
Riya Dixit | 087a751 | 2024-04-06 14:28:08 -0500 | [diff] [blame^] | 306 | error( |
| 307 | "Failed to stop the instance ID expiry timer, response code '{RC}'", |
| 308 | "RC", static_cast<int>(rc)); |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 309 | } |
| 310 | responseHandler(eid, response, respMsgLen); |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 311 | instanceIdDb.free(key.eid, key.instanceId); |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 312 | handlers.erase(key); |
Thu Nguyen | 4ddee3a | 2023-08-03 08:20:03 +0700 | [diff] [blame] | 313 | |
| 314 | endpointMessageQueues[eid]->activeRequest = false; |
| 315 | /* try to send new request if the endpoint is free */ |
| 316 | pollEndpointQueue(eid); |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 317 | } |
| 318 | else |
| 319 | { |
| 320 | // Got a response for a PLDM request message not registered with the |
| 321 | // request handler, so freeing up the instance ID, this can be other |
| 322 | // OpenBMC applications relying on PLDM D-Bus apis like |
| 323 | // openpower-occ-control and softoff |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 324 | instanceIdDb.free(key.eid, key.instanceId); |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | |
| 328 | private: |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 329 | PldmTransport* pldmTransport; //!< PLDM transport object |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 330 | sdeventplus::Event& event; //!< reference to PLDM daemon's main event loop |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 331 | pldm::InstanceIdDb& instanceIdDb; //!< reference to an InstanceIdDb |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 332 | bool verbose; //!< verbose tracing flag |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 333 | std::chrono::seconds |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 334 | instanceIdExpiryInterval; //!< Instance ID expiration interval |
| 335 | uint8_t numRetries; //!< number of request retries |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 336 | std::chrono::milliseconds |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 337 | responseTimeOut; //!< time to wait between each retry |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 338 | |
Tom Joseph | e5268cd | 2021-09-07 13:04:03 +0530 | [diff] [blame] | 339 | /** @brief Container for storing the details of the PLDM request |
| 340 | * message, handler for the corresponding PLDM response and the |
| 341 | * timer object for the Instance ID expiration |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 342 | */ |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 343 | using RequestValue = |
| 344 | std::tuple<std::unique_ptr<RequestInterface>, ResponseHandler, |
Patrick Williams | 35535cf | 2023-12-05 12:45:02 -0600 | [diff] [blame] | 345 | std::unique_ptr<sdbusplus::Timer>>; |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 346 | |
Thu Nguyen | 4ddee3a | 2023-08-03 08:20:03 +0700 | [diff] [blame] | 347 | // Manage the requests of responders base on MCTP EID |
| 348 | std::map<mctp_eid_t, std::shared_ptr<EndpointMessageQueue>> |
| 349 | endpointMessageQueues; |
| 350 | |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 351 | /** @brief Container for storing the PLDM request entries */ |
| 352 | std::unordered_map<RequestKey, RequestValue, RequestKeyHasher> handlers; |
| 353 | |
| 354 | /** @brief Container to store information about the request entries to be |
| 355 | * removed after the instance ID timer expires |
| 356 | */ |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 357 | std::unordered_map<RequestKey, std::unique_ptr<sdeventplus::source::Defer>, |
| 358 | RequestKeyHasher> |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 359 | removeRequestContainer; |
| 360 | |
| 361 | /** @brief Remove request entry for which the instance ID expired |
| 362 | * |
| 363 | * @param[in] key - key for the Request |
| 364 | */ |
| 365 | void removeRequestEntry(RequestKey key) |
| 366 | { |
| 367 | if (removeRequestContainer.contains(key)) |
| 368 | { |
| 369 | removeRequestContainer[key].reset(); |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 370 | instanceIdDb.free(key.eid, key.instanceId); |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 371 | handlers.erase(key); |
| 372 | removeRequestContainer.erase(key); |
| 373 | } |
| 374 | } |
| 375 | }; |
| 376 | |
| 377 | } // namespace requester |
| 378 | |
| 379 | } // namespace pldm |