1 #pragma once 2 3 #include <string> 4 #include <vector> 5 6 namespace blobs 7 { 8 9 enum OpenFlags 10 { 11 read = (1 << 0), 12 write = (1 << 1), 13 /* bits 3-7 reserved. */ 14 /* bits 8-15 given blob-specific definitions */ 15 }; 16 17 enum StateFlags 18 { 19 open_read = (1 << 0), 20 open_write = (1 << 1), 21 committing = (1 << 2), 22 committed = (1 << 3), 23 commit_error = (1 << 4), 24 }; 25 26 struct BlobMeta 27 { 28 uint16_t blobState; 29 uint32_t size; 30 std::vector<uint8_t> metadata; 31 }; 32 33 /* 34 * All blob specific objects implement this interface. 35 */ 36 class GenericBlobInterface 37 { 38 public: 39 virtual ~GenericBlobInterface() = default; 40 41 /** 42 * Checks if the handler will manage this file path. 43 * 44 * @param[in] blobId. 45 * @return bool whether it will manage the file path. 46 */ 47 virtual bool canHandleBlob(const std::string& path) = 0; 48 49 /** 50 * Return the name(s) of the blob(s). Used during GetCount. 51 * 52 * @return List of blobIds this handler manages. 53 */ 54 virtual std::vector<std::string> getBlobIds() = 0; 55 56 /** 57 * Attempt to delete the blob specified by the path. 58 * 59 * @param[in] path - the blobId to try and delete. 60 * @return bool - whether it was able to delete the blob. 61 */ 62 virtual bool deleteBlob(const std::string& path) = 0; 63 64 /** 65 * Return metadata about the blob. 66 * 67 * @param[in] path - the blobId for metadata. 68 * @param[in,out] meta - a pointer to a blobmeta. 69 * @return bool - true if it was successful. 70 */ 71 virtual bool stat(const std::string& path, struct BlobMeta* meta) = 0; 72 73 /* The methods below are per session. */ 74 75 /** 76 * Attempt to open a session from this path. 77 * 78 * @param[in] session - the session id. 79 * @param[in] flags - the open flags. 80 * @param[in] path - the blob path. 81 * @return bool - was able to open the session. 82 */ 83 virtual bool open(uint16_t session, uint16_t flags, 84 const std::string& path) = 0; 85 86 /** 87 * Attempt to read from a blob. 88 * 89 * @param[in] session - the session id. 90 * @param[in] offset - offset into the blob. 91 * @param[in] requestedSize - number of bytes to read. 92 * @return Bytes read back (0 length on error). 93 */ 94 virtual std::vector<uint8_t> read(uint16_t session, uint32_t offset, 95 uint32_t requestedSize) = 0; 96 97 /** 98 * Attempt to write to a blob. 99 * 100 * @param[in] session - the session id. 101 * @param[in] offset - offset into the blob. 102 * @param[in] data - the data to write. 103 * @return bool - was able to write. 104 */ 105 virtual bool write(uint16_t session, uint32_t offset, 106 const std::vector<uint8_t>& data) = 0; 107 108 /** 109 * Attempt to write metadata to a blob. 110 * 111 * @param[in] session - the session id. 112 * @param[in] offset - offset into the blob. 113 * @param[in] data - the data to write. 114 * @return bool - was able to write. 115 */ 116 virtual bool writeMeta(uint16_t session, uint32_t offset, 117 const std::vector<uint8_t>& data) = 0; 118 119 /** 120 * Attempt to commit to a blob. 121 * 122 * @param[in] session - the session id. 123 * @param[in] data - optional commit data. 124 * @return bool - was able to start commit. 125 */ 126 virtual bool commit(uint16_t session, const std::vector<uint8_t>& data) = 0; 127 128 /** 129 * Attempt to close your session. 130 * 131 * @param[in] session - the session id. 132 * @return bool - was able to close session. 133 */ 134 virtual bool close(uint16_t session) = 0; 135 136 /** 137 * Attempt to return metadata for the session's view of the blob. 138 * 139 * @param[in] session - the session id. 140 * @param[in,out] meta - pointer to update with the BlobMeta. 141 * @return bool - wether it was successful. 142 */ 143 virtual bool stat(uint16_t session, struct BlobMeta* meta) = 0; 144 145 /** 146 * Attempt to expire a session. This is called when a session has been 147 * inactive for at least 10 minutes. 148 * 149 * @param[in] session - the session id. 150 * @return bool - whether the session was able to be closed. 151 */ 152 virtual bool expire(uint16_t session) = 0; 153 }; 154 } // namespace blobs 155