blob: 73ce17e7975ad5f50c7059932456b065db51186e [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 /**
64 * Writes data to the currently openend blob.
65 * @param offset: offset into the blob to write
66 * @param data: bytes to write
67 * @returns True if able to write the entire data successfully
68 */
69 virtual bool write(uint32_t offset, const std::vector<uint8_t>& data) = 0;
70
71 /**
72 * Commits data to the persistent storage specified during blob init.
73 * @returns True if able to write data to sysfile successfully
74 */
75 virtual bool commit() = 0;
76
77 /**
78 * Closes blob, which prevents further modifications. Uncommitted data will
79 * be lost.
80 * @returns True if able to close the blob successfully
81 */
82 virtual bool close() = 0;
83
84 /**
85 * Returns blob stat flags.
86 * @param meta: output stat flags.
87 * @returns True if able to get the stat flags and write to *meta
88 */
89 virtual bool stat(blobs::BlobMeta* meta) = 0;
90};
91
92} // namespace binstore