blob: ad380b82e6a8a1f2f547ded654b62fd4ca6f5a87 [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>
13#include <unordered_map>
14#include <vector>
William A. Kennington IIIabf17352020-12-22 21:07:11 -080015
Jason Ling85e54f12020-11-05 18:47:21 -080016namespace ipmi_flash
17{
Jason Lingc78bfc82020-11-05 18:58:16 -080018
19class VersionBlobHandler : public blobs::GenericBlobInterface
20{
21 public:
William A. Kennington IIIabf17352020-12-22 21:07:11 -080022 struct ActionPack
23 {
24 /** Only file operation action supported currently */
25 std::unique_ptr<TriggerableActionInterface> onOpen;
26 };
27
Jason Lingc78bfc82020-11-05 18:58:16 -080028 /**
29 * Create a VersionBlobHandler.
30 *
William A. Kennington IIIabf17352020-12-22 21:07:11 -080031 * @param[in] configs - list of blob configurations to support
Jason Lingc78bfc82020-11-05 18:58:16 -080032 */
William A. Kennington IIIabf17352020-12-22 21:07:11 -080033 VersionBlobHandler(std::vector<HandlerConfig<ActionPack>>&& configs);
34
Jason Lingc78bfc82020-11-05 18:58:16 -080035 ~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 IIIabf17352020-12-22 21:07:11 -080069 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 Lingc78bfc82020-11-05 18:58:16 -080078 std::unordered_map<uint16_t, std::string> sessionToBlob;
79};
Jason Ling85e54f12020-11-05 18:47:21 -080080} // namespace ipmi_flash