From 43eee367a7cdce4ef2f59780a1f1eac6092eae88 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Mon, 22 Jul 2024 09:17:44 +0200 Subject: [PATCH] new comps also ids, some where forgotten --- src/CMakeLists.txt | 2 + .../object_store/meta_components.hpp | 2 +- .../object_store/meta_components_file.hpp | 148 ++++++++++++++++++ .../object_store/meta_components_file_id.inl | 36 +++++ .../object_store/meta_components_id.inl | 9 +- 5 files changed, 195 insertions(+), 2 deletions(-) create mode 100644 src/solanaceae/object_store/meta_components_file.hpp create mode 100644 src/solanaceae/object_store/meta_components_file_id.inl diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9a0c9c0..06d747c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,6 +6,8 @@ add_library(solanaceae_object_store ./solanaceae/object_store/types.hpp ./solanaceae/object_store/meta_components.hpp ./solanaceae/object_store/meta_components_id.inl + ./solanaceae/object_store/meta_components_file.hpp + ./solanaceae/object_store/meta_components_file_id.inl ./solanaceae/object_store/serializer_json.hpp ./solanaceae/object_store/object_store.hpp ./solanaceae/object_store/object_store.cpp diff --git a/src/solanaceae/object_store/meta_components.hpp b/src/solanaceae/object_store/meta_components.hpp index 0363caa..4ea5327 100644 --- a/src/solanaceae/object_store/meta_components.hpp +++ b/src/solanaceae/object_store/meta_components.hpp @@ -1,7 +1,7 @@ #pragma once #include "./types.hpp" -#include "./object_store.hpp" +#include "./fwd.hpp" #include #include diff --git a/src/solanaceae/object_store/meta_components_file.hpp b/src/solanaceae/object_store/meta_components_file.hpp new file mode 100644 index 0000000..f4361e7 --- /dev/null +++ b/src/solanaceae/object_store/meta_components_file.hpp @@ -0,0 +1,148 @@ +#pragma once + +#include "./meta_components.hpp" + +#include + +#include +#include + +namespace ObjectStore::Components { + + // until i find a better name + namespace File { + + // have bitsets + // there will be hash trees in the future too + // bitsets are not very flexible + + // TODO: use tag instead of bool? + // the have all tag sure was useful + struct TagLocalHaveAll {}; + + struct LocalHaveBitset { + BitSet have; + // TODO: store actual size, since bitset is mult of 8 + // size_t bits {0}; + }; + +#if 0 + // ephemeral?, not sure saving this to disk makes sense + // tag remove have all? + struct RemoteHaveBitset { + struct Entry { + bool have_all {false}; + BitSet have; + }; + entt::dense_map others; + }; +#endif + + + // for single files or member of a collection + // split up into comps? more info? + // other stuff like filesystems have? + struct SingleInfo { + std::string file_name; // full path relative to base + uint64_t file_size {0}; + }; + + // exists for stuff on disk + // there is no garantie this exists if its, eg. encrypted + struct SingleInfoLocal { + std::string file_path; + }; + + struct Collection { + std::vector objs; + }; + + // entries in a collection can have SingleInfo, + // but CollectionInfo is still required, so data might be duplicated + struct CollectionInfo { + // order is same as in `Collection` + std::vector file_list; + uint64_t total_size {0}; + }; + + struct CollectionInfoLocal { + // order is same as in `Collection` + // might contain empty entries + std::vector file_list; + }; + + // img stuff + // save in the message instead? no? + // struct FrameDims { + // struct ThumbHash { + // struct TagNotImage {}; + + + // receiving/sending/paused/canceled/stopped whatever + // think about this more + +#if 0 + // TODO: make an event instead/keeps on messages? + // TODO: rename to start? or set or ... + struct ActionAccept { + std::string save_to_path; + bool path_is_file = false; // if the path is not the folder to place the file into, overwrites the name + }; +#endif + + } // File + + namespace Ephemeral { + + namespace File { + + struct DownloadPriority { + // download/retreival priority in comparison to other objects + // not all backends implement this + // priority can be weak, meaning low priority DLs will still get transfer activity, just less often + enum class Priority { + HIGHEST, + HIGH, + NORMAL, + LOW, + LOWEST, + } p = Priority::NORMAL; + }; + + struct ReadHeadHint { + // points to the first byte we want + // this is just a hint, that can be set from outside + // to guide the sequential "piece picker" strategy + // ? the strategy *should* set this to the first byte we dont yet have + // ??? + uint64_t offset_into_file {0u}; + }; + + // this is per object/content + // more aplicable than "separated", so should be supported by most backends + struct TransferStats { + // in bytes per second + float rate_up {0.f}; + float rate_down {0.f}; + + // bytes + uint64_t total_up {0u}; + uint64_t total_down {0u}; + }; + +#if 0 + struct TransferStatsSeparated { + entt::dense_map stats; + }; +#endif + + } // File + + } // Ephemeral + + namespace F = File; + +} // ObjectStore::Components + +#include "./meta_components_file_id.inl" + diff --git a/src/solanaceae/object_store/meta_components_file_id.inl b/src/solanaceae/object_store/meta_components_file_id.inl new file mode 100644 index 0000000..a3c2599 --- /dev/null +++ b/src/solanaceae/object_store/meta_components_file_id.inl @@ -0,0 +1,36 @@ +#pragma once + +#include "./meta_components_file.hpp" + +#include + +// TODO: move more central +#define DEFINE_COMP_ID(x) \ +template<> \ +constexpr entt::id_type entt::type_hash::value() noexcept { \ + using namespace entt::literals; \ + return #x##_hs; \ +} \ +template<> \ +constexpr std::string_view entt::type_name::value() noexcept { \ + return #x; \ +} + +// cross compile(r) stable ids + +DEFINE_COMP_ID(ObjComp::F::TagLocalHaveAll) +DEFINE_COMP_ID(ObjComp::F::LocalHaveBitset) +//DEFINE_COMP_ID(ObjComp::F::RemoteHaveBitset) +DEFINE_COMP_ID(ObjComp::F::SingleInfo) +DEFINE_COMP_ID(ObjComp::F::SingleInfoLocal) +DEFINE_COMP_ID(ObjComp::F::Collection) +DEFINE_COMP_ID(ObjComp::F::CollectionInfo) +DEFINE_COMP_ID(ObjComp::F::CollectionInfoLocal) + +DEFINE_COMP_ID(ObjComp::Ephemeral::File::DownloadPriority) +DEFINE_COMP_ID(ObjComp::Ephemeral::File::ReadHeadHint) +DEFINE_COMP_ID(ObjComp::Ephemeral::File::TransferStats) +//DEFINE_COMP_ID(ObjComp::Ephemeral::File::TransferStatsSeparated) + +#undef DEFINE_COMP_ID + diff --git a/src/solanaceae/object_store/meta_components_id.inl b/src/solanaceae/object_store/meta_components_id.inl index d9f7de3..856f247 100644 --- a/src/solanaceae/object_store/meta_components_id.inl +++ b/src/solanaceae/object_store/meta_components_id.inl @@ -18,13 +18,20 @@ constexpr std::string_view entt::type_name::value() noexcept { \ // cross compiler stable ids +DEFINE_COMP_ID(ObjComp::ID) DEFINE_COMP_ID(ObjComp::DataEncryptionType) DEFINE_COMP_ID(ObjComp::DataCompressionType) +DEFINE_COMP_ID(ObjComp::Ephemeral::MetaFileType) +DEFINE_COMP_ID(ObjComp::Ephemeral::MetaEncryptionType) +DEFINE_COMP_ID(ObjComp::Ephemeral::MetaCompressionType) +DEFINE_COMP_ID(ObjComp::Ephemeral::Backend) +DEFINE_COMP_ID(ObjComp::Ephemeral::FilePath) +DEFINE_COMP_ID(ObjComp::Ephemeral::DirtyTag) // ?? + // old stuff DEFINE_COMP_ID(FragComp::DataEncryptionType) DEFINE_COMP_ID(FragComp::DataCompressionType) #undef DEFINE_COMP_ID -