blob: 4a3d7d4daef1232539d0c686b720333d99bb1a6d [file] [log] [blame]
#pragma once
#include "handler_config.hpp"
#include "image_handler.hpp"
#include "status.hpp"
#include "util.hpp"
#include <blobs-ipmid/blobs.hpp>
#include <cstdint>
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>
namespace ipmi_flash
{
class VersionBlobHandler : public blobs::GenericBlobInterface
{
public:
struct ActionPack
{
/** Only file operation action supported currently */
std::unique_ptr<TriggerableActionInterface> onOpen;
};
/**
* Create a VersionBlobHandler.
*
* @param[in] configs - list of blob configurations to support
*/
VersionBlobHandler(std::vector<HandlerConfig<ActionPack>>&& configs);
~VersionBlobHandler() = default;
VersionBlobHandler(const VersionBlobHandler&) = delete;
VersionBlobHandler& operator=(const VersionBlobHandler&) = delete;
VersionBlobHandler(VersionBlobHandler&&) = default;
VersionBlobHandler& operator=(VersionBlobHandler&&) = default;
bool canHandleBlob(const std::string& path) override;
std::vector<std::string> getBlobIds() override;
bool deleteBlob(const std::string& path) override;
bool stat(const std::string&, blobs::BlobMeta* meta) override;
bool open(uint16_t session, uint16_t flags,
const std::string& path) override;
std::vector<uint8_t> read(uint16_t session, uint32_t offset,
uint32_t requestedSize) override;
bool write(uint16_t session, uint32_t offset,
const std::vector<uint8_t>& data) override
{
return false; /* not supported */
};
bool writeMeta(uint16_t session, uint32_t offset,
const std::vector<uint8_t>& data) override
{
return false; /* not supported */
}
bool commit(uint16_t session, const std::vector<uint8_t>& data) override
{
return false; // not supported
}
bool close(uint16_t session) override;
bool stat(uint16_t session, blobs::BlobMeta* meta) override;
bool expire(uint16_t session) override;
private:
struct SessionInfo;
struct BlobInfo
{
Pinned<std::string> blobId;
std::unique_ptr<ActionPack> actions;
std::unique_ptr<ImageHandlerInterface> handler;
std::set<SessionInfo*> sessionsToUpdate;
};
struct SessionInfo
{
BlobInfo* blob;
// A cached copy of the version data shared by all clients for a single
// execution of the version retrieval action. This is is null until the
// TriggerableAction has completed. If the action is an error, the
// shared object is nullopt. Otherwise, contains a vector of the version
// data when successfully read.
std::shared_ptr<const std::optional<std::vector<uint8_t>>> data;
};
std::unordered_map<std::string_view, std::unique_ptr<BlobInfo>> blobInfoMap;
std::unordered_map<uint16_t, std::unique_ptr<SessionInfo>> sessionInfoMap;
};
} // namespace ipmi_flash