From d8660c8e66c5c73b0d695c0af265c8d27439b5fb Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 11 Apr 2023 14:44:12 +0200 Subject: [PATCH] Move interface class into namespace interface. --- ...lueStorageBase.hpp => KeyValueStorage.hpp} | 19 ++++++++++++------- src/util/storage/register_storage.hpp | 8 ++++---- 2 files changed, 16 insertions(+), 11 deletions(-) rename src/util/storage/{KeyValueStorageBase.hpp => KeyValueStorage.hpp} (79%) diff --git a/src/util/storage/KeyValueStorageBase.hpp b/src/util/storage/KeyValueStorage.hpp similarity index 79% rename from src/util/storage/KeyValueStorageBase.hpp rename to src/util/storage/KeyValueStorage.hpp index 36f33fa0..2199a14d 100644 --- a/src/util/storage/KeyValueStorageBase.hpp +++ b/src/util/storage/KeyValueStorage.hpp @@ -25,20 +25,23 @@ enum class Error : std::uint8_t Internal, ///< Internal failure in the filesystem (storage corruption or logic error). }; +namespace interface +{ + /// Key-value storage provides a very simple API for storing and retrieving named blobs. /// The underlying storage implementation is required to be power-loss tolerant and to /// validate data integrity per key (e.g., using CRC and such). /// This interface is fully blocking and should only be used during initialization and shutdown, /// never during normal operation. Non-blocking adapters can be built on top of it. -class KeyValueStorageBase +class KeyValueStorage { public: - KeyValueStorageBase() = default; - KeyValueStorageBase(const KeyValueStorageBase&) = delete; - KeyValueStorageBase(KeyValueStorageBase&&) = delete; - auto operator=(const KeyValueStorageBase&) -> KeyValueStorageBase& = delete; - auto operator=(KeyValueStorageBase&&) -> KeyValueStorageBase& = delete; - virtual ~KeyValueStorageBase() = default; + KeyValueStorage() = default; + KeyValueStorage(const KeyValueStorage&) = delete; + KeyValueStorage(KeyValueStorage&&) = delete; + auto operator=(const KeyValueStorage&) -> KeyValueStorage& = delete; + auto operator=(KeyValueStorage&&) -> KeyValueStorage& = delete; + virtual ~KeyValueStorage() = default; /// The return value is the number of bytes read into the buffer or the error. [[nodiscard]] virtual auto get(const std::string_view key, const std::size_t size, void* const data) const @@ -53,6 +56,8 @@ class KeyValueStorageBase [[nodiscard]] virtual auto drop(const std::string_view key) -> std::optional = 0; }; +} /* interface */ + } /* cyphal::support::platform::storage */ #endif /* __GNUC__ >= 11 */ diff --git a/src/util/storage/register_storage.hpp b/src/util/storage/register_storage.hpp index a6b390d6..960cf8d7 100644 --- a/src/util/storage/register_storage.hpp +++ b/src/util/storage/register_storage.hpp @@ -9,7 +9,7 @@ #if __GNUC__ >= 11 -#include "KeyValueStorageBase.hpp" +#include "KeyValueStorage.hpp" #include @@ -23,7 +23,7 @@ namespace cyphal::support /// Stored registers that are not present in the registry will not be loaded. /// The serialization format is simply the Cyphal DSDL. /// In case of error, only part of the registers may be loaded and the registry will be left in an inconsistent state. -[[nodiscard]] inline std::optional load(const platform::storage::KeyValueStorageBase& kv, +[[nodiscard]] inline std::optional load(const platform::storage::interface::KeyValueStorage& kv, registry::IIntrospectableRegistry& rgy) { for (std::size_t index = 0; index < rgy.size(); index++) @@ -82,7 +82,7 @@ namespace cyphal::support /// The removal predicate, if provided, allows the caller to specify which registers need to be removed from the /// storage instead of being saved. This is useful for implementing the "factory reset" feature. template -[[nodiscard]] std::optional save(platform::storage::KeyValueStorageBase& kv, +[[nodiscard]] std::optional save(platform::storage::interface::KeyValueStorage& kv, const registry::IIntrospectableRegistry& rgy, ResetPredicate const reset_predicate) { @@ -127,7 +127,7 @@ template } return std::nullopt; } -[[nodiscard]] inline std::optional save(platform::storage::KeyValueStorageBase& kv, +[[nodiscard]] inline std::optional save(platform::storage::interface::KeyValueStorage& kv, const registry::IIntrospectableRegistry& rgy) { return save(kv, rgy, [](std::string_view) { return false; });