cleanup: Use scoped initializers; move implementation to source file
Simplify code and address comments from
http://gerrit.openbmc-project.xyz/c/openbmc/phosphor-ipmi-blobs/+/27399:
* Use C++17 syntax of intializers in conditionals to simplify code.
* Move getActionHandle() implementation to .cpp
* return false explicitly
Tested:
Unit tests still pass.
Signed-off-by: Kun Yi <kunyi731@gmail.com>
Change-Id: I08a78125206f284d8c748822912e11828fb39968
diff --git a/manager.cpp b/manager.cpp
index 15ff083..0eec6f2 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -170,15 +170,26 @@
return nullptr;
}
+GenericBlobInterface* BlobManager::getActionHandle(uint16_t session,
+ uint16_t requiredFlags)
+{
+ if (auto item = sessions.find(session);
+ item != sessions.end() && (item->second.flags & requiredFlags))
+ {
+ item->second.lastActionTime = std::chrono::steady_clock::now();
+ return item->second.handler;
+ }
+ return nullptr;
+}
+
std::string BlobManager::getPath(uint16_t session) const
{
- auto item = sessions.find(session);
- if (item == sessions.end())
+ if (auto item = sessions.find(session); item != sessions.end())
{
- return "";
+ return item->second.blobId;
}
- return item->second.blobId;
+ return "";
}
bool BlobManager::stat(const std::string& path, BlobMeta* meta)
@@ -259,7 +270,7 @@
{
return handler->write(session, offset, data);
}
- return {};
+ return false;
}
bool BlobManager::deleteBlob(const std::string& path)
diff --git a/manager.hpp b/manager.hpp
index cba7935..3097201 100644
--- a/manager.hpp
+++ b/manager.hpp
@@ -256,16 +256,7 @@
*/
GenericBlobInterface* getActionHandle(
uint16_t session,
- uint16_t requiredFlags = std::numeric_limits<uint16_t>::max())
- {
- if (auto item = sessions.find(session);
- item != sessions.end() && (item->second.flags & requiredFlags))
- {
- item->second.lastActionTime = std::chrono::steady_clock::now();
- return item->second.handler;
- }
- return nullptr;
- }
+ uint16_t requiredFlags = std::numeric_limits<uint16_t>::max());
/**
* Given a session id will return associated path.