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 <unordered_map> 14 #include <vector> 15 16 namespace ipmi_flash 17 { 18 19 class VersionBlobHandler : public blobs::GenericBlobInterface 20 { 21 public: 22 struct ActionPack 23 { 24 /** Only file operation action supported currently */ 25 std::unique_ptr<TriggerableActionInterface> onOpen; 26 }; 27 28 /** 29 * Create a VersionBlobHandler. 30 * 31 * @param[in] configs - list of blob configurations to support 32 */ 33 VersionBlobHandler(std::vector<HandlerConfig<ActionPack>>&& configs); 34 35 ~VersionBlobHandler() = default; 36 VersionBlobHandler(const VersionBlobHandler&) = delete; 37 VersionBlobHandler& operator=(const VersionBlobHandler&) = delete; 38 VersionBlobHandler(VersionBlobHandler&&) = default; 39 VersionBlobHandler& operator=(VersionBlobHandler&&) = default; 40 41 bool canHandleBlob(const std::string& path) override; 42 std::vector<std::string> getBlobIds() override; 43 bool deleteBlob(const std::string& path) override; 44 bool stat(const std::string&, blobs::BlobMeta* meta) override; 45 bool open(uint16_t session, uint16_t flags, 46 const std::string& path) override; 47 std::vector<uint8_t> read(uint16_t session, uint32_t offset, 48 uint32_t requestedSize) override; 49 bool write(uint16_t session, uint32_t offset, 50 const std::vector<uint8_t>& data) override 51 { 52 return false; /* not supported */ 53 }; 54 bool writeMeta(uint16_t session, uint32_t offset, 55 const std::vector<uint8_t>& data) override 56 { 57 return false; /* not supported */ 58 } 59 bool commit(uint16_t session, const std::vector<uint8_t>& data) override 60 { 61 return false; // not supported 62 } 63 bool close(uint16_t session) override; 64 bool stat(uint16_t session, blobs::BlobMeta* meta) override; 65 bool expire(uint16_t session) override; 66 bool cleanup(uint16_t session); 67 68 private: 69 struct BlobInfo 70 { 71 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, BlobInfo> blobInfoMap; 78 std::unordered_map<uint16_t, std::string> sessionToBlob; 79 }; 80 } // namespace ipmi_flash 81