Jason Ling | 85e54f1 | 2020-11-05 18:47:21 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | #include "buildjson.hpp" |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 3 | #include "image_handler.hpp" |
Jason Ling | 85e54f1 | 2020-11-05 18:47:21 -0800 | [diff] [blame] | 4 | #include "status.hpp" |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 5 | #include "util.hpp" |
Jason Ling | 85e54f1 | 2020-11-05 18:47:21 -0800 | [diff] [blame] | 6 | |
| 7 | #include <blobs-ipmid/blobs.hpp> |
| 8 | |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 9 | #include <cstdint> |
| 10 | #include <map> |
Jason Ling | 85e54f1 | 2020-11-05 18:47:21 -0800 | [diff] [blame] | 11 | #include <memory> |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 12 | #include <string> |
| 13 | #include <unordered_map> |
| 14 | #include <vector> |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame^] | 15 | |
Jason Ling | 85e54f1 | 2020-11-05 18:47:21 -0800 | [diff] [blame] | 16 | namespace ipmi_flash |
| 17 | { |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 18 | |
| 19 | class VersionBlobHandler : public blobs::GenericBlobInterface |
| 20 | { |
| 21 | public: |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame^] | 22 | struct ActionPack |
| 23 | { |
| 24 | /** Only file operation action supported currently */ |
| 25 | std::unique_ptr<TriggerableActionInterface> onOpen; |
| 26 | }; |
| 27 | |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 28 | /** |
| 29 | * Create a VersionBlobHandler. |
| 30 | * |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame^] | 31 | * @param[in] configs - list of blob configurations to support |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 32 | */ |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame^] | 33 | VersionBlobHandler(std::vector<HandlerConfig<ActionPack>>&& configs); |
| 34 | |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 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: |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame^] | 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; |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 78 | std::unordered_map<uint16_t, std::string> sessionToBlob; |
| 79 | }; |
Jason Ling | 85e54f1 | 2020-11-05 18:47:21 -0800 | [diff] [blame] | 80 | } // namespace ipmi_flash |