blob: ba6dca3c960017a6a9d71e6433def08a25efce50 [file] [log] [blame]
Patrick Venture15f0f942020-07-09 09:38:18 -07001#pragma once
2
3#include <blobs-ipmid/blobs.hpp>
4#include <cstdint>
5#include <memory>
6#include <string>
7#include <vector>
8
9using std::size_t;
10using std::uint16_t;
11using std::uint32_t;
12using std::uint64_t;
13using std::uint8_t;
14
15namespace 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 */
22class 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 /**
33 * @returns List of all open blob IDs, plus the base.
34 */
35 virtual std::vector<std::string> getBlobIds() const = 0;
36
37 /**
38 * Opens a blob given its name. If there is no one, create one.
39 * @param blobId: The blob id to operate on.
40 * @param flags: Either read flag or r/w flag has to be specified.
41 * @returns True if open/create successfully.
42 */
43 virtual bool openOrCreateBlob(const std::string& blobId,
44 uint16_t flags) = 0;
45
46 /**
47 * Deletes a blob given its name. If there is no one,
48 * @param blobId: The blob id to operate on.
49 * @returns True if deleted.
50 */
51 virtual bool deleteBlob(const std::string& blobId) = 0;
52
53 /**
54 * Reads data from the currently opened blob.
55 * @param offset: offset into the blob to read
56 * @param requestedSize: how many bytes to read
57 * @returns Bytes able to read. Returns empty if nothing can be read or
58 * if there is no open blob.
59 */
60 virtual std::vector<uint8_t> read(uint32_t offset,
61 uint32_t requestedSize) = 0;
62
63 /**
Maksym Sloykoeb274112021-10-27 23:48:32 +000064 * Reads all data from the blob
65 * @param blobId: The blob id to operate on.
66 * @returns Bytes able to read. Returns empty if nothing can be read or
67 * if there is no such blob.
68 */
69 virtual std::vector<uint8_t> readBlob(const std::string& blobId) const = 0;
70
71 /**
Patrick Venture15f0f942020-07-09 09:38:18 -070072 * Writes data to the currently openend blob.
73 * @param offset: offset into the blob to write
74 * @param data: bytes to write
75 * @returns True if able to write the entire data successfully
76 */
77 virtual bool write(uint32_t offset, const std::vector<uint8_t>& data) = 0;
78
79 /**
80 * Commits data to the persistent storage specified during blob init.
81 * @returns True if able to write data to sysfile successfully
82 */
83 virtual bool commit() = 0;
84
85 /**
86 * Closes blob, which prevents further modifications. Uncommitted data will
87 * be lost.
88 * @returns True if able to close the blob successfully
89 */
90 virtual bool close() = 0;
91
92 /**
93 * Returns blob stat flags.
94 * @param meta: output stat flags.
95 * @returns True if able to get the stat flags and write to *meta
96 */
97 virtual bool stat(blobs::BlobMeta* meta) = 0;
98};
99
100} // namespace binstore