summaryrefslogtreecommitdiffstats
path: root/manager.cpp
diff options
context:
space:
mode:
authorKun Yi <kunyi731@gmail.com>2019-11-19 13:42:46 -0800
committerKun Yi <kunyi731@gmail.com>2019-11-19 13:47:45 -0800
commitc892f4a0a863ff982b108d1a73f65dacb2cfbdac (patch)
tree6f945e2288f970e74780953bcb199a5850445a15 /manager.cpp
parent8bc117792fbf118dd74d015546c22612961ccc26 (diff)
downloadphosphor-ipmi-blobs-c892f4a0a863ff982b108d1a73f65dacb2cfbdac.tar.gz
phosphor-ipmi-blobs-c892f4a0a863ff982b108d1a73f65dacb2cfbdac.zip
Refactor various methods to get session or blob handler
Use a single method to fetch the handler, if it can be found using session ID. Signed-off-by: Kun Yi <kunyi731@gmail.com> Change-Id: I648cbc48ebfae479f63d34e8f2465d2c8cbe9d64
Diffstat (limited to 'manager.cpp')
-rw-r--r--manager.cpp121
1 files changed, 27 insertions, 94 deletions
diff --git a/manager.cpp b/manager.cpp
index dcc223e..684f20c 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -155,31 +155,6 @@ GenericBlobInterface* BlobManager::getHandler(const std::string& path)
return nullptr;
}
-GenericBlobInterface* BlobManager::getHandler(uint16_t session)
-{
- auto item = sessions.find(session);
- if (item == sessions.end())
- {
- return nullptr;
- }
-
- return item->second.handler;
-}
-
-SessionInfo* BlobManager::getSessionInfo(uint16_t session)
-{
- auto item = sessions.find(session);
- if (item == sessions.end())
- {
- return nullptr;
- }
-
- /* If we go to multi-threaded, this pointer can be invalidated and this
- * method will need to change.
- */
- return &item->second;
-}
-
std::string BlobManager::getPath(uint16_t session) const
{
auto item = sessions.find(session);
@@ -207,69 +182,40 @@ bool BlobManager::stat(const std::string& path, BlobMeta* meta)
bool BlobManager::stat(uint16_t session, BlobMeta* meta)
{
- /* meta should never be NULL. */
- GenericBlobInterface* handler = getHandler(session);
-
- /* No handler found. */
- if (!handler)
+ if (auto handler = getActionHandle(session))
{
- return false;
+ return handler->stat(session, meta);
}
-
- return handler->stat(session, meta);
+ return false;
}
bool BlobManager::commit(uint16_t session, const std::vector<uint8_t>& data)
{
- GenericBlobInterface* handler = getHandler(session);
-
- /* No handler found. */
- if (!handler)
+ if (auto handler = getActionHandle(session))
{
- return false;
+ return handler->commit(session, data);
}
-
- return handler->commit(session, data);
+ return false;
}
bool BlobManager::close(uint16_t session)
{
- GenericBlobInterface* handler = getHandler(session);
-
- /* No handler found. */
- if (!handler)
- {
- return false;
- }
-
- /* Handler returns failure */
- if (!handler->close(session))
+ if (auto handler = getActionHandle(session))
{
- return false;
+ if (!handler->close(session))
+ {
+ return false;
+ }
+ sessions.erase(session);
+ decrementOpen(getPath(session));
+ return true;
}
-
- sessions.erase(session);
- decrementOpen(getPath(session));
- return true;
+ return false;
}
std::vector<uint8_t> BlobManager::read(uint16_t session, uint32_t offset,
uint32_t requestedSize)
{
- SessionInfo* info = getSessionInfo(session);
-
- /* No session found. */
- if (!info)
- {
- return std::vector<uint8_t>();
- }
-
- /* Check flags. */
- if (!(info->flags & OpenFlags::read))
- {
- return std::vector<uint8_t>();
- }
-
/* TODO: Currently, configure_ac isn't finding libuserlayer, w.r.t the
* symbols I need.
*/
@@ -284,30 +230,22 @@ std::vector<uint8_t> BlobManager::read(uint16_t session, uint32_t offset,
*/
// uint32_t maxTransportSize = ipmi::getChannelMaxTransferSize(ipmiChannel);
- /* Try reading from it. */
- return info->handler->read(session, offset,
- std::min(maximumReadSize, requestedSize));
+ if (auto handler = getActionHandle(session, OpenFlags::read))
+ {
+ return handler->read(session, offset,
+ std::min(maximumReadSize, requestedSize));
+ }
+ return {};
}
bool BlobManager::write(uint16_t session, uint32_t offset,
const std::vector<uint8_t>& data)
{
- SessionInfo* info = getSessionInfo(session);
-
- /* No session found. */
- if (!info)
+ if (auto handler = getActionHandle(session, OpenFlags::write))
{
- return false;
+ return handler->write(session, offset, data);
}
-
- /* Check flags. */
- if (!(info->flags & OpenFlags::write))
- {
- return false;
- }
-
- /* Try writing to it. */
- return info->handler->write(session, offset, data);
+ return {};
}
bool BlobManager::deleteBlob(const std::string& path)
@@ -333,16 +271,11 @@ bool BlobManager::deleteBlob(const std::string& path)
bool BlobManager::writeMeta(uint16_t session, uint32_t offset,
const std::vector<uint8_t>& data)
{
- SessionInfo* info = getSessionInfo(session);
-
- /* No session found. */
- if (!info)
+ if (auto handler = getActionHandle(session))
{
- return false;
+ return handler->writeMeta(session, offset, data);
}
-
- /* Try writing metadata to it. */
- return info->handler->writeMeta(session, offset, data);
+ return false;
}
bool BlobManager::getSession(uint16_t* sess)
OpenPOWER on IntegriCloud