1 #pragma once 2 #include "buildjson.hpp" 3 #include "image_handler.hpp" 4 #include "status.hpp" 5 #include "util.hpp" 6 7 #include <blobs-ipmid/blobs.hpp> 8 9 #include <cstdint> 10 #include <map> 11 #include <memory> 12 #include <string> 13 #include <string_view> 14 #include <unordered_map> 15 #include <vector> 16 17 namespace ipmi_flash 18 { 19 20 class VersionBlobHandler : public blobs::GenericBlobInterface 21 { 22 public: 23 struct ActionPack 24 { 25 /** Only file operation action supported currently */ 26 std::unique_ptr<TriggerableActionInterface> onOpen; 27 }; 28 29 /** 30 * Create a VersionBlobHandler. 31 * 32 * @param[in] configs - list of blob configurations to support 33 */ 34 VersionBlobHandler(std::vector<HandlerConfig<ActionPack>>&& configs); 35 36 ~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 68 private: 69 struct BlobInfo 70 { 71 Pinned<std::string> blobId; 72 std::unique_ptr<ActionPack> actions; 73 std::unique_ptr<ImageHandlerInterface> handler; 74 blobs::StateFlags blobState = static_cast<blobs::StateFlags>(0); 75 }; 76 77 std::unordered_map<std::string_view, std::unique_ptr<BlobInfo>> blobInfoMap; 78 std::unordered_map<uint16_t, BlobInfo*> sessionToBlob; 79 }; 80 } // namespace ipmi_flash 81