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> |
William A. Kennington III | b45eb5e | 2020-12-23 11:47:05 -0800 | [diff] [blame^] | 13 | #include <string_view> |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 14 | #include <unordered_map> |
| 15 | #include <vector> |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 16 | |
Jason Ling | 85e54f1 | 2020-11-05 18:47:21 -0800 | [diff] [blame] | 17 | namespace ipmi_flash |
| 18 | { |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 19 | |
| 20 | class VersionBlobHandler : public blobs::GenericBlobInterface |
| 21 | { |
| 22 | public: |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 23 | struct ActionPack |
| 24 | { |
| 25 | /** Only file operation action supported currently */ |
| 26 | std::unique_ptr<TriggerableActionInterface> onOpen; |
| 27 | }; |
| 28 | |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 29 | /** |
| 30 | * Create a VersionBlobHandler. |
| 31 | * |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 32 | * @param[in] configs - list of blob configurations to support |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 33 | */ |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 34 | VersionBlobHandler(std::vector<HandlerConfig<ActionPack>>&& configs); |
| 35 | |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 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 | bool cleanup(uint16_t session); |
| 68 | |
| 69 | private: |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 70 | struct BlobInfo |
| 71 | { |
William A. Kennington III | b45eb5e | 2020-12-23 11:47:05 -0800 | [diff] [blame^] | 72 | Pinned<std::string> blobId; |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 73 | 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 III | b45eb5e | 2020-12-23 11:47:05 -0800 | [diff] [blame^] | 78 | std::unordered_map<std::string_view, std::unique_ptr<BlobInfo>> blobInfoMap; |
| 79 | std::unordered_map<uint16_t, BlobInfo*> sessionToBlob; |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 80 | }; |
Jason Ling | 85e54f1 | 2020-11-05 18:47:21 -0800 | [diff] [blame] | 81 | } // namespace ipmi_flash |