Patrick Venture | 15f0f94 | 2020-07-09 09:38:18 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <blobs-ipmid/blobs.hpp> |
| 4 | #include <cstdint> |
| 5 | #include <memory> |
| 6 | #include <string> |
| 7 | #include <vector> |
| 8 | |
| 9 | using std::size_t; |
| 10 | using std::uint16_t; |
| 11 | using std::uint32_t; |
| 12 | using std::uint64_t; |
| 13 | using std::uint8_t; |
| 14 | |
| 15 | namespace binstore |
| 16 | { |
| 17 | |
| 18 | /** |
| 19 | * @class BinaryStoreInterface is an abstraction for a storage location. |
| 20 | * Each instance would be uniquely identified by a baseId string. |
| 21 | */ |
| 22 | class BinaryStoreInterface |
| 23 | { |
| 24 | public: |
| 25 | virtual ~BinaryStoreInterface() = default; |
| 26 | |
| 27 | /** |
| 28 | * @returns baseId string of the storage. |
| 29 | */ |
| 30 | virtual std::string getBaseBlobId() const = 0; |
| 31 | |
| 32 | /** |
Willy Tu | 7f10780 | 2023-11-06 23:05:25 -0800 | [diff] [blame^] | 33 | * Set the base blob id |
| 34 | * @param baseBlobId: The blob id to update to. |
| 35 | * @returns true if the binary store is updated with the new baseBlobId |
| 36 | */ |
| 37 | virtual bool setBaseBlobId(const std::string& baseBlobId) = 0; |
| 38 | |
| 39 | /** |
Patrick Venture | 15f0f94 | 2020-07-09 09:38:18 -0700 | [diff] [blame] | 40 | * @returns List of all open blob IDs, plus the base. |
| 41 | */ |
| 42 | virtual std::vector<std::string> getBlobIds() const = 0; |
| 43 | |
| 44 | /** |
| 45 | * Opens a blob given its name. If there is no one, create one. |
| 46 | * @param blobId: The blob id to operate on. |
| 47 | * @param flags: Either read flag or r/w flag has to be specified. |
| 48 | * @returns True if open/create successfully. |
| 49 | */ |
| 50 | virtual bool openOrCreateBlob(const std::string& blobId, |
| 51 | uint16_t flags) = 0; |
| 52 | |
| 53 | /** |
| 54 | * Deletes a blob given its name. If there is no one, |
| 55 | * @param blobId: The blob id to operate on. |
| 56 | * @returns True if deleted. |
| 57 | */ |
| 58 | virtual bool deleteBlob(const std::string& blobId) = 0; |
| 59 | |
| 60 | /** |
| 61 | * Reads data from the currently opened blob. |
| 62 | * @param offset: offset into the blob to read |
| 63 | * @param requestedSize: how many bytes to read |
| 64 | * @returns Bytes able to read. Returns empty if nothing can be read or |
| 65 | * if there is no open blob. |
| 66 | */ |
| 67 | virtual std::vector<uint8_t> read(uint32_t offset, |
| 68 | uint32_t requestedSize) = 0; |
| 69 | |
| 70 | /** |
Maksym Sloyko | eb27411 | 2021-10-27 23:48:32 +0000 | [diff] [blame] | 71 | * Reads all data from the blob |
| 72 | * @param blobId: The blob id to operate on. |
| 73 | * @returns Bytes able to read. Returns empty if nothing can be read or |
| 74 | * if there is no such blob. |
| 75 | */ |
| 76 | virtual std::vector<uint8_t> readBlob(const std::string& blobId) const = 0; |
| 77 | |
| 78 | /** |
Patrick Venture | 15f0f94 | 2020-07-09 09:38:18 -0700 | [diff] [blame] | 79 | * Writes data to the currently openend blob. |
| 80 | * @param offset: offset into the blob to write |
| 81 | * @param data: bytes to write |
| 82 | * @returns True if able to write the entire data successfully |
| 83 | */ |
| 84 | virtual bool write(uint32_t offset, const std::vector<uint8_t>& data) = 0; |
| 85 | |
| 86 | /** |
| 87 | * Commits data to the persistent storage specified during blob init. |
| 88 | * @returns True if able to write data to sysfile successfully |
| 89 | */ |
| 90 | virtual bool commit() = 0; |
| 91 | |
| 92 | /** |
| 93 | * Closes blob, which prevents further modifications. Uncommitted data will |
| 94 | * be lost. |
| 95 | * @returns True if able to close the blob successfully |
| 96 | */ |
| 97 | virtual bool close() = 0; |
| 98 | |
| 99 | /** |
| 100 | * Returns blob stat flags. |
| 101 | * @param meta: output stat flags. |
| 102 | * @returns True if able to get the stat flags and write to *meta |
| 103 | */ |
| 104 | virtual bool stat(blobs::BlobMeta* meta) = 0; |
| 105 | }; |
| 106 | |
| 107 | } // namespace binstore |