blob: 891977dd99a614927068f714c6e046d6e144b7fb [file] [log] [blame]
Jason Ling85e54f12020-11-05 18:47:21 -08001#pragma once
2#include "buildjson.hpp"
Jason Lingc78bfc82020-11-05 18:58:16 -08003#include "image_handler.hpp"
Jason Ling85e54f12020-11-05 18:47:21 -08004#include "status.hpp"
Jason Lingc78bfc82020-11-05 18:58:16 -08005#include "util.hpp"
Jason Ling85e54f12020-11-05 18:47:21 -08006
7#include <blobs-ipmid/blobs.hpp>
8
Jason Lingc78bfc82020-11-05 18:58:16 -08009#include <cstdint>
10#include <map>
Jason Ling85e54f12020-11-05 18:47:21 -080011#include <memory>
Jason Lingc78bfc82020-11-05 18:58:16 -080012#include <string>
William A. Kennington IIIb45eb5e2020-12-23 11:47:05 -080013#include <string_view>
Jason Lingc78bfc82020-11-05 18:58:16 -080014#include <unordered_map>
15#include <vector>
William A. Kennington IIIabf17352020-12-22 21:07:11 -080016
Jason Ling85e54f12020-11-05 18:47:21 -080017namespace ipmi_flash
18{
Jason Lingc78bfc82020-11-05 18:58:16 -080019
20class VersionBlobHandler : public blobs::GenericBlobInterface
21{
22 public:
William A. Kennington IIIabf17352020-12-22 21:07:11 -080023 struct ActionPack
24 {
25 /** Only file operation action supported currently */
26 std::unique_ptr<TriggerableActionInterface> onOpen;
27 };
28
Jason Lingc78bfc82020-11-05 18:58:16 -080029 /**
30 * Create a VersionBlobHandler.
31 *
William A. Kennington IIIabf17352020-12-22 21:07:11 -080032 * @param[in] configs - list of blob configurations to support
Jason Lingc78bfc82020-11-05 18:58:16 -080033 */
William A. Kennington IIIabf17352020-12-22 21:07:11 -080034 VersionBlobHandler(std::vector<HandlerConfig<ActionPack>>&& configs);
35
Jason Lingc78bfc82020-11-05 18:58:16 -080036 ~VersionBlobHandler() = default;
37 VersionBlobHandler(const VersionBlobHandler&) = delete;
38 VersionBlobHandler& operator=(const VersionBlobHandler&) = delete;
39 VersionBlobHandler(VersionBlobHandler&&) = default;
40 VersionBlobHandler& operator=(VersionBlobHandler&&) = default;
41
42 bool canHandleBlob(const std::string& path) override;
43 std::vector<std::string> getBlobIds() override;
44 bool deleteBlob(const std::string& path) override;
45 bool stat(const std::string&, blobs::BlobMeta* meta) override;
46 bool open(uint16_t session, uint16_t flags,
47 const std::string& path) override;
48 std::vector<uint8_t> read(uint16_t session, uint32_t offset,
49 uint32_t requestedSize) override;
50 bool write(uint16_t session, uint32_t offset,
51 const std::vector<uint8_t>& data) override
52 {
53 return false; /* not supported */
54 };
55 bool writeMeta(uint16_t session, uint32_t offset,
56 const std::vector<uint8_t>& data) override
57 {
58 return false; /* not supported */
59 }
60 bool commit(uint16_t session, const std::vector<uint8_t>& data) override
61 {
62 return false; // not supported
63 }
64 bool close(uint16_t session) override;
65 bool stat(uint16_t session, blobs::BlobMeta* meta) override;
66 bool expire(uint16_t session) override;
67 bool cleanup(uint16_t session);
68
69 private:
William A. Kennington IIIabf17352020-12-22 21:07:11 -080070 struct BlobInfo
71 {
William A. Kennington IIIb45eb5e2020-12-23 11:47:05 -080072 Pinned<std::string> blobId;
William A. Kennington IIIabf17352020-12-22 21:07:11 -080073 std::unique_ptr<ActionPack> actions;
74 std::unique_ptr<ImageHandlerInterface> handler;
75 blobs::StateFlags blobState = static_cast<blobs::StateFlags>(0);
76 };
77
William A. Kennington IIIb45eb5e2020-12-23 11:47:05 -080078 std::unordered_map<std::string_view, std::unique_ptr<BlobInfo>> blobInfoMap;
79 std::unordered_map<uint16_t, BlobInfo*> sessionToBlob;
Jason Lingc78bfc82020-11-05 18:58:16 -080080};
Jason Ling85e54f12020-11-05 18:47:21 -080081} // namespace ipmi_flash