squash getStat variations into one underlying method
Squash the getStat(name) and getStat(session) into one underlying
method.
Change-Id: I6c00b9f4128a64e3d1a918c8a9d1eaf252de32bc
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/src/ipmiblob/blob_handler.cpp b/src/ipmiblob/blob_handler.cpp
index 0d31b3f..8ec3f9c 100644
--- a/src/ipmiblob/blob_handler.cpp
+++ b/src/ipmiblob/blob_handler.cpp
@@ -212,17 +212,15 @@
return list;
}
-StatResponse BlobHandler::getStat(const std::string& id)
+StatResponse BlobHandler::statGeneric(BlobOEMCommands command,
+ const std::vector<std::uint8_t>& request)
{
StatResponse meta;
- std::vector<std::uint8_t> name, resp;
-
- std::copy(id.begin(), id.end(), std::back_inserter(name));
- name.push_back(0x00); /* need to add nul-terminator. */
+ std::vector<std::uint8_t> resp;
try
{
- resp = sendIpmiPayload(BlobOEMCommands::bmcBlobStat, name);
+ resp = sendIpmiPayload(command, request);
}
catch (const BlobException& b)
{
@@ -242,35 +240,23 @@
return meta;
}
+StatResponse BlobHandler::getStat(const std::string& id)
+{
+ std::vector<std::uint8_t> name;
+ std::copy(id.begin(), id.end(), std::back_inserter(name));
+ name.push_back(0x00); /* need to add nul-terminator. */
+
+ return statGeneric(BlobOEMCommands::bmcBlobStat, name);
+}
+
StatResponse BlobHandler::getStat(std::uint16_t session)
{
- StatResponse meta;
- std::vector<std::uint8_t> resp;
std::vector<std::uint8_t> request;
auto addrSession = reinterpret_cast<const std::uint8_t*>(&session);
std::copy(addrSession, addrSession + sizeof(session),
std::back_inserter(request));
- try
- {
- resp = sendIpmiPayload(BlobOEMCommands::bmcBlobSessionStat, request);
- }
- catch (const BlobException& b)
- {
- throw;
- }
-
- std::memcpy(&meta.blob_state, &resp[0], sizeof(meta.blob_state));
- std::memcpy(&meta.size, &resp[sizeof(meta.blob_state)], sizeof(meta.size));
- int offset = sizeof(meta.blob_state) + sizeof(meta.size);
- std::uint8_t len = resp[offset];
- if (len > 0)
- {
- std::copy(&resp[offset + 1], &resp[resp.size()],
- std::back_inserter(meta.metadata));
- }
-
- return meta;
+ return statGeneric(BlobOEMCommands::bmcBlobSessionStat, request);
}
std::uint16_t BlobHandler::openBlob(const std::string& id,
diff --git a/src/ipmiblob/blob_handler.hpp b/src/ipmiblob/blob_handler.hpp
index a663b63..bc3ebdc 100644
--- a/src/ipmiblob/blob_handler.hpp
+++ b/src/ipmiblob/blob_handler.hpp
@@ -107,6 +107,17 @@
std::uint32_t offset,
const std::vector<std::uint8_t>& bytes);
+ /**
+ * Generic stat reader.
+ *
+ * @param[in] command - the command associated with this write.
+ * @param[in] request - the bytes of the request
+ * @return the metadata StatResponse
+ * @throws BlobException on failure.
+ */
+ StatResponse statGeneric(BlobOEMCommands command,
+ const std::vector<std::uint8_t>& request);
+
IpmiInterface* ipmi;
};