Revert "pldm: use std::expected for instance ID allocation"
This reverts commit 70262ed7bf854b25d4b65628bc3c892ddfe9380f.
Change-Id: I1f54d6b60bf3cfa9f00764140eec6167e1e182d6
Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
diff --git a/common/instance_id.hpp b/common/instance_id.hpp
index 2a29f82..40de1f1 100644
--- a/common/instance_id.hpp
+++ b/common/instance_id.hpp
@@ -5,70 +5,12 @@
#include <cerrno>
#include <cstdint>
#include <exception>
-#include <expected>
#include <string>
#include <system_error>
namespace pldm
{
-/**
- * @class InstanceIdError
- * @brief Exception for PLDM instance ID allocation and management errors.
- */
-class InstanceIdError : public std::exception
-{
- public:
- InstanceIdError(const InstanceIdError&) noexcept = default;
- InstanceIdError(InstanceIdError&&) noexcept = default;
- InstanceIdError& operator=(const InstanceIdError&) noexcept = default;
- InstanceIdError& operator=(InstanceIdError&&) noexcept = default;
- ~InstanceIdError() noexcept override = default;
-
- /** @brief Construct with an error code. */
- explicit InstanceIdError(int rc) : rc_(rc), msg_(rcToMsg(rc)) {}
-
- /** @brief Construct with an error code and a string message (copied). */
- InstanceIdError(int rc, const std::string& m) : rc_(rc), msg_(m) {}
-
- /** @brief Construct with an error code and a string message (moved). */
- InstanceIdError(int rc, std::string&& m) : rc_(rc), msg_(std::move(m)) {}
-
- /** @brief Get the error code. */
- int rc() const noexcept
- {
- return rc_;
- }
-
- /** @brief Get the error message. */
- const std::string& msg() const noexcept
- {
- return msg_;
- }
-
- /** @brief Convert an error code to a message. */
- static std::string rcToMsg(int rc)
- {
- switch (rc)
- {
- case -EAGAIN:
- return "No free instance ids";
- default:
- return std::system_category().message(rc);
- }
- }
-
- /** @brief Get the error message (for std::exception). */
- const char* what() const noexcept override
- {
- return msg_.c_str();
- }
-
- private:
- int rc_;
- std::string msg_;
-};
-
/** @class InstanceId
* @brief Implementation of PLDM instance id as per DSP0240 v1.0.0
*/
@@ -111,19 +53,22 @@
/** @brief Allocate an instance ID for the given terminus
* @param[in] tid - the terminus ID the instance ID is associated with
- * @return - PLDM instance id on success, or InstanceIdError on failure
+ * @return - PLDM instance id or -EAGAIN if there are no available instance
+ * IDs
*/
- std::expected<uint8_t, InstanceIdError> next(uint8_t tid)
+ uint8_t next(uint8_t tid)
{
uint8_t id;
int rc = pldm_instance_id_alloc(pldmInstanceIdDb, tid, &id);
+ if (rc == -EAGAIN)
+ {
+ throw std::runtime_error("No free instance ids");
+ }
+
if (rc)
{
- return std::unexpected(
- InstanceIdError{rc, "Failed to allocate instance ID for EID " +
- std::to_string(tid) + ": " +
- InstanceIdError::rcToMsg(rc)});
+ throw std::system_category().default_error_condition(rc);
}
return id;
diff --git a/common/utils.hpp b/common/utils.hpp
index bccd929..358d0d7 100644
--- a/common/utils.hpp
+++ b/common/utils.hpp
@@ -1,6 +1,5 @@
#pragma once
-#include "instance_id.hpp"
#include "types.hpp"
#include <libpldm/base.h>
@@ -21,7 +20,6 @@
#include <cstdint>
#include <deque>
#include <exception>
-#include <expected>
#include <filesystem>
#include <iostream>
#include <map>
@@ -166,28 +164,6 @@
return bcd;
}
-/**
- * @brief Unwraps the result of InstanceId allocation and logs errors.
- *
- * Logs errors if present, but always returns the original result so the caller
- * can choose to handle the error (return, throw, etc).
- *
- * @tparam T Instance ID value type.
- * @param[in] result The result from InstanceIdDb::next().
- * @return std::expected<T, InstanceIdError>
- * Returns the original result (value or error).
- */
-template <typename T>
-std::expected<T, pldm::InstanceIdError> getInstanceId(
- const std::expected<T, pldm::InstanceIdError>& result)
-{
- if (!result)
- {
- std::cerr << result.error().msg() << std::endl;
- }
- return result;
-}
-
struct DBusMapping
{
std::string objectPath; //!< D-Bus object path
diff --git a/fw-update/device_updater.cpp b/fw-update/device_updater.cpp
index 759bf0d..f61428b 100644
--- a/fw-update/device_updater.cpp
+++ b/fw-update/device_updater.cpp
@@ -19,13 +19,7 @@
void DeviceUpdater::startFwUpdateFlow()
{
- auto instanceIdResult =
- pldm::utils::getInstanceId(updateManager->instanceIdDb.next(eid));
- if (!instanceIdResult)
- {
- return;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = updateManager->instanceIdDb.next(eid);
// NumberOfComponents
const auto& applicableComponents =
std::get<ApplicableComponents>(fwDeviceIDRecord);
@@ -120,13 +114,7 @@
{
pldmRequest.reset();
- auto instanceIdResult =
- pldm::utils::getInstanceId(updateManager->instanceIdDb.next(eid));
- if (!instanceIdResult)
- {
- return;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = updateManager->instanceIdDb.next(eid);
// TransferFlag
const auto& applicableComponents =
std::get<ApplicableComponents>(fwDeviceIDRecord);
@@ -277,13 +265,7 @@
{
pldmRequest.reset();
- auto instanceIdResult =
- pldm::utils::getInstanceId(updateManager->instanceIdDb.next(eid));
- if (!instanceIdResult)
- {
- return;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = updateManager->instanceIdDb.next(eid);
const auto& applicableComponents =
std::get<ApplicableComponents>(fwDeviceIDRecord);
const auto& comp = compImageInfos[applicableComponents[offset]];
@@ -728,14 +710,7 @@
void DeviceUpdater::sendActivateFirmwareRequest()
{
pldmRequest.reset();
-
- auto instanceIdResult =
- pldm::utils::getInstanceId(updateManager->instanceIdDb.next(eid));
- if (!instanceIdResult)
- {
- return;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = updateManager->instanceIdDb.next(eid);
Request request(
sizeof(pldm_msg_hdr) + sizeof(struct pldm_activate_firmware_req));
auto requestMsg = new (request.data()) pldm_msg;
@@ -806,14 +781,7 @@
void DeviceUpdater::sendCancelUpdateComponentRequest()
{
pldmRequest.reset();
-
- auto instanceIdResult =
- pldm::utils::getInstanceId(updateManager->instanceIdDb.next(eid));
- if (!instanceIdResult)
- {
- return;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = updateManager->instanceIdDb.next(eid);
Request request(sizeof(pldm_msg_hdr));
auto requestMsg = new (request.data()) pldm_msg;
diff --git a/fw-update/inventory_manager.cpp b/fw-update/inventory_manager.cpp
index 5f3b3fb..38e8392 100644
--- a/fw-update/inventory_manager.cpp
+++ b/fw-update/inventory_manager.cpp
@@ -34,12 +34,7 @@
void InventoryManager::sendQueryDeviceIdentifiersRequest(mctp_eid_t eid)
{
- auto instanceIdResult = pldm::utils::getInstanceId(instanceIdDb.next(eid));
- if (!instanceIdResult)
- {
- return;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb.next(eid);
Request requestMsg(
sizeof(pldm_msg_hdr) + PLDM_QUERY_DEVICE_IDENTIFIERS_REQ_BYTES);
auto request = new (requestMsg.data()) pldm_msg;
@@ -175,12 +170,7 @@
void InventoryManager::sendQueryDownstreamDevicesRequest(mctp_eid_t eid)
{
Request requestMsg(sizeof(pldm_msg_hdr));
- auto instanceIdResult = pldm::utils::getInstanceId(instanceIdDb.next(eid));
- if (!instanceIdResult)
- {
- return;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb.next(eid);
auto request = new (requestMsg.data()) pldm_msg;
auto rc = encode_query_downstream_devices_req(instanceId, request);
if (rc)
@@ -287,12 +277,7 @@
mctp_eid_t eid, uint32_t dataTransferHandle,
enum transfer_op_flag transferOperationFlag)
{
- auto instanceIdResult = pldm::utils::getInstanceId(instanceIdDb.next(eid));
- if (!instanceIdResult)
- {
- return;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb.next(eid);
Request requestMsg(
sizeof(pldm_msg_hdr) + PLDM_QUERY_DOWNSTREAM_IDENTIFIERS_REQ_BYTES);
auto request = new (requestMsg.data()) pldm_msg;
@@ -468,12 +453,7 @@
{
Request requestMsg(sizeof(pldm_msg_hdr) +
PLDM_GET_DOWNSTREAM_FIRMWARE_PARAMETERS_REQ_BYTES);
- auto instanceIdResult = pldm::utils::getInstanceId(instanceIdDb.next(eid));
- if (!instanceIdResult)
- {
- return;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb.next(eid);
auto request = new (requestMsg.data()) pldm_msg;
pldm_get_downstream_firmware_parameters_req requestParameters{
dataTransferHandle, static_cast<uint8_t>(transferOperationFlag)};
@@ -566,12 +546,7 @@
void InventoryManager::sendGetFirmwareParametersRequest(mctp_eid_t eid)
{
- auto instanceIdResult = pldm::utils::getInstanceId(instanceIdDb.next(eid));
- if (!instanceIdResult)
- {
- return;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb.next(eid);
Request requestMsg(
sizeof(pldm_msg_hdr) + PLDM_GET_FIRMWARE_PARAMETERS_REQ_BYTES);
auto request = new (requestMsg.data()) pldm_msg;
diff --git a/host-bmc/dbus_to_event_handler.cpp b/host-bmc/dbus_to_event_handler.cpp
index 3c82cef..6149050 100644
--- a/host-bmc/dbus_to_event_handler.cpp
+++ b/host-bmc/dbus_to_event_handler.cpp
@@ -27,13 +27,7 @@
void DbusToPLDMEvent::sendEventMsg(uint8_t eventType,
const std::vector<uint8_t>& eventDataVec)
{
- auto instanceIdResult =
- pldm::utils::getInstanceId(instanceIdDb.next(mctp_eid));
- if (!instanceIdResult)
- {
- return;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb.next(mctp_eid);
std::vector<uint8_t> requestMsg(
sizeof(pldm_msg_hdr) + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
eventDataVec.size());
diff --git a/host-bmc/host_pdr_handler.cpp b/host-bmc/host_pdr_handler.cpp
index 20f36df..61b4ccb 100644
--- a/host-bmc/host_pdr_handler.cpp
+++ b/host-bmc/host_pdr_handler.cpp
@@ -189,13 +189,7 @@
{
recordHandle = nextRecordHandle;
}
- auto instanceIdResult =
- pldm::utils::getInstanceId(instanceIdDb.next(mctp_eid));
- if (!instanceIdResult)
- {
- return;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb.next(mctp_eid);
auto rc =
encode_get_pdr_req(instanceId, recordHandle, 0, PLDM_GET_FIRSTPART,
@@ -394,13 +388,7 @@
"RC", rc);
return;
}
- auto instanceIdResult =
- pldm::utils::getInstanceId(instanceIdDb.next(mctp_eid));
- if (!instanceIdResult)
- {
- return;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb.next(mctp_eid);
std::vector<uint8_t> requestMsg(
sizeof(pldm_msg_hdr) + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
actualSize);
@@ -727,13 +715,7 @@
void HostPDRHandler::setHostFirmwareCondition()
{
responseReceived = false;
- auto instanceIdResult =
- pldm::utils::getInstanceId(instanceIdDb.next(mctp_eid));
- if (!instanceIdResult)
- {
- return;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb.next(mctp_eid);
std::vector<uint8_t> requestMsg(
sizeof(pldm_msg_hdr) + PLDM_GET_VERSION_REQ_BYTES);
auto request = new (requestMsg.data()) pldm_msg;
@@ -805,13 +787,7 @@
sensorRearm.byte = 0;
uint8_t tid = std::get<0>(terminusInfo);
- auto instanceIdResult =
- pldm::utils::getInstanceId(instanceIdDb.next(mctp_eid));
- if (!instanceIdResult)
- {
- return;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb.next(mctp_eid);
std::vector<uint8_t> requestMsg(
sizeof(pldm_msg_hdr) +
PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES);
@@ -953,13 +929,7 @@
void HostPDRHandler::getFRURecordTableMetadataByRemote(
const PDRList& fruRecordSetPDRs)
{
- auto instanceIdResult =
- pldm::utils::getInstanceId(instanceIdDb.next(mctp_eid));
- if (!instanceIdResult)
- {
- return;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb.next(mctp_eid);
std::vector<uint8_t> requestMsg(
sizeof(pldm_msg_hdr) + PLDM_GET_FRU_RECORD_TABLE_METADATA_REQ_BYTES);
@@ -1037,13 +1007,7 @@
return;
}
- auto instanceIdResult =
- pldm::utils::getInstanceId(instanceIdDb.next(mctp_eid));
- if (!instanceIdResult)
- {
- return;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb.next(mctp_eid);
std::vector<uint8_t> requestMsg(
sizeof(pldm_msg_hdr) + PLDM_GET_FRU_RECORD_TABLE_REQ_BYTES);
diff --git a/libpldmresponder/platform.cpp b/libpldmresponder/platform.cpp
index 601964b..7a3b63c 100644
--- a/libpldmresponder/platform.cpp
+++ b/libpldmresponder/platform.cpp
@@ -980,12 +980,7 @@
std::vector<uint8_t> requestMsg(
sizeof(pldm_msg_hdr) + PLDM_SET_EVENT_RECEIVER_REQ_BYTES);
auto request = new (requestMsg.data()) pldm_msg;
- auto instanceIdResult = pldm::utils::getInstanceId(instanceIdDb->next(eid));
- if (!instanceIdResult)
- {
- return;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb->next(eid);
uint8_t eventMessageGlobalEnable =
PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE;
uint8_t transportProtocolType = PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP;
diff --git a/oem/ibm/host-bmc/host_lamp_test.cpp b/oem/ibm/host-bmc/host_lamp_test.cpp
index 1dda9f2..e7485d8 100644
--- a/oem/ibm/host-bmc/host_lamp_test.cpp
+++ b/oem/ibm/host-bmc/host_lamp_test.cpp
@@ -109,13 +109,7 @@
uint8_t HostLampTest::setHostStateEffecter(uint16_t effecterID)
{
constexpr uint8_t effecterCount = 1;
- auto instanceIdResult =
- pldm::utils::getInstanceId(instanceIdDb.next(mctp_eid));
- if (!instanceIdResult)
- {
- return PLDM_ERROR;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb.next(mctp_eid);
std::vector<uint8_t> requestMsg(
sizeof(pldm_msg_hdr) + sizeof(effecterID) + sizeof(effecterCount) +
diff --git a/oem/ibm/libpldmresponder/oem_ibm_handler.cpp b/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
index 34e6d70..decb953 100644
--- a/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
+++ b/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
@@ -524,13 +524,7 @@
eventClass->sensor_offset = sensorOffset;
eventClass->event_state = eventState;
eventClass->previous_event_state = prevEventState;
- auto instanceIdResult =
- pldm::utils::getInstanceId(instanceIdDb.next(mctp_eid));
- if (!instanceIdResult)
- {
- return;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb.next(mctp_eid);
std::vector<uint8_t> requestMsg(
sizeof(pldm_msg_hdr) + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
sensorEventDataVec.size());
diff --git a/oem/ibm/libpldmresponder/platform_oem_ibm.cpp b/oem/ibm/libpldmresponder/platform_oem_ibm.cpp
index 0663b01..47c1e53 100644
--- a/oem/ibm/libpldmresponder/platform_oem_ibm.cpp
+++ b/oem/ibm/libpldmresponder/platform_oem_ibm.cpp
@@ -61,12 +61,7 @@
"ERROR", e);
}
- auto instanceIdResult = pldm::utils::getInstanceId(instanceIdDb->next(eid));
- if (!instanceIdResult)
- {
- return PLDM_ERROR;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb->next(eid);
std::vector<uint8_t> requestMsg(
sizeof(pldm_msg_hdr) + sizeof(pldm_bios_attribute_update_event_req) -
diff --git a/oem/ibm/requester/dbus_to_file_handler.cpp b/oem/ibm/requester/dbus_to_file_handler.cpp
index 8bc25af..6ca2975 100644
--- a/oem/ibm/requester/dbus_to_file_handler.cpp
+++ b/oem/ibm/requester/dbus_to_file_handler.cpp
@@ -40,13 +40,7 @@
"xyz.openbmc_project.bmc.pldm.InternalFailure");
return;
}
- auto instanceIdResult =
- pldm::utils::getInstanceId(instanceIdDb->next(mctp_eid));
- if (!instanceIdResult)
- {
- return;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb->next(mctp_eid);
std::vector<uint8_t> requestMsg(
sizeof(pldm_msg_hdr) + PLDM_NEW_FILE_REQ_BYTES);
auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
@@ -258,13 +252,7 @@
"xyz.openbmc_project.bmc.pldm.InternalFailure");
return;
}
- auto instanceIdResult =
- pldm::utils::getInstanceId(instanceIdDb->next(mctp_eid));
- if (!instanceIdResult)
- {
- return;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb->next(mctp_eid);
std::vector<uint8_t> requestMsg(
sizeof(pldm_msg_hdr) + PLDM_NEW_FILE_REQ_BYTES);
auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
diff --git a/platform-mc/dbus_to_terminus_effecters.cpp b/platform-mc/dbus_to_terminus_effecters.cpp
index 594e3c4..0c27f95 100644
--- a/platform-mc/dbus_to_terminus_effecters.cpp
+++ b/platform-mc/dbus_to_terminus_effecters.cpp
@@ -481,13 +481,7 @@
}
}
- auto instanceIdResult =
- pldm::utils::getInstanceId(instanceIdDb->next(mctpEid));
- if (!instanceIdResult)
- {
- return PLDM_ERROR;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb->next(mctpEid);
int rc = PLDM_ERROR;
std::vector<uint8_t> requestMsg;
@@ -626,13 +620,7 @@
}
uint8_t& compEffCnt = hostEffecterInfo[effecterInfoIndex].compEffecterCnt;
- auto instanceIdResult =
- pldm::utils::getInstanceId(instanceIdDb->next(mctpEid));
- if (!instanceIdResult)
- {
- return PLDM_ERROR;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb->next(mctpEid);
std::vector<uint8_t> requestMsg(
sizeof(pldm_msg_hdr) + sizeof(effecterId) + sizeof(compEffCnt) +
diff --git a/platform-mc/terminus_manager.cpp b/platform-mc/terminus_manager.cpp
index bd77fe6..d90b6cf 100644
--- a/platform-mc/terminus_manager.cpp
+++ b/platform-mc/terminus_manager.cpp
@@ -464,12 +464,7 @@
exec::task<int> TerminusManager::getTidOverMctp(mctp_eid_t eid, pldm_tid_t* tid)
{
- auto instanceIdResult = pldm::utils::getInstanceId(instanceIdDb.next(eid));
- if (!instanceIdResult)
- {
- co_return PLDM_ERROR;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb.next(eid);
Request request(sizeof(pldm_msg_hdr));
auto requestMsg = new (request.data()) pldm_msg;
auto rc = encode_get_tid_req(instanceId, requestMsg);
@@ -515,12 +510,7 @@
exec::task<int> TerminusManager::setTidOverMctp(mctp_eid_t eid, pldm_tid_t tid)
{
- auto instanceIdResult = pldm::utils::getInstanceId(instanceIdDb.next(eid));
- if (!instanceIdResult)
- {
- co_return PLDM_ERROR;
- }
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb.next(eid);
Request request(sizeof(pldm_msg_hdr) + sizeof(pldm_set_tid_req));
auto requestMsg = new (request.data()) pldm_msg;
auto rc = encode_set_tid_req(instanceId, tid, requestMsg);
@@ -694,12 +684,7 @@
auto eid = std::get<0>(mctpInfo.value());
auto requestMsg = new (request.data()) pldm_msg;
- auto instanceIdResult = pldm::utils::getInstanceId(instanceIdDb.next(eid));
- if (!instanceIdResult)
- {
- co_return PLDM_ERROR;
- }
- requestMsg->hdr.instance_id = instanceIdResult.value();
+ requestMsg->hdr.instance_id = instanceIdDb.next(eid);
auto rc = co_await sendRecvPldmMsgOverMctp(eid, request, responseMsg,
responseLen);
diff --git a/pldmtool/pldm_cmd_helper.cpp b/pldmtool/pldm_cmd_helper.cpp
index 54260e7..e488557 100644
--- a/pldmtool/pldm_cmd_helper.cpp
+++ b/pldmtool/pldm_cmd_helper.cpp
@@ -89,13 +89,7 @@
void CommandInterface::exec()
{
- auto instanceIdResult =
- pldm::utils::getInstanceId(instanceIdDb.next(mctp_eid));
- if (!instanceIdResult)
- {
- return;
- }
- auto instanceId = instanceIdResult.value();
+ instanceId = instanceIdDb.next(mctp_eid);
auto [rc, requestMsg] = createRequestMsg();
if (rc != PLDM_SUCCESS)
{
diff --git a/requester/test/handler_test.cpp b/requester/test/handler_test.cpp
index ebccdf7..caa4663 100644
--- a/requester/test/handler_test.cpp
+++ b/requester/test/handler_test.cpp
@@ -79,9 +79,7 @@
pldmTransport, event, instanceIdDb, false, seconds(1), 2,
milliseconds(100));
pldm::Request request{};
- auto instanceIdResult = pldm::utils::getInstanceId(instanceIdDb.next(eid));
- ASSERT_TRUE(instanceIdResult);
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb.next(eid);
EXPECT_EQ(instanceId, 0);
auto rc = reqHandler.registerRequest(
eid, instanceId, 0, 0, std::move(request),
@@ -104,9 +102,7 @@
pldmTransport, event, instanceIdDb, false, seconds(1), 2,
milliseconds(100));
pldm::Request request{};
- auto instanceIdResult = pldm::utils::getInstanceId(instanceIdDb.next(eid));
- ASSERT_TRUE(instanceIdResult);
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb.next(eid);
EXPECT_EQ(instanceId, 0);
auto rc = reqHandler.registerRequest(
eid, instanceId, 0, 0, std::move(request),
@@ -127,9 +123,7 @@
pldmTransport, event, instanceIdDb, false, seconds(2), 2,
milliseconds(100));
pldm::Request request{};
- auto instanceIdResult = pldm::utils::getInstanceId(instanceIdDb.next(eid));
- ASSERT_TRUE(instanceIdResult);
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb.next(eid);
EXPECT_EQ(instanceId, 0);
auto rc = reqHandler.registerRequest(
eid, instanceId, 0, 0, std::move(request),
@@ -139,10 +133,7 @@
EXPECT_EQ(rc, PLDM_SUCCESS);
pldm::Request requestNxt{};
- auto instanceIdNxtResult =
- pldm::utils::getInstanceId(instanceIdDb.next(eid));
- ASSERT_TRUE(instanceIdNxtResult);
- auto instanceIdNxt = instanceIdNxtResult.value();
+ auto instanceIdNxt = instanceIdDb.next(eid);
EXPECT_EQ(instanceIdNxt, 1);
rc = reqHandler.registerRequest(
eid, instanceIdNxt, 0, 0, std::move(requestNxt),
@@ -177,9 +168,7 @@
pldmTransport, event, instanceIdDb, false, seconds(1), 2,
milliseconds(100));
- auto instanceIdResult = pldm::utils::getInstanceId(instanceIdDb.next(eid));
- ASSERT_TRUE(instanceIdResult);
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb.next(eid);
EXPECT_EQ(instanceId, 0);
scope.spawn(
@@ -225,9 +214,7 @@
Handler<NiceMock<MockRequest>> reqHandler(
pldmTransport, event, instanceIdDb, false, seconds(1), 2,
milliseconds(100));
- auto instanceIdResult = pldm::utils::getInstanceId(instanceIdDb.next(eid));
- ASSERT_TRUE(instanceIdResult);
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb.next(eid);
EXPECT_EQ(instanceId, 0);
bool stopped = false;
@@ -284,9 +271,7 @@
exec::async_scope scope;
Handler<MockRequest> reqHandler(pldmTransport, event, instanceIdDb, false,
seconds(1), 2, milliseconds(100));
- auto instanceIdResult = pldm::utils::getInstanceId(instanceIdDb.next(eid));
- ASSERT_TRUE(instanceIdResult);
- auto instanceId = instanceIdResult.value();
+ auto instanceId = instanceIdDb.next(eid);
uint8_t expectedTid = 1;
diff --git a/softoff/softoff.cpp b/softoff/softoff.cpp
index d72af59..9721c7e 100644
--- a/softoff/softoff.cpp
+++ b/softoff/softoff.cpp
@@ -271,6 +271,7 @@
{
constexpr uint8_t effecterCount = 1;
PldmTransport pldmTransport{};
+ uint8_t instanceID;
uint8_t mctpEID;
mctpEID = pldm::utils::readHostEID();
@@ -284,13 +285,7 @@
auto request = new (requestMsg.data()) pldm_msg;
set_effecter_state_field stateField{
PLDM_REQUEST_SET, PLDM_SW_TERM_GRACEFUL_SHUTDOWN_REQUESTED};
- auto instanceIdResult =
- pldm::utils::getInstanceId(instanceIdDb.next(pldmTID));
- if (!instanceIdResult)
- {
- return PLDM_ERROR;
- }
- auto instanceID = instanceIdResult.value();
+ instanceID = instanceIdDb.next(pldmTID);
auto rc = encode_set_state_effecter_states_req(
instanceID, effecterID, effecterCount, &stateField, request);
if (rc != PLDM_SUCCESS)