Skip to content
Snippets Groups Projects
storage.hh 2.29 KiB
Newer Older
  • Learn to ignore specific revisions
  • Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
    #ifndef __VEREIGN_KVSTORE_STORAGE_HH
    #define __VEREIGN_KVSTORE_STORAGE_HH
    
    #include <vereign/bytes/buffer.hh>
    
    namespace vereign::kvstore {
    
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
    // The vereign RSA master key name.
    
    constexpr const auto VereignKeyName = std::string_view{"vereign_key"};
    
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
    /**
     * Key/value storage interface.
     */
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
    class Storage {
    public:
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
      /**
       * Locks the storage.
       *
       * The lock must be recursive, meaning that may be called multiple times.
       * Storage::Unlock must be called the same number of times the Storage::Lock was called.
       *
       * Use kvstore::Lock for lock guard and lock with retrials.
       *
       * @throws LockError when the lock is held by another process.
       */
    
      virtual void Lock() = 0;
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
    
      /**
       * Locks the storage.
       *
       * The lock must be recursive, meaning that may be called multiple times.
       * Storage::Unlock must be called the same number of times the Storage::Lock was called.
       *
       * Use kvstore::Lock for lock guard and lock with retrials.
       */
    
      virtual void Unlock() = 0;
    
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
      /**
       * Deletes all the values in the storage.
       */
    
      virtual void DeleteAll() = 0;
    
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
      /**
       * Store bytes value into the storage.
       *
       * @param key The key under which the value will be stored.
       * @param value The bytes that will be stored.
       */
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
      virtual void PutBytes(const std::string& key, bytes::View value) = 0;
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
    
      /**
       * Retrieve bytes value from the storage.
       *
       * @param key The key of the value that will be retrieved.
       * @param value Buffer where the value will be returned.
       *
       * @throws ValueNotFoundError when the key does not exist.
       */
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
      virtual void GetBytes(const std::string& key, bytes::Buffer& value) = 0;
    
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
      /**
       * Store int64_t value into the storage.
       *
       * @param key The key under which the value will be stored.
       * @param value The value that will be stored.
       */
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
      virtual void PutInt64(const std::string& key, int64_t value) = 0;
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
    
      /**
       * Retrieve int64_t value from the storage.
       *
       * @param key The key of the value that will be retrieved.
       * @param value Buffer where the value will be returned.
       *
       * @throws ValueNotFoundError when the key does not exist.
       */
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
      virtual auto GetInt64(const std::string& key) -> int64_t = 0;
    
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
      /**
       * Destroy and cleanup.
       */
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
      virtual ~Storage() = default;
    };
    
    } // namespace vereign::kvstore
    
    #endif // __VEREIGN_KVSTORE_STORAGE_HH