From ca6e71d40e3bf05a831c88fa718c75650c303847 Mon Sep 17 00:00:00 2001 From: BartolomeyKant Date: Fri, 19 Dec 2025 16:31:02 +0500 Subject: [PATCH 01/12] add hasher and reduce domain to only save and load state --- aether/crc.h | 13 +- aether/domain_storage/domain_storage_tele.h | 9 +- .../file_system_std_storage.cpp | 81 +++--- .../domain_storage/file_system_std_storage.h | 9 +- aether/domain_storage/ram_domain_storage.cpp | 101 +++----- aether/domain_storage/ram_domain_storage.h | 18 +- .../registrar_domain_storage.cpp | 91 ++----- .../domain_storage/registrar_domain_storage.h | 14 +- .../domain_storage/static_domain_storage.cpp | 6 - aether/domain_storage/static_domain_storage.h | 45 ++-- aether/domain_storage/static_object_types.h | 18 +- aether/domain_storage/sync_domain_storage.cpp | 22 +- aether/domain_storage/sync_domain_storage.h | 9 +- aether/misc/hash.h | 93 +++++++ aether/obj/component_context.h | 25 +- aether/obj/domain.cpp | 204 +-------------- aether/obj/domain.h | 233 ++---------------- aether/obj/dummy_obj.h | 5 +- aether/obj/idomain_storage.h | 29 +-- aether/obj/obj.cpp | 14 +- aether/obj/obj.h | 81 ++---- aether/obj/obj_id.cpp | 31 --- aether/obj/obj_id.h | 95 ------- aether/obj/obj_ptr.cpp | 73 ------ aether/obj/obj_ptr.h | 136 ---------- aether/obj/registrar.h | 79 ------ aether/obj/registry.cpp | 112 --------- aether/obj/registry.h | 73 ------ aether/types/address.h | 57 ++++- aether/types/statistic_counter.h | 2 +- aether/types/uid.h | 10 +- 31 files changed, 370 insertions(+), 1418 deletions(-) create mode 100644 aether/misc/hash.h delete mode 100644 aether/obj/obj_id.cpp delete mode 100644 aether/obj/obj_id.h delete mode 100644 aether/obj/obj_ptr.cpp delete mode 100644 aether/obj/obj_ptr.h delete mode 100644 aether/obj/registrar.h delete mode 100644 aether/obj/registry.cpp delete mode 100644 aether/obj/registry.h diff --git a/aether/crc.h b/aether/crc.h index e020a2f4..826a4cd8 100644 --- a/aether/crc.h +++ b/aether/crc.h @@ -42,9 +42,10 @@ constexpr auto checksum_from_literal(const char (&_str)[LEN]) -> std::uint32_t; // run-time versions -auto from_string(char const* _str, result_t _curr = result_t()) -> result_t; -auto from_buffer(const std::uint8_t* _buffer, size_t _cnt, - result_t _curr = result_t()) -> result_t; +constexpr auto from_string(char const* _str, result_t _curr = result_t()) + -> result_t; +constexpr auto from_buffer(const std::uint8_t* _buffer, size_t _cnt, + result_t _curr = result_t()) -> result_t; // ============== // Implementation @@ -167,7 +168,7 @@ constexpr auto checksum_from_literal(const char (&_str)[LEN]) -> std::uint32_t { return from_literal(_str).value ^ details::XOR_VALUE; } -inline auto from_string(char const* _str, result_t _curr) -> result_t { +constexpr auto from_string(char const* _str, result_t _curr) -> result_t { if (_str) { while (*_str != 0) { _curr.value = @@ -179,8 +180,8 @@ inline auto from_string(char const* _str, result_t _curr) -> result_t { return _curr; } -inline auto from_buffer(const std::uint8_t* _buff, size_t _cnt, result_t _curr) - -> result_t { +constexpr auto from_buffer(const std::uint8_t* _buff, size_t _cnt, + result_t _curr) -> result_t { if (_buff) { for (auto i = 0u; i < _cnt; ++i) { _curr.value = diff --git a/aether/domain_storage/domain_storage_tele.h b/aether/domain_storage/domain_storage_tele.h index 9e1a052b..fa38d238 100644 --- a/aether/domain_storage/domain_storage_tele.h +++ b/aether/domain_storage/domain_storage_tele.h @@ -22,22 +22,17 @@ AE_TELE_MODULE(kDomainStorage, 9, 171, 185); AE_TELE_MODULE(kDomainStorageDebug, 109, 300, 320); -AE_TAG(kFileSystemDsLoadObjClassIdNotFound, kDomainStorage) -AE_TAG(kFileSystemDsEnumObjIdNotFound, kDomainStorage) +AE_TAG(kFileSystemDsLoadDataKeyNotFound, kDomainStorage) +AE_TAG(kFileSystemDsEnumOpenFileFailed, kDomainStorage) AE_TAG(kFileSystemDsRemoveObjError, kDomainStorage) -AE_TAG(kFileSystemDsEnumerated, kDomainStorageDebug) AE_TAG(kFileSystemDsObjSaved, kDomainStorageDebug) AE_TAG(kFileSystemDsObjLoaded, kDomainStorageDebug) AE_TAG(kFileSystemDsObjRemoved, kDomainStorageDebug) AE_TAG(kRamDsLoadObjVersionNotFound, kDomainStorage) AE_TAG(kRamDsLoadObjIdNoFound, kDomainStorage) -AE_TAG(kRamDsLoadObjClassIdNotFound, kDomainStorage) -AE_TAG(kRamDsEnumObjIdNotFound, kDomainStorage) -AE_TAG(kRamDsRemoveObjError, kDomainStorage) -AE_TAG(kRamDsEnumerated, kDomainStorageDebug) AE_TAG(kRamDsObjSaved, kDomainStorageDebug) AE_TAG(kRamDsObjLoaded, kDomainStorageDebug) AE_TAG(kRamDsObjRemoved, kDomainStorageDebug) diff --git a/aether/domain_storage/file_system_std_storage.cpp b/aether/domain_storage/file_system_std_storage.cpp index ddcc1874..d51f84e7 100644 --- a/aether/domain_storage/file_system_std_storage.cpp +++ b/aether/domain_storage/file_system_std_storage.cpp @@ -31,14 +31,13 @@ namespace ae { class FstreamStorageWriter final : public IDomainStorageWriter { public: - FstreamStorageWriter(DomainQuery q, std::ofstream&& f) - : query{std::move(q)}, file{std::move(f)} {} + FstreamStorageWriter(DataKey key, std::uint8_t version, std::ofstream&& f) + : key{key}, version{version}, file{std::move(f)} {} ~FstreamStorageWriter() override { file.close(); - AE_TELE_DEBUG( - kFileSystemDsObjSaved, "Saved object id={}, class id={}, version={}", - query.id.ToString(), query.class_id, static_cast(query.version)); + AE_TELE_DEBUG(kFileSystemDsObjSaved, "Saved data key={}, version={}", key, + static_cast(version)); } void write(void const* data, std::size_t size) override { @@ -47,7 +46,8 @@ class FstreamStorageWriter final : public IDomainStorageWriter { } private: - DomainQuery query; + DataKey key; + std::uint8_t version; std::ofstream file; }; @@ -61,9 +61,6 @@ class FstreamStorageReader final : public IDomainStorageReader { static_cast(size)); } - ReadResult result() const override { return ReadResult::kYes; } - void result(ReadResult) override {} - private: std::ifstream file; }; @@ -73,74 +70,52 @@ FileSystemStdStorage::FileSystemStdStorage() = default; FileSystemStdStorage::~FileSystemStdStorage() = default; std::unique_ptr FileSystemStdStorage::Store( - DomainQuery const& query) { - auto class_dir = std::filesystem::path("state") / query.id.ToString() / - std::to_string(query.class_id); + DataKey key, std::uint8_t version) { + auto data_dir = std::filesystem::path("state") / std::to_string(key); - std::filesystem::create_directories(class_dir); - auto version_data_path = class_dir / std::to_string(query.version); + std::filesystem::create_directories(data_dir); + auto version_data_path = data_dir / std::to_string(version); std::ofstream f(version_data_path, std::ios::out | std::ios::binary | std::ios::trunc); - return std::make_unique(query, std::move(f)); -} - -ClassList FileSystemStdStorage::Enumerate(const ae::ObjId& obj_id) { - // collect unique classes - std::set classes; - - auto state_dir = std::filesystem::path{"state"}; - auto ec = std::error_code{}; - auto obj_dir = state_dir / obj_id.ToString(); - for (auto const& class_dir : - std::filesystem::directory_iterator(obj_dir, ec)) { - auto file_name = class_dir.path().filename().string(); - classes.insert(static_cast(std::stoul(file_name))); - } - AE_TELE_DEBUG(kFileSystemDsEnumerated, "Enumerated classes {}", classes); - - if (ec) { - AE_TELE_ERROR(kFileSystemDsEnumObjIdNotFound, - "Unable to open directory with error {}", ec.message()); - } - - return ClassList{classes.begin(), classes.end()}; + return std::make_unique(key, version, std::move(f)); } -DomainLoad FileSystemStdStorage::Load(DomainQuery const& query) { - auto object_dir = std::filesystem::path("state") / query.id.ToString(); +DomainLoad FileSystemStdStorage::Load(DataKey key, std::uint8_t version) { + auto data_dir = std::filesystem::path("state") / std::to_string(key); auto ec = std::error_code{}; - if (!std::filesystem::exists(object_dir, ec)) { + if (!std::filesystem::exists(data_dir, ec)) { + AE_TELE_INFO(kFileSystemDsLoadDataKeyNotFound, + "Data storage for key={}, version={} not found", key, + static_cast(version)); return {DomainLoadResult::kEmpty, {}}; } auto is_dir_empty = [&]() { - auto iter = std::filesystem::directory_iterator{object_dir}; + auto iter = std::filesystem::directory_iterator{data_dir}; return std::filesystem::begin(iter) == std::filesystem::end(iter); }; if (is_dir_empty()) { return {DomainLoadResult::kRemoved, {}}; } - auto class_dir = object_dir / std::to_string(query.class_id); - auto version_data_path = class_dir / std::to_string(query.version); + auto version_data_path = data_dir / std::to_string(version); std::ifstream f(version_data_path, std::ios::in | std::ios::binary); if (!f.good()) { - AE_TELE_ERROR(kFileSystemDsLoadObjClassIdNotFound, "Unable to open file {}", + AE_TELE_ERROR(kFileSystemDsEnumOpenFileFailed, "Unable to open file {}", version_data_path.string()); return DomainLoad{DomainLoadResult::kEmpty, {}}; } - AE_TELE_DEBUG( - kFileSystemDsObjLoaded, "Loaded object id={}, class id={}, version={}", - query.id.ToString(), query.class_id, static_cast(query.version)); + AE_TELE_DEBUG(kFileSystemDsObjLoaded, "Loaded object key={}, version={}", key, + static_cast(version)); return {DomainLoadResult::kLoaded, std::make_unique(std::move(f))}; } -void FileSystemStdStorage::Remove(ae::ObjId const& obj_id) { - auto object_dir = std::filesystem::path("state") / obj_id.ToString(); +void FileSystemStdStorage::Remove(DataKey key) { + auto object_dir = std::filesystem::path("state") / std::to_string(key); auto ec = std::error_code{}; if (!std::filesystem::exists(object_dir, ec)) { std::filesystem::create_directory(object_dir); @@ -152,17 +127,17 @@ void FileSystemStdStorage::Remove(ae::ObjId const& obj_id) { return; } - for (auto const& class_dir : + for (auto const& version_data_path : std::filesystem::directory_iterator(object_dir, ec)) { auto ec2 = std::error_code{}; - std::filesystem::remove_all(class_dir.path(), ec2); + std::filesystem::remove_all(version_data_path.path(), ec2); if (ec2) { AE_TELED_ERROR("Unable to remove dir {}, error {}", - class_dir.path().string(), ec2.message()); + version_data_path.path().string(), ec2.message()); continue; } AE_TELE_DEBUG(kFileSystemDsObjRemoved, "Object removed {}", - obj_id.ToString()); + std::to_string(key)); } if (ec) { AE_TELE_ERROR(kFileSystemDsRemoveObjError, diff --git a/aether/domain_storage/file_system_std_storage.h b/aether/domain_storage/file_system_std_storage.h index 652f1565..28c8663d 100644 --- a/aether/domain_storage/file_system_std_storage.h +++ b/aether/domain_storage/file_system_std_storage.h @@ -32,11 +32,10 @@ class FileSystemStdStorage : public IDomainStorage { FileSystemStdStorage(); ~FileSystemStdStorage() override; - std::unique_ptr Store( - DomainQuery const& query) override; - ClassList Enumerate(ObjId const& obj_id) override; - DomainLoad Load(DomainQuery const& query) override; - void Remove(ObjId const& obj_id) override; + std::unique_ptr Store(DataKey key, + std::uint8_t version) override; + DomainLoad Load(DataKey key, std::uint8_t version) override; + void Remove(DataKey key) override; void CleanUp() override; }; } // namespace ae diff --git a/aether/domain_storage/ram_domain_storage.cpp b/aether/domain_storage/ram_domain_storage.cpp index 572dae69..d9153753 100644 --- a/aether/domain_storage/ram_domain_storage.cpp +++ b/aether/domain_storage/ram_domain_storage.cpp @@ -26,27 +26,28 @@ namespace ae { class RamDomainStorageWriter final : public IDomainStorageWriter { public: - RamDomainStorageWriter(DomainQuery q, RamDomainStorage& s) - : query{std::move(q)}, storage{&s}, vector_writer{data_buffer} { + RamDomainStorageWriter(DataKey key, std::uint8_t version, RamDomainStorage& s) + : key{key}, version{version}, storage{&s}, vector_writer{data_buffer} { assert(!storage->write_lock); } ~RamDomainStorageWriter() override { - storage->SaveData(query, std::move(data_buffer)); + storage->SaveData(key, version, std::move(data_buffer)); } void write(void const* data, std::size_t size) override { vector_writer.write(data, size); } - DomainQuery query; + DataKey key; + std::uint8_t version; RamDomainStorage* storage; - ObjectData data_buffer; + DataValue data_buffer; VectorWriter vector_writer; }; class RamDomainStorageReader final : public IDomainStorageReader { public: - RamDomainStorageReader(ObjectData const& d, RamDomainStorage& s) + RamDomainStorageReader(DataValue const& d, RamDomainStorage& s) : storage{&s}, data_buffer{&d}, reader{*data_buffer} { storage->write_lock = true; } @@ -54,11 +55,8 @@ class RamDomainStorageReader final : public IDomainStorageReader { void read(void* data, std::size_t size) override { reader.read(data, size); } - ReadResult result() const override { return ReadResult::kYes; } - void result(ReadResult) override {} - RamDomainStorage* storage; - ObjectData const* data_buffer; + DataValue const* data_buffer; VectorReader reader; }; @@ -67,94 +65,61 @@ RamDomainStorage::RamDomainStorage() = default; RamDomainStorage::~RamDomainStorage() = default; std::unique_ptr RamDomainStorage::Store( - DomainQuery const& query) { - return std::make_unique(query, *this); + DataKey key, std::uint8_t version) { + return std::make_unique(key, version, *this); } -ClassList RamDomainStorage::Enumerate(ObjId const& obj_id) { - auto obj_map_it = state.find(obj_id); - if (obj_map_it == std::end(state)) { - AE_TELE_ERROR(kRamDsEnumObjIdNotFound, "Obj not found {}", - obj_id.ToString()); - return {}; - } - if (!obj_map_it->second) { - return {}; - } - - ClassList classes; - classes.reserve(obj_map_it->second->size()); - for (auto& [cls, _] : *obj_map_it->second) { - classes.emplace_back(cls); - } - AE_TELE_DEBUG(kRamDsEnumerated, "Enumerated for obj {} classes {}", - obj_id.ToString(), classes); - return classes; -} - -DomainLoad RamDomainStorage::Load(DomainQuery const& query) { - auto obj_map_it = state.find(query.id); +DomainLoad RamDomainStorage::Load(DataKey key, std::uint8_t version) { + auto obj_map_it = state.find(key); if (obj_map_it == std::end(state)) { AE_TELE_ERROR(kRamDsLoadObjIdNoFound, - "Unable to find object id={}, class id={}, version={}", - query.id.ToString(), query.class_id, - static_cast(query.version)); + "Unable to find data key={}, version={}", key, + static_cast(version)); return {DomainLoadResult::kEmpty, {}}; } if (!obj_map_it->second) { return {DomainLoadResult::kRemoved, {}}; } - auto class_map_it = obj_map_it->second->find(query.class_id); - if (class_map_it == std::end(*obj_map_it->second)) { - AE_TELE_ERROR(kRamDsLoadObjClassIdNotFound, - "Unable to find object id={}, class id={}, version={}", - query.id.ToString(), query.class_id, - static_cast(query.version)); - return {DomainLoadResult::kEmpty, {}}; - } - auto version_it = class_map_it->second.find(query.version); - if (version_it == std::end(class_map_it->second)) { + auto version_it = obj_map_it->second->find(version); + if (version_it == std::end(*obj_map_it->second)) { AE_TELE_ERROR(kRamDsLoadObjVersionNotFound, - "Unable to find object id={}, class id={}, version={}", - query.id.ToString(), query.class_id, - static_cast(query.version)); + "Unable to find data key={key}, version={}", key, + static_cast(version)); return {DomainLoadResult::kEmpty, {}}; } - AE_TELE_DEBUG(kRamDsObjLoaded, - "Loaded object id={}, class id={}, version={}, size={}", - query.id.ToString(), query.class_id, - static_cast(query.version), version_it->second.size()); + AE_TELE_DEBUG(kRamDsObjLoaded, "Loaded data key={}, version={}, size={}", key, + static_cast(version), version_it->second.size()); return {DomainLoadResult::kLoaded, std::make_unique(version_it->second, *this)}; } -void RamDomainStorage::Remove(ObjId const& obj_id) { - auto obj_map_it = state.find(obj_id); +void RamDomainStorage::Remove(DataKey key) { + auto obj_map_it = state.find(key); if (obj_map_it == std::end(state)) { - state.emplace(obj_id, std::nullopt); + // if there was no object, explicitly mark it as removed + state.emplace(key, std::nullopt); return; } obj_map_it->second.reset(); - AE_TELE_DEBUG(kRamDsObjRemoved, "Removed object {}", obj_id.ToString()); + AE_TELE_DEBUG(kRamDsObjRemoved, "Removed data {}", key); } void RamDomainStorage::CleanUp() { state.clear(); } -void RamDomainStorage::SaveData(DomainQuery const& query, ObjectData&& data) { - auto& objcect_classes = state[query.id]; - if (!objcect_classes) { - objcect_classes.emplace(); +void RamDomainStorage::SaveData(DataKey key, std::uint8_t version, + DataValue&& data) { + auto& versioned_data = state[key]; + if (!versioned_data) { + versioned_data.emplace(); } - auto& saved = (*objcect_classes)[query.class_id][query.version]; + auto& saved = (*versioned_data)[version]; saved = std::move(data); - AE_TELE_DEBUG(kRamDsObjSaved, - "Saved object id={}, class id={}, version={}, size={}", - query.id.ToString(), query.class_id, - std::to_string(query.version), saved.size()); + AE_TELE_DEBUG(kRamDsObjSaved, "Saved data key={}, version={}, size={}", key, + static_cast(version), saved.size()); } } // namespace ae diff --git a/aether/domain_storage/ram_domain_storage.h b/aether/domain_storage/ram_domain_storage.h index 3a79d351..d9dc499d 100644 --- a/aether/domain_storage/ram_domain_storage.h +++ b/aether/domain_storage/ram_domain_storage.h @@ -28,23 +28,19 @@ namespace ae { class RamDomainStorage : public IDomainStorage { public: - using Data = ObjectData; - using VersionData = std::map; - using ClassData = std::map; - using ObjClassData = std::map>; + using VersionData = std::map; + using ObjClassData = std::map>; RamDomainStorage(); ~RamDomainStorage() override; - std::unique_ptr Store( - DomainQuery const& query) override; - - ClassList Enumerate(ObjId const& obj_id) override; - DomainLoad Load(DomainQuery const& query) override; - void Remove(ObjId const& obj_id) override; + std::unique_ptr Store(DataKey key, + std::uint8_t version) override; + DomainLoad Load(DataKey key, std::uint8_t version) override; + void Remove(DataKey key) override; void CleanUp() override; - void SaveData(DomainQuery const& query, ObjectData&& data); + void SaveData(DataKey key, std::uint8_t version, DataValue&& data); ObjClassData state; bool write_lock = false; diff --git a/aether/domain_storage/registrar_domain_storage.cpp b/aether/domain_storage/registrar_domain_storage.cpp index c73b9043..0bbbd352 100644 --- a/aether/domain_storage/registrar_domain_storage.cpp +++ b/aether/domain_storage/registrar_domain_storage.cpp @@ -39,21 +39,15 @@ RegistrarDomainStorage::~RegistrarDomainStorage() { } std::unique_ptr RegistrarDomainStorage::Store( - DomainQuery const& query) { - return ram_storage.Store(query); + DataKey key, std::uint8_t version) { + return ram_storage.Store(key, version); } -ClassList RegistrarDomainStorage::Enumerate(const ObjId& obj_id) { - return ram_storage.Enumerate(obj_id); +DomainLoad RegistrarDomainStorage::Load(DataKey key, std::uint8_t version) { + return ram_storage.Load(key, version); } -DomainLoad RegistrarDomainStorage::Load(DomainQuery const& query) { - return ram_storage.Load(query); -} - -void RegistrarDomainStorage::Remove(ObjId const& obj_id) { - ram_storage.Remove(obj_id); -} +void RegistrarDomainStorage::Remove(DataKey key) { ram_storage.Remove(key); } void RegistrarDomainStorage::CleanUp() { ram_storage.CleanUp(); } @@ -75,66 +69,35 @@ void RegistrarDomainStorage::SaveState() { file << preamble; - // write list of class arrays - for (auto const& [obj_id, obj_data] : ram_storage.state) { - if (!obj_data) { - continue; - } - Format(file, - "static constexpr auto class_array_{} = " - "std::array{", - obj_id.ToString(), obj_data->size()); - PrintMapKeysAsData(file, *obj_data); - file << "};\n"; - } - file << "\n"; - // write list of data arrays - for (auto const& [obj_id, obj_data] : ram_storage.state) { - if (!obj_data) { + for (auto const& [key, version_data] : ram_storage.state) { + if (!version_data) { continue; } - for (auto const& [class_id, class_data] : *obj_data) { - for (auto const& [version, data] : class_data) { - Format(file, - "static constexpr auto data_array_{}_{}_{} = " - "std::array{", - obj_id.ToString(), class_id, static_cast(version), - data.size()); - PrintData(file, data); - file << "};\n"; - } + for (auto const& [version, data] : *version_data) { + Format(file, + "static constexpr auto data_array_{}_{} = " + "std::array{", + key, static_cast(version), data.size()); + PrintData(file, data); + file << "};\n"; } } file << "\n"; - file << "static constexpr auto static_domain_data = ae::StaticDomainData{\n"; - // write object map - file << " ae::StaticMap{{\n"; - for (auto const& [obj_id, obj_data] : ram_storage.state) { - file << " std::pair{ std::uint32_t{ " << obj_id.ToString() - << " } , ae::Span{ class_array_" << obj_id.ToString() << " }},\n"; - } - file << " }},\n"; - - file << "\n"; // write map file << " ae::StaticMap{{\n"; - for (auto const& [obj_id, obj_data] : ram_storage.state) { - if (!obj_data) { + for (auto const& [key, version_data] : ram_storage.state) { + if (!version_data) { continue; } - for (auto const& [class_id, class_data] : *obj_data) { - for (auto const& [version, _] : class_data) { - file << " std::pair{ ae::ObjectPathKey{ "; - Format(file, "{}, {}, {}", obj_id.ToString(), class_id, - static_cast(version)); - file << " }, ae::Span{ "; - Format(file, "data_array_{}_{}_{}", obj_id.ToString(), class_id, - static_cast(version)); - file << " }},\n"; - } + for (auto const& [version, _] : *version_data) { + file << " std::pair{ ae::ObjectPathKey{ "; + Format(file, "{}, {}", key, static_cast(version)); + file << " }, ae::Span{ "; + Format(file, "data_array_{}_{}", key, static_cast(version)); + file << " }},\n"; } } file << " \n}},\n"; @@ -150,16 +113,6 @@ void RegistrarDomainStorage::PrintData(std::ofstream& file, } file << std::setfill(' ') << std::dec << std::setw(0); } - -template -void RegistrarDomainStorage::PrintMapKeysAsData(std::ofstream& file, - std::map const& map) { - for (auto const& [k, _] : map) { - file << static_cast(k) << ", "; - } - file << std::setfill(' ') << std::dec << std::setw(0); -} - } // namespace ae #endif // REGISTRAR_DOMAIN_FACILITY_ENABLED diff --git a/aether/domain_storage/registrar_domain_storage.h b/aether/domain_storage/registrar_domain_storage.h index 7e58e262..0664a81f 100644 --- a/aether/domain_storage/registrar_domain_storage.h +++ b/aether/domain_storage/registrar_domain_storage.h @@ -30,18 +30,16 @@ class RegistrarDomainStorage : public IDomainStorage { explicit RegistrarDomainStorage(std::filesystem::path file_path); ~RegistrarDomainStorage() override; - std::unique_ptr Store( - DomainQuery const& query) override; - ClassList Enumerate(ObjId const& obj_id) override; - DomainLoad Load(DomainQuery const& query) override; - void Remove(const ae::ObjId& obj_id) override; + std::unique_ptr Store(DataKey key, + std::uint8_t version) override; + DomainLoad Load(DataKey key, std::uint8_t version) override; + void Remove(DataKey key) override; void CleanUp() override; private: void SaveState(); - void PrintData(std::ofstream& file, std::vector const& data); - template - void PrintMapKeysAsData(std::ofstream& file, std::map const& map); + static void PrintData(std::ofstream& file, + std::vector const& data); std::filesystem::path file_path_; RamDomainStorage ram_storage; diff --git a/aether/domain_storage/static_domain_storage.cpp b/aether/domain_storage/static_domain_storage.cpp index 0ef974eb..c1f4816c 100644 --- a/aether/domain_storage/static_domain_storage.cpp +++ b/aether/domain_storage/static_domain_storage.cpp @@ -31,10 +31,4 @@ void StaticDomainStorageReader::read(void* out, std::size_t size) { reinterpret_cast(out)); offset += size; } - -ReadResult StaticDomainStorageReader::result() const { - return ReadResult::kYes; -} - -void StaticDomainStorageReader::result(ReadResult) {} } // namespace ae diff --git a/aether/domain_storage/static_domain_storage.h b/aether/domain_storage/static_domain_storage.h index 4138fde9..8a758e71 100644 --- a/aether/domain_storage/static_domain_storage.h +++ b/aether/domain_storage/static_domain_storage.h @@ -29,59 +29,42 @@ class StaticDomainStorageReader final : public IDomainStorageReader { void read(void* out, std::size_t size) override; - ReadResult result() const override; - void result(ReadResult) override; - private: Span const* data; std::size_t offset; }; -template +template class StaticDomainStorage final : public IDomainStorage { public: constexpr explicit StaticDomainStorage( - StaticDomainData const& sdd) + StaticDomainData const& sdd) : static_domain_data_{&sdd} {} std::unique_ptr Store( - DomainQuery const& /*query*/) override { + DataKey /* key */, std::uint8_t /* version */) override { // does not supported return {}; } - ClassList Enumerate(ObjId const& obj_id) override { - // object_map is defined in FS_INIT - auto const classes = static_domain_data_->object_map.find(obj_id.id()); - if (classes == std::end(static_domain_data_->object_map)) { - AE_TELED_ERROR("Obj not found {}", obj_id.ToString()); - return {}; - } - AE_TELED_DEBUG("Enumerated for obj {} classes {}", obj_id.ToString(), - classes->second); - return ClassList{std::begin(classes->second), std::end(classes->second)}; - } - - DomainLoad Load(DomainQuery const& query) override { + DomainLoad Load(DataKey key, std::uint8_t version) override { // state_map is defined in FS_INIT - auto obj_path = ObjectPathKey{query.id.id(), query.class_id, query.version}; + auto obj_path = ObjectPathKey{key, version}; auto const data = static_domain_data_->state_map.find(obj_path); if (data == std::end(static_domain_data_->state_map)) { - AE_TELED_ERROR("Unable to find object id={}, class id={}, version={}", - query.id.ToString(), query.class_id, - static_cast(query.version)); + AE_TELED_ERROR("Unable to find object key={}, version={}", key, + static_cast(version)); return {DomainLoadResult::kEmpty, {}}; } - AE_TELED_DEBUG("Loaded object id={}, class id={}, version={}, size={}", - query.id.ToString(), query.class_id, - static_cast(query.version), data->second.size()); + AE_TELED_DEBUG("Loaded object key={}, version={}, size={}", key, + static_cast(version), data->second.size()); return DomainLoad{ DomainLoadResult::kLoaded, std::make_unique(data->second)}; } - void Remove(ObjId const& /*obj_id*/) override { + void Remove(DataKey /* key */) override { // does not supported } void CleanUp() override { @@ -89,12 +72,12 @@ class StaticDomainStorage final : public IDomainStorage { } private: - StaticDomainData const* static_domain_data_; + StaticDomainData const* static_domain_data_; }; -template -StaticDomainStorage(StaticDomainData const&) - -> StaticDomainStorage; +template +StaticDomainStorage(StaticDomainData const&) + -> StaticDomainStorage; } // namespace ae diff --git a/aether/domain_storage/static_object_types.h b/aether/domain_storage/static_object_types.h index 20637441..c43ba8ab 100644 --- a/aether/domain_storage/static_object_types.h +++ b/aether/domain_storage/static_object_types.h @@ -29,26 +29,22 @@ namespace ae { struct ObjectPathKey { bool operator==(ObjectPathKey const& right) const { - return std::tie(obj_id, class_id, version) == - std::tie(right.obj_id, right.class_id, right.version); + return std::tie(key, version) == std::tie(right.key, right.version); } - std::uint32_t obj_id; - std::uint32_t class_id; + std::uint32_t key; std::uint8_t version; }; -template +template struct StaticDomainData { - StaticMap, ObjectCount> object_map; - StaticMap, ClassDataCount> state_map; + StaticMap, ObjectCount> state_map; }; -template +template StaticDomainData( - StaticMap, ObjectCount>&& om, - StaticMap, ClassDataCount>&& sm) - -> StaticDomainData; + StaticMap, ObjectCount>&& sm) + -> StaticDomainData; } // namespace ae #endif // AETHER_DOMAIN_STORAGE_STATIC_OBJECT_TYPES_H_ diff --git a/aether/domain_storage/sync_domain_storage.cpp b/aether/domain_storage/sync_domain_storage.cpp index c1bb8824..8110a6ac 100644 --- a/aether/domain_storage/sync_domain_storage.cpp +++ b/aether/domain_storage/sync_domain_storage.cpp @@ -22,29 +22,19 @@ SyncDomainStorage::SyncDomainStorage(std::unique_ptr read_only, : read_only_{std::move(read_only)}, read_write_{std::move(read_write)} {} std::unique_ptr SyncDomainStorage::Store( - DomainQuery const& query) { - return read_write_->Store(query); + DataKey key, std::uint8_t version) { + return read_write_->Store(key, version); } -ClassList SyncDomainStorage::Enumerate(ObjId const& obj_id) { - auto rw_list = read_write_->Enumerate(obj_id); - if (rw_list.empty()) { - return read_only_->Enumerate(obj_id); - } - return rw_list; -} - -DomainLoad SyncDomainStorage::Load(DomainQuery const& query) { - auto rw_load = read_write_->Load(query); +DomainLoad SyncDomainStorage::Load(DataKey key, std::uint8_t version) { + auto rw_load = read_write_->Load(key, version); if (rw_load.result == DomainLoadResult::kEmpty) { - return read_only_->Load(query); + return read_only_->Load(key, version); } return rw_load; } -void SyncDomainStorage::Remove(ObjId const& obj_id) { - read_write_->Remove(obj_id); -} +void SyncDomainStorage::Remove(DataKey key) { read_write_->Remove(key); } void SyncDomainStorage::CleanUp() { read_write_->CleanUp(); } diff --git a/aether/domain_storage/sync_domain_storage.h b/aether/domain_storage/sync_domain_storage.h index 25855654..a7b903cb 100644 --- a/aether/domain_storage/sync_domain_storage.h +++ b/aether/domain_storage/sync_domain_storage.h @@ -27,11 +27,10 @@ class SyncDomainStorage final : public IDomainStorage { SyncDomainStorage(std::unique_ptr read_only, std::unique_ptr read_write); - std::unique_ptr Store( - DomainQuery const& query) override; - ClassList Enumerate(ObjId const& obj_id) override; - DomainLoad Load(DomainQuery const& query) override; - void Remove(ObjId const& obj_id) override; + std::unique_ptr Store(DataKey key, + std::uint8_t version) override; + DomainLoad Load(DataKey key, std::uint8_t version) override; + void Remove(DataKey key) override; void CleanUp() override; private: diff --git a/aether/misc/hash.h b/aether/misc/hash.h new file mode 100644 index 00000000..ef25cca3 --- /dev/null +++ b/aether/misc/hash.h @@ -0,0 +1,93 @@ +/* + * Copyright 2025 Aethernet Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AEHTER_MISC_HASH_H_ +#define AEHTER_MISC_HASH_H_ + +#include + +#include "aether/crc.h" + +namespace ae { +template +struct Hasher; + +/** + * \brief Get combined hash of multiple values + */ +template +constexpr crc32::result_t Hash(crc32::result_t res, TArgs const&... args) { + ((res = Hasher::Get(args, res)), ...); + return res; +} + +template +constexpr std::uint32_t Hash(TArgs const&... args) { + crc32::result_t res{}; + res = Hash(res, args...); + return res.value; +} + +/** + * Hasher implementations for various types. + */ + +// For integral and floating-point types +template +struct Hasher< + T, std::enable_if_t || std::is_floating_point_v>> { + static constexpr crc32::result_t Get(T value, crc32::result_t res) { + return crc32::from_buffer(reinterpret_cast(&value), + sizeof(T), res); + } +}; + +// For enums +template +struct Hasher>> { + static constexpr crc32::result_t Get(T value, crc32::result_t res) { + return crc32::from_buffer(reinterpret_cast(&value), + sizeof(T), res); + } +}; + +// For string values +template +struct Hasher>> { + static constexpr crc32::result_t Get(T const& value, crc32::result_t res) { + return crc32::from_string(value.c_str(), res); + } +}; + +template +struct Hasher>> { + static constexpr crc32::result_t Get(T const& value, crc32::result_t res) { + return crc32::from_buffer( + reinterpret_cast(value.data()), value.size(), res); + } +}; + +template +struct Hasher { + static constexpr crc32::result_t Get(char const (&value)[S], + crc32::result_t res) { + return crc32::from_string(value, res); + } +}; + +} // namespace ae + +#endif // AEHTER_MISC_HASH_H_ diff --git a/aether/obj/component_context.h b/aether/obj/component_context.h index 807129cd..e46846f8 100644 --- a/aether/obj/component_context.h +++ b/aether/obj/component_context.h @@ -17,13 +17,14 @@ #ifndef AETHER_OBJ_COMPONENT_CONTEXT_H_ #define AETHER_OBJ_COMPONENT_CONTEXT_H_ +#include #include +#include #include #include "aether/common.h" #include "aether/obj/obj.h" #include "aether/type_traits.h" -#include "aether/obj/obj_ptr.h" #include "aether/types/small_function.h" namespace ae { @@ -32,23 +33,23 @@ class ComponentContext { public: using TypeIndex = std::uint32_t; - template < - typename T, typename TFunc, - AE_REQUIRERS((IsFunctor(TContext const& context)>))> + template (TContext const& context)>))> void Factory(TFunc&& factory) { factories_[T::kClassId] = - [fac{std::forward(factory)}](TContext const& context) { - return fac(context); + [f{std::forward(factory)}](TContext const& context) mutable { + return std::invoke(std::forward(f), context); }; } template - ObjPtr Resolve() const { + std::shared_ptr Resolve() const { static constexpr auto class_id = T::kClassId; // try cached component auto it = components_.find(class_id); if (it != components_.end()) { - return it->second; + return std::static_pointer_cast(it->second); } // try factory auto factory_it = factories_.find(class_id); @@ -59,14 +60,14 @@ class ComponentContext { // create component and save it to factory auto component = factory_it->second(static_cast(*this)); components_[class_id] = component; - return component; + return std::static_pointer_cast(component); } private: - std::unordered_map(TContext const& context)>> + std::unordered_map< + TypeIndex, SmallFunction(TContext const& context)>> factories_; - mutable std::unordered_map> components_; + mutable std::unordered_map> components_; }; } // namespace ae diff --git a/aether/obj/domain.cpp b/aether/obj/domain.cpp index b37db0a2..b0eeb80c 100644 --- a/aether/obj/domain.cpp +++ b/aether/obj/domain.cpp @@ -16,213 +16,25 @@ #include "aether/obj/domain.h" -#include - -#include "aether/obj/obj.h" -#include "aether/obj/obj_tele.h" - namespace ae { -Domain::Domain(TimePoint p, IDomainStorage& storage) - : update_time_{p}, - storage_(&storage), - registry_{&Registry::GetRegistry()} {} - -TimePoint Domain::Update(TimePoint current_time) { - update_time_ = current_time; - auto next_time = current_time + std::chrono::hours(365); - for (auto& [_, ptr_view] : id_objects_) { - auto ptr = ptr_view.Lock(); - if (!ptr) { - continue; - } - // TODO: do not call update for someone who is not want it - ptr->Update(current_time); - if (ptr->update_time_ > current_time) { - next_time = std::min(next_time, ptr->update_time_); - } else if (ptr->update_time_ < current_time) { -#ifdef DEBUG - AE_TELE_ERROR(ObjectDomainUpdatePastTime, - "Update returned next time point in the past"); -#endif // DEBUG_ - } - } - return next_time; -} - -ObjPtr Domain::ConstructObj(Factory const& factory, ObjId obj_id) { - ObjPtr o = factory.create(); - AddObject(obj_id, o); - o.SetId(obj_id); - o->domain_ = this; - return o; -} - -bool Domain::IsLast(uint32_t class_id) const { - return registry_->relations.find(class_id) == registry_->relations.end(); -} - -bool Domain::IsExisting(uint32_t class_id) const { - return registry_->IsExisting(class_id); -} - -ObjPtr Domain::Find(ObjId obj_id) const { - if (auto it = id_objects_.find(obj_id.id()); it != id_objects_.end()) { - return it->second.Lock(); - } - return {}; -} - -void Domain::AddObject(ObjId id, ObjPtr const& obj) { - id_objects_.emplace(id.id(), obj); -} - -void Domain::RemoveObject(Obj* obj) { id_objects_.erase(obj->GetId().id()); } - -Factory* Domain::GetMostRelatedFactory(ObjId id) { - auto classes = storage_->Enumerate(id); - - // Remove all unsupported classes. - classes.erase( - std::remove_if(std::begin(classes), std::end(classes), - [this](auto const& c) { return !IsExisting(c); }), - std::end(classes)); +Domain::Domain(IDomainStorage& storage) : storage_{&storage} {} - if (classes.empty()) { - return nullptr; - } - - // Build inheritance chain. - // from base to derived. - std::sort(std::begin(classes), std::end(classes), - [this](auto left, auto right) { - if (registry_->GenerationDistance(right, left) > 0) { - return false; - } - if (registry_->GenerationDistance(left, right) >= 0) { - return true; - } - // All classes must be in one inheritance chain. - assert(false); - return false; - }); - - // Find the Final class for the most derived class provided and create it. - for (auto& f : registry_->factories) { - if (IsLast(f.first)) { - // check with most derived class - int distance = registry_->GenerationDistance(classes.back(), f.first); - if (distance >= 0) { - return &f.second; - } - } - } - - return nullptr; -} - -Factory* Domain::FindClassFactory(Obj const& obj) { - return registry_->FindFactory(obj.GetClassId()); -} - -std::unique_ptr Domain::GetReader( - DomainQuery const& query) { - auto load = storage_->Load(query); +std::unique_ptr Domain::GetReader(DataKey key, + std::uint8_t version) { + auto load = storage_->Load(key, version); if ((load.result == DomainLoadResult::kEmpty) || (load.result == DomainLoadResult::kRemoved)) { - load.reader = std::make_unique(); + return {}; } - assert(load.reader && "Reader must be created!"); return std::move(load.reader); } -std::unique_ptr Domain::GetWriter( - DomainQuery const& query) { - auto writer = storage_->Store(query); +std::unique_ptr Domain::GetWriter(DataKey key, + std::uint8_t version) { + auto writer = storage_->Store(key, version); assert(writer && "Writer must be created!"); return writer; } - -ObjPtr Domain::LoadRootImpl(ObjId obj_id, ObjFlags obj_flags) { - if (!obj_id.IsValid()) { - return {}; - } - // if already loaded - if (auto obj = Find(obj_id); obj) { - return obj; - } - - auto* factory = GetMostRelatedFactory(obj_id); - if (factory == nullptr) { - return {}; - } - - auto ptr = ConstructObj(*factory, obj_id); - ptr.SetFlags(obj_flags & ~ObjFlags::kUnloaded); - ptr = factory->load(this, ptr); - return ptr; -} - -void Domain::SaveRootImpl(ObjPtr const& ptr) { - if (!ptr) { - return; - } - if (auto* factory = FindClassFactory(*ptr); factory) { - factory->save(this, ptr); - } -} - -ObjPtr Domain::LoadCopyImpl(ObjPtr const& ref, ObjId copy_id) { - auto obj_id = ref.GetId(); - auto obj_flags = ref.GetFlags(); - if (!obj_id.IsValid() || !copy_id.IsValid()) { - return {}; - } - // if already loaded - if (auto obj = Find(copy_id); obj) { - return obj; - } - - auto* factory = GetMostRelatedFactory(obj_id); - if (factory == nullptr) { - assert(false); - return {}; - } - - auto ptr = ConstructObj(*factory, copy_id); - ptr.SetFlags(obj_flags & ~ObjFlags::kUnloaded & - ~ObjFlags::kUnloadedByDefault); - // temporary set obj_id - ptr.SetId(obj_id); - ptr = factory->load(this, ptr); - // return new id - ptr.SetId(copy_id); - return ptr; -} - -imstream& operator>>(imstream& is, - ObjPtr& ptr) { - ObjId id; - ObjFlags flags; - is >> id >> flags; - if ((flags & ObjFlags::kUnloadedByDefault) || (flags & ObjFlags::kUnloaded)) { - ptr.SetId(id); - ptr.SetFlags(flags); - return is; - } - - ptr = is.ib_.domain->LoadRootImpl(id, flags); - return is; -} - -omstream& operator<<(omstream& os, - ObjPtr const& ptr) { - auto id = ptr.GetId(); - auto flags = ptr.GetFlags(); - os << id << flags; - os.ob_.domain->SaveRootImpl(ptr); - return os; -} - } // namespace ae diff --git a/aether/obj/domain.h b/aether/obj/domain.h index 5c449d6c..2d4b5998 100644 --- a/aether/obj/domain.h +++ b/aether/obj/domain.h @@ -17,26 +17,10 @@ #ifndef AETHER_OBJ_DOMAIN_H_ #define AETHER_OBJ_DOMAIN_H_ -#include -#include -#include -#include #include #include -#include - -#include "aether/common.h" #include "aether/mstream.h" -#include "aether/mstream_buffers.h" - -#include "aether/ptr/ptr_view.h" -#include "aether/reflect/reflect.h" -#include "aether/reflect/domain_visitor.h" - -#include "aether/obj/obj_id.h" -#include "aether/obj/obj_ptr.h" -#include "aether/obj/registry.h" #include "aether/obj/idomain_storage.h" #include "aether/obj/version_iterator.h" @@ -44,35 +28,6 @@ namespace ae { class Obj; class Domain; -struct DomainCycleDetector { - struct Node { - bool operator==(const Node& other) const { - return id == other.id && class_id == other.class_id; - } - bool operator<(const Node& other) const { - return id < other.id || (id == other.id && class_id < other.class_id); - } - - ObjId id; - std::uint32_t class_id; - }; - - template - bool Add(T const* obj) { - auto [_, ok] = visited_nodes.insert(Node{obj->GetId(), T::kClassId}); - return ok; - } - - std::set visited_nodes; -}; - -class DomainStorageReaderEmpty final : public IDomainStorageReader { - public: - void read(void*, std::size_t) override {} - ReadResult result() const override { return ReadResult::kNo; } - void result(ReadResult) override {} -}; - struct DomainBufferWriter { using size_type = IDomainStorageReader::size_type; @@ -92,8 +47,6 @@ struct DomainBufferReader { : domain{d}, reader{&r} {} void read(void* data, std::size_t size) { reader->read(data, size); } - ReadResult result() const { return reader->result(); } - void result(ReadResult result) { reader->result(result); } Domain* domain{}; IDomainStorageReader* reader; @@ -101,140 +54,46 @@ struct DomainBufferReader { class Domain { public: - Domain(TimePoint p, IDomainStorage& storage); + explicit Domain(IDomainStorage& storage); - TimePoint Update(TimePoint current_time); - - // Create new object and add it to the domain - template - ObjPtr CreateObj(ObjId obj_id, TArgs&&... args); - template - ObjPtr CreateObj(TArg&& arg1, TArgs&&... args); - template - ObjPtr CreateObj(); - - // Load saved state of object - template - void LoadRoot(ObjPtr& ptr); - // Save state of object - template - void SaveRoot(ObjPtr const& ptr); - // Load a copy of object template - ObjPtr LoadCopy(ObjPtr const& ref, - ObjId copy_id = ObjId::GenerateUnique()); - - ObjPtr LoadRootImpl(ObjId obj_id, ObjFlags obj_flags); - ObjPtr LoadCopyImpl(ObjPtr const& ref, ObjId copy_id); - void SaveRootImpl(ObjPtr const& ptr); - - template - void Load(T& obj); + void Load(T& obj, DataKey key); template - void LoadVersion(Version version, T& obj); + void LoadVersion(Version version, T& obj, DataKey key); template - void Save(T const& obj); + void Save(T const& obj, DataKey key); template - void SaveVersion(Version version, T const& obj); - - // Search for the object by obj_id. - ObjPtr Find(ObjId obj_id) const; - - void AddObject(ObjId id, ObjPtr const& obj); - void RemoveObject(Obj* obj); - - AE_REFLECT() + void SaveVersion(Version version, T const& obj, DataKey key); private: - ObjPtr ConstructObj(Factory const& factory, ObjId id); - - bool IsLast(uint32_t class_id) const; - bool IsExisting(uint32_t class_id) const; - - Factory* GetMostRelatedFactory(ObjId id); - Factory* FindClassFactory(Obj const& obj); - - std::unique_ptr GetReader(DomainQuery const& query); - std::unique_ptr GetWriter(DomainQuery const& query); + std::unique_ptr GetReader(DataKey key, + std::uint8_t version); + std::unique_ptr GetWriter(DataKey key, + std::uint8_t version); - TimePoint update_time_; IDomainStorage* storage_; - Registry* registry_; - - std::map> id_objects_; - - DomainCycleDetector cycle_detector_{}; }; -template -ObjPtr Domain::CreateObj(ObjId obj_id, TArgs&&... args) { - static_assert( - std::is_constructible_v, - "Class must be constructible with passed arguments and Domain*"); - - // allocate object first and add it to the list - auto object = ObjPtr{MakePtr(std::forward(args)..., this)}; - AddObject(obj_id, object); - object.SetId(obj_id); - return object; -} - -template -ObjPtr Domain::CreateObj(TArg&& arg1, TArgs&&... args) { - if constexpr (std::is_convertible_v) { - // if first arg is object id - return CreateObj(ObjId{static_cast(arg1)}, - std::forward(args)...); - } else { - return CreateObj(ObjId::GenerateUnique(), std::forward(arg1), - std::forward(args)...); - } -} - -template -ObjPtr Domain::CreateObj() { - return CreateObj(ObjId::GenerateUnique()); -} - -template -void Domain::LoadRoot(ObjPtr& ptr) { - cycle_detector_ = {}; - ptr = LoadRootImpl(ptr.GetId(), ptr.GetFlags()); -} - -template -void Domain::SaveRoot(ObjPtr const& ptr) { - cycle_detector_ = {}; - SaveRootImpl(ptr); -} - template -ObjPtr Domain::LoadCopy(ObjPtr const& ref, ObjId copy_id) { - cycle_detector_ = {}; - return ObjPtr{LoadCopyImpl(ref, copy_id)}; -} - -template -void Domain::Load(T& obj) { - if (!cycle_detector_.Add(&obj)) { - return; - } - +void Domain::Load(T& obj, DataKey key) { if constexpr (HasAnyVersionedLoad::value) { constexpr auto version_bounds = VersionedLoadMinMax::value; IterateVersions( - obj, - [this](auto version, auto& obj) { this->LoadVersion(version, obj); }); + version_bounds.second>(obj, [&](auto version, auto& obj) { + this->LoadVersion(version, obj, key); + }); } else { - LoadVersion(T::kCurrentVersion, obj); + LoadVersion(T::kCurrentVersion, obj, key); } } template -void Domain::LoadVersion(Version version, T& obj) { - auto storage_reader = GetReader({obj.GetId(), T::kClassId, V}); +void Domain::LoadVersion(Version version, T& obj, DataKey key) { + auto storage_reader = GetReader(key, V); + if (!storage_reader) { + return; + } DomainBufferReader reader{this, *storage_reader}; imstream is(reader); @@ -254,25 +113,21 @@ void Domain::LoadVersion(Version version, T& obj) { } template -void Domain::Save(T const& obj) { - if (!cycle_detector_.Add(&obj)) { - return; - } - +void Domain::Save(T const& obj, DataKey key) { if constexpr (HasAnyVersionedSave::value) { constexpr auto version_bounds = VersionedSaveMinMax::value; IterateVersions(obj, [this](auto version, auto& obj) { - this->SaveVersion(version, obj); + version_bounds.first>(obj, [&](auto version, auto& obj) { + this->SaveVersion(version, obj, key); }); } else { - SaveVersion(T::kCurrentVersion, obj); + SaveVersion(T::kCurrentVersion, obj, key); } } template -void Domain::SaveVersion(Version version, T const& obj) { - auto storage_writer = GetWriter({obj.GetId(), T::kClassId, V}); +void Domain::SaveVersion(Version version, T const& obj, DataKey key) { + auto storage_writer = GetWriter(key, V); DomainBufferWriter writer{this, *storage_writer}; omstream os(writer); @@ -289,44 +144,6 @@ void Domain::SaveVersion(Version version, T const& obj) { reflect::DomainVisit(obj, std::move(visitor_func)); } } - -imstream& operator>>(imstream& is, - ObjPtr& ptr); - -omstream& operator<<(omstream& os, - ObjPtr const& ptr); - -template ))> -imstream& operator>>(imstream& is, - ObjPtr& ptr) { - auto obj_ptr = ObjPtr{}; - is >> obj_ptr; - ptr = obj_ptr; - return is; -} - -template ))> -omstream& operator<<(omstream& os, - ObjPtr const& ptr) { - auto obj_ptr = ObjPtr{ptr}; - os << obj_ptr; - return os; -} - -template -std::enable_if_t, imstream&> -operator>>(imstream& is, T& obj) { - is.ib_.domain->Load(obj); - return is; -} - -template -std::enable_if_t, omstream&> -operator<<(omstream& os, T const& obj) { - os.ob_.domain->Save(obj); - return os; -} - } // namespace ae #endif // AETHER_OBJ_DOMAIN_H_ diff --git a/aether/obj/dummy_obj.h b/aether/obj/dummy_obj.h index 1a770aac..af1ff40e 100644 --- a/aether/obj/dummy_obj.h +++ b/aether/obj/dummy_obj.h @@ -26,11 +26,8 @@ namespace ae { */ class DummyObj : public Obj { AE_OBJECT(DummyObj, Obj, 0) - - using Obj::Obj; - public: - AE_OBJECT_REFLECT() + using Obj::Obj; }; } // namespace ae diff --git a/aether/obj/idomain_storage.h b/aether/obj/idomain_storage.h index 9dce73f5..745be4d7 100644 --- a/aether/obj/idomain_storage.h +++ b/aether/obj/idomain_storage.h @@ -21,7 +21,7 @@ #include #include -#include "aether/obj/obj_id.h" +#include "aether/misc/hash.h" // IWYU pragma: keep namespace ae { @@ -31,14 +31,8 @@ enum class DomainLoadResult : std::uint8_t { kLoaded, //< Data loaded successfully }; -using ObjectData = std::vector; -using ClassList = std::vector; - -struct DomainQuery { - ObjId id; - std::uint32_t class_id; - std::uint8_t version; -}; +using DataKey = std::uint32_t; +using DataValue = std::vector; class IDomainStorageWriter { public: @@ -56,8 +50,6 @@ class IDomainStorageReader { virtual ~IDomainStorageReader() = default; virtual void read(void* data, std::size_t size) = 0; - virtual ReadResult result() const = 0; - virtual void result(ReadResult result) = 0; }; struct DomainLoad { @@ -72,23 +64,18 @@ class IDomainStorage { public: virtual ~IDomainStorage() = default; /** - * \brief Store an ObjectData by query. + * \brief Store an DataValue by query. */ - virtual std::unique_ptr Store( - DomainQuery const& query) = 0; - /** - * \brief Enumerate all classes for object. - */ - virtual ClassList Enumerate(ObjId const& obj_id) = 0; + virtual std::unique_ptr Store(DataKey key, + std::uint8_t version) = 0; /** * \brief Load object data by query. */ - virtual DomainLoad Load(DomainQuery const& query) = 0; - + virtual DomainLoad Load(DataKey key, std::uint8_t version) = 0; /** * \brief Remove object data by query */ - virtual void Remove(ObjId const& obj_id) = 0; + virtual void Remove(DataKey key) = 0; /** * \brief Clean up the whole storage. */ diff --git a/aether/obj/obj.cpp b/aether/obj/obj.cpp index b3c91395..e358624f 100644 --- a/aether/obj/obj.cpp +++ b/aether/obj/obj.cpp @@ -21,19 +21,7 @@ Obj::Obj() = default; Obj::Obj(Domain* domain) : domain_(domain) {} -Obj::~Obj() { - if (domain_ != nullptr) { - domain_->RemoveObject(this); - } -} +Obj::~Obj() = default; uint32_t Obj::GetClassId() const { return kClassId; } - -ObjId Obj::GetId() const { return id_; } - -void Obj::Update(TimePoint current_time) { - // FIXME: 365 * 24 ? - update_time_ = current_time + std::chrono::hours(365 * 24); -} - } // namespace ae diff --git a/aether/obj/obj.h b/aether/obj/obj.h index acb9b4e0..915945c1 100644 --- a/aether/obj/obj.h +++ b/aether/obj/obj.h @@ -29,17 +29,10 @@ #ifndef AETHER_OBJ_OBJ_H_ #define AETHER_OBJ_OBJ_H_ -#include - #include "aether/config.h" -#include "aether/common.h" #include "aether/crc.h" -#include "aether/obj/obj_id.h" -#include "aether/obj/obj_ptr.h" #include "aether/obj/domain.h" -#include "aether/obj/registry.h" -#include "aether/obj/registrar.h" #include "aether/reflect/reflect.h" namespace ae { @@ -51,13 +44,11 @@ class Obj { public: using CurrentVersion = Version<0>; - using ptr = ObjPtr; static constexpr std::uint32_t kClassId = crc32::from_literal("Obj").value; static constexpr std::uint32_t kBaseClassId = crc32::from_literal("Obj").value; - static constexpr std::uint32_t kVersion = 0; static constexpr CurrentVersion kCurrentVersion{}; Obj(); @@ -65,70 +56,30 @@ class Obj { virtual ~Obj(); virtual std::uint32_t GetClassId() const; - virtual void Update(TimePoint current_time); - - ObjId GetId() const; - - AE_REFLECT_MEMBERS(update_time_); Domain* domain_{}; - TimePoint update_time_; - - protected: - ObjId id_; - ObjFlags flags_; }; - -namespace reflect { -template -struct ObjectIndex>> { - static std::size_t GetIndex(T const* obj) { - std::array - buffer; - *reinterpret_cast(buffer.data()) = T::kClassId; - *reinterpret_cast(buffer.data() + sizeof(std::uint32_t)) = - obj->GetId().id(); - - return crc32::from_buffer(buffer.data(), buffer.size()).value; - } -}; -} // namespace reflect - } // namespace ae /** * \brief Use it inside each derived class to register it with the object system */ -#define AE_OBJECT(DERIVED, BASE, VERSION) \ - protected: \ - friend class ae::Registrar; \ - friend ae::Ptr ae::MakePtr(); \ - \ - public: \ - static constexpr std::uint32_t kClassId = \ - crc32::from_literal(#DERIVED).value; \ - static constexpr std::uint32_t kBaseClassId = \ - crc32::from_literal(#BASE).value; \ - static constexpr std::uint32_t kVersion = VERSION; \ - using CurrentVersion = Version; \ - static constexpr CurrentVersion kCurrentVersion{}; \ - inline static auto registrar_ = \ - ae::Registrar(kClassId, kBaseClassId); \ - \ - using Base = BASE; \ - using ptr = ae::ObjPtr; \ - \ - Base& base_{*this}; \ - \ - std::uint32_t GetClassId() const override { return kClassId; } \ - \ - private: \ +#define AE_OBJECT(DERIVED, BASE, VERSION) \ + public: \ + static constexpr std::uint32_t kClassId = \ + crc32::from_literal(#DERIVED).value; \ + static constexpr std::uint32_t kBaseClassId = \ + crc32::from_literal(#BASE).value; \ + using CurrentVersion = Version; \ + \ + static constexpr auto kTypeName = ae::reflect::GetTypeName(); \ + static constexpr CurrentVersion kCurrentVersion{}; \ + using Base = BASE; \ + Base& base_{*this}; \ + \ + std::uint32_t GetClassId() const override { return kClassId; } \ + \ + private: \ /* add rest class's staff after */ -/** - * \brief Obj class reflection - */ -#define AE_OBJECT_REFLECT(...) \ - AE_REFLECT(AE_REF_BASE(std::decay_t), __VA_ARGS__) - #endif // AETHER_OBJ_OBJ_H_ diff --git a/aether/obj/obj_id.cpp b/aether/obj/obj_id.cpp deleted file mode 100644 index 38aca449..00000000 --- a/aether/obj/obj_id.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2024 Aethernet Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "aether/obj/obj_id.h" - -#include - -namespace ae { -ObjId ObjId::GenerateUnique() { - // set seed once - static bool const seed = - (std::srand(static_cast(time(nullptr))), true); - (void)seed; - // new id would be bigger than any user defined id - auto value = std::rand() + 10000; - return ObjId{static_cast(value)}; -} -} // namespace ae diff --git a/aether/obj/obj_id.h b/aether/obj/obj_id.h deleted file mode 100644 index 3d279567..00000000 --- a/aether/obj/obj_id.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2024 Aethernet Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef AETHER_OBJ_OBJ_ID_H_ -#define AETHER_OBJ_OBJ_ID_H_ - -#include -#include - -#include "aether/mstream.h" - -namespace ae { - -class ObjId { - public: - using Type = std::uint32_t; - - static ObjId GenerateUnique(); - - ObjId() { Invalidate(); } - - explicit constexpr ObjId(Type i) : id_{i} {} - - constexpr Type id() const { return id_; } - - void Invalidate() { id_ = 0; } - constexpr bool IsValid() const { return id_ != 0; } - constexpr bool operator<(const ObjId& i) const { return id_ < i.id_; } - constexpr bool operator!=(const ObjId& i) const { return id_ != i.id_; } - constexpr bool operator==(const ObjId& i) const { return id_ == i.id_; } - - ObjId& operator+=(Type i) { - id_ += i; - return *this; - } - constexpr ObjId operator+(Type i) const { return ObjId{id_ + i}; } - - template - friend omstream& operator<<(omstream& s, const ObjId& i) { - return s << i.id_; - } - template - friend imstream& operator>>(imstream& s, ObjId& i) { - return s >> i.id_; - } - - std::string ToString() const { return std::to_string(id_); } - - protected: - Type id_; -}; - -class ObjFlags { - public: - enum { - // The object is not loaded with deserialization. Load method must be - // used for loading. - kUnloadedByDefault = 1, - kUnloaded = 2, - }; - - ObjFlags(uint8_t v) : value_(v) {} - ObjFlags() = default; - - operator std::uint8_t&() { return value_; } - - template - friend omstream& operator<<(omstream& s, const ObjFlags& i) { - return s << i.value_; - } - template - friend imstream& operator>>(imstream& s, ObjFlags& i) { - return s >> i.value_; - } - - private: - std::uint8_t value_ = 0; -}; - -} // namespace ae - -#endif // AETHER_OBJ_OBJ_ID_H_ */ diff --git a/aether/obj/obj_ptr.cpp b/aether/obj/obj_ptr.cpp deleted file mode 100644 index 269a4601..00000000 --- a/aether/obj/obj_ptr.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2024 Aethernet Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "aether/obj/obj_ptr.h" - -#include "aether/obj/obj.h" -#include "aether/obj/obj_id.h" - -namespace ae { - -ObjectPtrBase::ObjectPtrBase() : id_{}, flags_{ObjFlags::kUnloaded} {} -ObjectPtrBase::ObjectPtrBase(Obj* ptr) : ptr_{ptr}, id_{}, flags_{} { - if (ptr_) { - id_ = ptr_->id_; - flags_ = ptr_->flags_; - } -} - -ObjectPtrBase::ObjectPtrBase(ObjectPtrBase const& ptr) noexcept = default; - -ObjectPtrBase::ObjectPtrBase(ObjectPtrBase&& ptr) noexcept = default; - -void ObjectPtrBase::SetId(ObjId id) { - id_ = id; - if (ptr_ != nullptr) { - ptr_->id_ = id; - } -} -void ObjectPtrBase::SetFlags(ObjFlags flags) { - flags_ = flags; - if (ptr_ != nullptr) { - ptr_->flags_ = flags; - } -} - -ObjId ObjectPtrBase::GetId() const { - return (ptr_ != nullptr) ? ptr_->id_ : id_; -} -ObjFlags ObjectPtrBase::GetFlags() const { - return (ptr_ != nullptr) ? ptr_->flags_ : flags_; -} - -ObjectPtrBase& ObjectPtrBase::operator=(Obj* ptr) noexcept { - ptr_ = ptr; - if (ptr_ != nullptr) { - id_ = ptr_->id_; - flags_ = ptr_->flags_; - } else { - id_ = {}; - flags_ = {}; - } - return *this; -} - -ObjectPtrBase& ObjectPtrBase::operator=(ObjectPtrBase const& ptr) noexcept = - default; - -ObjectPtrBase& ObjectPtrBase::operator=(ObjectPtrBase&& ptr) noexcept = default; - -} // namespace ae diff --git a/aether/obj/obj_ptr.h b/aether/obj/obj_ptr.h deleted file mode 100644 index 61a57a93..00000000 --- a/aether/obj/obj_ptr.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright 2024 Aethernet Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef AETHER_OBJ_OBJ_PTR_H_ -#define AETHER_OBJ_OBJ_PTR_H_ - -#include -#include -#include - -#include "aether/ptr/ptr.h" -#include "aether/obj/obj_id.h" -#include "aether/reflect/domain_visitor.h" // IWYU pragma: keep - -namespace ae { -class Obj; - -template -struct IsObjType : std::false_type {}; - -template -struct IsObjType> : std::true_type {}; - -class ObjectPtrBase { - public: - ObjectPtrBase(); - explicit ObjectPtrBase(Obj* ptr); - - ObjectPtrBase(ObjectPtrBase const& ptr) noexcept; - ObjectPtrBase(ObjectPtrBase&& ptr) noexcept; - - void SetId(ObjId id); - void SetFlags(ObjFlags flags); - - ObjId GetId() const; - ObjFlags GetFlags() const; - - protected: - ObjectPtrBase& operator=(Obj* ptr) noexcept; - ObjectPtrBase& operator=(ObjectPtrBase const& ptr) noexcept; - ObjectPtrBase& operator=(ObjectPtrBase&& ptr) noexcept; - - private: - Obj* ptr_ = nullptr; - ObjId id_; - ObjFlags flags_; -}; - -template -class ObjPtr : public Ptr, public ObjectPtrBase { - template - friend class ObjPtr; - - public: - ObjPtr() noexcept : Ptr{}, ObjectPtrBase{} {} - explicit ObjPtr(std::nullptr_t) noexcept : Ptr{nullptr}, ObjectPtrBase{} {} - - ~ObjPtr() { Ptr::Reset(); } - - ObjPtr(Ptr const& ptr) noexcept - : Ptr{ptr}, ObjectPtrBase(Ptr::get()) {} - ObjPtr(Ptr&& ptr) noexcept - : Ptr(std::move(ptr)), ObjectPtrBase(Ptr::get()) {} - - ObjPtr(ObjPtr const& ptr) noexcept : Ptr{ptr}, ObjectPtrBase{ptr} {} - ObjPtr(ObjPtr&& ptr) noexcept - : Ptr{std::move(ptr)}, ObjectPtrBase{std::move(ptr)} {} - - template ))> - ObjPtr(ObjPtr const& ptr) noexcept : Ptr{ptr}, ObjectPtrBase{ptr} {} - - template ))> - ObjPtr(ObjPtr&& ptr) noexcept - : Ptr(std::move(ptr)), ObjectPtrBase(std::move(ptr)) {} - - ObjPtr& operator=(ObjPtr const& ptr) noexcept { - Ptr::operator=(ptr); - ObjectPtrBase::operator=(ptr); - return *this; - } - ObjPtr& operator=(ObjPtr&& ptr) noexcept { - Ptr::operator=(std::move(ptr)); - ObjectPtrBase::operator=(std::move(ptr)); - return *this; - } - - template ::value, int> = 0> - ObjPtr& operator=(ObjPtr const& ptr) noexcept { - Ptr::operator=(ptr); - ObjectPtrBase::operator=(ptr); - return *this; - } - template ::value, int> = 0> - ObjPtr& operator=(ObjPtr&& ptr) noexcept { - Ptr::operator=(std::move(ptr)); - ObjectPtrBase::operator=(std::move(ptr)); - return *this; - } -}; -} // namespace ae - -namespace ae::reflect { -template -struct NodeVisitor> : NodeVisitor> { - using Policy = AnyPolicyMatch; - - template - void Visit(ae::ObjPtr& obj_ptr, CycleDetector& cycle_detector, - Visitor&& visitor) const { - NodeVisitor>::Visit(obj_ptr, cycle_detector, - std::forward(visitor)); - } - - template - void Visit(ae::ObjPtr const& obj_ptr, CycleDetector& cycle_detector, - Visitor&& visitor) const { - NodeVisitor>::Visit(obj_ptr, cycle_detector, - std::forward(visitor)); - } -}; -} // namespace ae::reflect - -#endif // AETHER_OBJ_OBJ_PTR_H_ diff --git a/aether/obj/registrar.h b/aether/obj/registrar.h deleted file mode 100644 index 92f695da..00000000 --- a/aether/obj/registrar.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2024 Aethernet Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef AETHER_OBJ_REGISTRAR_H_ -#define AETHER_OBJ_REGISTRAR_H_ - -#include - -#include "aether/obj/domain.h" -#include "aether/obj/registry.h" -#include "aether/obj/obj_ptr.h" -#include "aether/reflect/type_index.h" - -namespace ae { -template -class Registrar { - public: - Registrar(std::uint32_t cls_id, std::uint32_t base_id) { - Registry::GetRegistry().RegisterClass( - cls_id, base_id, - { - Factory::CreateFunc(&Create), - Factory::LoadFunc(&Load), - Factory::SaveFunc(&Save) -#ifdef DEBUG - , - std::string{reflect::GetTypeName()}, - cls_id, - base_id, -#endif // DEBUG - }); - } - - private: - // like std::is_default_constructible but with respect to Registrar<-Ojb - // friendship - template - struct IsDefaultConstructible : std::false_type {}; - template - struct IsDefaultConstructible> - : std::true_type {}; - - static ObjPtr Create() { - if constexpr (std::is_abstract_v) { - assert(false && "Create called on abstract class"); - return {}; - } else { - static_assert(IsDefaultConstructible::value, - "AE_OBJECT class should be default constructible"); - return ObjPtr(MakePtr()); - } - } - - static ObjPtr Load(Domain* domain, ObjPtr obj) { - auto self_ptr = ObjPtr{std::move(obj)}; - domain->Load(*self_ptr.get()); - return self_ptr; - } - - static void Save(Domain* domain, ObjPtr const& obj) { - auto self_ptr = static_cast(obj.get()); - domain->Save(*self_ptr); - } -}; -} // namespace ae -#endif // AETHER_OBJ_REGISTRAR_H_ diff --git a/aether/obj/registry.cpp b/aether/obj/registry.cpp deleted file mode 100644 index e33bb1ce..00000000 --- a/aether/obj/registry.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2024 Aethernet Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "aether/obj/registry.h" - -#include - -#include "aether/crc.h" -#include "aether/obj/obj_tele.h" - -namespace ae { -Registry& Registry::GetRegistry() { - static Registry registry; - return registry; -} - -void Registry::RegisterClass(uint32_t cls_id, std::uint32_t base_id, - Factory&& factory) { -#ifdef DEBUG - // Fixme: Commented out to fix the build crash in MinGW - /*std::cout << "Registering class " << factory.class_name << " id " << cls_id - << " with base " << base_id << std::endl;*/ - - // TODO: move into compil-time. - // TODO: check at compile-time that the base_id to be existing class. - // Visual Studio 2017 has a bug with multiple static inline members - // initialization - // https://developercommunity.visualstudio.com/t/multiple-initializations-of-inline-static-data-mem/261624 - // Refer to - // https://learn.microsoft.com/en-us/cpp/overview/compiler-versions?view=msvc-170 -# if !defined(_MSC_VER) || _MSC_VER >= 1920 - auto no_duplication = factories.find(cls_id) == factories.end(); - assert(no_duplication && "Duplicate class id in registry"); -# endif // !defined(_MSC_VER) || _MSC_VER >= 1920 -#endif // DEBUG - factories.emplace(cls_id, std::move(factory)); - // TODO: maybe remove this check - if (base_id != crc32::from_literal("Obj").value) { - relations[base_id].push_back(cls_id); - } -} - -bool Registry::IsExisting(uint32_t class_id) { - return factories.find(class_id) != factories.end(); -} - -int Registry::GenerationDistanceInternal(std::uint32_t base_id, - std::uint32_t derived_id) { - auto d = relations.find(base_id); - // The base class is final. - if (d == relations.end()) { - return -1; - } - - for (auto& c : d->second) { - if (derived_id == c) { - return 1; - } - - int distance = GenerationDistanceInternal(c, derived_id); - if (distance >= 0) { - return distance + 1; - } - } - - return -1; -} - -int Registry::GenerationDistance(std::uint32_t base_id, - std::uint32_t derived_id) { - if (!IsExisting(base_id) || !IsExisting(derived_id)) { - return -1; - } - - if (base_id == derived_id) { - return 0; - } - - return GenerationDistanceInternal(base_id, derived_id); -} - -Factory* Registry::FindFactory(std::uint32_t base_id) { - auto it = factories.find(base_id); - if (it == factories.end()) { - return nullptr; - } - return &it->second; -} - -void Registry::Log() { -#ifdef DEBUG - for (const auto& c : factories) { - AE_TELE_DEBUG(ObjectRegistryLog, "name {}, id {}, base_id {}", - c.second.class_name, c.second.cls_id, c.second.base_id); - } -#endif // DEBUG -} - -} // namespace ae diff --git a/aether/obj/registry.h b/aether/obj/registry.h deleted file mode 100644 index b5d742d9..00000000 --- a/aether/obj/registry.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2024 Aethernet Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef AETHER_OBJ_REGISTRY_H_ -#define AETHER_OBJ_REGISTRY_H_ - -#include -#include -#include -#include - -#include "aether/config.h" -#include "aether/obj/obj_ptr.h" - -namespace ae { -class Obj; -class Domain; - -struct Factory { - using CreateFunc = ObjPtr (*)(); - using LoadFunc = ObjPtr (*)(Domain* domain, ObjPtr prefab); - using SaveFunc = void (*)(Domain* domain, ObjPtr const& obj); - - CreateFunc create; - LoadFunc load; - SaveFunc save; -#ifdef DEBUG - std::string class_name{}; - std::uint32_t cls_id{}; - std::uint32_t base_id{}; -#endif // DEBUG -}; - -class Registry { - public: - using Relations = std::unordered_map>; - using Factories = std::unordered_map; - - static Registry& GetRegistry(); - - void RegisterClass(uint32_t cls_id, std::uint32_t base_id, Factory&& factory); - void Log(); - bool IsExisting(uint32_t class_id); - - int GenerationDistanceInternal(std::uint32_t base_id, - std::uint32_t derived_id); - - // Calculates distance from base to derived in generations: - // -1 - derived is not inherited directly or indirectly from base or any - // class doesn't exist. - int GenerationDistance(std::uint32_t base_id, std::uint32_t derived_id); - - Factory* FindFactory(uint32_t base_id); - - Relations relations; - Factories factories; -}; -} // namespace ae - -#endif // AETHER_OBJ_REGISTRY_H_ */ diff --git a/aether/types/address.h b/aether/types/address.h index c2474375..728c974a 100644 --- a/aether/types/address.h +++ b/aether/types/address.h @@ -21,11 +21,11 @@ #include #include "aether/config.h" +#include "aether/misc/hash.h" +#include "aether/format/format.h" #include "aether/reflect/reflect.h" #include "aether/types/variant_type.h" -#include "aether/format/format.h" - namespace ae { enum class AddrVersion : std::uint8_t { @@ -192,6 +192,59 @@ struct Formatter { static_cast(value.protocol)); } }; + +template <> +struct Hasher { + static constexpr std::uint32_t Get([[maybe_unused]] IpV4Addr const& value, + crc32::result_t res) { +#if AE_SUPPORT_IPV4 + return crc32::from_buffer(value.ipv4_value, sizeof(value.ipv4_value), res) + .value; +#else + return res; +#endif + } +}; +template <> +struct Hasher { + static constexpr crc32::result_t Get([[maybe_unused]] IpV6Addr const& value, + crc32::result_t res) { +#if AE_SUPPORT_IPV6 + return crc32::from_buffer(value.ipv6_value, sizeof(value.ipv6_value), res); +#else + return res; +#endif + } +}; +template <> +struct Hasher { + static constexpr crc32::result_t Get([[maybe_unused]] NamedAddr const& value, + crc32::result_t res) { +#if AE_SUPPORT_CLOUD_DNS + return Hash(res, value.name); +#else + return res; +#endif + } +}; + +template <> +struct Hasher
{ + static constexpr crc32::result_t Get(Address const& value, + crc32::result_t res) { + return std::visit([&](auto const& value) { return Hash(res, value); }, + value); + } +}; + +template <> +struct Hasher { + static constexpr crc32::result_t Get(Endpoint const& value, + crc32::result_t res) { + return Hash(res, value.address, value.port, value.protocol); + } +}; + } // namespace ae #endif // AETHER_TYPES_ADDRESS_H_ diff --git a/aether/types/statistic_counter.h b/aether/types/statistic_counter.h index 67864494..ac64fbf9 100644 --- a/aether/types/statistic_counter.h +++ b/aether/types/statistic_counter.h @@ -123,7 +123,7 @@ class StatisticsCounter final { } private: - etl::circular_buffer value_buffer_; + etl::circular_buffer value_buffer_{}; }; /** diff --git a/aether/types/uid.h b/aether/types/uid.h index 8af4fb4a..d4b3f998 100644 --- a/aether/types/uid.h +++ b/aether/types/uid.h @@ -24,8 +24,9 @@ #include #include -#include "aether/type_traits.h" +#include "aether/misc/hash.h" #include "aether/types/span.h" +#include "aether/type_traits.h" #include "aether/format/format.h" #include "aether/reflect/reflect.h" #include "aether/types/literal_array.h" @@ -108,6 +109,13 @@ struct Formatter { } }; +template <> +struct Hasher { + static constexpr crc32::result_t Get(Uid const& value, crc32::result_t res) { + return crc32::from_buffer(value.value.data(), value.value.size(), res); + } +}; + } // namespace ae #endif // AETHER_TYPES_UID_H_ */ From f7fb64e91a6dd8bbabe00d84f383c35026e116ac Mon Sep 17 00:00:00 2001 From: BartolomeyKant Date: Fri, 19 Dec 2025 16:31:31 +0500 Subject: [PATCH 02/12] use new object system --- aether/CMakeLists.txt | 3 - aether/access_points/access_point.h | 8 +- .../access_points/ethernet_access_point.cpp | 34 +++--- aether/access_points/ethernet_access_point.h | 17 ++- aether/access_points/wifi_access_point.cpp | 42 +++---- aether/access_points/wifi_access_point.h | 23 ++-- aether/actions/action_trigger.cpp | 2 +- aether/adapter_registry.cpp | 6 +- aether/adapter_registry.h | 12 +- aether/adapters/adapter.cpp | 2 - aether/adapters/adapter.h | 11 +- aether/adapters/ethernet.cpp | 11 +- aether/adapters/ethernet.h | 14 +-- aether/adapters/parent_wifi.cpp | 19 +-- aether/adapters/parent_wifi.h | 19 +-- aether/adapters/proxy.h | 8 +- aether/adapters/wifi_adapter.cpp | 35 ++---- aether/adapters/wifi_adapter.h | 16 +-- aether/ae_actions/ping.cpp | 12 +- aether/ae_actions/ping.h | 6 +- aether/ae_actions/select_client.cpp | 13 +-- aether/ae_actions/select_client.h | 7 +- aether/ae_actions/telemetry.cpp | 12 +- aether/ae_actions/telemetry.h | 6 +- aether/aether.cpp | 103 +++++++---------- aether/aether.h | 67 +++-------- aether/aether_app.cpp | 109 ++++++++---------- aether/aether_app.h | 62 +++++----- aether/aether_c/aether_capi.cpp | 31 +++-- aether/aether_c/c_conf.h | 4 +- aether/all.h | 3 - aether/api_protocol/api_pack_parser.cpp | 4 +- aether/api_protocol/api_pack_parser.h | 2 +- aether/channels/channel.cpp | 32 +++-- aether/channels/channel.h | 10 +- aether/channels/channel_statistics.cpp | 1 - aether/channels/channel_statistics.h | 11 +- aether/channels/ethernet_channel.cpp | 45 +++----- aether/channels/ethernet_channel.h | 14 +-- .../channels/ethernet_transport_factory.cpp | 10 +- aether/channels/ethernet_transport_factory.h | 7 +- aether/channels/wifi_channel.cpp | 66 ++++------- aether/channels/wifi_channel.h | 18 +-- aether/client.cpp | 93 ++++++++------- aether/client.h | 49 +++----- aether/client_connections/cloud_connection.h | 1 + aether/client_messages/p2p_message_stream.cpp | 31 ++--- aether/client_messages/p2p_message_stream.h | 9 +- .../p2p_message_stream_manager.cpp | 12 +- .../p2p_message_stream_manager.h | 8 +- aether/cloud.cpp | 23 ---- aether/cloud.h | 11 +- .../client_cloud_manager.cpp | 70 +++++------ .../connection_manager/client_cloud_manager.h | 39 +++++-- .../client_connection_manager.cpp | 14 +-- .../client_connection_manager.h | 7 +- .../server_connection_manager.cpp | 13 +-- .../server_connection_manager.h | 12 +- aether/crypto.h | 10 +- aether/dns/dns_c_ares.cpp | 11 +- aether/dns/dns_c_ares.h | 9 +- aether/dns/dns_resolve.cpp | 8 +- aether/dns/dns_resolve.h | 16 +-- aether/dns/esp32_dns_resolve.cpp | 14 +-- aether/dns/esp32_dns_resolve.h | 10 +- aether/global_ids.h | 58 ---------- aether/mstream.h | 91 ++------------- aether/mstream_buffers.h | 49 +++----- aether/poller/epoll_poller.cpp | 18 +-- aether/poller/epoll_poller.h | 9 -- aether/poller/freertos_poller.cpp | 45 +++----- aether/poller/freertos_poller.h | 11 +- aether/poller/kqueue_poller.cpp | 18 +-- aether/poller/kqueue_poller.h | 8 -- aether/poller/poller.cpp | 15 --- aether/poller/poller.h | 13 +-- aether/poller/win_poller.cpp | 13 +-- aether/poller/win_poller.h | 6 - aether/ptr/rc_ptr.h | 8 +- aether/registration/registration.cpp | 49 ++++---- aether/registration/registration.h | 17 +-- .../root_server_select_stream.cpp | 15 +-- .../registration/root_server_select_stream.h | 5 +- aether/registration/root_server_stream.cpp | 3 +- aether/registration/root_server_stream.h | 2 +- aether/registration_cloud.cpp | 16 +-- aether/registration_cloud.h | 17 +-- aether/serial_ports/serial_port_factory.cpp | 5 +- aether/serial_ports/serial_port_factory.h | 2 +- aether/serial_ports/unix_serial_port.cpp | 9 +- aether/serial_ports/unix_serial_port.h | 5 +- aether/serial_ports/win_serial_port.cpp | 24 ++-- aether/serial_ports/win_serial_port.h | 4 +- aether/server.cpp | 57 ++++----- aether/server.h | 20 ++-- .../server_connections/channel_connection.cpp | 13 +-- .../server_connections/channel_connection.h | 8 +- aether/server_connections/channel_manager.cpp | 14 +-- aether/server_connections/channel_manager.h | 5 +- .../channel_selection_stream.cpp | 13 +-- .../client_server_connection.cpp | 31 ++--- .../client_server_connection.h | 7 +- .../iserver_connection_factory.h | 5 +- aether/server_connections/server_channel.cpp | 19 +-- aether/server_connections/server_channel.h | 9 +- .../server_connections/server_connection.cpp | 14 +-- aether/server_connections/server_connection.h | 7 +- aether/stream_api/buffer_stream.h | 2 +- aether/tele/tele_init.cpp | 4 +- aether/tele/tele_init.h | 3 +- aether/tele/traps/tele_statistics.cpp | 9 +- aether/tele/traps/tele_statistics.h | 17 ++- aether/transport/data_packet_collector.cpp | 7 +- aether/transport/system_sockets/tcp/tcp.cpp | 27 +---- aether/transport/system_sockets/tcp/tcp.h | 5 +- aether/transport/system_sockets/udp/udp.cpp | 14 +-- aether/transport/system_sockets/udp/udp.h | 4 +- aether/work_cloud.cpp | 38 +++++- aether/work_cloud.h | 20 +++- 119 files changed, 840 insertions(+), 1474 deletions(-) delete mode 100644 aether/global_ids.h diff --git a/aether/CMakeLists.txt b/aether/CMakeLists.txt index 74bb93eb..af6409d9 100644 --- a/aether/CMakeLists.txt +++ b/aether/CMakeLists.txt @@ -83,9 +83,6 @@ list(APPEND dns_srcs list(APPEND obj_srcs "obj/obj.cpp" "obj/domain.cpp" - "obj/obj_id.cpp" - "obj/registry.cpp" - "obj/obj_ptr.cpp" ) list(APPEND ptr_srcs diff --git a/aether/access_points/access_point.h b/aether/access_points/access_point.h index 2bd3c8a3..16893eb4 100644 --- a/aether/access_points/access_point.h +++ b/aether/access_points/access_point.h @@ -20,8 +20,6 @@ #include #include "aether/obj/obj.h" -#include "aether/obj/obj_ptr.h" - namespace ae { class Channel; class Server; @@ -41,10 +39,8 @@ class AccessPoint : public Obj { explicit AccessPoint(Domain* domain); - AE_OBJECT_REFLECT() - - virtual std::vector> GenerateChannels( - ObjPtr const& server) = 0; + virtual std::vector> GenerateChannels( + Server& server) = 0; }; } // namespace ae diff --git a/aether/access_points/ethernet_access_point.cpp b/aether/access_points/ethernet_access_point.cpp index 71db425d..d7b81992 100644 --- a/aether/access_points/ethernet_access_point.cpp +++ b/aether/access_points/ethernet_access_point.cpp @@ -17,9 +17,6 @@ #include "aether/access_points/ethernet_access_point.h" -#include - -#include "aether/aether.h" #include "aether/server.h" #include "aether/poller/poller.h" #include "aether/dns/dns_resolve.h" @@ -27,29 +24,24 @@ #include "aether/access_points/filter_protocols.h" namespace ae { -EthernetAccessPoint::EthernetAccessPoint(ObjPtr aether, - ObjPtr poller, - ObjPtr dns_resolver, +EthernetAccessPoint::EthernetAccessPoint(Aether& aether, IPoller& poller, + DnsResolver& dns_resolver, Domain* domain) : AccessPoint{domain}, - aether_{std::move(aether)}, - poller_{std::move(poller)}, - dns_resolver_{std::move(dns_resolver)} {} - -std::vector> EthernetAccessPoint::GenerateChannels( - ObjPtr const& server) { - Aether::ptr aether = aether_; - DnsResolver::ptr resolver = dns_resolver_; - IPoller::ptr poller = poller_; - - std::vector> channels; - channels.reserve(server->endpoints.size()); - for (auto const& endpoint : server->endpoints) { + aether_{&aether}, + poller_{&poller}, + dns_resolver_{&dns_resolver} {} + +std::vector> EthernetAccessPoint::GenerateChannels( + Server& server) { + std::vector> channels; + channels.reserve(server.endpoints.size()); + for (auto const& endpoint : server.endpoints) { if (!FilterProtocol(endpoint)) { continue; } - channels.emplace_back(domain_->CreateObj( - aether, resolver, poller, endpoint)); + channels.emplace_back(std::make_unique( + *aether_, *dns_resolver_, *poller_, endpoint, domain_)); } return channels; } diff --git a/aether/access_points/ethernet_access_point.h b/aether/access_points/ethernet_access_point.h index fdde45e1..9a722d90 100644 --- a/aether/access_points/ethernet_access_point.h +++ b/aether/access_points/ethernet_access_point.h @@ -20,7 +20,6 @@ #include "aether/access_points/access_point.h" #include "aether/obj/obj.h" -#include "aether/obj/obj_ptr.h" namespace ae { class Aether; @@ -33,18 +32,16 @@ class EthernetAccessPoint : public AccessPoint { public: EthernetAccessPoint() = default; - EthernetAccessPoint(ObjPtr aether, ObjPtr poller, - ObjPtr dns_resolver, Domain* domain); + EthernetAccessPoint(Aether& aether, IPoller& poller, + DnsResolver& dns_resolver, Domain* domain); - AE_OBJECT_REFLECT(AE_MMBRS(aether_, poller_, dns_resolver_)) - - std::vector> GenerateChannels( - ObjPtr const& server) override; + std::vector> GenerateChannels( + Server& server) override; private: - Obj::ptr aether_; - Obj::ptr poller_; - Obj::ptr dns_resolver_; + Aether* aether_; + IPoller* poller_; + DnsResolver* dns_resolver_; }; } // namespace ae diff --git a/aether/access_points/wifi_access_point.cpp b/aether/access_points/wifi_access_point.cpp index b8e44f76..eca690c3 100644 --- a/aether/access_points/wifi_access_point.cpp +++ b/aether/access_points/wifi_access_point.cpp @@ -65,33 +65,26 @@ UpdateStatus WifiConnectAction::Update() { WifiConnectAction::State WifiConnectAction::state() const { return state_; } -WifiAccessPoint::WifiAccessPoint(ObjPtr aether, - ObjPtr adapter, - ObjPtr poller, - ObjPtr resolver, +WifiAccessPoint::WifiAccessPoint(Aether& aether, WifiAdapter& adapter, + IPoller& poller, DnsResolver& resolver, WifiCreds wifi_creds, Domain* domain) : AccessPoint{domain}, - aether_{std::move(aether)}, - adapter_{std::move(adapter)}, - poller_{std::move(poller)}, - resolver_{std::move(resolver)}, + aether_{&aether}, + adapter_{&adapter}, + poller_{&poller}, + resolver_{&resolver}, wifi_creds_{std::move(wifi_creds)} {} -std::vector> WifiAccessPoint::GenerateChannels( - ObjPtr const& server) { - Aether::ptr aether = aether_; - IPoller::ptr poller = poller_; - DnsResolver::ptr resolver = resolver_; - WifiAccessPoint::ptr wifi_access_point = MakePtrFromThis(this); - - std::vector> channels; - channels.reserve(server->endpoints.size()); - for (auto const& endpoint : server->endpoints) { +std::vector> WifiAccessPoint::GenerateChannels( + Server& server) { + std::vector> channels; + channels.reserve(server.endpoints.size()); + for (auto const& endpoint : server.endpoints) { if (!FilterProtocol(endpoint)) { continue; } - channels.emplace_back(domain_->CreateObj( - aether, poller, resolver, wifi_access_point, endpoint)); + channels.emplace_back(std::make_unique( + *aether_, *poller_, *resolver_, *this, endpoint, domain_)); } return channels; } @@ -99,9 +92,8 @@ std::vector> WifiAccessPoint::GenerateChannels( ActionPtr WifiAccessPoint::Connect() { // reuse connect action if it's in progress if (!connect_action_) { - connect_action_ = ActionPtr{ - *aether_.as(), adapter_.as()->driver(), - wifi_creds_}; + connect_action_ = + ActionPtr{*aether_, adapter_->driver(), wifi_creds_}; connect_sub_ = connect_action_->FinishedEvent().Subscribe( [this]() { connect_action_.reset(); }); } @@ -109,9 +101,11 @@ ActionPtr WifiAccessPoint::Connect() { } bool WifiAccessPoint::IsConnected() { - auto& driver = adapter_.as()->driver(); + auto& driver = adapter_->driver(); auto connected_to = driver.connected_to(); return connected_to.ssid == wifi_creds_.ssid; } +WifiCreds const& WifiAccessPoint::creds() const { return wifi_creds_; } + } // namespace ae diff --git a/aether/access_points/wifi_access_point.h b/aether/access_points/wifi_access_point.h index c319b416..a3abdbdf 100644 --- a/aether/access_points/wifi_access_point.h +++ b/aether/access_points/wifi_access_point.h @@ -19,7 +19,6 @@ #include -#include "aether/obj/obj_ptr.h" #include "aether/actions/action.h" #include "aether/actions/action_ptr.h" #include "aether/types/state_machine.h" @@ -61,15 +60,11 @@ class WifiAccessPoint final : public AccessPoint { WifiAccessPoint() = default; public: - WifiAccessPoint(ObjPtr aether, ObjPtr adapter, - ObjPtr poller, ObjPtr resolver, - WifiCreds wifi_creds, Domain* domain); + WifiAccessPoint(Aether& aether, WifiAdapter& adapter, IPoller& poller, + DnsResolver& resolver, WifiCreds wifi_creds, Domain* domain); - AE_OBJECT_REFLECT(AE_MMBRS(aether_, adapter_, poller_, resolver_, - wifi_creds_)) - - std::vector> GenerateChannels( - ObjPtr const& server) override; + std::vector> GenerateChannels( + Server& server) override; /** * \brief Connect or ensure it's connected to current access point. @@ -78,11 +73,13 @@ class WifiAccessPoint final : public AccessPoint { bool IsConnected(); + WifiCreds const& creds() const; + private: - Obj::ptr aether_; - Obj::ptr adapter_; - Obj::ptr poller_; - Obj::ptr resolver_; + Aether* aether_; + WifiAdapter* adapter_; + IPoller* poller_; + DnsResolver* resolver_; WifiCreds wifi_creds_; ActionPtr connect_action_; Subscription connect_sub_; diff --git a/aether/actions/action_trigger.cpp b/aether/actions/action_trigger.cpp index 6aeb3f99..fd94409b 100644 --- a/aether/actions/action_trigger.cpp +++ b/aether/actions/action_trigger.cpp @@ -38,7 +38,7 @@ bool ActionTrigger::WaitUntil(TimePoint timeout) { } void ActionTrigger::Trigger() { - std::lock_guard lock(sync_object_->mutex); + std::scoped_lock lock(sync_object_->mutex); sync_object_->triggered = true; sync_object_->condition.notify_all(); } diff --git a/aether/adapter_registry.cpp b/aether/adapter_registry.cpp index ff046950..395aa340 100644 --- a/aether/adapter_registry.cpp +++ b/aether/adapter_registry.cpp @@ -17,15 +17,13 @@ #include "aether/adapter_registry.h" namespace ae { -#if AE_DISTILLATION AdapterRegistry::AdapterRegistry(Domain* domain) : Obj{domain} {} -#endif -void AdapterRegistry::Add(Adapter::ptr adapter) { +void AdapterRegistry::Add(std::shared_ptr adapter) { adapters_.emplace_back(std::move(adapter)); } -std::vector const& AdapterRegistry::adapters() const { +std::vector> const& AdapterRegistry::adapters() const { return adapters_; } } // namespace ae diff --git a/aether/adapter_registry.h b/aether/adapter_registry.h index 489e868a..56e01ff8 100644 --- a/aether/adapter_registry.h +++ b/aether/adapter_registry.h @@ -25,24 +25,18 @@ namespace ae { class AdapterRegistry final : public Obj { AE_OBJECT(AdapterRegistry, Obj, 0) - AdapterRegistry() = default; - public: -#if AE_DISTILLATION explicit AdapterRegistry(Domain* domain); -#endif - - AE_OBJECT_REFLECT(AE_MMBRS(adapters_)) /** * \brief Add adapter to the registry */ - void Add(Adapter::ptr adapter); + void Add(std::shared_ptr adapter); - std::vector const& adapters() const; + std::vector> const& adapters() const; private: - std::vector adapters_; + std::vector> adapters_; }; } // namespace ae diff --git a/aether/adapters/adapter.cpp b/aether/adapters/adapter.cpp index 7eb8fb29..674b75d0 100644 --- a/aether/adapters/adapter.cpp +++ b/aether/adapters/adapter.cpp @@ -17,9 +17,7 @@ #include "aether/adapters/adapter.h" namespace ae { -#ifdef AE_DISTILLATION Adapter::Adapter(Domain* domain) : Obj{domain} {} -#endif // AE_DISTILLATION Adapter::NewAccessPoint::Subscriber Adapter::new_access_point() { return EventSubscriber{new_access_point_event_}; diff --git a/aether/adapters/adapter.h b/aether/adapters/adapter.h index 4259ba97..1e8843cf 100644 --- a/aether/adapters/adapter.h +++ b/aether/adapters/adapter.h @@ -32,19 +32,12 @@ namespace ae { class Adapter : public Obj { AE_OBJECT(Adapter, Obj, 0) - protected: - Adapter() = default; - public: - using NewAccessPoint = Event; + using NewAccessPoint = Event; -#ifdef AE_DISTILLATION explicit Adapter(Domain* domain); -#endif // AE_DISTILLATION - - AE_OBJECT_REFLECT() - virtual std::vector access_points() = 0; + virtual std::vector access_points() = 0; virtual NewAccessPoint::Subscriber new_access_point(); diff --git a/aether/adapters/ethernet.cpp b/aether/adapters/ethernet.cpp index 27ad7357..b162c16d 100644 --- a/aether/adapters/ethernet.cpp +++ b/aether/adapters/ethernet.cpp @@ -24,17 +24,16 @@ namespace ae { #ifdef AE_DISTILLATION -EthernetAdapter::EthernetAdapter(ObjPtr aether, IPoller::ptr poller, - DnsResolver::ptr dns_resolver, Domain* domain) +EthernetAdapter::EthernetAdapter(Aether& aether, IPoller& poller, + DnsResolver& dns_resolver, Domain* domain) : Adapter{domain}, - ethernet_access_point_{domain->CreateObj( - std::move(aether), std::move(poller), std::move(dns_resolver))} { + ethernet_access_point_{aether, poller, dns_resolver, domain_} { AE_TELED_INFO("EthernetAdapter created"); } #endif // AE_DISTILLATION -std::vector EthernetAdapter::access_points() { - return {ethernet_access_point_}; +std::vector EthernetAdapter::access_points() { + return {ðernet_access_point_}; } } // namespace ae diff --git a/aether/adapters/ethernet.h b/aether/adapters/ethernet.h index 6f277814..179acbea 100644 --- a/aether/adapters/ethernet.h +++ b/aether/adapters/ethernet.h @@ -36,20 +36,14 @@ class Aether; class EthernetAdapter final : public Adapter { AE_OBJECT(EthernetAdapter, Adapter, 0) - EthernetAdapter() = default; - public: -#ifdef AE_DISTILLATION - EthernetAdapter(ObjPtr aether, IPoller::ptr poller, - DnsResolver::ptr dns_resolver, Domain* domain); -#endif // AE_DISTILLATION - - AE_OBJECT_REFLECT(AE_MMBRS(ethernet_access_point_)) + EthernetAdapter(Aether& aether, IPoller& poller, DnsResolver& dns_resolver, + Domain* domain); - std::vector access_points() override; + std::vector access_points() override; private: - EthernetAccessPoint::ptr ethernet_access_point_; + EthernetAccessPoint ethernet_access_point_; }; } // namespace ae diff --git a/aether/adapters/parent_wifi.cpp b/aether/adapters/parent_wifi.cpp index a4b5abfa..11f0d351 100644 --- a/aether/adapters/parent_wifi.cpp +++ b/aether/adapters/parent_wifi.cpp @@ -18,24 +18,15 @@ #include -#include "aether/aether.h" -#include "aether/poller/poller.h" -#include "aether/dns/dns_resolve.h" - namespace ae { - -#if defined AE_DISTILLATION -ParentWifiAdapter::ParentWifiAdapter(ObjPtr aether, - ObjPtr poller, - ObjPtr dns_resolver, +ParentWifiAdapter::ParentWifiAdapter(Aether& aether, IPoller& poller, + DnsResolver& dns_resolver, std::string ssid, std::string pass, Domain* domain) : Adapter{domain}, - aether_{std::move(aether)}, - poller_{std::move(poller)}, - dns_resolver_{std::move(dns_resolver)}, + aether_{&aether}, + poller_{&poller}, + dns_resolver_{&dns_resolver}, ssid_{std::move(ssid)}, pass_{std::move(pass)} {} -#endif // AE_DISTILLATION - } /* namespace ae */ diff --git a/aether/adapters/parent_wifi.h b/aether/adapters/parent_wifi.h index 2b4d01e9..2db56e59 100644 --- a/aether/adapters/parent_wifi.h +++ b/aether/adapters/parent_wifi.h @@ -19,7 +19,6 @@ #include -#include "aether/aether.h" #include "aether/adapters/adapter.h" namespace ae { @@ -30,21 +29,13 @@ class IPoller; class ParentWifiAdapter : public Adapter { AE_OBJECT(ParentWifiAdapter, Adapter, 0) - protected: - ParentWifiAdapter() = default; - public: -#ifdef AE_DISTILLATION - ParentWifiAdapter(ObjPtr aether, ObjPtr poller, - ObjPtr dns_resolver, std::string ssid, - std::string pass, Domain* domain); -#endif // AE_DISTILLATION - - AE_OBJECT_REFLECT(AE_MMBRS(aether_, poller_, ssid_, pass_)) + ParentWifiAdapter(Aether& aether, IPoller& poller, DnsResolver& dns_resolver, + std::string ssid, std::string pass, Domain* domain); - Obj::ptr aether_; - Obj::ptr poller_; - Obj::ptr dns_resolver_; + Aether* aether_; + IPoller* poller_; + DnsResolver* dns_resolver_; std::string ssid_; std::string pass_; diff --git a/aether/adapters/proxy.h b/aether/adapters/proxy.h index 85f7c66f..865a367a 100644 --- a/aether/adapters/proxy.h +++ b/aether/adapters/proxy.h @@ -25,16 +25,12 @@ namespace ae { class Proxy : public Obj { AE_OBJECT(Proxy, Obj, 0) - Proxy() = default; - public: -#ifdef AE_DISTILLATION explicit Proxy(Domain* domain) : Obj{domain} {} -#endif // AE_DISTILLATION #if AE_SUPPORT_PROXY == 1 - AE_OBJECT_REFLECT(/* end_point_, mode_ */) + AE_REFLECT(/* end_point_, mode_ */) Endpoint end_point_; enum class Mode : std::uint8_t { @@ -43,7 +39,7 @@ class Proxy : public Obj { }; // [[maybe_unused]] Mode mode_; #else - AE_OBJECT_REFLECT() + AE_REFLECT() #endif // AE_SUPPORT_PROXY == 1 }; diff --git a/aether/adapters/wifi_adapter.cpp b/aether/adapters/wifi_adapter.cpp index b21d40fd..6fef33dd 100644 --- a/aether/adapters/wifi_adapter.cpp +++ b/aether/adapters/wifi_adapter.cpp @@ -26,35 +26,22 @@ #include "aether/access_points/wifi_access_point.h" namespace ae { -#if defined AE_DISTILLATION -WifiAdapter::WifiAdapter(ObjPtr aether, IPoller::ptr poller, - DnsResolver::ptr dns_resolver, std::string ssid, +WifiAdapter::WifiAdapter(Aether& aether, IPoller& poller, + DnsResolver& dns_resolver, std::string ssid, std::string pass, Domain* domain) - : ParentWifiAdapter{std::move(aether), std::move(poller), - std::move(dns_resolver), std::move(ssid), - std::move(pass), domain} { + : ParentWifiAdapter{aether, poller, dns_resolver, + std::move(ssid), std::move(pass), domain}, + wifi_driver_{WifiDriverFactory::CreateWifiDriver()}, + access_point_{ + aether, *this, poller, dns_resolver, WifiCreds{ssid_, pass_}, domain_, + } { AE_TELED_DEBUG("Wifi instance created!"); } -#endif // AE_DISTILLATION -std::vector WifiAdapter::access_points() { - if (!access_point_) { - Aether::ptr aether = aether_; - DnsResolver::ptr dns_resolver = dns_resolver_; - IPoller::ptr poller = poller_; - WifiAdapter::ptr self_ptr = MakePtrFromThis(this); - access_point_ = domain_->CreateObj( - aether, self_ptr, poller, dns_resolver, WifiCreds{ssid_, pass_}); - } - - return {access_point_}; +std::vector WifiAdapter::access_points() { + return {&access_point_}; } -WifiDriver& WifiAdapter::driver() { - if (!wifi_driver_) { - wifi_driver_ = WifiDriverFactory::CreateWifiDriver(); - } - return *wifi_driver_; -} +WifiDriver& WifiAdapter::driver() { return *wifi_driver_; } } // namespace ae diff --git a/aether/adapters/wifi_adapter.h b/aether/adapters/wifi_adapter.h index b3393853..7e4fb580 100644 --- a/aether/adapters/wifi_adapter.h +++ b/aether/adapters/wifi_adapter.h @@ -22,29 +22,23 @@ #include "aether/wifi/wifi_driver.h" #include "aether/adapters/parent_wifi.h" +#include "aether/access_points/wifi_access_point.h" namespace ae { class WifiAdapter final : public ParentWifiAdapter { AE_OBJECT(WifiAdapter, ParentWifiAdapter, 0) - WifiAdapter() = default; - public: -#ifdef AE_DISTILLATION - WifiAdapter(ObjPtr aether, IPoller::ptr poller, - DnsResolver::ptr dns_resolver, std::string ssid, std::string pass, - Domain* domain); -#endif // AE_DISTILLATION - - AE_OBJECT_REFLECT(AE_MMBRS(access_point_)) + WifiAdapter(Aether& aether, IPoller& poller, DnsResolver& dns_resolver, + std::string ssid, std::string pass, Domain* domain); - std::vector access_points() override; + std::vector access_points() override; WifiDriver& driver(); private: std::unique_ptr wifi_driver_; - AccessPoint::ptr access_point_; + WifiAccessPoint access_point_; }; } // namespace ae #endif // AETHER_ADAPTERS_WIFI_ADAPTER_H_ diff --git a/aether/ae_actions/ping.cpp b/aether/ae_actions/ping.cpp index 7c4ef6d2..58fc7434 100644 --- a/aether/ae_actions/ping.cpp +++ b/aether/ae_actions/ping.cpp @@ -25,11 +25,11 @@ #include "aether/ae_actions/ae_actions_tele.h" namespace ae { -Ping::Ping(ActionContext action_context, Ptr const& channel, +Ping::Ping(ActionContext action_context, Channel& channel, ClientServerConnection& client_server_connection, Duration ping_interval) : Action{action_context}, - channel_{channel}, + channel_{&channel}, client_server_connection_{&client_server_connection}, ping_interval_{ping_interval}, state_{State::kSendPing} { @@ -77,9 +77,7 @@ void Ping::SendPing() { .count())); // save the ping request auto current_time = Now(); - auto channel_ptr = channel_.Lock(); - assert(channel_ptr); - auto expected_ping_time = channel_ptr->ResponseTimeout(); + auto expected_ping_time = channel_->ResponseTimeout(); AE_TELED_DEBUG("Ping request expected time {:%S}s", expected_ping_time); ping_requests_.push(PingRequest{ @@ -144,10 +142,8 @@ void Ping::PingResponse(RequestId request_id) { std::chrono::duration_cast(current_time - *request_time); AE_TELED_DEBUG("Ping received by {:%S} s", ping_duration); - auto channel_ptr = channel_.Lock(); - assert(channel_ptr); - channel_ptr->channel_statistics().AddResponseTime(ping_duration); + channel_->channel_statistics().AddResponseTime(ping_duration); state_ = State::kWaitInterval; } diff --git a/aether/ae_actions/ping.h b/aether/ae_actions/ping.h index 6c4c1e61..4d25fc02 100644 --- a/aether/ae_actions/ping.h +++ b/aether/ae_actions/ping.h @@ -27,8 +27,6 @@ IGNORE_IMPLICIT_CONVERSION() DISABLE_WARNING_POP() #include "aether/common.h" -#include "aether/ptr/ptr.h" -#include "aether/ptr/ptr_view.h" #include "aether/actions/action.h" #include "aether/types/state_machine.h" #include "aether/actions/action_context.h" @@ -58,7 +56,7 @@ class Ping : public Action { }; public: - Ping(ActionContext action_context, Ptr const& channel, + Ping(ActionContext action_context, Channel& channel, ClientServerConnection& client_server_connection, Duration ping_interval); @@ -73,7 +71,7 @@ class Ping : public Action { TimePoint WaitResponse(); void PingResponse(RequestId request_id); - PtrView channel_; + Channel* channel_; ClientServerConnection* client_server_connection_; Duration ping_interval_; diff --git a/aether/ae_actions/select_client.cpp b/aether/ae_actions/select_client.cpp index 8a5d26c6..3a7d3d8b 100644 --- a/aether/ae_actions/select_client.cpp +++ b/aether/ae_actions/select_client.cpp @@ -24,8 +24,10 @@ namespace ae { SelectClientAction::SelectClientAction(ActionContext action_context, - Client::ptr const& client) - : Action{action_context}, client_{client}, state_{State::kClientReady} { + std::shared_ptr client) + : Action{action_context}, + client_{std::move(client)}, + state_{State::kClientReady} { AE_TELED_DEBUG("Select loaded client"); Action::Trigger(); } @@ -75,12 +77,7 @@ UpdateStatus SelectClientAction::Update() { return {}; } -Client::ptr SelectClientAction::client() const { - auto client_ptr = client_.Lock(); - assert(client_ptr); - return client_ptr; -} - +std::shared_ptr SelectClientAction::client() const { return client_; } SelectClientAction::State SelectClientAction::state() const { return state_; } } // namespace ae diff --git a/aether/ae_actions/select_client.h b/aether/ae_actions/select_client.h index 3712fd21..3a15e0f6 100644 --- a/aether/ae_actions/select_client.h +++ b/aether/ae_actions/select_client.h @@ -42,7 +42,8 @@ class SelectClientAction final : public Action { /** * \brief Create with client already ready. */ - SelectClientAction(ActionContext action_context, Client::ptr const& client); + SelectClientAction(ActionContext action_context, + std::shared_ptr client); /** * \brief Wait for client registration or error. */ @@ -54,11 +55,11 @@ class SelectClientAction final : public Action { UpdateStatus Update(); - Client::ptr client() const; + std::shared_ptr client() const; State state() const; private: - PtrView client_; + std::shared_ptr client_; StateMachine state_; #if AE_SUPPORT_REGISTRATION diff --git a/aether/ae_actions/telemetry.cpp b/aether/ae_actions/telemetry.cpp index 99407969..b41ea5ff 100644 --- a/aether/ae_actions/telemetry.cpp +++ b/aether/ae_actions/telemetry.cpp @@ -29,10 +29,10 @@ # include "aether/ae_actions/ae_actions_tele.h" namespace ae { -Telemetry::Telemetry(ActionContext action_context, ObjPtr const& aether, +Telemetry::Telemetry(ActionContext action_context, Aether& aether, CloudConnection& cloud_connection) : Action{action_context}, - aether_{aether}, + aether_{&aether}, cloud_connection_{&cloud_connection}, state_{State::kWaitRequest} { AE_TELE_INFO(TelemetryCreated); @@ -104,13 +104,7 @@ void Telemetry::OnRequestTelemetry(std::size_t server_priority) { std::optional Telemetry::CollectTelemetry( StreamInfo const& stream_info) { - auto aether_ptr = aether_.Lock(); - if (!aether_ptr) { - assert(false); - return std::nullopt; - } - auto& statistics_storage = - aether_ptr->tele_statistics->trap()->statistics_store; + auto& statistics_storage = aether_->tele_statistics->trap()->statistics_store; auto& env_storage = statistics_storage.env_store(); Telemetric res{}; res.cpp.utm_id = env_storage.utm_id; diff --git a/aether/ae_actions/telemetry.h b/aether/ae_actions/telemetry.h index 9fc456fe..dbfb87d6 100644 --- a/aether/ae_actions/telemetry.h +++ b/aether/ae_actions/telemetry.h @@ -23,8 +23,6 @@ # include -# include "aether/obj/obj_ptr.h" -# include "aether/ptr/ptr_view.h" # include "aether/actions/action.h" # include "aether/stream_api/istream.h" # include "aether/types/state_machine.h" @@ -43,7 +41,7 @@ class Telemetry : public Action { }; public: - Telemetry(ActionContext action_context, ObjPtr const& aether, + Telemetry(ActionContext action_context, Aether& aether, CloudConnection& cloud_connection); AE_CLASS_NO_COPY_MOVE(Telemetry) @@ -58,7 +56,7 @@ class Telemetry : public Action { void OnRequestTelemetry(std::size_t server_priority); std::optional CollectTelemetry(StreamInfo const& stream_info); - PtrView aether_; + Aether* aether_; CloudConnection* cloud_connection_; CloudConnection::ReplicaSubscription telemetry_request_sub_; diff --git a/aether/aether.cpp b/aether/aether.cpp index b048f6da..6a03dfd3 100644 --- a/aether/aether.cpp +++ b/aether/aether.cpp @@ -18,112 +18,93 @@ #include -#include "aether/global_ids.h" -#include "aether/obj/obj_ptr.h" - #include "aether/work_cloud.h" #include "aether/aether_tele.h" namespace ae { -#ifdef AE_DISTILLATION - Aether::Aether(Domain* domain) : Obj{domain} { - auto self_ptr = MakePtrFromThis(this); - - client_prefab = domain->CreateObj(GlobalId::kClientFactory, self_ptr); - client_prefab.SetFlags(ae::ObjFlags::kUnloadedByDefault); - - tele_statistics = - domain->CreateObj(GlobalId::kTeleStatistics); - + tele_statistics = std::make_shared(domain_); AE_TELE_DEBUG(AetherCreated); } -#endif // AE_DISTILLATION Aether::~Aether() { AE_TELE_DEBUG(AetherDestroyed); } -ActionPtr Aether::SelectClient( - [[maybe_unused]] Uid parent_uid, std::uint32_t client_id) { - AE_TELED_DEBUG("Select parent {}'s client with id {}", parent_uid, client_id); +ActionPtr Aether::SelectClient(Uid parent_uid, + std::string client_id) { + AE_TELED_DEBUG("Select client parent_uid={}, id={}", parent_uid, client_id); auto client = FindClient(client_id); - if (client) { - return ActionPtr{*action_processor, client}; + if (!client) { + client = AddClient(parent_uid, std::move(client_id)); } + + // if existing client + if (!client->uid().empty()) { + return ActionPtr{*action_processor, std::move(client)}; + } + + // register new client #if AE_SUPPORT_REGISTRATION - auto registration = RegisterClient(parent_uid, client_id); - return ActionPtr{*action_processor, *registration}; + auto reg = FindRegistration(client->client_id()); + if (!reg) { + reg = RegisterClient(std::move(client)); + } + return ActionPtr{*action_processor, *reg}; #else return ActionPtr{*action_processor}; #endif } -void Aether::AddServer(Server::ptr s) { +void Aether::AddServer(std::shared_ptr s) { servers_.insert({s->server_id, std::move(s)}); } -Server::ptr Aether::GetServer(ServerId server_id) { +std::shared_ptr Aether::GetServer(ServerId server_id) { auto it = servers_.find(server_id); if (it == std::end(servers_)) { return {}; } - if (!it->second) { - domain_->LoadRoot(it->second); - } return it->second; } -void Aether::Update(TimePoint current_time) { - update_time_ = action_processor->Update(current_time); -} - -Client::ptr Aether::FindClient(std::uint32_t client_id) { - auto client_it = clients_.find(client_id); +std::shared_ptr Aether::FindClient(std::string const& client_id) { + auto client_it = std::find_if( + std::begin(clients_), std::end(clients_), + [&](auto const& client) { return client->client_id() == client_id; }); if (client_it == std::end(clients_)) { return {}; } - if (!client_it->second) { - domain_->LoadRoot(client_it->second); - } - return client_it->second; + return *client_it; +} + +std::shared_ptr Aether::AddClient(Uid parent_uid, + std::string client_id) { + auto client = std::make_shared(*this, parent_uid, + std::move(client_id), domain_); + clients_.push_back(client); + return client; } #if AE_SUPPORT_REGISTRATION -ActionPtr Aether::RegisterClient(Uid parent_uid, - std::uint32_t client_id) { - // try to find existent registrations +ActionPtr Aether::FindRegistration(std::string const& client_id) { auto reg_it = registration_actions_.find(client_id); if (reg_it != std::end(registration_actions_)) { - return ActionPtr{reg_it->second}; + return reg_it->second; } + return {}; +} - if (!registration_cloud) { - domain_->LoadRoot(registration_cloud); - } - auto self_ptr = MakePtrFromThis(this); - - auto new_client = domain_->LoadCopy(client_prefab); - new_client.SetFlags(ObjFlags::kUnloadedByDefault); - - // registration new client is long termed process - // after registration done, add it to clients list - // user also can get new client after +ActionPtr Aether::RegisterClient(std::shared_ptr client) { + auto client_id = client->client_id(); auto [new_reg_it, _] = registration_actions_.emplace( client_id, - ActionPtr(*action_processor, self_ptr, registration_cloud, - parent_uid, std::move(new_client))); + ActionPtr(*action_processor, *this, *registration_cloud, + std::move(client))); - // on registration success save client to client_ and remove registration - // action at the end + // on registration success remove registration action at the end registration_subscriptions_.Push( - new_reg_it->second->StatusEvent().Subscribe( - OnResult{[this, client_id](auto const& action) { - auto client = action.client(); - assert(client); - clients_.emplace(client_id, std::move(client)); - }}), new_reg_it->second->FinishedEvent().Subscribe( [this, client_id]() { registration_actions_.erase(client_id); })); diff --git a/aether/aether.h b/aether/aether.h index 774d50a0..0d2a99ae 100644 --- a/aether/aether.h +++ b/aether/aether.h @@ -44,80 +44,45 @@ namespace ae { class Aether : public Obj { AE_OBJECT(Aether, Obj, 0) - Aether() = default; - public: - // Internal. -#ifdef AE_DISTILLATION explicit Aether(Domain* domain); -#endif // AE_DISTILLATION - ~Aether() override; -#if AE_SUPPORT_REGISTRATION - AE_OBJECT_REFLECT(AE_MMBRS(client_prefab, registration_cloud, crypto, - clients_, servers_, tele_statistics, poller, - dns_resolver, adapter_registry, - registration_actions_, - registration_subscriptions_)) -#else - AE_OBJECT_REFLECT(AE_MMBRS(client_prefab, registration_cloud, crypto, - clients_, servers_, tele_statistics, poller, - dns_resolver, adapter_registry)) -#endif - - template - void Load(CurrentVersion, Dnv& dnv) { - dnv(base_); - dnv(client_prefab, registration_cloud, crypto, clients_, servers_, - tele_statistics, poller, dns_resolver, adapter_registry); - } - - template - void Save(CurrentVersion, Dnv& dnv) const { - dnv(base_); - dnv(client_prefab, registration_cloud, crypto, clients_, servers_, - tele_statistics, poller, dns_resolver, adapter_registry); - } - - void Update(TimePoint current_time) override; - // User-facing API. operator ActionContext() const { return ActionContext{*action_processor}; } ActionPtr SelectClient(Uid parent_uid, - std::uint32_t client_id); + std::string client_id); - void AddServer(Server::ptr s); - Server::ptr GetServer(ServerId server_id); + void AddServer(std::shared_ptr s); + std::shared_ptr GetServer(ServerId server_id); std::unique_ptr action_processor = make_unique(); - RegistrationCloud::ptr registration_cloud; + std::shared_ptr registration_cloud; - Crypto::ptr crypto; - IPoller::ptr poller; - DnsResolver::ptr dns_resolver; + std::shared_ptr crypto; + std::shared_ptr poller; + std::shared_ptr dns_resolver; - AdapterRegistry::ptr adapter_registry; + std::shared_ptr adapter_registry; - tele::TeleStatistics::ptr tele_statistics; + std::shared_ptr tele_statistics; private: - Client::ptr FindClient(std::uint32_t client_id); + std::shared_ptr FindClient(std::string const& client_id); + std::shared_ptr AddClient(Uid parent_uid, std::string client_id); #if AE_SUPPORT_REGISTRATION - ActionPtr RegisterClient(Uid parent_uid, - std::uint32_t client_id); + ActionPtr FindRegistration(std::string const& client_id); + ActionPtr RegisterClient(std::shared_ptr client); #endif - Client::ptr client_prefab; - - std::map clients_; - std::map servers_; + std::vector> clients_; + std::map> servers_; #if AE_SUPPORT_REGISTRATION - std::map> registration_actions_; + std::map> registration_actions_; MultiSubscription registration_subscriptions_; #endif }; diff --git a/aether/aether_app.cpp b/aether/aether_app.cpp index 7c6a1493..1262084b 100644 --- a/aether/aether_app.cpp +++ b/aether/aether_app.cpp @@ -43,7 +43,6 @@ AetherAppContext::TelemetryInit::TelemetryInit() { tele::TeleInit::Init(); AE_TELE_ENV(); AE_TELE_INFO(AetherStarted); - Registry::GetRegistry().Log(); } void AetherAppContext::TelemetryInit::operator()( @@ -52,122 +51,110 @@ void AetherAppContext::TelemetryInit::operator()( } void AetherAppContext::InitComponentContext() { -#if defined AE_DISTILLATION Factory([](AetherAppContext const& context) { - auto adapter_registry = context.domain().CreateObj(); - adapter_registry->Add(context.domain().CreateObj( - GlobalId::kEthernetAdapter, context.aether(), context.poller(), - context.dns_resolver())); + auto adapter_registry = std::make_shared(context.domain()); + adapter_registry->Add(std::make_shared( + *context.aether(), *context.poller(), *context.dns_resolver(), + context.domain())); return adapter_registry; }); -# if AE_SUPPORT_REGISTRATION +#if AE_SUPPORT_REGISTRATION Factory([](AetherAppContext const& context) { - auto reg_c = context.domain().CreateObj( - GlobalId::kRegistrationCloud, context.aether()); -# if defined _AE_REG_CLOUD_IP + auto reg_c = std::make_shared(*context.aether(), + context.domain()); +# if defined _AE_REG_CLOUD_IP auto reg_cloud_addr = AddressParser::StringToAddress(_AE_REG_CLOUD_IP); reg_c->AddServerSettings(Endpoint{{reg_cloud_addr, 9010}, Protocol::kTcp}); -# endif -# if !AE_SUPPORT_CLOUD_DNS +# endif +# if !AE_SUPPORT_CLOUD_DNS auto reg_cloud_addr = IpAddressParser::StringToAddress("34.60.244.148"); reg_c->AddServerSettings(Endpoint{{reg_cloud_addr, 9010}, Protocol::kTcp}); -# else +# else auto reg_cloud_addr_name = AddressParser::StringToAddress("registration.aethernet.io"); // in case of ip address change reg_c->AddServerSettings( Endpoint{{reg_cloud_addr_name, 9010}, Protocol::kTcp}); -# endif +# endif return reg_c; }); -# endif // AE_SUPPORT_REGISTRATION +#endif // AE_SUPPORT_REGISTRATION Factory([](AetherAppContext const& context) { - auto crypto = context.domain().CreateObj(GlobalId::kCrypto); -# if AE_SIGNATURE == AE_ED25519 + auto crypto = std::make_shared(context.domain()); +#if AE_SIGNATURE == AE_ED25519 crypto->signs_pk_[ae::SignatureMethod::kEd25519] = ae::SodiumSignPublicKey{ MakeArray("4F202A94AB729FE9B381613AE77A8A7D89EDAB9299C33" "20D1A0B994BA710CCEB")}; -# elif AE_SIGNATURE == AE_HYDRO_SIGNATURE +#elif AE_SIGNATURE == AE_HYDRO_SIGNATURE crypto->signs_pk_[ae::SignatureMethod::kHydroSignature] = ae::HydrogenSignPublicKey{ MakeArray("883B4D7E0FB04A38CA12B3A451B00942048858263EE6E" "6D61150F2EF15F40343")}; -# endif // AE_SIGNATURE == AE_ED25519 +#endif // AE_SIGNATURE == AE_ED25519 return crypto; }); Factory([](AetherAppContext const& context) { auto poller = -# if defined EPOLL_POLLER_ENABLED - context.domain().CreateObj(GlobalId::kPoller); -# elif defined KQUEUE_POLLER_ENABLED - context.domain().CreateObj(GlobalId::kPoller); -# elif defined FREERTOS_POLLER_ENABLED - context.domain().CreateObj(GlobalId::kPoller); -# elif defined WIN_POLLER_ENABLED - context.domain().CreateObj(GlobalId::kPoller); -# endif +#if defined EPOLL_POLLER_ENABLED + std::make_shared(context.domain()); +#elif defined KQUEUE_POLLER_ENABLED + std::make_shared(context.domain()); +#elif defined FREERTOS_POLLER_ENABLED + std::make_shared(context.domain()); +#elif defined WIN_POLLER_ENABLED + std::make_shared(context.domain()); +#endif return poller; }); Factory([](AetherAppContext const& context) { -# if AE_SUPPORT_CLOUD_DNS +#if AE_SUPPORT_CLOUD_DNS auto dns_resolver = -# if defined DNS_RESOLVE_ARES_ENABLED - context.domain().CreateObj(GlobalId::kDnsResolver, - context.aether()); -# elif defined ESP32_DNS_RESOLVER_ENABLED - context.domain().CreateObj(GlobalId::kDnsResolver, - context.aether()); -# endif - return dns_resolver; -# else - return context.domain().CreateObj(GlobalId::kDnsResolver); +# if defined DNS_RESOLVE_ARES_ENABLED + std::make_shared(*context.aether(), context.domain()); +# elif defined ESP32_DNS_RESOLVER_ENABLED + std::make_shared(*context.aether(), context.domain()); # endif + return dns_resolver; +#else + return std::make_shared(context.domain()); +#endif }); -#endif // defined AE_DISTILLATION } RcPtr AetherApp::Construct(AetherAppContext&& context) { auto app = MakeRcPtr(); - app->aether_ = context.aether(); + auto* aether = context.aether(); context.init_tele_(context); -#if defined AE_DISTILLATION - app->aether_->adapter_registry = context.adapter_registry(); + aether->adapter_registry = context.adapter_registry(); -# if AE_SUPPORT_REGISTRATION - app->aether_->registration_cloud = context.registration_cloud(); - app->aether_->poller.SetFlags(ObjFlags::kUnloadedByDefault); -# endif // AE_SUPPORT_REGISTRATION - app->aether_->crypto = context.crypto(); +#if AE_SUPPORT_REGISTRATION + aether->registration_cloud = context.registration_cloud(); +#endif // AE_SUPPORT_REGISTRATION + aether->crypto = context.crypto(); - app->aether_->poller = context.poller(); - -# if AE_SUPPORT_CLOUD_DNS - app->aether_->dns_resolver = context.dns_resolver(); - app->aether_->dns_resolver.SetFlags(ObjFlags::kUnloadedByDefault); -# endif + aether->poller = context.poller(); - context.domain().SaveRoot(app->aether_); -#endif // defined AE_DISTILLATION +#if AE_SUPPORT_CLOUD_DNS + aether->dns_resolver = context.dns_resolver(); +#endif app->domain_facility_ = std::move(std::move(context).domain_storage_); app->domain_ = std::move(std::move(context).domain_); + app->aether_ = std::move(std::move(context).aether_); return app; } AetherApp::~AetherApp() { - // save aether_ state on exit - if (domain_ && aether_) { - domain_->SaveRoot(aether_); - } + // TODO: save internal states // reset telemetry before delete all objects TELE_SINK::Instance().SetTrap(nullptr); - aether_.Reset(); + aether_.reset(); } } // namespace ae diff --git a/aether/aether_app.h b/aether/aether_app.h index 40ebe35e..215340c1 100644 --- a/aether/aether_app.h +++ b/aether/aether_app.h @@ -23,10 +23,8 @@ #include "aether/config.h" #include "aether/common.h" -#include "aether/ptr/ptr.h" #include "aether/ptr/rc_ptr.h" #include "aether/obj/domain.h" -#include "aether/global_ids.h" #include "aether/type_traits.h" #include "aether/types/small_function.h" @@ -49,6 +47,7 @@ namespace ae { class AetherAppContext : public ComponentContext { friend class AetherApp; + class TelemetryInit { public: TelemetryInit(); @@ -66,34 +65,27 @@ class AetherAppContext : public ComponentContext { TeleInit const& tele_init = TelemetryInit{}) : init_tele_{tele_init}, domain_storage_{facility_factory()}, - domain_{make_unique(Now(), *domain_storage_)} { + domain_{make_unique(*domain_storage_)} { InitComponentContext(); -#if defined AE_DISTILLATION + // TODO: add cleanup condition // clean old state - domain_storage_->CleanUp(); - - aether_ = domain_->CreateObj(GlobalId::kAether); - assert(aether_); -#else - aether_.SetId(GlobalId::kAether); - domain_->LoadRoot(aether_); - assert(aether_); -#endif // defined AE_DISTILLATION + // domain_storage_->CleanUp(); + + aether_ = std::make_unique(domain_.get()); } - Domain& domain() const { return *domain_; } - Aether::ptr aether() const { return aether_; } + Domain* domain() const { return domain_.get(); } + Aether* aether() const { return aether_.get(); } -#if defined AE_DISTILLATION - AdapterRegistry::ptr adapter_registry() const { + std::shared_ptr adapter_registry() const { return Resolve(); } -# if AE_SUPPORT_REGISTRATION - Cloud::ptr registration_cloud() const { return Resolve(); } -# endif // AE_SUPPORT_REGISTRATION - Crypto::ptr crypto() const { return Resolve(); } - IPoller::ptr poller() const { return Resolve(); } - DnsResolver::ptr dns_resolver() const { return Resolve(); } + std::shared_ptr registration_cloud() const { return Resolve(); } + std::shared_ptr crypto() const { return Resolve(); } + std::shared_ptr poller() const { return Resolve(); } + std::shared_ptr dns_resolver() const { + return Resolve(); + } template AetherAppContext&& AdaptersFactory(TFunc&& func) && { @@ -101,13 +93,13 @@ class AetherAppContext : public ComponentContext { return std::move(*this); } -# if AE_SUPPORT_REGISTRATION +#if AE_SUPPORT_REGISTRATION template AetherAppContext&& RegistrationCloudFactory(TFunc&& func) && { Factory(std::forward(func)); return std::move(*this); } -# endif // AE_SUPPORT_REGISTRATION +#endif // AE_SUPPORT_REGISTRATION template AetherAppContext&& CryptoFactory(TFunc&& func) && { @@ -120,14 +112,14 @@ class AetherAppContext : public ComponentContext { Factory(std::forward(func)); return std::move(*this); } -# if AE_SUPPORT_CLOUD_DNS + +#if AE_SUPPORT_CLOUD_DNS template AetherAppContext&& DnsResolverFactory(TFunc&& func) && { Factory(std::forward(func)); return std::move(*this); } -# endif -#endif // defined AE_DISTILLATION +#endif private: void InitComponentContext(); @@ -135,7 +127,7 @@ class AetherAppContext : public ComponentContext { SmallFunction init_tele_; std::unique_ptr domain_storage_; std::unique_ptr domain_; - Aether::ptr aether_; + std::unique_ptr aether_; }; /** @@ -166,7 +158,11 @@ class AetherApp { * \brief Run one iteration of application update loop. */ TimePoint Update(TimePoint current_time) { - return domain_->Update(current_time); + auto next_time = aether_->action_processor->Update(current_time); + if (next_time == current_time) { + return current_time + std::chrono::hours{24 * 365}; + } + return next_time; } /** @@ -203,8 +199,8 @@ class AetherApp { } } - Domain& domain() const { return *domain_; } - Aether::ptr const& aether() const { return aether_; } + Domain* domain() const { return domain_.get(); } + Aether* aether() const { return aether_.get(); } // Action context protocol operator ActionContext() const { return ActionContext{*aether_}; } @@ -212,7 +208,7 @@ class AetherApp { private: std::unique_ptr domain_facility_; std::unique_ptr domain_; - Aether::ptr aether_; + std::unique_ptr aether_; std::optional exit_code_; }; diff --git a/aether/aether_c/aether_capi.cpp b/aether/aether_c/aether_capi.cpp index a54d4624..d6fdf5ab 100644 --- a/aether/aether_c/aether_capi.cpp +++ b/aether/aether_c/aether_capi.cpp @@ -24,8 +24,6 @@ #include "aether/aether_c/c_errors.h" #include "aether/memory.h" -#include "aether/ptr/ptr.h" -#include "aether/obj/obj_ptr.h" #include "aether/actions/action.h" #include "aether/actions/pipeline.h" #include "aether/actions/actions_queue.h" @@ -52,7 +50,7 @@ static ae::RcPtr aether_app; struct AetherClient { ClientConfig config; - ae::Client::ptr client; + std::shared_ptr client; std::map> streams; ae::OwnActionPtr actions_queue_; }; @@ -69,7 +67,7 @@ ae::ActionPtr SelectClientImpl( AetherClient* client, ClientConfig const* config) { auto parent_uid = ae::Uid{config->parent_uid.value}; auto select_action = - aether_app->aether()->SelectClient(parent_uid, config->id); + aether_app->aether()->SelectClient(parent_uid, config->client_id); struct SelectContext { AetherClient* client; @@ -236,29 +234,30 @@ int AetherInit(AetherConfig const* config) { }) #if AE_DISTILLATION .AdaptersFactory([&](ae::AetherAppContext const& context) { - auto adapters = context.domain().CreateObj(); + auto adapter_registry = + std::make_shared(context.domain()); if (config->adapters == nullptr) { - adapters->Add(context.domain().CreateObj( - context.aether(), context.poller(), context.dns_resolver())); + adapter_registry->Add(std::make_shared( + *context.aether(), *context.poller(), *context.dns_resolver(), + context.domain())); } else { assert(config->adapters->count != 0); for (size_t i = 0; i < config->adapters->count; ++i) { auto* conf = config->adapters->adapters[i]; switch (conf->type) { case AeEthernetAdapter: { - adapters->Add( - context.domain().CreateObj( - context.aether(), context.poller(), - context.dns_resolver())); + adapter_registry->Add(std::make_shared( + *context.aether(), *context.poller(), + *context.dns_resolver(), context.domain())); break; } case AeWifiAdapter: { auto* wifi_conf = reinterpret_cast(conf); - adapters->Add(context.domain().CreateObj( - context.aether(), context.poller(), - context.dns_resolver(), wifi_conf->ssid, - wifi_conf->password)); + adapter_registry->Add(std::make_shared( + *context.aether(), *context.poller(), + *context.dns_resolver(), wifi_conf->ssid, + wifi_conf->password, context.domain())); break; } default: @@ -267,7 +266,7 @@ int AetherInit(AetherConfig const* config) { } // switch } // for } // if - return adapters; + return adapter_registry; }) #endif // AE_DISTILLATION ); diff --git a/aether/aether_c/c_conf.h b/aether/aether_c/c_conf.h index c60e1a00..8a096ba5 100644 --- a/aether/aether_c/c_conf.h +++ b/aether/aether_c/c_conf.h @@ -106,8 +106,8 @@ typedef void (*MessageReceivedCb)(AetherClient* client, CUid sender, * \brief Client configuration */ struct ClientConfig { - uint32_t id; //< the local id of client - CUid parent_uid; //< the parent uid, required for client registration + char const* client_id; //< the local id of client + CUid parent_uid; //< the parent uid, required for client registration ClientSelectedCb client_selected_cb; //< callback for client selection, // called when client is selected MessageReceivedCb message_received_cb; //< callback for message reception, diff --git a/aether/all.h b/aether/all.h index 5432acb4..c1c9c415 100644 --- a/aether/all.h +++ b/aether/all.h @@ -42,10 +42,7 @@ #include "aether/ptr/rc_ptr.h" #include "aether/ptr/ptr_view.h" #include "aether/obj/obj.h" -#include "aether/obj/obj_id.h" #include "aether/obj/domain.h" -#include "aether/obj/obj_ptr.h" -#include "aether/obj/registry.h" #include "aether/tele/tele_init.h" diff --git a/aether/api_protocol/api_pack_parser.cpp b/aether/api_protocol/api_pack_parser.cpp index bc3f9222..995f8f58 100644 --- a/aether/api_protocol/api_pack_parser.cpp +++ b/aether/api_protocol/api_pack_parser.cpp @@ -33,9 +33,7 @@ ApiParser::~ApiParser() { protocol_context_.PopParser(); } ProtocolContext& ApiParser::Context() { return protocol_context_; } -void ApiParser::Cancel() { - buffer_reader_.offset_ = buffer_reader_.data_.size(); -} +void ApiParser::Cancel() { buffer_reader_.offset = buffer_reader_.data.size(); } ApiPacker::ApiPacker(ProtocolContext& protocol_context_, std::vector& data) diff --git a/aether/api_protocol/api_pack_parser.h b/aether/api_protocol/api_pack_parser.h index 473d070f..f0ce3191 100644 --- a/aether/api_protocol/api_pack_parser.h +++ b/aether/api_protocol/api_pack_parser.h @@ -42,7 +42,7 @@ class ApiParser { template void Parse(TApiClass& api_class) { - while (buffer_reader_.offset_ < buffer_reader_.data_.size()) { + while (buffer_reader_.offset < buffer_reader_.data.size()) { MessageId message_id{std::numeric_limits::max()}; istream_ >> message_id; api_class.LoadFactory(message_id, *this); diff --git a/aether/channels/channel.cpp b/aether/channels/channel.cpp index dfd4aaa9..67972349 100644 --- a/aether/channels/channel.cpp +++ b/aether/channels/channel.cpp @@ -20,30 +20,40 @@ #include "aether/config.h" +#include "aether/tele/tele.h" + namespace ae { -Channel::Channel(Domain* domain) - : Obj{domain}, channel_statistics_{domain->CreateObj()} { - channel_statistics_->AddResponseTime( - std::chrono::milliseconds{AE_DEFAULT_RESPONSE_TIMEOUT_MS}); - channel_statistics_->AddConnectionTime( - std::chrono::milliseconds{AE_DEFAULT_CONNECTION_TIMEOUT_MS}); +Channel::Channel(DataKey channel_key, Domain* domain) + : Obj{domain}, channel_key_{channel_key} { + AE_TELED_DEBUG("Create channel with key {}", Hash(kTypeName, channel_key_)); + domain_->Load(*this, Hash(kTypeName, channel_key_)); + + if (channel_statistics_.connection_time_statistics().empty()) { + channel_statistics_.AddConnectionTime( + std::chrono::milliseconds{AE_DEFAULT_CONNECTION_TIMEOUT_MS}); + } + if (channel_statistics_.response_time_statistics().empty()) { + channel_statistics_.AddResponseTime( + std::chrono::milliseconds{AE_DEFAULT_RESPONSE_TIMEOUT_MS}); + } + // TODO: add save while state updated } +Channel::~Channel() { domain_->Save(*this, Hash(kTypeName, channel_key_)); } + ChannelTransportProperties const& Channel::transport_properties() const { return transport_properties_; } -ChannelStatistics& Channel::channel_statistics() { - return *channel_statistics_; -} +ChannelStatistics& Channel::channel_statistics() { return channel_statistics_; } Duration Channel::TransportBuildTimeout() const { - return channel_statistics_->connection_time_statistics().percentile<99>(); + return channel_statistics_.connection_time_statistics().percentile<99>(); } Duration Channel::ResponseTimeout() const { - return channel_statistics_->response_time_statistics().percentile<99>(); + return channel_statistics_.response_time_statistics().percentile<99>(); } } // namespace ae diff --git a/aether/channels/channel.h b/aether/channels/channel.h index 6d31e0c1..a7ec957f 100644 --- a/aether/channels/channel.h +++ b/aether/channels/channel.h @@ -27,11 +27,10 @@ class Channel : public Obj { AE_OBJECT(Channel, Obj, 0) public: - Channel() = default; + Channel(DataKey channel_key, Domain* domain); + ~Channel(); - explicit Channel(Domain* domain); - - AE_OBJECT_REFLECT(AE_MMBRS(transport_properties_, channel_statistics_)) + AE_REFLECT_MEMBERS(transport_properties_, channel_statistics_) /** * \brief Make transport from this channel. @@ -45,8 +44,9 @@ class Channel : public Obj { virtual Duration ResponseTimeout() const; protected: + DataKey channel_key_; ChannelTransportProperties transport_properties_; - ChannelStatistics::ptr channel_statistics_; + ChannelStatistics channel_statistics_; }; } // namespace ae diff --git a/aether/channels/channel_statistics.cpp b/aether/channels/channel_statistics.cpp index b4499408..1f8f1bb5 100644 --- a/aether/channels/channel_statistics.cpp +++ b/aether/channels/channel_statistics.cpp @@ -17,7 +17,6 @@ #include "aether/channels/channel_statistics.h" namespace ae { -ChannelStatistics::ChannelStatistics(Domain* domain) : Base{domain} {} void ChannelStatistics::AddConnectionTime(Duration duration) { connection_time_statistics_.Add(std::move(duration)); diff --git a/aether/channels/channel_statistics.h b/aether/channels/channel_statistics.h index 7706adf0..3d4292a7 100644 --- a/aether/channels/channel_statistics.h +++ b/aether/channels/channel_statistics.h @@ -19,15 +19,11 @@ #include "aether/config.h" #include "aether/common.h" -#include "aether/obj/obj.h" #include "aether/types/statistic_counter.h" namespace ae { -class ChannelStatistics final : public Obj { - AE_OBJECT(ChannelStatistics, Obj, 0) - ChannelStatistics() = default; - +class ChannelStatistics { static constexpr std::size_t kConnectionWindowSize = AE_STATISTICS_CONNECTION_WINDOW_SIZE; static constexpr std::size_t kResponseWindowSize = @@ -39,10 +35,9 @@ class ChannelStatistics final : public Obj { StatisticsCounter; public: - explicit ChannelStatistics(Domain* domain); + ChannelStatistics() = default; - AE_OBJECT_REFLECT(AE_MMBRS(connection_time_statistics_, - response_time_statistics_)) + AE_REFLECT_MEMBERS(connection_time_statistics_, response_time_statistics_) void AddConnectionTime(Duration duration); void AddResponseTime(Duration duration); diff --git a/aether/channels/ethernet_channel.cpp b/aether/channels/ethernet_channel.cpp index 20de943a..3ffb933d 100644 --- a/aether/channels/ethernet_channel.cpp +++ b/aether/channels/ethernet_channel.cpp @@ -45,14 +45,13 @@ class EthernetTransportBuilderAction final : public TransportBuilderAction { EthernetTransportBuilderAction(ActionContext action_context, EthernetChannel& channel, Endpoint address, - DnsResolver::ptr const& dns_resolver, - IPoller::ptr const& poller) + DnsResolver& dns_resolver, IPoller& poller) : TransportBuilderAction{action_context}, action_context_{action_context}, ethernet_channel_{&channel}, address_{std::move(address)}, - resolver_{dns_resolver}, - poller_{poller}, + resolver_{&dns_resolver}, + poller_{&poller}, state_{State::kAddressResolve}, start_time_{Now()} {} @@ -92,9 +91,7 @@ class EthernetTransportBuilderAction final : public TransportBuilderAction { #if AE_SUPPORT_CLOUD_DNS void DoResolverAddress(NamedAddr const& name_address, std::uint16_t port, Protocol protocol) { - auto dns_resolver = resolver_.Lock(); - assert(dns_resolver); - auto resolve_action = dns_resolver->Resolve(name_address, port, protocol); + auto resolve_action = resolver_->Resolve(name_address, port, protocol); address_resolve_sub_ = resolve_action->StatusEvent().Subscribe( ActionHandler{OnResult{[this](auto& action) { @@ -127,11 +124,9 @@ class EthernetTransportBuilderAction final : public TransportBuilderAction { Action::Trigger(); return; } - IPoller::ptr poller = poller_.Lock(); - assert(poller); auto& addr = *(it_++); transport_stream_ = - EthernetTransportFactory::Create(action_context_, poller, addr); + EthernetTransportFactory::Create(action_context_, *poller_, addr); if (!transport_stream_) { // try next address @@ -172,8 +167,8 @@ class EthernetTransportBuilderAction final : public TransportBuilderAction { ActionContext action_context_; EthernetChannel* ethernet_channel_; Endpoint address_; - PtrView resolver_; - PtrView poller_; + DnsResolver* resolver_; + IPoller* poller_; StateMachine state_; std::vector ip_addresses_; std::vector::iterator it_; @@ -185,15 +180,14 @@ class EthernetTransportBuilderAction final : public TransportBuilderAction { }; } // namespace ethernet_access_point_internal -EthernetChannel::EthernetChannel(ObjPtr aether, - ObjPtr dns_resolver, - ObjPtr poller, Endpoint address, +EthernetChannel::EthernetChannel(Aether& aether, DnsResolver& dns_resolver, + IPoller& poller, Endpoint address, Domain* domain) - : Channel{domain}, + : Channel{Hash(kTypeName, address), domain}, address{std::move(address)}, - aether_{std::move(aether)}, - poller_{std::move(poller)}, - dns_resolver_{std::move(dns_resolver)} { + aether_{&aether}, + poller_{&poller}, + dns_resolver_{&dns_resolver} { // fill transport properties auto protocol = address.protocol; @@ -220,20 +214,9 @@ EthernetChannel::EthernetChannel(ObjPtr aether, } ActionPtr EthernetChannel::TransportBuilder() { - if (!dns_resolver_) { - aether_->domain_->LoadRoot(dns_resolver_); - } - if (!poller_) { - aether_->domain_->LoadRoot(poller_); - } - - DnsResolver::ptr dns_resolver = dns_resolver_; - IPoller::ptr poller = poller_; - assert(dns_resolver); - assert(poller); return ActionPtr< ethernet_access_point_internal::EthernetTransportBuilderAction>( - *aether_.as(), *this, address, dns_resolver, poller); + *aether_, *this, address, *dns_resolver_, *poller_); } } // namespace ae diff --git a/aether/channels/ethernet_channel.h b/aether/channels/ethernet_channel.h index 9887ce6f..bac6bb88 100644 --- a/aether/channels/ethernet_channel.h +++ b/aether/channels/ethernet_channel.h @@ -28,21 +28,19 @@ class DnsResolver; class EthernetChannel : public Channel { AE_OBJECT(EthernetChannel, Channel, 0) public: - EthernetChannel() = default; + EthernetChannel(Aether& aether, DnsResolver& dns_resolver, IPoller& poller, + Endpoint address, Domain* domain); - EthernetChannel(ObjPtr aether, ObjPtr dns_resolver, - ObjPtr poller, Endpoint address, Domain* domain); - - AE_OBJECT_REFLECT(AE_MMBRS(aether_, poller_, dns_resolver_, address)) + AE_REFLECT_MEMBERS(address) ActionPtr TransportBuilder() override; Endpoint address; private: - Obj::ptr aether_; - Obj::ptr poller_; - Obj::ptr dns_resolver_; + Aether* aether_; + IPoller* poller_; + DnsResolver* dns_resolver_; }; } // namespace ae diff --git a/aether/channels/ethernet_transport_factory.cpp b/aether/channels/ethernet_transport_factory.cpp index c8631abc..13374fab 100644 --- a/aether/channels/ethernet_transport_factory.cpp +++ b/aether/channels/ethernet_transport_factory.cpp @@ -25,7 +25,7 @@ namespace ae { std::unique_ptr EthernetTransportFactory::Create( - ActionContext action_context, ObjPtr const& poller, + ActionContext action_context, IPoller& poller, Endpoint address_port_protocol) { switch (address_port_protocol.protocol) { case Protocol::kTcp: @@ -41,7 +41,7 @@ std::unique_ptr EthernetTransportFactory::Create( #if AE_SUPPORT_TCP std::unique_ptr EthernetTransportFactory::BuildTcp( [[maybe_unused]] ActionContext action_context, - [[maybe_unused]] ObjPtr const& poller, + [[maybe_unused]] IPoller& poller, [[maybe_unused]] Endpoint address_port_protocol) { # if defined COMMON_TCP_TRANSPORT_ENABLED return std::make_unique(action_context, poller, @@ -53,7 +53,7 @@ std::unique_ptr EthernetTransportFactory::BuildTcp( #else std::unique_ptr EthernetTransportFactory::BuildTcp( [[maybe_unused]] ActionContext action_context, - [[maybe_unused]] ObjPtr const& poller, + [[maybe_unused]] IPoller& poller, [[maybe_unused]] Endpoint address_port_protocol) { return nullptr; } @@ -62,7 +62,7 @@ std::unique_ptr EthernetTransportFactory::BuildTcp( #if AE_SUPPORT_UDP std::unique_ptr EthernetTransportFactory::BuildUdp( [[maybe_unused]] ActionContext action_context, - [[maybe_unused]] ObjPtr const& poller, + [[maybe_unused]] IPoller& poller, [[maybe_unused]] Endpoint address_port_protocol) { # if defined SYSTEM_SOCKET_UDP_TRANSPORT_ENABLED return std::make_unique(action_context, poller, @@ -74,7 +74,7 @@ std::unique_ptr EthernetTransportFactory::BuildUdp( #else std::unique_ptr EthernetTransportFactory::BuildUdp( [[maybe_unused]] ActionContext action_context, - [[maybe_unused]] ObjPtr const& poller, + [[maybe_unused]] IPoller& poller, [[maybe_unused]] Endpoint address_port_protocol) { return nullptr; } diff --git a/aether/channels/ethernet_transport_factory.h b/aether/channels/ethernet_transport_factory.h index 86e2cbd2..cf48269b 100644 --- a/aether/channels/ethernet_transport_factory.h +++ b/aether/channels/ethernet_transport_factory.h @@ -18,7 +18,6 @@ #include -#include "aether/obj/obj_ptr.h" #include "aether/types/address.h" #include "aether/stream_api/istream.h" @@ -28,15 +27,15 @@ class IPoller; class EthernetTransportFactory { public: static std::unique_ptr Create(ActionContext action_context, - ObjPtr const& poller, + IPoller& poller, Endpoint address_port_protocol); private: static std::unique_ptr BuildTcp(ActionContext action_context, - ObjPtr const& poller, + IPoller& poller, Endpoint address_port_protocol); static std::unique_ptr BuildUdp(ActionContext action_context, - ObjPtr const& poller, + IPoller& poller, Endpoint address_port_protocol); }; } // namespace ae diff --git a/aether/channels/wifi_channel.cpp b/aether/channels/wifi_channel.cpp index e68d3ea4..d7df176d 100644 --- a/aether/channels/wifi_channel.cpp +++ b/aether/channels/wifi_channel.cpp @@ -20,7 +20,6 @@ #include #include -#include "aether/ptr/ptr_view.h" #include "aether/actions/action.h" #include "aether/types/state_machine.h" #include "aether/events/event_subscription.h" @@ -45,15 +44,14 @@ class WifiTransportBuilderAction final : public TransportBuilderAction { }; WifiTransportBuilderAction(ActionContext action_context, WifiChannel& channel, - WifiAccessPoint::ptr const& access_point, - IPoller::ptr const& poller, - DnsResolver::ptr const& resolver, Endpoint address) + WifiAccessPoint& access_point, IPoller& poller, + DnsResolver& resolver, Endpoint address) : TransportBuilderAction{action_context}, action_context_{action_context}, channel_{&channel}, - access_point_{access_point}, - poller_{poller}, - resolver_{resolver}, + access_point_{&access_point}, + poller_{&poller}, + resolver_{&resolver}, address_{std::move(address)}, state_{State::kWifiConnect} {} @@ -86,9 +84,7 @@ class WifiTransportBuilderAction final : public TransportBuilderAction { private: void WifiConnect() { - auto access_point = access_point_.Lock(); - assert(access_point); - auto connect_action = access_point->Connect(); + auto connect_action = access_point_->Connect(); wifi_connected_sub_ = connect_action->StatusEvent().Subscribe(ActionHandler{ OnResult{[this]() { // build transport start after wifi is connected @@ -114,9 +110,7 @@ class WifiTransportBuilderAction final : public TransportBuilderAction { #if AE_SUPPORT_CLOUD_DNS void DoResolverAddress(NamedAddr const& name_address, std::uint16_t port, Protocol protocol) { - auto dns_resolver = resolver_.Lock(); - assert(dns_resolver); - auto resolve_action = dns_resolver->Resolve(name_address, port, protocol); + auto resolve_action = resolver_->Resolve(name_address, port, protocol); address_resolve_sub_ = resolve_action->StatusEvent().Subscribe( ActionHandler{OnResult{[this](auto& action) { @@ -150,11 +144,9 @@ class WifiTransportBuilderAction final : public TransportBuilderAction { return; } - IPoller::ptr poller = poller_.Lock(); - assert(poller); auto& addr = *(it_++); transport_stream_ = - EthernetTransportFactory::Create(action_context_, poller, addr); + EthernetTransportFactory::Create(action_context_, *poller_, addr); if (!transport_stream_) { // try next address state_ = State::kTransportCreate; @@ -191,9 +183,9 @@ class WifiTransportBuilderAction final : public TransportBuilderAction { ActionContext action_context_; WifiChannel* channel_; - PtrView access_point_; - PtrView poller_; - PtrView resolver_; + WifiAccessPoint* access_point_; + IPoller* poller_; + DnsResolver* resolver_; Endpoint address_; std::vector ip_addresses_; @@ -207,16 +199,17 @@ class WifiTransportBuilderAction final : public TransportBuilderAction { }; } // namespace wifi_channel_internal -WifiChannel::WifiChannel(ObjPtr aether, ObjPtr poller, - ObjPtr resolver, - WifiAccessPoint::ptr access_point, Endpoint address, +WifiChannel::WifiChannel(Aether& aether, IPoller& poller, DnsResolver& resolver, + WifiAccessPoint& access_point, Endpoint address, Domain* domain) - : Channel{domain}, + : Channel{Hash(kTypeName, access_point.creds().ssid, + access_point.creds().password), + domain}, address{std::move(address)}, - aether_(std::move(aether)), - poller_(std::move(poller)), - resolver_(std::move(resolver)), - access_point_(std::move(access_point)) { + aether_(&aether), + poller_(&poller), + resolver_(&resolver), + access_point_(&access_point) { // fill transport properties auto protocol = address.protocol; @@ -244,29 +237,16 @@ WifiChannel::WifiChannel(ObjPtr aether, ObjPtr poller, Duration WifiChannel::TransportBuildTimeout() const { if (access_point_->IsConnected()) { - return channel_statistics_->connection_time_statistics().percentile<99>(); + return channel_statistics_.connection_time_statistics().percentile<99>(); } // add time required for wifi connection - return channel_statistics_->connection_time_statistics().percentile<99>() + + return channel_statistics_.connection_time_statistics().percentile<99>() + std::chrono::milliseconds{AE_WIFI_CONNECTION_TIMEOUT_MS}; } ActionPtr WifiChannel::TransportBuilder() { - if (!resolver_) { - aether_->domain_->LoadRoot(resolver_); - } - if (!poller_) { - aether_->domain_->LoadRoot(poller_); - } - if (!access_point_) { - aether_->domain_->LoadRoot(access_point_); - } - - IPoller::ptr poller = poller_; - DnsResolver::ptr resolver = resolver_; - return ActionPtr{ - *aether_.as(), *this, access_point_, poller, resolver, address}; + *aether_, *this, *access_point_, *poller_, *resolver_, address}; } } // namespace ae diff --git a/aether/channels/wifi_channel.h b/aether/channels/wifi_channel.h index 13b192b3..d848444c 100644 --- a/aether/channels/wifi_channel.h +++ b/aether/channels/wifi_channel.h @@ -28,15 +28,9 @@ class DnsResolver; class WifiChannel final : public Channel { AE_OBJECT(WifiChannel, Channel, 0) - WifiChannel() = default; - public: - WifiChannel(ObjPtr aether, ObjPtr poller, - ObjPtr resolver, WifiAccessPoint::ptr access_point, - Endpoint address, Domain* domain); - - AE_OBJECT_REFLECT(AE_MMBRS(aether_, poller_, resolver_, access_point_, - address)) + WifiChannel(Aether& aether, IPoller& poller, DnsResolver& resolver, + WifiAccessPoint& access_point, Endpoint address, Domain* domain); Duration TransportBuildTimeout() const override; @@ -45,10 +39,10 @@ class WifiChannel final : public Channel { Endpoint address; private: - Obj::ptr aether_; - Obj::ptr poller_; - Obj::ptr resolver_; - WifiAccessPoint::ptr access_point_; + Aether* aether_; + IPoller* poller_; + DnsResolver* resolver_; + WifiAccessPoint* access_point_; }; } // namespace ae diff --git a/aether/client.cpp b/aether/client.cpp index 852a84f3..a2519f0a 100644 --- a/aether/client.cpp +++ b/aether/client.cpp @@ -19,16 +19,32 @@ #include #include "aether/aether.h" +#include "aether/work_cloud.h" + +#include "aether/tele/tele.h" namespace ae { -#ifdef AE_DISTILLATION -Client::Client(Aether::ptr aether, Domain* domain) - : Base(domain), aether_{std::move(aether)} {} -#endif // AE_DISTILLATION +Client::Client(Aether& aether, Uid parent_uid, std::string id, Domain* domain) + : Obj{domain}, + aether_{&aether}, + id_{std::move(id)}, + parent_uid_{parent_uid} { + AE_TELED_DEBUG("Created client parent_uid={}, id={}", parent_uid_, id_); + domain_->Load(*this, Hash(kTypeName, id_)); + if (uid_.empty()) { + return; + } + + AE_TELED_DEBUG("Loaded client id={}, uid={}", id_, uid_); + Init(std::make_unique(*aether_, uid_, domain_)); +} +std::string const& Client::client_id() const { return id_; } +Uid const& Client::parent_uid() const { return parent_uid_; } Uid const& Client::uid() const { return uid_; } Uid const& Client::ephemeral_uid() const { return ephemeral_uid_; } + ServerKeys* Client::server_state(ServerId server_id) { auto ss_it = server_keys_.find(server_id); if (ss_it == server_keys_.end()) { @@ -37,68 +53,37 @@ ServerKeys* Client::server_state(ServerId server_id) { return &ss_it->second; } -Cloud::ptr const& Client::cloud() const { return cloud_; } +Cloud& Client::cloud() { return *cloud_; } -ClientCloudManager::ptr const& Client::cloud_manager() const { - assert(client_cloud_manager_); - return client_cloud_manager_; -} +ClientCloudManager& Client::cloud_manager() { return *client_cloud_manager_; } ServerConnectionManager& Client::server_connection_manager() { - if (!server_connection_manager_) { - auto aether = Aether::ptr{aether_}; - server_connection_manager_ = std::make_unique( - *aether, MakePtrFromThis(this)); - } return *server_connection_manager_; } ClientConnectionManager& Client::connection_manager() { - if (!client_connection_manager_) { - auto aether = Aether::ptr{aether_}; - client_connection_manager_ = std::make_unique( - cloud_, server_connection_manager().GetServerConnectionFactory()); - } return *client_connection_manager_; } -CloudConnection& Client::cloud_connection() { - if (!cloud_connection_) { - auto aether = Aether::ptr{aether_}; - cloud_connection_ = std::make_unique( - *aether, connection_manager(), AE_CLOUD_MAX_SERVER_CONNECTIONS); - -#if AE_TELE_ENABLED - // also create telemetry - telemetry_ = ActionPtr(*aether, aether, *cloud_connection_); -#endif - } - - return *cloud_connection_; -} +CloudConnection& Client::cloud_connection() { return *cloud_connection_; } P2pMessageStreamManager& Client::message_stream_manager() { - if (!message_stream_manager_) { - auto aether = Aether::ptr{aether_}; - message_stream_manager_ = std::make_unique( - *aether, MakePtrFromThis(this)); - } return *message_stream_manager_; } void Client::SetConfig(Uid uid, Uid ephemeral_uid, Key master_key, - Cloud::ptr cloud) { + std::unique_ptr c) { uid_ = uid; ephemeral_uid_ = ephemeral_uid; master_key_ = std::move(master_key); - cloud_ = std::move(cloud); - - for (auto& s : cloud_->servers()) { + for (auto& s : c->servers()) { server_keys_.emplace(s->server_id, ServerKeys{s->server_id, master_key_}); } - client_cloud_manager_ = domain_->CreateObj( - ObjPtr{aether_}, MakePtrFromThis(this)); + Init(std::move(c)); + + // Save the config + domain_->Save(*this, Hash(kTypeName, id_)); } void Client::SendTelemetry() { @@ -107,4 +92,24 @@ void Client::SendTelemetry() { #endif } +void Client::Init(std::unique_ptr cloud) { + cloud_ = std::move(cloud); + client_cloud_manager_ = + std::make_unique(*aether_, *this, domain_); + server_connection_manager_ = + std::make_unique(*aether_, *this); + + client_connection_manager_ = std::make_unique( + *cloud_, server_connection_manager_->GetServerConnectionFactory()); + cloud_connection_ = std::make_unique( + *aether_, connection_manager(), AE_CLOUD_MAX_SERVER_CONNECTIONS); + message_stream_manager_ = + std::make_unique(*aether_, *this); +#if AE_TELE_ENABLED + // also create telemetry + telemetry_ = ActionPtr(ActionContext{*aether_}, *aether_, + *cloud_connection_); +#endif +} + } // namespace ae diff --git a/aether/client.h b/aether/client.h index b206a1a9..33f6aa0b 100644 --- a/aether/client.h +++ b/aether/client.h @@ -21,7 +21,6 @@ #include #include "aether/memory.h" -#include "aether/common.h" #include "aether/cloud.h" #include "aether/obj/obj.h" #include "aether/types/uid.h" @@ -37,61 +36,49 @@ namespace ae { class Aether; -class Client : public Obj { +class Client final : public Obj { AE_OBJECT(Client, Obj, 0) - Client() = default; - public: - // Internal -#ifdef AE_DISTILLATION - Client(ObjPtr aether, Domain* domain); -#endif // AE_DISTILLATION + Client(Aether& aether, Uid parent_uid, std::string id, Domain* domain); + + AE_REFLECT_MEMBERS(parent_uid_, uid_, ephemeral_uid_, master_key_, + server_keys_) // Public API. + std::string const& client_id() const; + Uid const& parent_uid() const; Uid const& uid() const; Uid const& ephemeral_uid() const; ServerKeys* server_state(ServerId server_id); - Cloud::ptr const& cloud() const; - ClientCloudManager::ptr const& cloud_manager() const; + Cloud& cloud(); + ClientCloudManager& cloud_manager(); ServerConnectionManager& server_connection_manager(); ClientConnectionManager& connection_manager(); CloudConnection& cloud_connection(); P2pMessageStreamManager& message_stream_manager(); - void SetConfig(Uid uid, Uid ephemeral_uid, Key master_key, Cloud::ptr c); - - AE_OBJECT_REFLECT(AE_MMBRS(aether_, uid_, ephemeral_uid_, master_key_, cloud_, - server_keys_, client_cloud_manager_)) - - template - void Load(CurrentVersion, Dnv& dnv) { - dnv(base_); - dnv(aether_, uid_, ephemeral_uid_, master_key_, cloud_, server_keys_, - client_cloud_manager_); - } - - template - void Save(CurrentVersion, Dnv& dnv) const { - dnv(base_); - dnv(aether_, uid_, ephemeral_uid_, master_key_, cloud_, server_keys_, - client_cloud_manager_); - } + void SetConfig(Uid uid, Uid ephemeral_uid, Key master_key, + std::unique_ptr c); void SendTelemetry(); private: - Obj::ptr aether_; + void Init(std::unique_ptr cloud); + + Aether* aether_; + std::string id_; //< User defined client id // configuration + Uid parent_uid_{}; Uid uid_{}; Uid ephemeral_uid_{}; Key master_key_; - Cloud::ptr cloud_; + std::unique_ptr cloud_; // states std::map server_keys_; - ClientCloudManager::ptr client_cloud_manager_; + std::unique_ptr client_cloud_manager_; std::unique_ptr server_connection_manager_; std::unique_ptr client_connection_manager_; std::unique_ptr cloud_connection_; diff --git a/aether/client_connections/cloud_connection.h b/aether/client_connections/cloud_connection.h index 68b52b0b..137c15e7 100644 --- a/aether/client_connections/cloud_connection.h +++ b/aether/client_connections/cloud_connection.h @@ -17,6 +17,7 @@ #define AETHER_CLIENT_CONNECTIONS_CLOUD_CONNECTION_H_ #include +#include #include "aether/events/events.h" #include "aether/actions/action_ptr.h" diff --git a/aether/client_messages/p2p_message_stream.cpp b/aether/client_messages/p2p_message_stream.cpp index b4cd3d9d..01d9d4ff 100644 --- a/aether/client_messages/p2p_message_stream.cpp +++ b/aether/client_messages/p2p_message_stream.cpp @@ -176,10 +176,10 @@ class ReadMessageGate { } // namespace p2p_stream_internal -P2pStream::P2pStream(ActionContext action_context, ObjPtr const& client, +P2pStream::P2pStream(ActionContext action_context, Client& client, Uid destination) : action_context_{action_context}, - client_{client}, + client_{&client}, destination_{destination}, // TODO: add buffer config buffer_stream_{action_context_, 100} { @@ -215,9 +215,7 @@ P2pStream::OutDataEvent::Subscriber P2pStream::out_data_event() { void P2pStream::Restream() { AE_TELED_DEBUG("Restream message stream"); - auto client_ptr = client_.Lock(); - assert(client_ptr); - client_ptr->cloud_connection().Restream(); + client_->cloud_connection().Restream(); buffer_stream_.Restream(); } @@ -230,28 +228,22 @@ void P2pStream::WriteOut(DataBuffer const& data) { Uid P2pStream::destination() const { return destination_; } void P2pStream::ConnectReceive() { - auto client_ptr = client_.Lock(); - assert(client_ptr); // TODO: config request policy read_message_gate_ = std::make_unique( - destination_, client_ptr->cloud_connection(), - RequestPolicy::Replica{ - client_ptr->cloud_connection().count_connections()}); + destination_, client_->cloud_connection(), + RequestPolicy::Replica{client_->cloud_connection().count_connections()}); // write out received data read_message_gate_->out_data_event().Subscribe( MethodPtr<&P2pStream::WriteOut>{this}); } void P2pStream::ConnectSend() { - auto client_ptr = client_.Lock(); - assert(client_ptr); - - auto get_client_cloud = client_ptr->cloud_manager()->GetCloud(destination_); + auto get_client_cloud = client_->cloud_manager().GetCloud(destination_); get_client_connection_sub_ = get_client_cloud->StatusEvent().Subscribe( OnResult{[this](GetCloudAction& action) { - auto cloud = action.cloud(); - destination_connection_manager_ = MakeConnectionManager(cloud); + destination_connection_manager_ = + MakeConnectionManager(*action.cloud()); destination_cloud_connection_ = MakeDestinationStream(*destination_connection_manager_); // TODO: add config for request policy @@ -264,12 +256,9 @@ void P2pStream::ConnectSend() { } std::unique_ptr P2pStream::MakeConnectionManager( - ObjPtr const& cloud) { - auto client_ptr = client_.Lock(); - assert(client_ptr); + Cloud& cloud) { return std::make_unique( - cloud, - client_ptr->server_connection_manager().GetServerConnectionFactory()); + cloud, client_->server_connection_manager().GetServerConnectionFactory()); } std::unique_ptr P2pStream::MakeDestinationStream( diff --git a/aether/client_messages/p2p_message_stream.h b/aether/client_messages/p2p_message_stream.h index 0aab4370..88d86472 100644 --- a/aether/client_messages/p2p_message_stream.h +++ b/aether/client_messages/p2p_message_stream.h @@ -20,7 +20,6 @@ #include "aether/common.h" #include "aether/types/uid.h" -#include "aether/ptr/ptr_view.h" #include "aether/actions/action_context.h" #include "aether/stream_api/buffer_stream.h" @@ -39,8 +38,7 @@ class ReadMessageGate; class P2pStream final : public ByteIStream { public: - P2pStream(ActionContext action_context, ObjPtr const& client, - Uid destination); + P2pStream(ActionContext action_context, Client& client, Uid destination); ~P2pStream() override; @@ -65,13 +63,12 @@ class P2pStream final : public ByteIStream { void ConnectSend(); void DataReceived(AeMessage const& data); - std::unique_ptr MakeConnectionManager( - ObjPtr const& cloud); + std::unique_ptr MakeConnectionManager(Cloud& cloud); std::unique_ptr MakeDestinationStream( ClientConnectionManager& connection_manager); ActionContext action_context_; - PtrView client_; + Client* client_; Uid destination_; // connection manager to destination cloud diff --git a/aether/client_messages/p2p_message_stream_manager.cpp b/aether/client_messages/p2p_message_stream_manager.cpp index 848f060c..17c8e428 100644 --- a/aether/client_messages/p2p_message_stream_manager.cpp +++ b/aether/client_messages/p2p_message_stream_manager.cpp @@ -21,11 +21,11 @@ namespace ae { P2pMessageStreamManager::P2pMessageStreamManager(ActionContext action_context, - ObjPtr const& client) + Client& client) : action_context_{action_context}, - client_{client}, - connection_manager_{&client->connection_manager()}, - cloud_connection_{&client->cloud_connection()} { + client_{&client}, + connection_manager_{&client_->connection_manager()}, + cloud_connection_{&client_->cloud_connection()} { on_message_received_sub_ = cloud_connection_->ClientApiSubscription( [this](ClientApiSafe& client_api, auto*) { return client_api.send_message_event().Subscribe( @@ -77,9 +77,7 @@ void P2pMessageStreamManager::CleanUpStreams() { } RcPtr P2pMessageStreamManager::MakeStream(Uid destination) { - Client::ptr client_ptr = client_.Lock(); - assert(client_ptr); - return MakeRcPtr(action_context_, client_ptr, destination); + return MakeRcPtr(action_context_, *client_, destination); } } // namespace ae diff --git a/aether/client_messages/p2p_message_stream_manager.h b/aether/client_messages/p2p_message_stream_manager.h index 03e17d82..83dd440d 100644 --- a/aether/client_messages/p2p_message_stream_manager.h +++ b/aether/client_messages/p2p_message_stream_manager.h @@ -21,10 +21,7 @@ #include "aether/types/uid.h" #include "aether/ptr/rc_ptr.h" -#include "aether/ptr/ptr_view.h" -#include "aether/obj/obj_ptr.h" #include "aether/events/events.h" -#include "aether/events/event_subscription.h" #include "aether/client_messages/p2p_message_stream.h" #include "aether/client_connections/cloud_connection.h" @@ -34,8 +31,7 @@ class P2pMessageStreamManager { public: using NewStreamEvent = Event)>; - P2pMessageStreamManager(ActionContext action_context, - ObjPtr const& client); + P2pMessageStreamManager(ActionContext action_context, Client& client); RcPtr CreateStream(Uid destination); NewStreamEvent::Subscriber new_stream_event(); @@ -46,7 +42,7 @@ class P2pMessageStreamManager { RcPtr MakeStream(Uid destination); ActionContext action_context_; - PtrView client_; + Client* client_; ClientConnectionManager* connection_manager_; CloudConnection* cloud_connection_; std::map> streams_; diff --git a/aether/cloud.cpp b/aether/cloud.cpp index 4ff53700..2cadc278 100644 --- a/aether/cloud.cpp +++ b/aether/cloud.cpp @@ -20,29 +20,6 @@ namespace ae { Cloud::Cloud(Domain* domain) : Obj{domain} {} -void Cloud::AddServer(Server::ptr server) { - servers_.emplace_back(std::move(server)); - servers_.back().SetFlags(ObjFlags::kUnloadedByDefault); - cloud_updated_.Emit(); -} - -void Cloud::AddServers(std::vector servers) { - for (auto&& s : std::move(servers)) { - servers_.emplace_back(std::move(s)); - servers_.back().SetFlags(ObjFlags::kUnloadedByDefault); - } - cloud_updated_.Emit(); -} - -void Cloud::LoadServer(Server::ptr& server) { - if (!server) { - domain_->LoadRoot(server); - assert(server); - } -} - -std::vector& Cloud::servers() { return servers_; } - EventSubscriber Cloud::cloud_updated() { return EventSubscriber{cloud_updated_}; } diff --git a/aether/cloud.h b/aether/cloud.h index 247fc6a8..d71021e1 100644 --- a/aether/cloud.h +++ b/aether/cloud.h @@ -34,17 +34,10 @@ class Cloud : public Obj { public: explicit Cloud(Domain* domain); - AE_OBJECT_REFLECT(AE_MMBRS(servers_)) - - void AddServer(Server::ptr server); - void AddServers(std::vector servers); - void LoadServer(Server::ptr& server); - - std::vector& servers(); + virtual std::vector>& servers() = 0; EventSubscriber cloud_updated(); - private: - std::vector servers_; + protected: Event cloud_updated_; }; diff --git a/aether/connection_manager/client_cloud_manager.cpp b/aether/connection_manager/client_cloud_manager.cpp index d00d4037..b9d20c90 100644 --- a/aether/connection_manager/client_cloud_manager.cpp +++ b/aether/connection_manager/client_cloud_manager.cpp @@ -35,15 +35,15 @@ namespace ae { namespace client_cloud_manager_internal { class GetCloudFromCache final : public GetCloudAction { public: - GetCloudFromCache(ActionContext action_context, Cloud::ptr cloud) + GetCloudFromCache(ActionContext action_context, std::shared_ptr cloud) : GetCloudAction{action_context}, cloud_{std::move(cloud)} {} UpdateStatus Update() override { return UpdateStatus::Result(); } - Cloud::ptr cloud() override { return std::move(cloud_); } + std::shared_ptr cloud() override { return std::move(cloud_); } void Stop() override {}; private: - Cloud::ptr cloud_; + std::shared_ptr cloud_; }; class GetCloudFromAether : public GetCloudAction { @@ -85,7 +85,7 @@ class GetCloudFromAether : public GetCloudAction { return {}; } - Cloud::ptr cloud() override { return std::move(cloud_); } + std::shared_ptr cloud() override { return std::move(cloud_); } void Stop() override { state_ = State::kStopped; }; private: @@ -114,6 +114,7 @@ class GetCloudFromAether : public GetCloudAction { missing_servers.push_back(sid); } } + if (!missing_servers.empty()) { // If there are missing servers, resolve them from the cloud get_servers_action_ = OwnActionPtr{ @@ -150,9 +151,9 @@ class GetCloudFromAether : public GetCloudAction { } } - std::vector BuildNewServers( + std::vector> BuildNewServers( std::vector const& descriptors) { - std::vector servers; + std::vector> servers; for (auto const& sd : descriptors) { std::vector endpoints; for (auto const& ip : sd.ips) { @@ -160,16 +161,16 @@ class GetCloudFromAether : public GetCloudAction { endpoints.emplace_back(Endpoint{{ip.ip, pp.port}, pp.protocol}); } } - Server::ptr s = - aether_->domain_->CreateObj(sd.server_id, endpoints); - s->Register(aether_->adapter_registry); + + auto s = std::make_shared( + sd.server_id, endpoints, aether_->adapter_registry, aether_->domain_); aether_->AddServer(s); servers.emplace_back(std::move(s)); } return servers; } - void RegisterCloud(std::vector servers) { + void RegisterCloud(std::vector> servers) { cloud_ = client_cloud_manager_->RegisterCloud(client_uid_, std::move(servers)); } @@ -185,53 +186,38 @@ class GetCloudFromAether : public GetCloudAction { OwnActionPtr get_servers_action_; Subscription get_servers_sub_; std::vector cloud_sids_; - std::vector servers_; - Cloud::ptr cloud_; + std::vector> servers_; + std::shared_ptr cloud_; }; } // namespace client_cloud_manager_internal -ClientCloudManager::ClientCloudManager(ObjPtr aether, - ObjPtr client, Domain* domain) - : Obj(domain), aether_{std::move(aether)}, client_{std::move(client)} {} +ClientCloudManager::ClientCloudManager(Aether& aether, Client& client, + Domain* domain) + : Obj{domain}, aether_{&aether}, client_{&client} { + domain_->Load(*this, Hash(kTypeName, client_->uid())); +} ActionPtr ClientCloudManager::GetCloud(Uid client_uid) { - if (!aether_) { - domain_->LoadRoot(aether_); - } - assert(aether_); - auto* aether = aether_.as(); - auto cached = cloud_cache_.find(client_uid); if (cached != cloud_cache_.end()) { - if (!cached->second) { - domain_->LoadRoot(cached->second); - } - assert(cached->second); return ActionPtr{ - *aether, cached->second}; + *aether_, cached->second}; } // get from aethernet - if (!client_) { - domain_->LoadRoot(client_); - } - assert(client_); - - auto* client = client_.as(); return ActionPtr{ - *aether, *aether, *this, client->cloud_connection(), client_uid}; + ActionContext{*aether_}, *aether_, *this, client_->cloud_connection(), + client_uid}; } -Cloud::ptr ClientCloudManager::RegisterCloud(Uid uid, - std::vector servers) { - if (!aether_) { - domain_->LoadRoot(aether_); - } - auto new_cloud = domain_->CreateObj(); - assert(new_cloud); - new_cloud->AddServers(std::move(servers)); - +std::shared_ptr ClientCloudManager::RegisterCloud( + Uid uid, std::vector> servers) { + auto new_cloud = std::make_shared(*aether_, uid, aether_->domain_); + new_cloud->SetServers(std::move(servers)); cloud_cache_[uid] = new_cloud; + // save updated cache + domain_->Save(*this, Hash(kTypeName, client_->uid())); + return new_cloud; } diff --git a/aether/connection_manager/client_cloud_manager.h b/aether/connection_manager/client_cloud_manager.h index a47ad14d..c6e07b2e 100644 --- a/aether/connection_manager/client_cloud_manager.h +++ b/aether/connection_manager/client_cloud_manager.h @@ -20,13 +20,11 @@ #include #include "aether/obj/obj.h" -#include "aether/ptr/ptr.h" #include "aether/actions/action.h" #include "aether/actions/action_ptr.h" -#include "aether/cloud.h" #include "aether/types/uid.h" -#include "aether/types/server_id.h" +#include "aether/work_cloud.h" namespace ae { class Aether; @@ -41,7 +39,7 @@ class GetCloudAction : public Action { using Action::Action; virtual UpdateStatus Update() = 0; - virtual Cloud::ptr cloud() = 0; + virtual std::shared_ptr cloud() = 0; virtual void Stop() = 0; }; @@ -51,21 +49,38 @@ class ClientCloudManager : public Obj { ClientCloudManager() = default; public: - explicit ClientCloudManager(ObjPtr aether, ObjPtr client, - Domain* domain); + explicit ClientCloudManager(Aether& aether, Client& client, Domain* domain); AE_CLASS_NO_COPY_MOVE(ClientCloudManager) ActionPtr GetCloud(Uid client_uid); - Cloud::ptr RegisterCloud(Uid uid, std::vector servers); - - AE_OBJECT_REFLECT(AE_MMBRS(aether_, client_, cloud_cache_)) + std::shared_ptr RegisterCloud( + Uid uid, std::vector> servers); + + template + void Load(CurrentVersion, Dnv& dnv) { + std::vector uids; + dnv(uids); + for (auto const& uid : uids) { + cloud_cache_[uid] = std::make_shared(*aether_, uid, domain_); + } + } + + template + void Save(CurrentVersion, Dnv& dnv) const { + std::vector uids; + uids.reserve(cloud_cache_.size()); + for (auto const& [uid, _] : cloud_cache_) { + uids.push_back(uid); + } + dnv(uids); + } private: - Obj::ptr aether_; - Obj::ptr client_; - std::map cloud_cache_; + Aether* aether_; + Client* client_; + std::map> cloud_cache_; }; } // namespace ae diff --git a/aether/connection_manager/client_connection_manager.cpp b/aether/connection_manager/client_connection_manager.cpp index 436f97b5..7a1ab7a2 100644 --- a/aether/connection_manager/client_connection_manager.cpp +++ b/aether/connection_manager/client_connection_manager.cpp @@ -22,9 +22,9 @@ namespace ae { ClientConnectionManager::ClientConnectionManager( - ObjPtr const& cloud, + Cloud& cloud, std::unique_ptr&& connection_factory) - : cloud_{cloud}, connection_factory_{std::move(connection_factory)} { + : cloud_{&cloud}, connection_factory_{std::move(connection_factory)} { InitServerConnections(); } @@ -33,14 +33,8 @@ std::vector& ClientConnectionManager::server_connections() { } void ClientConnectionManager::InitServerConnections() { - Cloud::ptr cloud = cloud_.Lock(); - assert(cloud); - server_connections_.reserve(cloud->servers().size()); - for (auto& server : cloud->servers()) { - if (!server) { - cloud->LoadServer(server); - } - assert(server); + server_connections_.reserve(cloud_->servers().size()); + for (auto& server : cloud_->servers()) { server_connections_.emplace_back(server, *connection_factory_); } } diff --git a/aether/connection_manager/client_connection_manager.h b/aether/connection_manager/client_connection_manager.h index 92ad6a9f..085c4e64 100644 --- a/aether/connection_manager/client_connection_manager.h +++ b/aether/connection_manager/client_connection_manager.h @@ -17,8 +17,7 @@ #ifndef AETHER_CONNECTION_MANAGER_CLIENT_CONNECTION_MANAGER_H_ #define AETHER_CONNECTION_MANAGER_CLIENT_CONNECTION_MANAGER_H_ -#include "aether/obj/obj_ptr.h" -#include "aether/ptr/ptr_view.h" +#include #include "aether/server_connections/server_connection.h" #include "aether/server_connections/iserver_connection_factory.h" @@ -32,7 +31,7 @@ class Cloud; class ClientConnectionManager { public: ClientConnectionManager( - ObjPtr const& cloud, + Cloud& cloud, std::unique_ptr&& connection_factory); std::vector& server_connections(); @@ -40,7 +39,7 @@ class ClientConnectionManager { private: void InitServerConnections(); - PtrView cloud_; + Cloud* cloud_; std::unique_ptr connection_factory_; std::vector server_connections_; }; diff --git a/aether/connection_manager/server_connection_manager.cpp b/aether/connection_manager/server_connection_manager.cpp index 2e580ecf..5e34599b 100644 --- a/aether/connection_manager/server_connection_manager.cpp +++ b/aether/connection_manager/server_connection_manager.cpp @@ -26,13 +26,13 @@ ServerConnectionManager::ServerConnectionFactory::ServerConnectionFactory( RcPtr ServerConnectionManager::ServerConnectionFactory::CreateConnection( - ObjPtr const& server) { + std::shared_ptr const& server) { return server_connection_manager_->CreateConnection(server); } ServerConnectionManager::ServerConnectionManager(ActionContext action_context, - ObjPtr const& client) - : action_context_{action_context}, client_{client}, cached_connections_{} {} + Client& client) + : action_context_{action_context}, client_{&client} {} std::unique_ptr ServerConnectionManager::GetServerConnectionFactory() { @@ -40,18 +40,15 @@ ServerConnectionManager::GetServerConnectionFactory() { } RcPtr ServerConnectionManager::CreateConnection( - Server::ptr const& server) { + std::shared_ptr const& server) { auto in_cache = FindInCache(server->server_id); if (in_cache) { return in_cache; } // make new connection - auto client = client_.Lock(); - assert(client); - auto connection = - MakeRcPtr(action_context_, client, server); + MakeRcPtr(action_context_, *client_, *server); // save in cache cached_connections_[server->server_id] = connection; return connection; diff --git a/aether/connection_manager/server_connection_manager.h b/aether/connection_manager/server_connection_manager.h index c48c75f5..a0a7842a 100644 --- a/aether/connection_manager/server_connection_manager.h +++ b/aether/connection_manager/server_connection_manager.h @@ -20,8 +20,6 @@ #include #include "aether/ptr/rc_ptr.h" -#include "aether/obj/obj_ptr.h" -#include "aether/ptr/ptr_view.h" #include "aether/actions/action_context.h" #include "aether/server_connections/client_server_connection.h" #include "aether/server_connections/iserver_connection_factory.h" @@ -36,25 +34,25 @@ class ServerConnectionManager { ServerConnectionManager& server_connection_manager); RcPtr CreateConnection( - ObjPtr const& server) override; + std::shared_ptr const& server) override; private: ServerConnectionManager* server_connection_manager_; }; public: - ServerConnectionManager(ActionContext action_context, - ObjPtr const& client); + ServerConnectionManager(ActionContext action_context, Client& client); std::unique_ptr GetServerConnectionFactory(); - RcPtr CreateConnection(ObjPtr const& server); + RcPtr CreateConnection( + std::shared_ptr const& server); RcPtr FindInCache(ServerId server_id) const; private: ActionContext action_context_; - PtrView client_; + Client* client_; std::map> cached_connections_; }; } // namespace ae diff --git a/aether/crypto.h b/aether/crypto.h index cd4f31ce..fd13bfec 100644 --- a/aether/crypto.h +++ b/aether/crypto.h @@ -31,14 +31,14 @@ class Crypto : public Obj { Crypto() = default; public: -#ifdef AE_DISTILLATION - Crypto(Domain* domain) : Obj{domain} {} -#endif // AE_DISTILLATION + explicit Crypto(Domain* domain) : Obj{domain} { + domain_->Load(*this, Hash(kTypeName)); + } #if AE_SIGNATURE != AE_NONE - AE_OBJECT_REFLECT(AE_MMBR(signs_pk_)) + AE_REFLECT_MEMBERS(signs_pk_) #else - AE_OBJECT_REFLECT() + AE_REFLECT() #endif #if AE_SIGNATURE != AE_NONE diff --git a/aether/dns/dns_c_ares.cpp b/aether/dns/dns_c_ares.cpp index 1b8c55ed..8b188b8f 100644 --- a/aether/dns/dns_c_ares.cpp +++ b/aether/dns/dns_c_ares.cpp @@ -187,21 +187,14 @@ class AresImpl { AE_MAY_UNUSED_MEMBER SocketInitializer socket_initializer_; }; -DnsResolverCares::DnsResolverCares() = default; - -# if defined AE_DISTILLATION -DnsResolverCares::DnsResolverCares(ObjPtr aether, Domain* domain) - : DnsResolver(domain), aether_{std::move(aether)} {} -# endif +DnsResolverCares::DnsResolverCares(Aether& aether, Domain* domain) + : DnsResolver(domain), ares_impl_{std::make_unique(aether)} {} DnsResolverCares::~DnsResolverCares() = default; ActionPtr DnsResolverCares::Resolve( NamedAddr const& name_address, std::uint16_t port_hint, Protocol protocol_hint) { - if (!ares_impl_) { - ares_impl_ = std::make_unique(*aether_.as()); - } return ares_impl_->Query(name_address, port_hint, protocol_hint); } diff --git a/aether/dns/dns_c_ares.h b/aether/dns/dns_c_ares.h index e8cdec3e..8fa8c94c 100644 --- a/aether/dns/dns_c_ares.h +++ b/aether/dns/dns_c_ares.h @@ -37,22 +37,15 @@ class AresImpl; class DnsResolverCares : public DnsResolver { AE_OBJECT(DnsResolverCares, DnsResolver, 0) - DnsResolverCares(); - public: -# if defined AE_DISTILLATION - DnsResolverCares(ObjPtr aether, Domain* domain); -# endif + DnsResolverCares(Aether& aether, Domain* domain); ~DnsResolverCares() override; - AE_OBJECT_REFLECT(AE_MMBR(aether_)) - ActionPtr Resolve(NamedAddr const& name_address, std::uint16_t port_hint, Protocol protocol_hint) override; private: - Obj::ptr aether_; std::unique_ptr ares_impl_; }; } // namespace ae diff --git a/aether/dns/dns_resolve.cpp b/aether/dns/dns_resolve.cpp index 85bc2ab0..d6a2c31f 100644 --- a/aether/dns/dns_resolve.cpp +++ b/aether/dns/dns_resolve.cpp @@ -43,13 +43,7 @@ void ResolveAction::Failed() { this->Trigger(); } -ActionPtr DnsResolver::Resolve( - NamedAddr const& /* name_address */, std::uint16_t /* port_hint */, - Protocol /* protocol_hint */) { - // must be overridden - assert(false); - return {}; -} +DnsResolver::DnsResolver(Domain* domain) : Obj{domain} {} } // namespace ae #endif diff --git a/aether/dns/dns_resolve.h b/aether/dns/dns_resolve.h index fe8c551e..a7b581e2 100644 --- a/aether/dns/dns_resolve.h +++ b/aether/dns/dns_resolve.h @@ -22,7 +22,8 @@ #include "aether/config.h" #include "aether/obj/obj.h" -#include "aether/obj/dummy_obj.h" +#include "aether/obj/dummy_obj.h" // IWYU pragma: keep + #if AE_SUPPORT_CLOUD_DNS # include "aether/types/address.h" # include "aether/actions/action.h" @@ -52,31 +53,22 @@ class DnsResolver : public Obj { AE_OBJECT(DnsResolver, Obj, 0) protected: - DnsResolver() = default; - public: -# if defined AE_DISTILLATION - explicit DnsResolver(Domain* domain) : Obj{domain} {} -# endif + explicit DnsResolver(Domain* domain); ~DnsResolver() override = default; - AE_OBJECT_REFLECT() - // Make a host name resolve virtual ActionPtr Resolve(NamedAddr const& name_address, std::uint16_t port_hint, - Protocol protocol_hint); + Protocol protocol_hint) = 0; }; } // namespace ae #else namespace ae { class DnsResolver : public DummyObj { AE_OBJECT(DnsResolver, DummyObj, 0) - public: using DummyObj::DummyObj; - - AE_OBJECT_REFLECT() }; } // namespace ae #endif diff --git a/aether/dns/esp32_dns_resolve.cpp b/aether/dns/esp32_dns_resolve.cpp index 7c4d7d07..e8c9ae16 100644 --- a/aether/dns/esp32_dns_resolve.cpp +++ b/aether/dns/esp32_dns_resolve.cpp @@ -172,22 +172,16 @@ class GethostByNameDnsResolver { MultiSubscription multi_subscription_; }; -Esp32DnsResolver::Esp32DnsResolver() = default; - -# ifdef AE_DISTILLATION -Esp32DnsResolver::Esp32DnsResolver(ObjPtr aether, Domain* domain) - : DnsResolver{domain}, aether_{std::move(aether)} {} -# endif +Esp32DnsResolver::Esp32DnsResolver(Aether& aether, Domain* domain) + : DnsResolver{domain}, + gethostbyname_dns_resolver_{ + std::make_unique(aether)} {} Esp32DnsResolver::~Esp32DnsResolver() = default; ActionPtr Esp32DnsResolver::Resolve( NamedAddr const& name_address, std::uint16_t port_hint, Protocol protocol_hint) { - if (!gethostbyname_dns_resolver_) { - gethostbyname_dns_resolver_ = - std::make_unique(*aether_.as()); - } return gethostbyname_dns_resolver_->Query(name_address, port_hint, protocol_hint); } diff --git a/aether/dns/esp32_dns_resolve.h b/aether/dns/esp32_dns_resolve.h index 8a100062..bc786fc3 100644 --- a/aether/dns/esp32_dns_resolve.h +++ b/aether/dns/esp32_dns_resolve.h @@ -36,23 +36,15 @@ class GethostByNameDnsResolver; class Esp32DnsResolver : public DnsResolver { AE_OBJECT(Esp32DnsResolver, DnsResolver, 0) - Esp32DnsResolver(); - public: -# ifdef AE_DISTILLATION - Esp32DnsResolver(ObjPtr aether, Domain* domain); -# endif - + Esp32DnsResolver(Aether& aether, Domain* domain); ~Esp32DnsResolver() override; - AE_OBJECT_REFLECT(AE_MMBR(aether_)) - ActionPtr Resolve(NamedAddr const& name_address, std::uint16_t port_hint, Protocol protocol_hint) override; private: - Obj::ptr aether_; std::unique_ptr gethostbyname_dns_resolver_; }; } // namespace ae diff --git a/aether/global_ids.h b/aether/global_ids.h deleted file mode 100644 index aed5101b..00000000 --- a/aether/global_ids.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2024 Aethernet Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef AETHER_GLOBAL_IDS_H_ -#define AETHER_GLOBAL_IDS_H_ - -#include "aether/obj/obj_id.h" - -namespace ae { -static constexpr ObjId kGlobalIdAdaptersOffset{1000}; -static constexpr ObjId kGlobalIdFactoriesOffset{2000}; -static constexpr ObjId kGlobalIdCryptoOffset{3000}; -static constexpr ObjId kGlobalIdPollerOffset{4000}; -static constexpr ObjId kGlobalIdDnsResolverOffset{5000}; - -struct GlobalId { - static constexpr ObjId kAether{1}; - static constexpr ObjId kRegistrationCloud{2}; - static constexpr ObjId kTeleStatistics{3}; - static constexpr ObjId kEthernetAdapter = kGlobalIdAdaptersOffset + 1; - static constexpr ObjId kLanAdapter = kGlobalIdAdaptersOffset + 2; - static constexpr ObjId kWiFiAdapter = kGlobalIdAdaptersOffset + 3; - static constexpr ObjId kRegisterWifiAdapter = kGlobalIdAdaptersOffset + 4; - static constexpr ObjId kModemAdapter = kGlobalIdAdaptersOffset + 5; - static constexpr ObjId kRegisterModemAdapter = kGlobalIdAdaptersOffset + 6; - static constexpr ObjId kLoraModuleAdapter = kGlobalIdAdaptersOffset + 7; - static constexpr ObjId kRegisterLoraModuleAdapter = - kGlobalIdAdaptersOffset + 8; - - static constexpr ObjId kServerFactory = kGlobalIdFactoriesOffset + 0; - static constexpr ObjId kClientFactory = kGlobalIdFactoriesOffset + 1; - static constexpr ObjId kIpFactory = kGlobalIdFactoriesOffset + 2; - static constexpr ObjId kChannelFactory = kGlobalIdFactoriesOffset + 3; - static constexpr ObjId kProxyFactory = kGlobalIdFactoriesOffset + 5; - static constexpr ObjId kStatisticsFactory = kGlobalIdFactoriesOffset + 6; - - static constexpr ObjId kPoller = kGlobalIdPollerOffset + 0; - static constexpr ObjId kDnsResolver = kGlobalIdDnsResolverOffset + 0; - - static constexpr ObjId kCrypto = kGlobalIdCryptoOffset + 0; -}; - -} // namespace ae - -#endif // AETHER_GLOBAL_IDS_H_ */ diff --git a/aether/mstream.h b/aether/mstream.h index e7faab77..292ecbbc 100644 --- a/aether/mstream.h +++ b/aether/mstream.h @@ -70,17 +70,10 @@ class omstream : public ostream { void write(const void* data, size_t size) { ob_.write(data, size); } }; -enum class ReadResult { - kNo, - kYes, -}; - /** * struct IBuffer { * using size_type = std::uint32_t; * size_t read(void* data, size_t size, size_t minimum_size); - * ReadResult result() const; - * void result(ReadResult); }; */ @@ -92,26 +85,8 @@ class imstream : public istream { imstream(IBuffer& input_buffer) : ib_{input_buffer} {} void read(void* data, size_t size) { ib_.read(data, size); } - - ReadResult result() const { return ib_.result(); } - void result(ReadResult result) { ib_.result(result); } }; -template -inline bool data_was_read(TStream& /* is */) { - return true; -} - -template -inline bool data_was_read(imstream& is) { - return is.result() == ReadResult::kYes; -} - -template -inline bool data_was_written(TStream& /* s */) { - return true; -} - template struct omstream_enable_if : std::enable_if&> {}; @@ -174,9 +149,7 @@ imstream_enable_if_t::value, Ib> operator>>(imstream& s, using Type = typename std::underlying_type::type; Type t; s >> t; - if (s.result() == ReadResult::kYes) { - v = static_cast(t); - } + v = static_cast(t); return s; } @@ -220,10 +193,8 @@ template imstream& operator>>(imstream& s, std::string& t) { typename Ib::size_type size; s >> size; - if (data_was_read(s)) { - t.resize(static_cast(size)); - s.read(t.data(), static_cast(size)); - } + t.resize(static_cast(size)); + s.read(t.data(), static_cast(size)); return s; } @@ -247,10 +218,8 @@ imstream_enable_if_t, Ib> operator>>(imstream& s, std::vector& t) { typename Ib::size_type size; s >> size; - if (data_was_read(s)) { - t.resize(static_cast(size)); - s.read(reinterpret_cast(t.data()), t.size() * sizeof(T)); - } + t.resize(static_cast(size)); + s.read(reinterpret_cast(t.data()), t.size() * sizeof(T)); return s; } @@ -269,15 +238,9 @@ imstream_enable_if_t, Ib> operator>>(imstream& s, std::vector& t) { typename Ib::size_type size; s >> size; - if (!data_was_read(s)) { - return s; - } t.resize(static_cast(size)); for (auto& v : t) { s >> v; - if (!data_was_read(s)) { - break; - } } return s; } @@ -324,9 +287,6 @@ imstream_enable_if_t, Ib> operator>>(imstream& s, std::array& t) { for (auto& v : t) { s >> v; - if (!data_was_read(s)) { - break; - } } return s; } @@ -352,16 +312,10 @@ template imstream& operator>>(imstream& s, std::map& t) { typename Ib::size_type size{}; s >> size; - if (!data_was_read(s)) { - return s; - } t.clear(); for (uint32_t i = 0; i < static_cast(size); i++) { std::pair kv; s >> kv; - if (!data_was_read(s)) { - break; - } t.emplace(std::move(kv)); } return s; @@ -371,17 +325,11 @@ template imstream& operator>>(imstream& s, std::unordered_map& t) { typename Ib::size_type size{}; s >> size; - if (!data_was_read(s)) { - return s; - } t.clear(); t.reserve(static_cast(size)); for (auto i = 0; i < static_cast(size); ++i) { std::pair kv; s >> kv; - if (!data_was_read(s)) { - break; - } t.emplace(std::move(kv)); } return s; @@ -411,16 +359,10 @@ imstream& operator>>(imstream& s, std::deque& t) { typename Ib::size_type size; s >> size; - if (!data_was_read(s)) { - return s; - } t.resize(static_cast(size)); for (auto& v : t) { s >> v; - if (!data_was_read(s)) { - break; - } } return s; } @@ -439,16 +381,10 @@ imstream_enable_if_t, Ib>& operator>>( imstream& s, std::list& t) { typename Ib::size_type size; s >> size; - if (!data_was_read(s)) { - return s; - } t.clear(); for (uint32_t i = 0; i < size; i++) { T v; s >> v; - if (!data_was_read(s)) { - break; - } t.push_back(std::move(v)); } return s; @@ -485,9 +421,6 @@ template imstream& operator>>(imstream& s, std::chrono::time_point& t) { std::uint64_t tp; s >> tp; - if (!data_was_read(s)) { - return s; - } t = std::chrono::time_point(std::chrono::microseconds(tp)); return s; } @@ -518,15 +451,10 @@ template imstream& operator>>(imstream& s, std::unique_ptr& v) { bool has_value{}; s >> has_value; - if (!data_was_read(s)) { - return s; - } if (has_value) { auto temp = std::make_unique(); s >> *temp; - if (data_was_read(s)) { - v = std::move(temp); - } + v = std::move(temp); } return s; } @@ -535,15 +463,10 @@ template imstream& operator>>(imstream& s, std::shared_ptr& v) { bool has_value{}; s >> has_value; - if (!data_was_read(s)) { - return s; - } if (has_value) { auto temp = std::make_unique(); s >> *temp; - if (data_was_read(s)) { - v = std::move(temp); - } + v = std::move(temp); } return s; } diff --git a/aether/mstream_buffers.h b/aether/mstream_buffers.h index 7a9eba20..6747010e 100644 --- a/aether/mstream_buffers.h +++ b/aether/mstream_buffers.h @@ -19,8 +19,9 @@ #include #include +#include +#include -#include "aether/mstream.h" #include "aether/memory_buffer.h" namespace ae { @@ -45,26 +46,19 @@ struct VectorWriter { template struct VectorReader { using size_type = SizeType; - std::vector const& data_; - std::size_t offset_ = 0; - ReadResult result_{}; - VectorReader(std::vector const& data) : data_(data) {} + VectorReader(std::vector const& d) : data{d} {} virtual ~VectorReader() = default; - size_t read(void* data, size_t size) { - if (offset_ + size > data_.size()) { - result_ = ReadResult::kNo; - return 0; - } - std::memcpy(data, data_.data() + offset_, size); - offset_ += size; - result_ = ReadResult::kYes; + size_t read(void* d, size_t size) { + assert(((offset + size) <= data.size()) && "Read overflow"); + std::memcpy(d, data.data() + offset, size); + offset += size; return size; } - ReadResult result() const { return result_; } - void result(ReadResult result) { result_ = result; } + std::vector const& data; + std::size_t offset = 0; }; /** @@ -98,33 +92,24 @@ template struct MemStreamReader { using size_type = SizeType; - MemStreamBuf<> buffer_; - - ReadResult read_result_{}; - size_t add_data(uint8_t const* data, size_t size) { // expand buffer with new data - auto s = buffer_.sputn(reinterpret_cast(data), - static_cast(size)); + auto s = buffer.sputn(reinterpret_cast(data), + static_cast(size)); return static_cast(s); } - void reset_read() { buffer_.pubseekpos(0, std::ios_base::in); } - void reset_write() { buffer_.pubseekpos(0, std::ios_base::out); } + void reset_read() { buffer.pubseekpos(0, std::ios_base::in); } + void reset_write() { buffer.pubseekpos(0, std::ios_base::out); } size_t read(void* dst, size_t size) { - auto s = buffer_.sgetn(static_cast(dst), - static_cast(size)); - if (s != size) { - read_result_ = ReadResult::kNo; - } else { - read_result_ = ReadResult::kYes; - } + auto s = buffer.sgetn(static_cast(dst), + static_cast(size)); + assert((s == size) && "Read overflow"); return static_cast(s); } - ReadResult result() const { return read_result_; } - void result(ReadResult result) { read_result_ = result; } + MemStreamBuf<> buffer; }; template diff --git a/aether/poller/epoll_poller.cpp b/aether/poller/epoll_poller.cpp index e0eb309c..9d170238 100644 --- a/aether/poller/epoll_poller.cpp +++ b/aether/poller/epoll_poller.cpp @@ -23,7 +23,6 @@ # include # include -# include # include # include # include @@ -198,30 +197,17 @@ class EpollPoller::PollWorker { std::thread thread_; }; -EpollPoller::EpollPoller() = default; - -# if defined AE_DISTILLATION -EpollPoller::EpollPoller(Domain* domain) : IPoller(domain) {} -# endif +EpollPoller::EpollPoller(Domain* domain) + : IPoller(domain), poll_worker_{std::make_unique()} {} EpollPoller::~EpollPoller() = default; EpollPoller::OnPollEventSubscriber EpollPoller::Add(DescriptorType descriptor) { - if (!poll_worker_) { - InitPollWorker(); - } return poll_worker_->Add(descriptor); } void EpollPoller::Remove(DescriptorType descriptor) { - if (!poll_worker_) { - return; - } poll_worker_->Remove(descriptor); } - -void EpollPoller::InitPollWorker() { - poll_worker_ = std::make_unique(); -} } // namespace ae #endif diff --git a/aether/poller/epoll_poller.h b/aether/poller/epoll_poller.h index 5142e2a8..042b4438 100644 --- a/aether/poller/epoll_poller.h +++ b/aether/poller/epoll_poller.h @@ -31,23 +31,14 @@ class EpollPoller : public IPoller { class PollWorker; - EpollPoller(); - public: -# if defined AE_DISTILLATION explicit EpollPoller(Domain* domain); -# endif - ~EpollPoller() override; - AE_OBJECT_REFLECT() - [[nodiscard]] OnPollEventSubscriber Add(DescriptorType descriptor) override; void Remove(DescriptorType descriptor) override; private: - void InitPollWorker(); - std::unique_ptr poll_worker_; }; diff --git a/aether/poller/freertos_poller.cpp b/aether/poller/freertos_poller.cpp index 95d0b7c5..5619a9ec 100644 --- a/aether/poller/freertos_poller.cpp +++ b/aether/poller/freertos_poller.cpp @@ -51,14 +51,14 @@ inline int MakeListenPart() { } fcntl(l_socket, F_SETFL, O_NONBLOCK); auto const addr = MakeLoopbackAddr(); - if (bind(l_socket, reinterpret_cast(&addr), sizeof(addr)) != + if (bind(l_socket, reinterpret_cast(&addr), sizeof(addr)) != 0) { AE_TELED_ERROR("Bind listen socket failed with {}", errno); close(l_socket); assert(false); return -1; } - if (connect(l_socket, reinterpret_cast(&addr), + if (connect(l_socket, reinterpret_cast(&addr), sizeof(addr)) != 0) { AE_TELED_ERROR("Create socket failed with {}", errno); close(l_socket); @@ -73,13 +73,13 @@ inline std::array MakePipe() { return {sock, sock}; } -inline void WritePipe(std::array const &pipe) { +inline void WritePipe(std::array const& pipe) { if (pipe[1] != -1) { send(pipe[1], "1", 1, 0); } } -inline void ReadPipe(std::array const &pipe) { +inline void ReadPipe(std::array const& pipe) { if (pipe[0] != -1) { std::uint8_t buff[16]; auto n = recv(pipe[0], &buff, sizeof(buff), 0); @@ -87,7 +87,7 @@ inline void ReadPipe(std::array const &pipe) { } } -inline void ClosePipe(std::array &pipe) { +inline void ClosePipe(std::array& pipe) { if (pipe[1] != -1) { close(pipe[1]); pipe[1] = -1; @@ -99,7 +99,7 @@ inline void ClosePipe(std::array &pipe) { } } // namespace freertos_poller_internal -void vTaskFunction(void *pvParameters); +void vTaskFunction(void* pvParameters); class FreertosPoller::PollWorker { public: @@ -109,8 +109,8 @@ class FreertosPoller::PollWorker { assert(wake_up_pipe_[0] != -1); assert(wake_up_pipe_[1] != -1); - xTaskCreate(static_cast(&vTaskFunction), "Poller loop", - 4096, static_cast(this), tskIDLE_PRIORITY, + xTaskCreate(static_cast(&vTaskFunction), "Poller loop", + 4096, static_cast(this), tskIDLE_PRIORITY, &myTaskHandle_); AE_TELE_DEBUG(kFreertosWorkerCreate, "Poll worker was created"); } @@ -161,7 +161,7 @@ class FreertosPoller::PollWorker { continue; } - for (auto const &v : fds_vector) { + for (auto const& v : fds_vector) { if ((v.fd == wake_up_pipe_[0])) { if ((v.revents & POLLIN) != 0) { freertos_poller_internal::ReadPipe(wake_up_pipe_); @@ -176,7 +176,7 @@ class FreertosPoller::PollWorker { } private: - std::vector FillFdsVector(std::set const &descriptors) { + std::vector FillFdsVector(std::set const& descriptors) { std::vector fds; fds.reserve(descriptors_.size() + 1); { @@ -187,7 +187,7 @@ class FreertosPoller::PollWorker { fds.push_back(pfd); } - for (const auto &desc : descriptors) { + for (const auto& desc : descriptors) { pollfd pfd; pfd.fd = desc; pfd.events = POLLIN | POLLOUT; @@ -222,40 +222,27 @@ class FreertosPoller::PollWorker { OnPollEvent poll_event_; }; -void vTaskFunction(void *pvParameters) { - FreertosPoller::PollWorker *poller; +void vTaskFunction(void* pvParameters) { + FreertosPoller::PollWorker* poller; - poller = static_cast(pvParameters); + poller = static_cast(pvParameters); poller->Loop(); } -FreertosPoller::FreertosPoller() = default; - -# if defined AE_DISTILLATION -FreertosPoller::FreertosPoller(Domain *domain) : IPoller(domain) {} -# endif +FreertosPoller::FreertosPoller(Domain* domain) + : IPoller(domain), poll_worker_{std::make_unique()} {} FreertosPoller::~FreertosPoller() = default; FreertosPoller::OnPollEventSubscriber FreertosPoller::Add( DescriptorType descriptor) { - if (!poll_worker_) { - InitPollWorker(); - } return poll_worker_->Add(descriptor); } void FreertosPoller::Remove(DescriptorType descriptor) { - if (!poll_worker_) { - return; - } poll_worker_->Remove(descriptor); } - -void FreertosPoller::InitPollWorker() { - poll_worker_ = std::make_unique(); -} } // namespace ae #endif diff --git a/aether/poller/freertos_poller.h b/aether/poller/freertos_poller.h index 9deab6ff..560443d8 100644 --- a/aether/poller/freertos_poller.h +++ b/aether/poller/freertos_poller.h @@ -28,25 +28,16 @@ namespace ae { class FreertosPoller : public IPoller { AE_OBJECT(FreertosPoller, IPoller, 0) - - FreertosPoller(); + class PollWorker; public: - class PollWorker; -# if defined AE_DISTILLATION explicit FreertosPoller(Domain* domain); -# endif - ~FreertosPoller() override; - AE_OBJECT_REFLECT() - [[nodiscard]] OnPollEventSubscriber Add(DescriptorType descriptor) override; void Remove(DescriptorType descriptor) override; private: - void InitPollWorker(); - std::unique_ptr poll_worker_; }; diff --git a/aether/poller/kqueue_poller.cpp b/aether/poller/kqueue_poller.cpp index 5933ecee..75f7d32a 100644 --- a/aether/poller/kqueue_poller.cpp +++ b/aether/poller/kqueue_poller.cpp @@ -24,7 +24,6 @@ # include # include -# include # include # include # include @@ -177,31 +176,18 @@ class KqueuePoller::PollerWorker { std::thread thread_; }; -KqueuePoller::KqueuePoller() = default; - -# if defined AE_DISTILLATION -KqueuePoller::KqueuePoller(Domain* domain) : IPoller(domain) {} -# endif +KqueuePoller::KqueuePoller(Domain* domain) + : IPoller(domain), poller_worker_{std::make_unique()} {} KqueuePoller::~KqueuePoller() = default; [[nodiscard]] KqueuePoller::OnPollEventSubscriber KqueuePoller::Add( DescriptorType descriptor) { - if (!poller_worker_) { - InitPollWorker(); - } return poller_worker_->Add(descriptor); } void KqueuePoller::Remove(DescriptorType descriptor) { - if (!poller_worker_) { - return; - } poller_worker_->Remove(descriptor); } - -void KqueuePoller::InitPollWorker() { - poller_worker_ = std::make_unique(); -} } // namespace ae #endif diff --git a/aether/poller/kqueue_poller.h b/aether/poller/kqueue_poller.h index 75c762df..9d0c1947 100644 --- a/aether/poller/kqueue_poller.h +++ b/aether/poller/kqueue_poller.h @@ -30,22 +30,14 @@ class KqueuePoller : public IPoller { class PollerWorker; - KqueuePoller(); - public: -# if defined AE_DISTILLATION KqueuePoller(Domain* domain); -# endif ~KqueuePoller() override; - AE_OBJECT_REFLECT() - [[nodiscard]] OnPollEventSubscriber Add(DescriptorType descriptor) override; void Remove(DescriptorType descriptor) override; private: - void InitPollWorker(); - std::unique_ptr poller_worker_; }; } // namespace ae diff --git a/aether/poller/poller.cpp b/aether/poller/poller.cpp index 4ae8b912..ccdf9c96 100644 --- a/aether/poller/poller.cpp +++ b/aether/poller/poller.cpp @@ -17,21 +17,6 @@ #include "aether/poller/poller.h" namespace ae { -#if defined AE_DISTILLATION IPoller::IPoller(Domain* domain) : Obj{domain} {} -#endif IPoller::~IPoller() = default; - -[[noreturn]] IPoller::OnPollEventSubscriber no_return_subscriber() { - std::abort(); -} - -IPoller::OnPollEventSubscriber IPoller::Add(DescriptorType /* descriptor */) { - assert(false); - // this must never invoked - return no_return_subscriber(); -} - -void IPoller::Remove(DescriptorType /* descriptor */) { assert(false); } - } // namespace ae diff --git a/aether/poller/poller.h b/aether/poller/poller.h index c2cf08ed..b97dd3ed 100644 --- a/aether/poller/poller.h +++ b/aether/poller/poller.h @@ -24,10 +24,6 @@ namespace ae { class IPoller : public Obj { AE_OBJECT(IPoller, Obj, 0) - - protected: - IPoller() = default; - public: /** * \brief Event type for event. @@ -36,22 +32,19 @@ class IPoller : public Obj { using OnPollEvent = Event; using OnPollEventSubscriber = typename OnPollEvent::Subscriber; -#if defined AE_DISTILLATION explicit IPoller(Domain* domain); -#endif ~IPoller() override; - AE_OBJECT_REFLECT() - /** * \brief Add event for descriptor * User must subscribe to returned event subscriber, \see OnPollEvent */ - [[nodiscard]] virtual OnPollEventSubscriber Add(DescriptorType descriptor); + [[nodiscard]] virtual OnPollEventSubscriber Add( + DescriptorType descriptor) = 0; /** * \brief Remove event for descriptor */ - virtual void Remove(DescriptorType descriptor); + virtual void Remove(DescriptorType descriptor) = 0; }; } // namespace ae diff --git a/aether/poller/win_poller.cpp b/aether/poller/win_poller.cpp index baf5eb9c..e7db3824 100644 --- a/aether/poller/win_poller.cpp +++ b/aether/poller/win_poller.cpp @@ -150,25 +150,16 @@ class WinPoller::IoCPPoller { std::thread loop_thread_; }; -WinPoller::WinPoller() = default; - -# if defined AE_DISTILLATION -WinPoller::WinPoller(Domain* domain) : IPoller(domain) {} -# endif +WinPoller::WinPoller(Domain* domain) + : IPoller(domain), iocp_poller_{std::make_unique()} {} WinPoller::~WinPoller() = default; WinPoller::OnPollEventSubscriber WinPoller::Add(DescriptorType descriptor) { - if (!iocp_poller_) { - iocp_poller_ = std::make_unique(); - } return iocp_poller_->Add(descriptor); } void WinPoller::Remove(DescriptorType descriptor) { - if (!iocp_poller_) { - return; - } iocp_poller_->Remove(descriptor); } diff --git a/aether/poller/win_poller.h b/aether/poller/win_poller.h index 84778164..b89ac5df 100644 --- a/aether/poller/win_poller.h +++ b/aether/poller/win_poller.h @@ -44,16 +44,10 @@ class WinPoller : public IPoller { class IoCPPoller; - WinPoller(); - public: -# if defined AE_DISTILLATION explicit WinPoller(Domain* domain); -# endif ~WinPoller() override; - AE_OBJECT_REFLECT() - OnPollEventSubscriber Add(DescriptorType descriptor) override; void Remove(DescriptorType descriptor) override; diff --git a/aether/ptr/rc_ptr.h b/aether/ptr/rc_ptr.h index e8b98f0c..e2f1b206 100644 --- a/aether/ptr/rc_ptr.h +++ b/aether/ptr/rc_ptr.h @@ -288,15 +288,11 @@ template imstream& operator>>(imstream& s, RcPtr& v) { bool has_value{}; s >> has_value; - if (!data_was_read(s)) { - return s; - } + if (has_value) { auto temp = MakeRcPtr(); s >> *temp; - if (data_was_read(s)) { - v = std::move(temp); - } + v = std::move(temp); } return s; } diff --git a/aether/registration/registration.cpp b/aether/registration/registration.cpp index 2cb91a45..7318eca2 100644 --- a/aether/registration/registration.cpp +++ b/aether/registration/registration.cpp @@ -38,15 +38,12 @@ namespace ae { -Registration::Registration(ActionContext action_context, - ObjPtr const& aether, - RegistrationCloud::ptr const& reg_cloud, - Uid parent_uid, Client::ptr client) +Registration::Registration(ActionContext action_context, Aether& aether, + Cloud& reg_cloud, std::shared_ptr client) : Action{action_context}, action_context_{action_context}, - aether_{aether}, + aether_{&aether}, client_{std::move(client)}, - parent_uid_{std::move(parent_uid)}, root_crypto_provider_{std::make_unique()}, global_crypto_provider_{std::make_unique()}, client_root_api_{protocol_context_, *root_crypto_provider_->decryptor(), @@ -58,15 +55,14 @@ Registration::Registration(ActionContext action_context, state_{State::kInitConnection}, // TODO: add configuration response_timeout_{std::chrono::seconds(20)}, - sign_pk_{aether_.Lock()->crypto->signs_pk_[kDefaultSignatureMethod]} { + sign_pk_{aether_->crypto->signs_pk_[kDefaultSignatureMethod]} { AE_TELE_INFO(RegisterStarted); // parent uid must not be empty - assert(!parent_uid_.empty()); + assert(!client_->parent_uid().empty()); // trigger action on state change - state_change_subscription_ = - state_.changed_event().Subscribe([this](auto) { Action::Trigger(); }); + state_.changed_event().Subscribe([this](auto) { Action::Trigger(); }); } Registration::~Registration() { AE_TELED_DEBUG("~Registration"); } @@ -111,7 +107,7 @@ UpdateStatus Registration::Update() { return {}; } -Client::ptr Registration::client() const { return client_; } +std::shared_ptr Registration::client() const { return client_; } void Registration::InitConnection() { AE_TELED_DEBUG("Registration::InitConnection"); @@ -208,7 +204,7 @@ void Registration::RequestPowParams() { SubApi{[this, &ret_key](ApiContext& server_api) { server_api->set_return_key(std::move(ret_key)); auto pow_params_promise = server_api->request_proof_of_work_data( - parent_uid_, PowMethod::kBCryptCrc32); + client_->parent_uid(), PowMethod::kBCryptCrc32); response_sub_ = pow_params_promise->StatusEvent().Subscribe(ActionHandler{ OnResult{[&](auto& promise) { @@ -269,7 +265,8 @@ void Registration::MakeRegistration() { kDefaultCryptoLibProfile, SubApi{[this, &proofs](ApiContext& server_api) { server_api->registration( - pow_params_.salt, pow_params_.password_suffix, proofs, parent_uid_, + pow_params_.salt, pow_params_.password_suffix, proofs, + client_->parent_uid(), SubApi{[this](ApiContext& global_api) { // set master key and wait for confirmation global_api->set_master_key(master_key_); @@ -332,20 +329,15 @@ void Registration::OnCloudResolved( std::vector const& servers) { AE_TELE_INFO(RegisterResolveCloudResponse); - auto aether = aether_.Lock(); - if (!aether) { - return; - } - - Cloud::ptr new_cloud = aether->domain_->CreateObj(); - assert(new_cloud); + auto new_cloud = + std::make_unique(*aether_, uid_, aether_->domain_); - std::vector server_objects; + std::vector> server_objects; server_objects.reserve(servers.size()); for (const auto& description : servers) { auto server_id = description.server_id; - auto cached_server = aether->GetServer(server_id); + auto cached_server = aether_->GetServer(server_id); if (cached_server) { AE_TELED_DEBUG("Use cached server {}", cached_server->server_id); server_objects.emplace_back(cached_server); @@ -363,18 +355,17 @@ void Registration::OnCloudResolved( AE_TELED_DEBUG("Got server endpoints {}", endpoints); - Server::ptr server = - aether->domain_->CreateObj(server_id, std::move(endpoints)); - assert(server); - server->Register(aether->adapter_registry); - aether->AddServer(server); + auto server = + std::make_shared(server_id, std::move(endpoints), + aether_->adapter_registry, aether_->domain_); + aether_->AddServer(server); server_objects.emplace_back(std::move(server)); } // sort server objects by order of client_cloud_ std::sort( std::begin(server_objects), std::end(server_objects), - [this](Server::ptr const& left, Server::ptr const& right) { + [this](auto const& left, auto const& right) { auto left_order = std::find(std::begin(client_cloud_), std::end(client_cloud_), left->server_id); auto right_order = std::find(std::begin(client_cloud_), @@ -382,7 +373,7 @@ void Registration::OnCloudResolved( return left_order < right_order; }); - new_cloud->AddServers(std::move(server_objects)); + new_cloud->SetServers(std::move(server_objects)); client_->SetConfig(uid_, ephemeral_uid_, master_key_, std::move(new_cloud)); AE_TELE_DEBUG(RegisterClientRegistered, diff --git a/aether/registration/registration.h b/aether/registration/registration.h index a80cb2d6..157fb59b 100644 --- a/aether/registration/registration.h +++ b/aether/registration/registration.h @@ -25,14 +25,10 @@ # include "aether/common.h" # include "aether/memory.h" -# include "aether/ptr/ptr.h" # include "aether/types/uid.h" -# include "aether/ptr/ptr_view.h" # include "aether/actions/action.h" # include "aether/actions/action_ptr.h" -# include "aether/stream_api/istream.h" # include "aether/types/state_machine.h" -# include "aether/events/multi_subscription.h" # include "aether/client.h" # include "aether/registration_cloud.h" @@ -60,14 +56,13 @@ class Registration final : public Action { }; public: - Registration(ActionContext action_context, ObjPtr const& aether, - RegistrationCloud::ptr const& reg_cloud, Uid parent_uid, - Client::ptr client); + Registration(ActionContext action_context, Aether& aether, Cloud& reg_cloud, + std::shared_ptr client); ~Registration() override; UpdateStatus Update(); - Client::ptr client() const; + std::shared_ptr client() const; private: void InitConnection(); @@ -80,9 +75,8 @@ class Registration final : public Action { void OnCloudResolved(std::vector const& servers); ActionContext action_context_; - PtrView aether_; - Ptr client_; - Uid parent_uid_; + Aether* aether_; + std::shared_ptr client_; ProtocolContext protocol_context_; @@ -114,7 +108,6 @@ class Registration final : public Action { Subscription raw_transport_send_action_subscription_; Subscription reg_server_write_subscription_; Subscription response_sub_; - Subscription state_change_subscription_; }; } // namespace ae diff --git a/aether/registration/root_server_select_stream.cpp b/aether/registration/root_server_select_stream.cpp index ce848278..21566841 100644 --- a/aether/registration/root_server_select_stream.cpp +++ b/aether/registration/root_server_select_stream.cpp @@ -21,9 +21,9 @@ # include "aether/tele/tele.h" namespace ae { -RootServerSelectStream::RootServerSelectStream( - ActionContext action_context, RegistrationCloud::ptr const& cloud) - : action_context_{action_context}, cloud_{cloud}, server_index_{} { +RootServerSelectStream::RootServerSelectStream(ActionContext action_context, + Cloud& cloud) + : action_context_{action_context}, cloud_{&cloud}, server_index_{} { SelectServer(); } @@ -59,16 +59,13 @@ RootServerSelectStream::server_changed_event() { } void RootServerSelectStream::SelectServer() { - RegistrationCloud::ptr cloud_ptr = cloud_.Lock(); - assert(cloud_ptr); - - if (server_index_ >= cloud_ptr->servers().size()) { + if (server_index_ >= cloud_->servers().size()) { StreamUpdateError(); return; } - auto chosen_server = cloud_ptr->servers()[server_index_++]; + auto chosen_server = cloud_->servers()[server_index_++]; - server_stream_.emplace(action_context_, chosen_server); + server_stream_.emplace(action_context_, *chosen_server); stream_update_sub_ = server_stream_->stream_update_event().Subscribe( MethodPtr<&RootServerSelectStream::StreamUpdate>{this}); out_data_sub_ = server_stream_->out_data_event().Subscribe(out_data_event_); diff --git a/aether/registration/root_server_select_stream.h b/aether/registration/root_server_select_stream.h index 980f9714..b4b1e46c 100644 --- a/aether/registration/root_server_select_stream.h +++ b/aether/registration/root_server_select_stream.h @@ -35,8 +35,7 @@ class RootServerSelectStream final : public ByteIStream { public: using ServerChangedEvent = Event; - RootServerSelectStream(ActionContext action_context, - RegistrationCloud::ptr const& cloud); + RootServerSelectStream(ActionContext action_context, Cloud& cloud); ActionPtr Write(DataBuffer&& data) override; StreamInfo stream_info() const override; @@ -52,7 +51,7 @@ class RootServerSelectStream final : public ByteIStream { void StreamUpdateError(); ActionContext action_context_; - PtrView cloud_; + Cloud* cloud_; std::size_t server_index_; std::optional server_stream_; diff --git a/aether/registration/root_server_stream.cpp b/aether/registration/root_server_stream.cpp index 666dec96..d440a35c 100644 --- a/aether/registration/root_server_stream.cpp +++ b/aether/registration/root_server_stream.cpp @@ -20,8 +20,7 @@ namespace ae { -RootServerStream::RootServerStream(ActionContext action_context, - ObjPtr const& server) +RootServerStream::RootServerStream(ActionContext action_context, Server& server) : action_context_{action_context}, channel_manager_{action_context, server}, channel_select_stream_{action_context, channel_manager_} {} diff --git a/aether/registration/root_server_stream.h b/aether/registration/root_server_stream.h index f1040d36..638aaacf 100644 --- a/aether/registration/root_server_stream.h +++ b/aether/registration/root_server_stream.h @@ -29,7 +29,7 @@ class Server; class RootServerStream final : public ByteIStream { public: - RootServerStream(ActionContext action_context, ObjPtr const& server); + RootServerStream(ActionContext action_context, Server& server); ActionPtr Write(DataBuffer&& data) override; StreamInfo stream_info() const override; diff --git a/aether/registration_cloud.cpp b/aether/registration_cloud.cpp index c1b5e4cd..0bd7e1bc 100644 --- a/aether/registration_cloud.cpp +++ b/aether/registration_cloud.cpp @@ -24,18 +24,18 @@ namespace ae { -# ifdef AE_DISTILLATION -RegistrationCloud::RegistrationCloud(ObjPtr aether, Domain* domain) - : Cloud{domain}, aether_{std::move(aether)} {} -# endif +RegistrationCloud::RegistrationCloud(Aether& aether, Domain* domain) + : Cloud{domain}, aether_{&aether} {} void RegistrationCloud::AddServerSettings(Endpoint address) { // don't care about server id for registration - auto server = - domain_->CreateObj(ServerId{0}, std::vector{std::move(address)}); - server->Register(aether_.as()->adapter_registry); + servers_.emplace_back(std::make_shared( + ServerId{0}, std::vector{std::move(address)}, + aether_->adapter_registry, domain_)); +} - AddServer(server); +std::vector>& RegistrationCloud::servers() { + return servers_; } } // namespace ae diff --git a/aether/registration_cloud.h b/aether/registration_cloud.h index 06e45a5e..a4a8c391 100644 --- a/aether/registration_cloud.h +++ b/aether/registration_cloud.h @@ -27,22 +27,19 @@ namespace ae { class Aether; -class RegistrationCloud : public Cloud { +class RegistrationCloud final : public Cloud { AE_OBJECT(RegistrationCloud, Cloud, 0) - RegistrationCloud() = default; - public: -# ifdef AE_DISTILLATION - explicit RegistrationCloud(ObjPtr aether, Domain* domain); -# endif - - AE_OBJECT_REFLECT(AE_MMBRS(aether_)); + RegistrationCloud(Aether& aether, Domain* domain); void AddServerSettings(Endpoint address); + std::vector>& servers() override; + private: - Obj::ptr aether_; + Aether* aether_; + std::vector> servers_; }; } // namespace ae #else @@ -52,8 +49,6 @@ class RegistrationCloud : public DummyObj { public: using DummyObj::DummyObj; - - AE_OBJECT_REFLECT() }; } // namespace ae #endif // AE_SUPPORT_REGISTRATION diff --git a/aether/serial_ports/serial_port_factory.cpp b/aether/serial_ports/serial_port_factory.cpp index 0fdd6fb0..5b1846db 100644 --- a/aether/serial_ports/serial_port_factory.cpp +++ b/aether/serial_ports/serial_port_factory.cpp @@ -25,8 +25,9 @@ namespace ae { std::unique_ptr SerialPortFactory::CreatePort( - [[maybe_unused]] ActionContext action_context, IPoller::ptr const& poller, - SerialInit const& serial_init) { + [[maybe_unused]] ActionContext action_context, + [[maybe_unused]] IPoller& poller, + [[maybe_unused]] SerialInit const& serial_init) { #if WIN_SERIAL_PORT_ENABLED == 1 return std::make_unique(action_context, serial_init, poller); #elif ESP32_SERIAL_PORT_ENABLED == 1 diff --git a/aether/serial_ports/serial_port_factory.h b/aether/serial_ports/serial_port_factory.h index 6beaf37c..046b467e 100644 --- a/aether/serial_ports/serial_port_factory.h +++ b/aether/serial_ports/serial_port_factory.h @@ -28,7 +28,7 @@ namespace ae { class SerialPortFactory { public: static std::unique_ptr CreatePort(ActionContext action_context, - IPoller::ptr const& poller, + IPoller& poller, SerialInit const& serial_init); }; } // namespace ae diff --git a/aether/serial_ports/unix_serial_port.cpp b/aether/serial_ports/unix_serial_port.cpp index a11afb1f..126c8e0c 100644 --- a/aether/serial_ports/unix_serial_port.cpp +++ b/aether/serial_ports/unix_serial_port.cpp @@ -34,10 +34,8 @@ UnixSerialPort::ReadAction::ReadAction(ActionContext action_context, if (serial_port_->fd_ == kInvalidPort) { return; } - auto poller = serial_port_->poller_.Lock(); - assert(poller); poll_sub_ = - poller->Add({serial_port_->fd_}) + serial_port_->poller_->Add({serial_port_->fd_}) .Subscribe( MethodPtr<&UnixSerialPort::ReadAction::ReadAction::PollEvent>{ this}); @@ -85,11 +83,10 @@ void UnixSerialPort::ReadAction::ReadData() { } UnixSerialPort::UnixSerialPort(ActionContext action_context, - SerialInit serial_init, - IPoller::ptr const& poller) + SerialInit serial_init, IPoller& poller) : action_context_{action_context}, serial_init_{std::move(serial_init)}, - poller_{poller}, + poller_{&poller}, fd_{OpenPort(serial_init_)}, read_action_{action_context_, *this} {} diff --git a/aether/serial_ports/unix_serial_port.h b/aether/serial_ports/unix_serial_port.h index 32b8f00e..d7450284 100644 --- a/aether/serial_ports/unix_serial_port.h +++ b/aether/serial_ports/unix_serial_port.h @@ -25,7 +25,6 @@ # include # include -# include "aether/ptr/ptr_view.h" # include "aether/actions/action.h" # include "aether/actions/action_ptr.h" # include "aether/actions/action_context.h" @@ -54,7 +53,7 @@ class UnixSerialPort final : public ISerialPort { public: explicit UnixSerialPort(ActionContext action_context, SerialInit serial_init, - IPoller::ptr const& poller); + IPoller& poller); ~UnixSerialPort() override; void Write(DataBuffer const& data) override; @@ -71,7 +70,7 @@ class UnixSerialPort final : public ISerialPort { ActionContext action_context_; SerialInit serial_init_; - PtrView poller_; + IPoller* poller_; std::mutex fd_lock_; int fd_; diff --git a/aether/serial_ports/win_serial_port.cpp b/aether/serial_ports/win_serial_port.cpp index ffdaad7a..9dc95457 100644 --- a/aether/serial_ports/win_serial_port.cpp +++ b/aether/serial_ports/win_serial_port.cpp @@ -24,7 +24,7 @@ namespace ae { WinSerialPort::ReadAction::ReadAction(ActionContext action_context, - WinSerialPort &serial_port) + WinSerialPort& serial_port) : Action{action_context}, serial_port_{&serial_port}, read_event_{}, @@ -33,10 +33,8 @@ WinSerialPort::ReadAction::ReadAction(ActionContext action_context, if (serial_port_->fd_ == INVALID_HANDLE_VALUE) { return; } - auto poller = serial_port_->poller_.Lock(); - assert(poller); poll_sub_ = - poller->Add({serial_port_->fd_}) + serial_port_->poller_->Add({serial_port_->fd_}) .Subscribe( MethodPtr<&WinSerialPort::ReadAction::ReadAction::PollEvent>{ this}); @@ -47,7 +45,7 @@ WinSerialPort::ReadAction::ReadAction(ActionContext action_context, UpdateStatus WinSerialPort::ReadAction::Update() { if (read_event_) { - for (auto const &b : buffers_) { + for (auto const& b : buffers_) { serial_port_->read_event_.Emit(b); } buffers_.clear(); @@ -77,7 +75,7 @@ void WinSerialPort::ReadAction::ReadData() { void WinSerialPort::ReadAction::RequestRead() { DWORD dwErr, dwRead, fRes; - OVERLAPPED *overlapped_rd = reinterpret_cast(&overlapped_rd_); + OVERLAPPED* overlapped_rd = reinterpret_cast(&overlapped_rd_); if (serial_port_->fd_ == INVALID_HANDLE_VALUE) { AE_TELE_ERROR(kAdapterSerialNotOpen, "Port is not open"); @@ -105,7 +103,7 @@ void WinSerialPort::ReadAction::RequestRead() { void WinSerialPort::ReadAction::HandleRead() { DWORD dwErr; DWORD dwRead; - OVERLAPPED *overlapped_rd = reinterpret_cast(&overlapped_rd_); + OVERLAPPED* overlapped_rd = reinterpret_cast(&overlapped_rd_); if (!::GetOverlappedResult(serial_port_->fd_, overlapped_rd, &dwRead, FALSE)) { @@ -127,16 +125,16 @@ void WinSerialPort::ReadAction::HandleRead() { } WinSerialPort::WinSerialPort(ActionContext action_context, - SerialInit serial_init, IPoller::ptr const &poller) + SerialInit serial_init, IPoller& poller) : action_context_{action_context}, serial_init_{std::move(serial_init)}, - poller_{poller}, + poller_{&poller}, fd_{OpenPort(serial_init_)}, read_action_{action_context_, *this} {} WinSerialPort::~WinSerialPort() { Close(); } -void WinSerialPort::Write(DataBuffer const &data) { +void WinSerialPort::Write(DataBuffer const& data) { DWORD dwWrite, dwErr, dwRes; BOOL fSuccess{FALSE}; @@ -207,9 +205,9 @@ WinSerialPort::DataReadEvent::Subscriber WinSerialPort::read_event() { bool WinSerialPort::IsOpen() { return fd_ != INVALID_HANDLE_VALUE; } -void *WinSerialPort::OpenPort(SerialInit const &serial_init) { +void* WinSerialPort::OpenPort(SerialInit const& serial_init) { /* open the port */ - void *fd; + void* fd; std::string full_name = "\\\\.\\" + serial_init.port_name; fd = CreateFileA(full_name.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, @@ -234,7 +232,7 @@ void *WinSerialPort::OpenPort(SerialInit const &serial_init) { return fd; } -bool WinSerialPort::SetOptions(void *fd, SerialInit const &serial_init) { +bool WinSerialPort::SetOptions(void* fd, SerialInit const& serial_init) { // void WINSerialPort::ConfigurePort(std::uint32_t baud_rate) { DCB dcb{}; if (!GetCommState(fd, &dcb)) { diff --git a/aether/serial_ports/win_serial_port.h b/aether/serial_ports/win_serial_port.h index d969bb01..eadd30f7 100644 --- a/aether/serial_ports/win_serial_port.h +++ b/aether/serial_ports/win_serial_port.h @@ -65,7 +65,7 @@ class WinSerialPort final : public ISerialPort { public: explicit WinSerialPort(ActionContext action_context, SerialInit serial_init, - IPoller::ptr const& poller); + IPoller& poller); ~WinSerialPort() override; void Write(DataBuffer const& data) override; @@ -82,7 +82,7 @@ class WinSerialPort final : public ISerialPort { ActionContext action_context_; SerialInit serial_init_; - PtrView poller_; + IPoller* poller_; std::mutex fd_lock_; void* fd_; diff --git a/aether/server.cpp b/aether/server.cpp index 2bab0d4b..8f7c665f 100644 --- a/aether/server.cpp +++ b/aether/server.cpp @@ -17,56 +17,61 @@ #include "aether/server.h" #include +#include + +#include "aether/tele/tele.h" namespace ae { +Server::Server(ServerId server_id, + std::shared_ptr adapter_registry, + Domain* domain) + : Obj{domain}, + server_id{server_id}, + adapter_registry_{std::move(adapter_registry)} { + assert((server_id != 0) && "Server ID must be non-zero"); + domain_->Load(*this, Hash(kTypeName, server_id)); + AE_TELED_DEBUG("Loaded server id={}, endpoints={}", server_id, endpoints); + Register(); +} + Server::Server(ServerId server_id, std::vector endpoints, + std::shared_ptr adapter_registry, Domain* domain) : Obj{domain}, server_id{server_id}, endpoints{std::move(endpoints)}, - subscribed_{} {} + adapter_registry_{std::move(adapter_registry)} { + Register(); + domain_->Save(*this, Hash(kTypeName, server_id)); +} -void Server::Update(TimePoint current_time) { - if (!subscribed_) { - subscribed_ = true; - UpdateSubscription(); - } - update_time_ = current_time; +Server::ChannelsChanged::Subscriber Server::channels_changed() { + return EventSubscriber{channels_changed_}; } -void Server::Register(AdapterRegistry::ptr adapter_registry) { - adapter_registry_ = std::move(adapter_registry); +void Server::Register() { UpdateSubscription(); for (auto const& adapter : adapter_registry_->adapters()) { - for (auto const& ap : adapter->access_points()) { - AddChannels(ap); + for (auto* ap : adapter->access_points()) { + AddChannels(*ap); } } - subscribed_ = true; - channels_changed_.Emit(); -} - -Server::ChannelsChanged::Subscriber Server::channels_changed() { - return EventSubscriber{channels_changed_}; } void Server::UpdateSubscription() { - if (!adapter_registry_) { - domain_->LoadRoot(adapter_registry_); - } - assert(adapter_registry_); for (auto const& adapter : adapter_registry_->adapters()) { access_point_added_.Push(adapter->new_access_point().Subscribe( MethodPtr<&Server::AddChannels>{this})); } } -void Server::AddChannels(AccessPoint::ptr const& access_point) { - auto server_ptr = MakePtrFromThis(this); - auto new_channels = access_point->GenerateChannels(server_ptr); - channels.insert(std::end(channels), std::begin(new_channels), - std::end(new_channels)); +void Server::AddChannels(AccessPoint& access_point) { + auto new_channels = access_point.GenerateChannels(*this); + channels.reserve(channels.size() + new_channels.size()); + for (auto& ch : new_channels) { + channels.emplace_back(std::move(ch)); + } channels_changed_.Emit(); } diff --git a/aether/server.h b/aether/server.h index 181ad9de..ab07df36 100644 --- a/aether/server.h +++ b/aether/server.h @@ -30,34 +30,32 @@ namespace ae { class Server : public Obj { AE_OBJECT(Server, Obj, 0) - Server() = default; - public: using ChannelsChanged = Event; - explicit Server(ServerId server_id, std::vector endpoints, - Domain* domain); + Server(ServerId server_id, std::shared_ptr adapter_registry, + Domain* domain); - AE_OBJECT_REFLECT(AE_MMBRS(server_id, endpoints, adapter_registry_, channels)) + Server(ServerId server_id, std::vector endpoints, + std::shared_ptr adapter_registry, Domain* domain); - void Update(TimePoint current_time) override; + AE_REFLECT_MEMBERS(server_id, endpoints) - void Register(AdapterRegistry::ptr adapter_registry); ChannelsChanged::Subscriber channels_changed(); ServerId server_id; std::vector endpoints; - std::vector channels; + std::vector> channels; private: + void Register(); void UpdateSubscription(); - void AddChannels(AccessPoint::ptr const& access_point); + void AddChannels(AccessPoint& access_point); - AdapterRegistry::ptr adapter_registry_; + std::shared_ptr adapter_registry_; MultiSubscription access_point_added_; ChannelsChanged channels_changed_; - bool subscribed_; }; } // namespace ae #endif // AETHER_SERVER_H_ */ diff --git a/aether/server_connections/channel_connection.cpp b/aether/server_connections/channel_connection.cpp index 008a8fb9..cbcb7fd5 100644 --- a/aether/server_connections/channel_connection.cpp +++ b/aether/server_connections/channel_connection.cpp @@ -20,20 +20,15 @@ namespace ae { ChannelConnection::ChannelConnection(ActionContext action_context, - Channel::ptr const& channel) + Channel& channel) : connection_penalty{}, action_context_{action_context}, - channel_{channel} {} + channel_{&channel} {} -ObjPtr ChannelConnection::channel() const { - Channel::ptr channel = channel_.Lock(); - return channel; -} +Channel& ChannelConnection::channel() const { return *channel_; } std::unique_ptr ChannelConnection::GetServerChannel() { - Channel::ptr channel = channel_.Lock(); - assert(channel); - return std::make_unique(action_context_, channel); + return std::make_unique(action_context_, *channel_); } void ChannelConnection::Reset() { connection_penalty = 0; } diff --git a/aether/server_connections/channel_connection.h b/aether/server_connections/channel_connection.h index 301e2bec..d6b16949 100644 --- a/aether/server_connections/channel_connection.h +++ b/aether/server_connections/channel_connection.h @@ -18,7 +18,6 @@ #define AETHER_SERVER_CONNECTIONS_CHANNEL_CONNECTION_H_ #include "aether/common.h" -#include "aether/ptr/ptr_view.h" #include "aether/actions/action_context.h" #include "aether/server_connections/server_channel.h" @@ -27,12 +26,11 @@ namespace ae { class Channel; class ChannelConnection { public: - ChannelConnection(ActionContext action_context, - ObjPtr const& channel); + ChannelConnection(ActionContext action_context, Channel& channel); AE_CLASS_MOVE_ONLY(ChannelConnection) - ObjPtr channel() const; + Channel& channel() const; /** * \brief Return ServerChannel. @@ -48,7 +46,7 @@ class ChannelConnection { private: ActionContext action_context_; - PtrView channel_; + Channel* channel_; }; } // namespace ae diff --git a/aether/server_connections/channel_manager.cpp b/aether/server_connections/channel_manager.cpp index 76ce8305..349a5596 100644 --- a/aether/server_connections/channel_manager.cpp +++ b/aether/server_connections/channel_manager.cpp @@ -21,9 +21,8 @@ #include "aether/tele/tele.h" namespace ae { -ChannelManager::ChannelManager(ActionContext action_context, - ObjPtr const& server) - : action_context_(action_context), server_(server) { +ChannelManager::ChannelManager(ActionContext action_context, Server& server) + : action_context_{action_context}, server_{&server} { AE_TELED_DEBUG("Create channel manager"); InitChannels(); } @@ -31,13 +30,10 @@ ChannelManager::ChannelManager(ActionContext action_context, std::vector& ChannelManager::channels() { return channels_; } void ChannelManager::InitChannels() { - auto server = server_.Lock(); - assert(server); - // TODO: add update channels - channels_.reserve(server->channels.size()); - for (auto const& channel : server->channels) { - channels_.emplace_back(action_context_, channel); + channels_.reserve(server_->channels.size()); + for (auto const& channel : server_->channels) { + channels_.emplace_back(action_context_, *channel); } } diff --git a/aether/server_connections/channel_manager.h b/aether/server_connections/channel_manager.h index 2d1c42a0..7bc3ce9b 100644 --- a/aether/server_connections/channel_manager.h +++ b/aether/server_connections/channel_manager.h @@ -18,6 +18,7 @@ #define AETHER_SERVER_CONNECTIONS_CHANNEL_MANAGER_H_ #include +#include #include "aether/ptr/ptr_view.h" @@ -27,7 +28,7 @@ namespace ae { class Server; class ChannelManager { public: - ChannelManager(ActionContext action_context, ObjPtr const& server); + ChannelManager(ActionContext action_context, Server& server); std::vector& channels(); @@ -35,7 +36,7 @@ class ChannelManager { void InitChannels(); ActionContext action_context_; - PtrView server_; + Server* server_; std::vector channels_; }; } // namespace ae diff --git a/aether/server_connections/channel_selection_stream.cpp b/aether/server_connections/channel_selection_stream.cpp index b4d7d447..3688814d 100644 --- a/aether/server_connections/channel_selection_stream.cpp +++ b/aether/server_connections/channel_selection_stream.cpp @@ -102,21 +102,20 @@ ChannelSelectStream::TopChannel() { return false; } - auto props_a = a->channel()->transport_properties(); - auto props_b = b->channel()->transport_properties(); + auto props_a = a->channel().transport_properties(); + auto props_b = b->channel().transport_properties(); // select the fastest connection type if (props_a.connection_type > props_b.connection_type) { return true; } if (props_a.connection_type == props_b.connection_type) { // select the lower connection time - if (a->channel()->TransportBuildTimeout() < - b->channel()->TransportBuildTimeout()) { + if (a->channel().TransportBuildTimeout() < + b->channel().TransportBuildTimeout()) { return true; } // select the lower ping time - if (a->channel()->ResponseTimeout() < - b->channel()->ResponseTimeout()) { + if (a->channel().ResponseTimeout() < b->channel().ResponseTimeout()) { return true; } } @@ -147,7 +146,7 @@ void ChannelSelectStream::SelectChannel() { AE_TELED_DEBUG("New channel selected"); - auto const& tp = server_channel_->channel()->transport_properties(); + auto const& tp = server_channel_->channel().transport_properties(); stream_info_.max_element_size = tp.max_packet_size; stream_info_.rec_element_size = tp.rec_packet_size; stream_info_.is_reliable = (tp.reliability == Reliability::kReliable); diff --git a/aether/server_connections/client_server_connection.cpp b/aether/server_connections/client_server_connection.cpp index 49b27623..c195d06c 100644 --- a/aether/server_connections/client_server_connection.cpp +++ b/aether/server_connections/client_server_connection.cpp @@ -29,20 +29,18 @@ namespace ae { namespace _internal { class ClientKeyProvider : public ISyncKeyProvider { public: - explicit ClientKeyProvider(Ptr const& client, ServerId server_id) - : client_{client}, server_id_{server_id} {} + explicit ClientKeyProvider(Client& client, ServerId server_id) + : client_{&client}, server_id_{server_id} {} CryptoNonce const& Nonce() const override { - auto client_ptr = client_.Lock(); - assert(client_ptr); - auto* server_key = client_ptr->server_state(server_id_); + auto* server_key = client_->server_state(server_id_); assert(server_key); server_key->Next(); return server_key->nonce(); } protected: - PtrView client_; + Client* client_; ServerId server_id_; }; @@ -51,9 +49,7 @@ class ClientEncryptKeyProvider : public ClientKeyProvider { using ClientKeyProvider::ClientKeyProvider; Key GetKey() const override { - auto client_ptr = client_.Lock(); - assert(client_ptr); - auto const* server_key = client_ptr->server_state(server_id_); + auto const* server_key = client_->server_state(server_id_); assert(server_key); return server_key->client_to_server(); @@ -65,9 +61,7 @@ class ClientDecryptKeyProvider : public ClientKeyProvider { using ClientKeyProvider::ClientKeyProvider; Key GetKey() const override { - auto client_ptr = client_.Lock(); - assert(client_ptr); - auto const* server_key = client_ptr->server_state(server_id_); + auto const* server_key = client_->server_state(server_id_); assert(server_key); return server_key->server_to_client(); @@ -76,7 +70,7 @@ class ClientDecryptKeyProvider : public ClientKeyProvider { class ClientCryptoProvider final : public ICryptoProvider { public: - ClientCryptoProvider(Ptr const& client, ServerId server_id) + ClientCryptoProvider(Client& client, ServerId server_id) : encryptor_{std::make_unique(client, server_id)}, decryptor_{ @@ -93,13 +87,12 @@ class ClientCryptoProvider final : public ICryptoProvider { } // namespace _internal ClientServerConnection::ClientServerConnection(ActionContext action_context, - ObjPtr const& client, - Server::ptr const& server) + Client& client, Server& server) : action_context_{action_context}, - server_{server}, - ephemeral_uid_{client->ephemeral_uid()}, + server_{&server}, + ephemeral_uid_{client.ephemeral_uid()}, crypto_provider_{std::make_unique<_internal::ClientCryptoProvider>( - client, server->server_id)}, + client, server_->server_id)}, client_api_unsafe_{protocol_context_, *crypto_provider_->decryptor()}, login_api_{protocol_context_, action_context_, *crypto_provider_->encryptor()}, @@ -161,8 +154,6 @@ void ClientServerConnection::StreamUpdate() { server_channel_ = channel; AE_TELED_DEBUG("Channel is linked, make new ping"); - Server::ptr server = server_.Lock(); - assert(server); // Create new ping if channel is updated // TODO: add ping interval config ping_ = OwnActionPtr{action_context_, server_channel_->channel(), *this, diff --git a/aether/server_connections/client_server_connection.h b/aether/server_connections/client_server_connection.h index 8fcf6862..f43213a5 100644 --- a/aether/server_connections/client_server_connection.h +++ b/aether/server_connections/client_server_connection.h @@ -42,9 +42,8 @@ class Channel; */ class ClientServerConnection { public: - explicit ClientServerConnection(ActionContext action_context, - ObjPtr const& client, - ObjPtr const& server); + explicit ClientServerConnection(ActionContext action_context, Client& client, + Server& server); AE_CLASS_NO_COPY_MOVE(ClientServerConnection) @@ -62,7 +61,7 @@ class ClientServerConnection { void StreamUpdate(); ActionContext action_context_; - PtrView server_; + Server* server_; Uid ephemeral_uid_; std::unique_ptr crypto_provider_; diff --git a/aether/server_connections/iserver_connection_factory.h b/aether/server_connections/iserver_connection_factory.h index 3fe2b58f..fb4aed36 100644 --- a/aether/server_connections/iserver_connection_factory.h +++ b/aether/server_connections/iserver_connection_factory.h @@ -17,8 +17,9 @@ #ifndef AETHER_SERVER_CONNECTIONS_ISERVER_CONNECTION_FACTORY_H_ #define AETHER_SERVER_CONNECTIONS_ISERVER_CONNECTION_FACTORY_H_ +#include + #include "aether/ptr/rc_ptr.h" -#include "aether/obj/obj_ptr.h" #include "aether/server_connections/client_server_connection.h" namespace ae { @@ -28,7 +29,7 @@ class IServerConnectionFactory { virtual ~IServerConnectionFactory() = default; virtual RcPtr CreateConnection( - ObjPtr const& server) = 0; + std::shared_ptr const& server) = 0; }; } // namespace ae diff --git a/aether/server_connections/server_channel.cpp b/aether/server_connections/server_channel.cpp index 70efb322..d56a9719 100644 --- a/aether/server_connections/server_channel.cpp +++ b/aether/server_connections/server_channel.cpp @@ -21,16 +21,16 @@ #include "aether/tele/tele.h" namespace ae { -ServerChannel::ServerChannel(ActionContext action_context, - Channel::ptr const& channel) +ServerChannel::ServerChannel(ActionContext action_context, Channel& channel) : action_context_{action_context}, - channel_{channel}, - build_transport_action_{channel->TransportBuilder()}, + channel_{&channel}, + build_transport_action_{channel_->TransportBuilder()}, build_transport_sub_{ build_transport_action_->StatusEvent().Subscribe(ActionHandler{ OnResult{[this](auto& action) { OnTransportCreated(action); }}, OnError{[this]() { OnTransportCreateFailed(); }}})}, - transport_build_timer_{action_context_, channel->TransportBuildTimeout()}, + transport_build_timer_{action_context_, + channel_->TransportBuildTimeout()}, transport_build_timer_sub_{ transport_build_timer_->StatusEvent().Subscribe( OnResult{[this](auto const& timer) { @@ -41,11 +41,7 @@ ServerChannel::ServerChannel(ActionContext action_context, ByteIStream* ServerChannel::stream() { return transport_stream_.get(); } -ObjPtr ServerChannel::channel() const { - auto channel_ptr = channel_.Lock(); - assert(channel_ptr); - return channel_ptr; -} +Channel& ServerChannel::channel() const { return *channel_; } ServerChannel::ConnectionResult::Subscriber ServerChannel::connection_result() { return EventSubscriber{connection_result_event_}; @@ -58,9 +54,6 @@ void ServerChannel::OnTransportCreated( build_transport_sub_.Reset(); transport_build_timer_->Stop(); - auto channel_ptr = channel_.Lock(); - assert(channel_ptr); - transport_stream_ = transport_builder_action.transport_stream(); connection_result_event_.Emit(true); } diff --git a/aether/server_connections/server_channel.h b/aether/server_connections/server_channel.h index 005e988a..a54f65cc 100644 --- a/aether/server_connections/server_channel.h +++ b/aether/server_connections/server_channel.h @@ -17,12 +17,11 @@ #ifndef AETHER_SERVER_CONNECTIONS_SERVER_CHANNEL_H_ #define AETHER_SERVER_CONNECTIONS_SERVER_CHANNEL_H_ +#include #include #include "aether/common.h" #include "aether/memory.h" -#include "aether/obj/obj_ptr.h" -#include "aether/ptr/ptr_view.h" #include "aether/events/events.h" #include "aether/actions/action_ptr.h" #include "aether/actions/timer_action.h" @@ -38,7 +37,7 @@ class ServerChannel final { // Connected or not using ConnectionResult = Event; - ServerChannel(ActionContext action_context, ObjPtr const& channel); + ServerChannel(ActionContext action_context, Channel& channel); AE_CLASS_NO_COPY_MOVE(ServerChannel) @@ -46,7 +45,7 @@ class ServerChannel final { * \brief Get the channel stream. May be null. */ ByteIStream* stream(); - ObjPtr channel() const; + Channel& channel() const; ConnectionResult::Subscriber connection_result(); private: @@ -54,7 +53,7 @@ class ServerChannel final { void OnTransportCreateFailed(); ActionContext action_context_; - PtrView channel_; + Channel* channel_; std::unique_ptr transport_stream_; diff --git a/aether/server_connections/server_connection.cpp b/aether/server_connections/server_connection.cpp index 13453aa9..55320fc1 100644 --- a/aether/server_connections/server_connection.cpp +++ b/aether/server_connections/server_connection.cpp @@ -19,9 +19,9 @@ #include "aether/server.h" namespace ae { -ServerConnection::ServerConnection(ObjPtr const& server, +ServerConnection::ServerConnection(std::shared_ptr server, IServerConnectionFactory& connection_factory) - : server_{server}, + : server_{std::move(server)}, connection_factory_{&connection_factory}, priority_{}, is_connection_{}, @@ -41,10 +41,8 @@ void ServerConnection::Restream() { void ServerConnection::BeginConnection(std::size_t priority) { priority_ = priority; if (!is_connection_) { - Server::ptr server = server_.Lock(); - assert(server); client_connection_.Reset(); - client_connection_ = connection_factory_->CreateConnection(server); + client_connection_ = connection_factory_->CreateConnection(server_); } is_connection_ = true; } @@ -61,10 +59,6 @@ ClientServerConnection* ServerConnection::ClientConnection() { return nullptr; } -ObjPtr ServerConnection::server() const { - Server::ptr server = server_.Lock(); - assert(server); - return server; -} +std::shared_ptr ServerConnection::server() const { return server_; } } // namespace ae diff --git a/aether/server_connections/server_connection.h b/aether/server_connections/server_connection.h index a59b0691..d89410d0 100644 --- a/aether/server_connections/server_connection.h +++ b/aether/server_connections/server_connection.h @@ -18,7 +18,6 @@ #define AETHER_SERVER_CONNECTIONS_SERVER_CONNECTION_H_ #include "aether/ptr/rc_ptr.h" -#include "aether/obj/obj_ptr.h" #include "aether/ptr/ptr_view.h" #include "aether/server_connections/client_server_connection.h" #include "aether/server_connections/iserver_connection_factory.h" @@ -31,7 +30,7 @@ class Server; */ class ServerConnection { public: - ServerConnection(ObjPtr const& server, + ServerConnection(std::shared_ptr server, IServerConnectionFactory& connection_factory); std::size_t priority() const; @@ -68,10 +67,10 @@ class ServerConnection { */ ClientServerConnection* ClientConnection(); - ObjPtr server() const; + std::shared_ptr server() const; private: - PtrView server_; + std::shared_ptr server_; IServerConnectionFactory* connection_factory_; RcPtr client_connection_; std::size_t priority_; diff --git a/aether/stream_api/buffer_stream.h b/aether/stream_api/buffer_stream.h index 448ea2e5..51c52e01 100644 --- a/aether/stream_api/buffer_stream.h +++ b/aether/stream_api/buffer_stream.h @@ -169,7 +169,7 @@ class BufferStream final : public Stream { void UpdateStream() { auto out_info = Base::out_->stream_info(); - AE_TELED_DEBUG("Rec element size {}", out_info.rec_element_size); + AE_TELED_DEBUG("Link state is {}", out_info.link_state); if (last_out_stream_info_ != out_info) { stream_info_.link_state = out_info.link_state; stream_info_.is_reliable = out_info.is_reliable; diff --git a/aether/tele/tele_init.cpp b/aether/tele/tele_init.cpp index e5fc6fae..f65b6542 100644 --- a/aether/tele/tele_init.cpp +++ b/aether/tele/tele_init.cpp @@ -44,7 +44,7 @@ static void TeleSinkInit() { template static void TeleSinkReInit( - [[maybe_unused]] TeleStatistics::ptr const& tele_statistics) { + [[maybe_unused]] std::shared_ptr const& tele_statistics) { #if AE_TELE_ENABLED # if AE_TELE_LOG_CONSOLE // statistics trap + print logs to iostream @@ -68,7 +68,7 @@ static void TeleSinkReInit( } void TeleInit::Init() { TeleSinkInit(); } -void TeleInit::Init(TeleStatistics::ptr const& tele_statistics) { +void TeleInit::Init(std::shared_ptr const& tele_statistics) { TeleSinkReInit(tele_statistics); } diff --git a/aether/tele/tele_init.h b/aether/tele/tele_init.h index aa1605b3..42e96ae3 100644 --- a/aether/tele/tele_init.h +++ b/aether/tele/tele_init.h @@ -18,6 +18,7 @@ #define AETHER_TELE_TELE_INIT_H_ // IWYU pragma: begin_keeps +#include #include "aether/tele/tele.h" #include "aether/tele/traps/tele_statistics.h" // IWYU pragma: end_keeps @@ -25,7 +26,7 @@ namespace ae::tele { struct TeleInit { static void Init(); - static void Init(TeleStatistics::ptr const& tele_statistics); + static void Init(std::shared_ptr const& tele_statistics); }; } // namespace ae::tele diff --git a/aether/tele/traps/tele_statistics.cpp b/aether/tele/traps/tele_statistics.cpp index 9478357c..34bf84ff 100644 --- a/aether/tele/traps/tele_statistics.cpp +++ b/aether/tele/traps/tele_statistics.cpp @@ -17,9 +17,12 @@ #include "aether/tele/traps/tele_statistics.h" namespace ae::tele { -#ifdef AE_DISTILLATION -TeleStatistics::TeleStatistics(Domain* domain) : Obj{domain} {} -#endif +TeleStatistics::TeleStatistics(Domain* domain) : Obj{domain} { + domain_->Load(*this, Hash(kTypeName)); + // TODO: add save +} + +void TeleStatistics::Save() { domain_->Save(*this, Hash(kTypeName)); } #if AE_TELE_ENABLED std::shared_ptr const& TeleStatistics::trap() { diff --git a/aether/tele/traps/tele_statistics.h b/aether/tele/traps/tele_statistics.h index affa87ab..50a81a51 100644 --- a/aether/tele/traps/tele_statistics.h +++ b/aether/tele/traps/tele_statistics.h @@ -18,8 +18,6 @@ #define AETHER_TELE_TRAPS_TELE_STATISTICS_H_ #include "aether/obj/obj.h" -#include "aether/ptr/rc_ptr.h" -#include "aether/reflect/reflect.h" #include "aether/tele/tele.h" #include "aether/tele/traps/statistics_trap.h" @@ -31,23 +29,24 @@ class TeleStatistics : public Obj { TeleStatistics() = default; public: -#ifdef AE_DISTILLATION explicit TeleStatistics(Domain* domain); -#endif // AE_DISTILLATION -#if AE_TELE_ENABLED - AE_OBJECT_REFLECT(AE_MMBR(trap_)) + void Save(); +#if AE_TELE_ENABLED template void Load(CurrentVersion, Dnv& dnv) { - dnv(base_, *trap_); + dnv(*trap_); } template void Save(CurrentVersion, Dnv& dnv) const { - dnv(base_, *trap_); + dnv(*trap_); } #else - AE_OBJECT_REFLECT() + template + void Load(CurrentVersion, Dnv&) {} + template + void Save(CurrentVersion, Dnv&) const {} #endif #if AE_TELE_ENABLED diff --git a/aether/transport/data_packet_collector.cpp b/aether/transport/data_packet_collector.cpp index a1001041..999a5cd6 100644 --- a/aether/transport/data_packet_collector.cpp +++ b/aether/transport/data_packet_collector.cpp @@ -93,15 +93,12 @@ std::pair StreamDataPacketCollector::GetPacketSize( PacketSize packet_size; is >> packet_size; - if (!data_was_read(is)) { - return {0, size}; - } temp_data_buffer_.clear(); - assert((temp_buffer_size + size) >= reader.offset_); + assert((temp_buffer_size + size) >= reader.offset); return {static_cast(packet_size), - reader.offset_ - temp_buffer_size}; + reader.offset - temp_buffer_size}; } std::size_t StreamDataPacketCollector::WriteToPacket(Packet& packet, diff --git a/aether/transport/system_sockets/tcp/tcp.cpp b/aether/transport/system_sockets/tcp/tcp.cpp index 60072aca..8f2de692 100644 --- a/aether/transport/system_sockets/tcp/tcp.cpp +++ b/aether/transport/system_sockets/tcp/tcp.cpp @@ -87,24 +87,15 @@ void TcpTransport::ConnectionAction::Connect() { void TcpTransport::ConnectionAction::WaitConnection() { state_ = State::kWaitConnection; - auto poller_ptr = transport_->poller_.Lock(); - if (!poller_ptr) { - AE_TELED_ERROR("Poller is null"); - state_ = State::kConnectionFailed; - return; - } - poller_subscription_ = - poller_ptr->Add(static_cast(transport_->socket_)) + transport_->poller_->Add(static_cast(transport_->socket_)) .Subscribe([&](auto event) { if (event.descriptor != static_cast(transport_->socket_)) { return; } // remove poller first - auto poller_ptr = transport_->poller_.Lock(); - assert(poller_ptr); - poller_ptr->Remove( + transport_->poller_->Remove( static_cast(transport_->socket_)); state_ = State::kGetConnectionUpdate; }); @@ -227,11 +218,10 @@ void TcpTransport::ReadAction::DataReceived() { } } -TcpTransport::TcpTransport(ActionContext action_context, - IPoller::ptr const& poller, +TcpTransport::TcpTransport(ActionContext action_context, IPoller& poller, AddressPort const& endpoint) : action_context_{action_context}, - poller_{poller}, + poller_{&poller}, endpoint_{endpoint}, stream_info_{}, socket_{}, @@ -314,11 +304,8 @@ void TcpTransport::OnConnected() { Disconnect(); }}); - auto poller_ptr = poller_.Lock(); - assert(poller_ptr); - socket_poll_subscription_ = - poller_ptr->Add(static_cast(socket_)) + poller_->Add(static_cast(socket_)) .Subscribe([this](auto const& event) { if (event.descriptor != static_cast(socket_)) { return; @@ -359,9 +346,7 @@ void TcpTransport::Disconnect() { if (!socket_.IsValid()) { return; } - if (auto poller_ptr = poller_.Lock(); poller_ptr) { - poller_ptr->Remove(static_cast(socket_)); - } + poller_->Remove(static_cast(socket_)); socket_.Disconnect(); } diff --git a/aether/transport/system_sockets/tcp/tcp.h b/aether/transport/system_sockets/tcp/tcp.h index d82fc9e8..8914e8c3 100644 --- a/aether/transport/system_sockets/tcp/tcp.h +++ b/aether/transport/system_sockets/tcp/tcp.h @@ -28,7 +28,6 @@ # include # include "aether/common.h" -# include "aether/ptr/ptr_view.h" # include "aether/poller/poller.h" # include "aether/actions/action.h" # include "aether/actions/notify_action.h" @@ -115,7 +114,7 @@ class TcpTransport final : public ByteIStream { }; public: - TcpTransport(ActionContext action_context, IPoller::ptr const& poller, + TcpTransport(ActionContext action_context, IPoller& poller, AddressPort const& endpoint); ~TcpTransport() override; @@ -135,7 +134,7 @@ class TcpTransport final : public ByteIStream { void Disconnect(); ActionContext action_context_; - PtrView poller_; + IPoller* poller_; AddressPort endpoint_; StreamInfo stream_info_; diff --git a/aether/transport/system_sockets/udp/udp.cpp b/aether/transport/system_sockets/udp/udp.cpp index acabd400..1cbef27e 100644 --- a/aether/transport/system_sockets/udp/udp.cpp +++ b/aether/transport/system_sockets/udp/udp.cpp @@ -134,10 +134,10 @@ void UdpTransport::SendAction::Send() { state_ = State::kDone; } -UdpTransport::UdpTransport(ActionContext action_context, - IPoller::ptr const& poller, AddressPort endpoint) +UdpTransport::UdpTransport(ActionContext action_context, IPoller& poller, + AddressPort endpoint) : action_context_{std::move(action_context)}, - poller_{poller}, + poller_{&poller}, endpoint_{std::move(endpoint)}, send_queue_manager_{action_context_}, notify_error_action_{action_context_} { @@ -176,10 +176,8 @@ void UdpTransport::Connect() { Disconnect(); }}); - auto poller_ptr = poller_.Lock(); - assert(poller_ptr); socket_event_sub_ = - poller_ptr->Add(static_cast(socket_)) + poller_->Add(static_cast(socket_)) .Subscribe([this](PollerEvent event) { if (event.descriptor != static_cast(socket_)) { return; @@ -252,9 +250,7 @@ void UdpTransport::Disconnect() { if (!socket_.IsValid()) { return; } - if (auto poller_ptr = poller_.Lock(); poller_ptr) { - poller_ptr->Remove(static_cast(socket_)); - } + poller_->Remove(static_cast(socket_)); socket_.Disconnect(); } diff --git a/aether/transport/system_sockets/udp/udp.h b/aether/transport/system_sockets/udp/udp.h index e6e86923..28f65f1f 100644 --- a/aether/transport/system_sockets/udp/udp.h +++ b/aether/transport/system_sockets/udp/udp.h @@ -79,7 +79,7 @@ class UdpTransport : public ByteIStream { using ErrorEventAction = NotifyAction; public: - UdpTransport(ActionContext action_context, IPoller::ptr const& poller, + UdpTransport(ActionContext action_context, IPoller& poller, AddressPort endpoint); ~UdpTransport() override; @@ -98,7 +98,7 @@ class UdpTransport : public ByteIStream { void Disconnect(); ActionContext action_context_; - PtrView poller_; + IPoller* poller_; AddressPort endpoint_; std::mutex socket_mutex_; diff --git a/aether/work_cloud.cpp b/aether/work_cloud.cpp index 2beff20e..ed1e2acc 100644 --- a/aether/work_cloud.cpp +++ b/aether/work_cloud.cpp @@ -16,6 +16,42 @@ #include "aether/work_cloud.h" +#include "aether/aether.h" + +#include "aether/tele/tele.h" + namespace ae { -WorkCloud::WorkCloud(Domain* domain) : Cloud(domain) {} +WorkCloud::WorkCloud(Aether& aether, Uid uid, Domain* domain) + : Cloud(domain), aether_{&aether}, uid_{uid} { + domain_->Load(*this, Hash(kTypeName, uid_)); + if (cloud_.empty()) { + return; + } + AE_TELED_DEBUG("Loaded work cloud for uid {} sids [{}]", uid_, cloud_); + for (auto const& sid : cloud_) { + // check server in aether + auto s = aether_->GetServer(sid); + if (s) { + servers_.emplace_back(std::move(s)); + } else { + s = std::make_shared(sid, aether_->adapter_registry, domain_); + aether_->AddServer(s); + servers_.emplace_back(std::move(s)); + } + } +} + +void WorkCloud::SetServers(std::vector> servers) { + servers_ = std::move(servers); + cloud_.clear(); + for (auto const& server : servers_) { + cloud_.push_back(server->server_id); + } + // save cloud + domain_->Save(*this, Hash(kTypeName, uid_)); + cloud_updated_.Emit(); +} + +std::vector>& WorkCloud::servers() { return servers_; } + } // namespace ae diff --git a/aether/work_cloud.h b/aether/work_cloud.h index aa66a16f..66777df8 100644 --- a/aether/work_cloud.h +++ b/aether/work_cloud.h @@ -17,20 +17,28 @@ #ifndef AETHER_WORK_CLOUD_H_ #define AETHER_WORK_CLOUD_H_ -#include "aether/obj/obj.h" #include "aether/cloud.h" +#include "aether/types/uid.h" namespace ae { class Aether; -class WorkCloud : public Cloud { +class WorkCloud final : public Cloud { AE_OBJECT(WorkCloud, Cloud, 0) - WorkCloud() = default; - public: - explicit WorkCloud(Domain* domain); + explicit WorkCloud(Aether& aether, Uid uid, Domain* domain); + + AE_REFLECT_MEMBERS(cloud_) + + void SetServers(std::vector> servers); + std::vector>& servers() override; + + private: + Aether* aether_; + Uid uid_; - AE_OBJECT_REFLECT() + std::vector cloud_; + std::vector> servers_; }; } // namespace ae #endif // AETHER_WORK_CLOUD_H_ From bd03e2b496591b9325b5d2b4a00a2efe77e21202 Mon Sep 17 00:00:00 2001 From: BartolomeyKant Date: Fri, 19 Dec 2025 17:40:16 +0500 Subject: [PATCH 03/12] make examples build --- examples/benches/send_message_delays/main.cpp | 12 ++++++------ examples/benches/send_message_delays/receiver.cpp | 2 +- examples/benches/send_message_delays/receiver.h | 4 ++-- examples/benches/send_message_delays/sender.cpp | 2 +- examples/benches/send_message_delays/sender.h | 6 +++--- .../send_messages_bandwidth/receiver/receiver.cpp | 2 +- .../send_messages_bandwidth/receiver/receiver.h | 4 ++-- .../receiver/receiver_main.cpp | 4 ++-- .../send_messages_bandwidth/sender/sender.cpp | 2 +- .../benches/send_messages_bandwidth/sender/sender.h | 8 +++----- .../send_messages_bandwidth/sender/sender_main.cpp | 4 ++-- examples/capi/oddity/aether_oddity.c | 2 +- examples/cloud/aether_construct_ethernet.h | 8 ++++---- examples/cloud/cloud_test.cpp | 11 +++++------ 14 files changed, 34 insertions(+), 37 deletions(-) diff --git a/examples/benches/send_message_delays/main.cpp b/examples/benches/send_message_delays/main.cpp index f9bd73ed..3bbc1224 100644 --- a/examples/benches/send_message_delays/main.cpp +++ b/examples/benches/send_message_delays/main.cpp @@ -66,9 +66,9 @@ class TestSendMessageDelaysAction : public Action { private: void GetClients() { auto get_sender = aether_->SelectClient( - Uid::FromString("3ac93165-3d37-4970-87a6-fa4ee27744e4"), 1); + Uid::FromString("3ac93165-3d37-4970-87a6-fa4ee27744e4"), "Sender"); auto get_receiver = aether_->SelectClient( - Uid::FromString("3ac93165-3d37-4970-87a6-fa4ee27744e4"), 2); + Uid::FromString("3ac93165-3d37-4970-87a6-fa4ee27744e4"), "Receiver"); client_selected_event_.Connect( [&](auto client_setter, auto result) { @@ -152,13 +152,13 @@ class TestSendMessageDelaysAction : public Action { }}}); } - Aether::ptr aether_; + Aether* aether_; std::ostream& write_results_stream_; - Client::ptr client_sender_; - Client::ptr client_receiver_; + std::shared_ptr client_sender_; + std::shared_ptr client_receiver_; std::unique_ptr send_message_delays_manager_; - CumulativeEvent client_selected_event_; + CumulativeEvent, 2> client_selected_event_; Subscription clients_selected_sub_; Subscription test_result_sub_; StateMachine state_; diff --git a/examples/benches/send_message_delays/receiver.cpp b/examples/benches/send_message_delays/receiver.cpp index 26caca7b..eebbacac 100644 --- a/examples/benches/send_message_delays/receiver.cpp +++ b/examples/benches/send_message_delays/receiver.cpp @@ -27,7 +27,7 @@ #include "aether/tele/tele.h" namespace ae::bench { -Receiver::Receiver(ActionContext action_context, Client::ptr client, +Receiver::Receiver(ActionContext action_context, std::shared_ptr client, SafeStreamConfig safe_stream_config) : action_context_{action_context}, client_{std::move(client)}, diff --git a/examples/benches/send_message_delays/receiver.h b/examples/benches/send_message_delays/receiver.h index 72060a04..33d3636c 100644 --- a/examples/benches/send_message_delays/receiver.h +++ b/examples/benches/send_message_delays/receiver.h @@ -32,7 +32,7 @@ namespace ae::bench { class Receiver { public: - Receiver(ActionContext action_context, Client::ptr client, + Receiver(ActionContext action_context, std::shared_ptr client, SafeStreamConfig safe_stream_config); void Connect(); @@ -51,7 +51,7 @@ class Receiver { void OnRecvData(DataBuffer const& data); ActionContext action_context_; - Client::ptr client_; + std::shared_ptr client_; SafeStreamConfig safe_stream_config_; ProtocolContext protocol_context_; diff --git a/examples/benches/send_message_delays/sender.cpp b/examples/benches/send_message_delays/sender.cpp index 3af6d011..4a6ac667 100644 --- a/examples/benches/send_message_delays/sender.cpp +++ b/examples/benches/send_message_delays/sender.cpp @@ -27,7 +27,7 @@ #include "send_message_delays/api/bench_delays_api.h" namespace ae::bench { -Sender::Sender(ActionContext action_context, Client::ptr client, +Sender::Sender(ActionContext action_context, std::shared_ptr client, Uid destination_uid, SafeStreamConfig safe_stream_config) : action_context_{action_context}, client_{std::move(client)}, diff --git a/examples/benches/send_message_delays/sender.h b/examples/benches/send_message_delays/sender.h index a24f2b04..20889399 100644 --- a/examples/benches/send_message_delays/sender.h +++ b/examples/benches/send_message_delays/sender.h @@ -35,8 +35,8 @@ namespace ae::bench { class Sender { public: - Sender(ActionContext action_context, Client::ptr client, Uid destination_uid, - SafeStreamConfig safe_stream_config); + Sender(ActionContext action_context, std::shared_ptr client, + Uid destination_uid, SafeStreamConfig safe_stream_config); void ConnectP2pStream(); void ConnectP2pSafeStream(); @@ -54,7 +54,7 @@ class Sender { Duration min_send_interval); ActionContext action_context_; - Client::ptr client_; + std::shared_ptr client_; Uid destination_uid_; SafeStreamConfig safe_stream_config_; diff --git a/examples/benches/send_messages_bandwidth/receiver/receiver.cpp b/examples/benches/send_messages_bandwidth/receiver/receiver.cpp index af2a17e4..3582c8a7 100644 --- a/examples/benches/send_messages_bandwidth/receiver/receiver.cpp +++ b/examples/benches/send_messages_bandwidth/receiver/receiver.cpp @@ -22,7 +22,7 @@ #include "aether/tele/tele.h" namespace ae::bench { -Receiver::Receiver(ActionContext action_context, Client::ptr client) +Receiver::Receiver(ActionContext action_context, std::shared_ptr client) : action_context_{action_context}, client_{std::move(client)}, bandwidth_api_{action_context, protocol_context_} {} diff --git a/examples/benches/send_messages_bandwidth/receiver/receiver.h b/examples/benches/send_messages_bandwidth/receiver/receiver.h index 0b007c4b..3ad1c165 100644 --- a/examples/benches/send_messages_bandwidth/receiver/receiver.h +++ b/examples/benches/send_messages_bandwidth/receiver/receiver.h @@ -31,7 +31,7 @@ namespace ae::bench { class Receiver { public: - Receiver(ActionContext action_context, Client::ptr client); + Receiver(ActionContext action_context, std::shared_ptr client); EventSubscriber error_event(); @@ -48,7 +48,7 @@ class Receiver { void OnRecvData(DataBuffer const& data); ActionContext action_context_; - Client::ptr client_; + std::shared_ptr client_; ProtocolContext protocol_context_; BandwidthApi bandwidth_api_; diff --git a/examples/benches/send_messages_bandwidth/receiver/receiver_main.cpp b/examples/benches/send_messages_bandwidth/receiver/receiver_main.cpp index 026d93b9..d20a6257 100644 --- a/examples/benches/send_messages_bandwidth/receiver/receiver_main.cpp +++ b/examples/benches/send_messages_bandwidth/receiver/receiver_main.cpp @@ -26,11 +26,11 @@ namespace ae::bench { int test_receiver_bandwidth() { auto aether_app = ae::AetherApp::Construct(AetherAppContext{}); - ae::Client::ptr client; + std::shared_ptr client; // get one client auto get_client = aether_app->aether()->SelectClient( - Uid::FromString("3ac93165-3d37-4970-87a6-fa4ee27744e4"), 1); + Uid::FromString("3ac93165-3d37-4970-87a6-fa4ee27744e4"), "Receiver"); get_client->StatusEvent().Subscribe( OnResult{[&](auto const& reg) { client = reg.client(); }}); diff --git a/examples/benches/send_messages_bandwidth/sender/sender.cpp b/examples/benches/send_messages_bandwidth/sender/sender.cpp index a167cab9..22dfb1e7 100644 --- a/examples/benches/send_messages_bandwidth/sender/sender.cpp +++ b/examples/benches/send_messages_bandwidth/sender/sender.cpp @@ -23,7 +23,7 @@ #include "aether/tele/tele.h" namespace ae::bench { -Sender::Sender(ActionContext action_context, Client::ptr client, +Sender::Sender(ActionContext action_context, std::shared_ptr client, Uid destination) : action_context_{action_context}, client_{std::move(client)}, diff --git a/examples/benches/send_messages_bandwidth/sender/sender.h b/examples/benches/send_messages_bandwidth/sender/sender.h index 276341d4..343dc61c 100644 --- a/examples/benches/send_messages_bandwidth/sender/sender.h +++ b/examples/benches/send_messages_bandwidth/sender/sender.h @@ -17,12 +17,9 @@ #ifndef EXAMPLES_BENCHES_SEND_MESSAGES_BANDWIDTH_COMMON_SENDER_H_ #define EXAMPLES_BENCHES_SEND_MESSAGES_BANDWIDTH_COMMON_SENDER_H_ -#include - #include "aether/client.h" #include "aether/memory.h" #include "aether/events/events.h" -#include "aether/stream_api/istream.h" #include "aether/actions/action_context.h" #include "aether/actions/repeatable_task.h" #include "aether/events/event_subscription.h" @@ -36,7 +33,8 @@ namespace ae::bench { class Sender { public: - Sender(ActionContext action_context, Client::ptr client, Uid destination); + Sender(ActionContext action_context, std::shared_ptr client, + Uid destination); EventSubscriber error_event(); @@ -54,7 +52,7 @@ class Sender { void OnRecvData(DataBuffer const& data); ActionContext action_context_; - Client::ptr client_; + std::shared_ptr client_; Uid destination_; ProtocolContext protocol_context_; BandwidthApi bandwidth_api_; diff --git a/examples/benches/send_messages_bandwidth/sender/sender_main.cpp b/examples/benches/send_messages_bandwidth/sender/sender_main.cpp index 85cd184f..60bbca74 100644 --- a/examples/benches/send_messages_bandwidth/sender/sender_main.cpp +++ b/examples/benches/send_messages_bandwidth/sender/sender_main.cpp @@ -25,11 +25,11 @@ namespace ae::bench { int test_sender_bandwidth(Uid receiver_uid) { auto aether_app = ae::AetherApp::Construct(AetherAppContext{}); - ae::Client::ptr client; + std::shared_ptr client; // select one client auto select_client = aether_app->aether()->SelectClient( - Uid::FromString("3ac93165-3d37-4970-87a6-fa4ee27744e4"), 2); + Uid::FromString("3ac93165-3d37-4970-87a6-fa4ee27744e4"), "Sender"); select_client->StatusEvent().Subscribe( OnResult{[&](auto const& reg) { client = reg.client(); }}); diff --git a/examples/capi/oddity/aether_oddity.c b/examples/capi/oddity/aether_oddity.c index edf3c314..db9daf45 100644 --- a/examples/capi/oddity/aether_oddity.c +++ b/examples/capi/oddity/aether_oddity.c @@ -31,7 +31,7 @@ int AetherOddity(char const* destination_uid) { // Send a message and wait for response ClientConfig client_config = { - .id = 0, + .client_id = "tom", .parent_uid = CUidFromString("3ac93165-3d37-4970-87a6-fa4ee27744e4"), .message_received_cb = MessageReceived, }; diff --git a/examples/cloud/aether_construct_ethernet.h b/examples/cloud/aether_construct_ethernet.h index a70a9ec3..c8374e57 100644 --- a/examples/cloud/aether_construct_ethernet.h +++ b/examples/cloud/aether_construct_ethernet.h @@ -27,10 +27,10 @@ static RcPtr construct_aether_app() { # if defined AE_DISTILLATION .AdaptersFactory([](AetherAppContext const& context) { auto adapter_registry = - context.domain().CreateObj(); - adapter_registry->Add(context.domain().CreateObj( - GlobalId::kEthernetAdapter, context.aether(), context.poller(), - context.dns_resolver())); + std::make_shared(context.domain()); + adapter_registry->Add(std::make_shared( + *context.aether(), *context.poller(), *context.dns_resolver(), + context.domain())); return adapter_registry; }) # endif diff --git a/examples/cloud/cloud_test.cpp b/examples/cloud/cloud_test.cpp index 480731ca..46797bed 100644 --- a/examples/cloud/cloud_test.cpp +++ b/examples/cloud/cloud_test.cpp @@ -63,17 +63,17 @@ int AetherCloudExample() { * Clients might be loaded from data storage saved during previous run * or Registered if not found. */ - ae::Client::ptr client_a; - ae::Client::ptr client_b; + std::shared_ptr client_a; + std::shared_ptr client_b; auto select_client_a = aether_app->aether()->SelectClient( - ae::Uid::FromString("3ac93165-3d37-4970-87a6-fa4ee27744e4"), 0); + ae::Uid::FromString("3ac93165-3d37-4970-87a6-fa4ee27744e4"), "A"); select_client_a->StatusEvent().Subscribe(ae::ActionHandler{ ae::OnResult{[&](auto const& action) { client_a = action.client(); }}, ae::OnError{[&]() { aether_app->Exit(1); }}}); auto select_client_b = aether_app->aether()->SelectClient( - ae::Uid::FromString("3ac93165-3d37-4970-87a6-fa4ee27744e4"), 1); + ae::Uid::FromString("3ac93165-3d37-4970-87a6-fa4ee27744e4"), "B"); select_client_b->StatusEvent().Subscribe(ae::ActionHandler{ ae::OnResult{[&](auto const& action) { client_b = action.client(); }}, ae::OnError{[&]() { aether_app->Exit(1); }}}); @@ -170,8 +170,7 @@ int AetherCloudExample() { // Wait for next event or timeout auto current_time = ae::Now(); auto next_time = aether_app->Update(current_time); - aether_app->WaitUntil( - std::min(next_time, current_time + std::chrono::seconds{5})); + aether_app->WaitUntil(next_time); } return aether_app->ExitCode(); From c84b8c058bb22e5ef587a52ce1f9113b69786eff Mon Sep 17 00:00:00 2001 From: BartolomeyKant Date: Fri, 19 Dec 2025 17:40:33 +0500 Subject: [PATCH 04/12] make registrator build --- tools/registrator/register_wifi.cpp | 21 ++++------ tools/registrator/register_wifi.h | 16 +++---- tools/registrator/registrator.cpp | 53 +++++++++++------------- tools/registrator/registrator_action.cpp | 4 +- tools/registrator/registrator_action.h | 2 +- 5 files changed, 39 insertions(+), 57 deletions(-) diff --git a/tools/registrator/register_wifi.cpp b/tools/registrator/register_wifi.cpp index e2eb68f2..3eb199fc 100644 --- a/tools/registrator/register_wifi.cpp +++ b/tools/registrator/register_wifi.cpp @@ -20,26 +20,21 @@ namespace ae::registrator { -#ifdef AE_DISTILLATION -RegisterWifiAdapter::RegisterWifiAdapter(ObjPtr aether, - IPoller::ptr poller, - DnsResolver::ptr dns_resolver, +RegisterWifiAdapter::RegisterWifiAdapter(Aether& aether, IPoller& poller, + DnsResolver& dns_resolver, std::string ssid, std::string pass, Domain* domain) - : ParentWifiAdapter{std::move(aether), std::move(poller), - std::move(dns_resolver), std::move(ssid), - std::move(pass), domain}, - ethernet_adapter_{domain->CreateObj(aether_, poller_, - dns_resolver_)} {} -#endif // AE_DISTILLATION + : ParentWifiAdapter{aether, poller, dns_resolver, + std::move(ssid), std::move(pass), domain}, + ethernet_adapter_{*aether_, *poller_, *dns_resolver_, domain_} {} -std::vector RegisterWifiAdapter::access_points() { - return ethernet_adapter_->access_points(); +std::vector RegisterWifiAdapter::access_points() { + return ethernet_adapter_.access_points(); } RegisterWifiAdapter::NewAccessPoint::Subscriber RegisterWifiAdapter::new_access_point() { - return ethernet_adapter_->new_access_point(); + return ethernet_adapter_.new_access_point(); } } // namespace ae::registrator diff --git a/tools/registrator/register_wifi.h b/tools/registrator/register_wifi.h index 3b90889b..f787adf3 100644 --- a/tools/registrator/register_wifi.h +++ b/tools/registrator/register_wifi.h @@ -17,30 +17,24 @@ #ifndef REGISTRATOR_REGISTER_WIFI_H_ #define REGISTRATOR_REGISTER_WIFI_H_ -#include "aether/adapters/parent_wifi.h" #include "aether/adapters/ethernet.h" +#include "aether/adapters/parent_wifi.h" namespace ae::registrator { class RegisterWifiAdapter : public ParentWifiAdapter { AE_OBJECT(RegisterWifiAdapter, ParentWifiAdapter, 0) - RegisterWifiAdapter() = default; - public: -#ifdef AE_DISTILLATION - RegisterWifiAdapter(ObjPtr aether, IPoller::ptr poller, - DnsResolver::ptr dns_resolver, std::string ssid, + RegisterWifiAdapter(Aether& aether, IPoller& poller, + DnsResolver& dns_resolver, std::string ssid, std::string pass, Domain* domain); -#endif // AE_DISTILLATION - - AE_OBJECT_REFLECT(AE_MMBR(ethernet_adapter_)) - std::vector access_points() override; + std::vector access_points() override; NewAccessPoint::Subscriber new_access_point() override; private: // whose doing all job - EthernetAdapter::ptr ethernet_adapter_; + EthernetAdapter ethernet_adapter_; }; } // namespace ae::registrator diff --git a/tools/registrator/registrator.cpp b/tools/registrator/registrator.cpp index 0b383187..0607b68a 100644 --- a/tools/registrator/registrator.cpp +++ b/tools/registrator/registrator.cpp @@ -58,47 +58,42 @@ int AetherRegistrator(const std::string& ini_file, // empty tele initializer [](auto const&) {}} .AdaptersFactory([®istrator_config]( - ae::AetherAppContext const& context) - -> ae::AdapterRegistry::ptr { + ae::AetherAppContext const& context) { auto adapter_registry = - context.domain().CreateObj(); + std::make_shared(context.domain()); if (registrator_config.GetWiFiIsSet()) { AE_TELED_DEBUG("ae::registrator::RegisterWifiAdapter"); adapter_registry->Add( - context.domain() - .CreateObj( - ae::GlobalId::kRegisterWifiAdapter, context.aether(), - context.poller(), context.dns_resolver(), - registrator_config.GetWiFiSsid(), - registrator_config.GetWiFiPass())); + std::make_shared( + *context.aether(), *context.poller(), + *context.dns_resolver(), registrator_config.GetWiFiSsid(), + registrator_config.GetWiFiPass(), context.domain())); } else { AE_TELED_DEBUG("ae::EthernetAdapter"); - adapter_registry->Add( - context.domain().CreateObj( - ae::GlobalId::kEthernetAdapter, context.aether(), - context.poller(), context.dns_resolver())); + adapter_registry->Add(std::make_shared( + *context.aether(), *context.poller(), *context.dns_resolver(), + context.domain())); } return adapter_registry; }) - .RegistrationCloudFactory( - [®istrator_config](ae::AetherAppContext const& context) { - auto registration_cloud = - context.domain().CreateObj( - ae::GlobalId::kRegistrationCloud, context.aether()); + .RegistrationCloudFactory([®istrator_config]( + ae::AetherAppContext const& context) { + auto registration_cloud = std::make_shared( + *context.aether(), context.domain()); - auto servers_list = registrator_config.GetServers(); - for (auto s : servers_list) { - AE_TELED_DEBUG("Server address={}", s.server_ip_address); - AE_TELED_DEBUG("Server port={}", s.server_port); - AE_TELED_DEBUG("Server protocol={}", s.server_protocol); + auto servers_list = registrator_config.GetServers(); + for (auto s : servers_list) { + AE_TELED_DEBUG("Server address={}", s.server_ip_address); + AE_TELED_DEBUG("Server port={}", s.server_port); + AE_TELED_DEBUG("Server protocol={}", s.server_protocol); - ae::Endpoint settings{{s.server_ip_address, s.server_port}, - s.server_protocol}; - registration_cloud->AddServerSettings(settings); - } - return registration_cloud; - })); + ae::Endpoint settings{{s.server_ip_address, s.server_port}, + s.server_protocol}; + registration_cloud->AddServerSettings(settings); + } + return registration_cloud; + })); auto registrator_action = ae::ActionPtr{ *aether_app, aether_app, registrator_config}; diff --git a/tools/registrator/registrator_action.cpp b/tools/registrator/registrator_action.cpp index 7d4de099..ad1bd7a3 100644 --- a/tools/registrator/registrator_action.cpp +++ b/tools/registrator/registrator_action.cpp @@ -57,14 +57,12 @@ void RegistratorAction::RegisterClients() { // registration should be supported for this tool assert(false); #else - auto aether_ptr = aether_.Lock(); - assert(aether_ptr); for (auto const& p : registrator_config_.GetParents()) { auto parent_uid = ae::Uid::FromString(p.uid_str); auto clients_num = p.clients_num; for (auto i = 0; i < clients_num; i++) { - auto select_action = aether_ptr->SelectClient(parent_uid, i); + auto select_action = aether_->SelectClient(parent_uid, std::to_string(i)); registration_sub_.Push(select_action->StatusEvent().Subscribe( ActionHandler{OnResult{[this](auto const&) { diff --git a/tools/registrator/registrator_action.h b/tools/registrator/registrator_action.h index 04112e10..7efe2d60 100644 --- a/tools/registrator/registrator_action.h +++ b/tools/registrator/registrator_action.h @@ -38,7 +38,7 @@ class RegistratorAction : public Action { private: void RegisterClients(); - PtrView aether_; + Aether* aether_; RegistratorConfig registrator_config_; std::size_t clients_registered_{0}; From d0a6a75ada317e5098aa5ec7ba39d4623fdc6c5d Mon Sep 17 00:00:00 2001 From: BartolomeyKant Date: Fri, 19 Dec 2025 17:40:55 +0500 Subject: [PATCH 05/12] WIP on tests --- tests/test-api-protocol/assert_packet.h | 2 +- .../test_ds_synchronization.cpp | 100 +++++++----------- tests/test-object-system/CMakeLists.txt | 7 +- tests/test-object-system/main.cpp | 4 +- .../test-object-system/map_domain_storage.cpp | 88 +++++++-------- tests/test-object-system/map_domain_storage.h | 21 ++-- tests/test-object-system/test-obj-create.cpp | 3 +- .../test-tele-statistics.cpp | 44 ++++---- .../test-data-packet-collector.cpp | 1 - 9 files changed, 110 insertions(+), 160 deletions(-) diff --git a/tests/test-api-protocol/assert_packet.h b/tests/test-api-protocol/assert_packet.h index bbb8b491..34284b4b 100644 --- a/tests/test-api-protocol/assert_packet.h +++ b/tests/test-api-protocol/assert_packet.h @@ -59,7 +59,7 @@ void AssertPacket(std::vector const& data, Args const&... args) { ae::VectorReader ib{data}; imstream_t is{ib}; (AssertPacketEntry(is, args), ...); - TEST_ASSERT_EQUAL_MESSAGE(data.size(), ib.offset_, FUNCTION_NAME); + TEST_ASSERT_EQUAL_MESSAGE(data.size(), ib.offset, FUNCTION_NAME); UnitySetTestFile(old_file); } diff --git a/tests/test-domain-storage/test_ds_synchronization.cpp b/tests/test-domain-storage/test_ds_synchronization.cpp index b1ddeef7..5dcf80a5 100644 --- a/tests/test-domain-storage/test_ds_synchronization.cpp +++ b/tests/test-domain-storage/test_ds_synchronization.cpp @@ -50,26 +50,17 @@ std::vector DataGetter( return res; } -static constexpr auto classes_1 = std::array{100, 101}; -static constexpr auto classes_2 = std::array{200}; -static constexpr auto classes_3 = std::array{300, 302}; - static constexpr auto data_1 = std::array{4, 251, 12, 42, 11}; static constexpr auto data_2 = std::array{4, 252, 13, 42, 11}; static constexpr auto data_3 = std::array{4, 253, 14, 42, 11}; static constexpr auto data_4 = std::array{4, 254, 15, 42, 11}; static constexpr auto static_data = StaticDomainData{ - // object map - StaticMap{{ - std::pair{std::uint32_t{1}, Span{classes_1}}, - std::pair{std::uint32_t{2}, Span{classes_2}}, - }}, // data map StaticMap{{ - std::pair{ObjectPathKey{1, 100, 0}, Span{data_1}}, - std::pair{ObjectPathKey{1, 101, 0}, Span{data_2}}, - std::pair{ObjectPathKey{2, 200, 0}, Span{data_3}}, + std::pair{ObjectPathKey{1, 0}, Span{data_1}}, + std::pair{ObjectPathKey{2, 0}, Span{data_2}}, + std::pair{ObjectPathKey{3, 0}, Span{data_3}}, }}, }; @@ -77,72 +68,59 @@ template void TestSyncDataStorage(std::unique_ptr sds, std::unique_ptr rwds) { auto data_storage = SyncDomainStorage{std::move(sds), std::move(rwds)}; - // check enumeration - { - auto first = data_storage.Enumerate(ObjId{1}); - TEST_ASSERT_EQUAL_UINT32_ARRAY(classes_1.data(), first.data(), - classes_1.size()); - auto second = data_storage.Enumerate(ObjId{2}); - TEST_ASSERT_EQUAL_UINT32_ARRAY(classes_2.data(), second.data(), - classes_2.size()); - auto third = data_storage.Enumerate(ObjId{3}); - TEST_ASSERT(third.empty()); - } // get data { - auto load_1_100 = data_storage.Load({ObjId{1}, 100, 0}); - TEST_ASSERT(load_1_100.result == DomainLoadResult::kLoaded); - auto data_1_100 = DataGetter(load_1_100.reader); - TEST_ASSERT_EQUAL_UINT8_ARRAY(data_1.data(), data_1_100.data(), + auto load_1_0 = data_storage.Load(1, 0); + TEST_ASSERT(load_1_0.result == DomainLoadResult::kLoaded); + auto data_1_0 = DataGetter(load_1_0.reader); + TEST_ASSERT_EQUAL_UINT8_ARRAY(data_1.data(), data_1_0.data(), data_1.size()); - auto load_2_200 = data_storage.Load({ObjId{2}, 200, 0}); - TEST_ASSERT(load_2_200.result == DomainLoadResult::kLoaded); - auto data_2_200 = DataGetter(load_2_200.reader); - TEST_ASSERT_EQUAL_UINT8_ARRAY(data_3.data(), data_2_200.data(), - data_3.size()); + auto load_2_0 = data_storage.Load(2, 0); + TEST_ASSERT(load_2_0.result == DomainLoadResult::kLoaded); + auto data_2_0 = DataGetter(load_2_0.reader); + TEST_ASSERT_EQUAL_UINT8_ARRAY(data_2.data(), data_2_0.data(), + data_2.size()); - auto load_2_201 = data_storage.Load({ObjId{2}, 201, 0}); - TEST_ASSERT(load_2_201.result == DomainLoadResult::kEmpty); + auto load_2_1 = data_storage.Load(2, 1); + TEST_ASSERT(load_2_1.result == DomainLoadResult::kEmpty); } // add data and get after { - auto writer_2_201 = data_storage.Store({ObjId{2}, 201, 0}); - writer_2_201->write(data_4.data(), data_4.size()); - writer_2_201.reset(); - - auto load_2_201 = data_storage.Load({ObjId{2}, 201, 0}); - TEST_ASSERT(load_2_201.result == DomainLoadResult::kLoaded); - auto data_2_201 = DataGetter(load_2_201.reader); - TEST_ASSERT_EQUAL_UINT8_ARRAY(data_4.data(), data_2_201.data(), + auto writer_2_1 = data_storage.Store(2, 1); + writer_2_1->write(data_4.data(), data_4.size()); + writer_2_1.reset(); + + auto load_2_1 = data_storage.Load(2, 0); + TEST_ASSERT(load_2_1.result == DomainLoadResult::kLoaded); + auto data_2_1 = DataGetter(load_2_1.reader); + TEST_ASSERT_EQUAL_UINT8_ARRAY(data_4.data(), data_2_1.data(), data_4.size()); } // remove data and try to load { - data_storage.Remove(ObjId{1}); - auto load_1_100 = data_storage.Load({ObjId{1}, 100, 0}); - TEST_ASSERT(load_1_100.result == DomainLoadResult::kRemoved); - auto load_1_101 = data_storage.Load({ObjId{1}, 101, 0}); - TEST_ASSERT(load_1_101.result == DomainLoadResult::kRemoved); - auto load_2_200 = data_storage.Load({ObjId{2}, 200, 0}); - TEST_ASSERT(load_2_200.result == DomainLoadResult::kLoaded); + data_storage.Remove(1); + auto load_1_0 = data_storage.Load(1, 0); + TEST_ASSERT(load_1_0.result == DomainLoadResult::kRemoved); + auto load_2_0 = data_storage.Load(2, 0); + TEST_ASSERT(load_2_0.result == DomainLoadResult::kLoaded); } // add an object { - auto writer_3_300 = data_storage.Store({ObjId{3}, 300, 0}); - writer_3_300->write(data_4.data(), data_4.size()); - writer_3_300.reset(); - - auto load_3_300 = data_storage.Load({ObjId{3}, 300, 0}); - TEST_ASSERT(load_3_300.result == DomainLoadResult::kLoaded); - auto data_3_300 = DataGetter(load_3_300.reader); - TEST_ASSERT_EQUAL_UINT8_ARRAY(data_4.data(), data_3_300.data(), + auto writer_3_0 = data_storage.Store(3, 0); + writer_3_0->write(data_4.data(), data_4.size()); + writer_3_0.reset(); + + auto load_3_0 = data_storage.Load(3, 0); + TEST_ASSERT(load_3_0.result == DomainLoadResult::kLoaded); + auto data_3_0 = DataGetter(load_3_0.reader); + TEST_ASSERT_EQUAL_UINT8_ARRAY(data_4.data(), data_3_0.data(), data_4.size()); - load_3_300.reader.reset(); + load_3_0.reader.reset(); - data_storage.Remove(ObjId{3}); - auto load_3_300_r = data_storage.Load({ObjId{3}, 300, 0}); - TEST_ASSERT(load_3_300_r.result == DomainLoadResult::kRemoved); + data_storage.Remove(3); + auto load_3_0_r = data_storage.Load(3, 0); + TEST_ASSERT(load_3_0_r.result == DomainLoadResult::kRemoved); } } diff --git a/tests/test-object-system/CMakeLists.txt b/tests/test-object-system/CMakeLists.txt index 261a0bc9..ea970bad 100644 --- a/tests/test-object-system/CMakeLists.txt +++ b/tests/test-object-system/CMakeLists.txt @@ -23,17 +23,14 @@ list(APPEND obj_srcs ${ROOT_DIR}/aether/ptr/ptr.cpp ${ROOT_DIR}/aether/ptr/ptr_view.cpp ${ROOT_DIR}/aether/ptr/ref_tree.cpp - ${ROOT_DIR}/aether/obj/obj_ptr.cpp ${ROOT_DIR}/aether/obj/obj.cpp ${ROOT_DIR}/aether/obj/domain.cpp - ${ROOT_DIR}/aether/obj/obj_id.cpp - ${ROOT_DIR}/aether/obj/registry.cpp ) list(APPEND test_srcs main.cpp - test-obj-create.cpp - test-update-objects.cpp + # test-obj-create.cpp + # test-update-objects.cpp test-version-iterator.cpp map_domain_storage.cpp ) diff --git a/tests/test-object-system/main.cpp b/tests/test-object-system/main.cpp index 5f77783b..58046630 100644 --- a/tests/test-object-system/main.cpp +++ b/tests/test-object-system/main.cpp @@ -25,8 +25,8 @@ extern int run_test_version_iterator(); int main() { int res{}; - res += run_test_object_create(); + // res += run_test_object_create(); res += run_test_version_iterator(); - res += run_test_update_objects(); + // res += run_test_update_objects(); return res; } diff --git a/tests/test-object-system/map_domain_storage.cpp b/tests/test-object-system/map_domain_storage.cpp index 910c98e5..7c0b1b73 100644 --- a/tests/test-object-system/map_domain_storage.cpp +++ b/tests/test-object-system/map_domain_storage.cpp @@ -21,91 +21,79 @@ namespace ae { class MapDomainStorageWriter final : public IDomainStorageWriter { public: - MapDomainStorageWriter(DomainQuery q, MapDomainStorage& s) - : query{std::move(q)}, storage{&s}, vector_writer{data} {} + MapDomainStorageWriter(DataKey key, std::uint8_t version, MapDomainStorage& s) + : key{key}, version{version}, storage{&s}, vector_writer{data_buffer} {} ~MapDomainStorageWriter() override { - storage->SaveData(query, std::move(data)); + storage->SaveData(key, version, std::move(data_buffer)); } void write(void const* data, std::size_t size) override { vector_writer.write(data, size); } - DomainQuery query; + DataKey key; + std::uint8_t version; MapDomainStorage* storage; - ObjectData data; + DataValue data_buffer; VectorWriter vector_writer; }; class MapDomainStorageReader final : public IDomainStorageReader { public: - explicit MapDomainStorageReader(ObjectData const& d) - : data{&d}, reader{*data} {} + MapDomainStorageReader(DataValue const& d, MapDomainStorage& s) + : storage{&s}, data_buffer{&d}, reader{*data_buffer} {} void read(void* data, std::size_t size) override { reader.read(data, size); } - ReadResult result() const override { return ReadResult::kYes; } - void result(ReadResult) override {} - - ObjectData const* data; + MapDomainStorage* storage; + DataValue const* data_buffer; VectorReader reader; }; std::unique_ptr MapDomainStorage::Store( - DomainQuery const& query) { - return std::make_unique(query, *this); -} - -ClassList MapDomainStorage::Enumerate(ObjId const& obj_id) { - auto class_data_it = map.find(obj_id.id()); - if (class_data_it == std::end(map)) { - return {}; - } - ClassList classes; - classes.reserve(class_data_it->second.size()); - for (auto& [cls, _] : class_data_it->second) { - classes.push_back(cls); - } - return classes; + DataKey key, std::uint8_t version) { + return std::make_unique(key, version, *this); } -DomainLoad MapDomainStorage::Load(DomainQuery const& query) { - auto obj_map_it = map.find(query.id.id()); +DomainLoad MapDomainStorage::Load(DataKey key, std::uint8_t version) { + auto obj_map_it = map.find(key); if (obj_map_it == std::end(map)) { - return DomainLoad{DomainLoadResult::kEmpty, {}}; + return {DomainLoadResult::kEmpty, {}}; } - auto class_map_it = obj_map_it->second.find(query.class_id); - if (class_map_it == std::end(obj_map_it->second)) { - return DomainLoad{DomainLoadResult::kEmpty, {}}; + if (!obj_map_it->second) { + return {DomainLoadResult::kRemoved, {}}; } - auto version_it = class_map_it->second.find(query.version); - if (version_it == std::end(class_map_it->second)) { - return DomainLoad{DomainLoadResult::kEmpty, {}}; - } - if (!version_it->second) { - return DomainLoad{DomainLoadResult::kRemoved, {}}; + + auto version_it = obj_map_it->second->find(version); + if (version_it == std::end(*obj_map_it->second)) { + return {DomainLoadResult::kEmpty, {}}; } - return DomainLoad{ - DomainLoadResult::kLoaded, - std::make_unique(*version_it->second)}; + + return {DomainLoadResult::kLoaded, + std::make_unique(version_it->second, *this)}; } -void MapDomainStorage::Remove(ObjId const& obj_id) { - auto obj_map_it = map.find(obj_id.id()); +void MapDomainStorage::Remove(DataKey key) { + auto obj_map_it = map.find(key); if (obj_map_it == std::end(map)) { + // if there was no object, explicitly mark it as removed + map.emplace(key, std::nullopt); return; } - for (auto& [_, class_data] : obj_map_it->second) { - for (auto& [_, version_data] : class_data) { - version_data.reset(); - } - } + + obj_map_it->second.reset(); } void MapDomainStorage::CleanUp() { map.clear(); } -void MapDomainStorage::SaveData(DomainQuery const& query, ObjectData&& data) { - map[query.id.id()][query.class_id][query.version] = std::move(data); +void MapDomainStorage::SaveData(DataKey key, std::uint8_t version, + DataValue&& data) { + auto& versioned_data = map[key]; + if (!versioned_data) { + versioned_data.emplace(); + } + auto& saved = (*versioned_data)[version]; + saved = std::move(data); } } // namespace ae diff --git a/tests/test-object-system/map_domain_storage.h b/tests/test-object-system/map_domain_storage.h index 4bc0b5f1..be8dd83d 100644 --- a/tests/test-object-system/map_domain_storage.h +++ b/tests/test-object-system/map_domain_storage.h @@ -17,7 +17,6 @@ #ifndef TESTS_TEST_OBJECT_SYSTEM_MAP_DOMAIN_STORAGE_H_ #define TESTS_TEST_OBJECT_SYSTEM_MAP_DOMAIN_STORAGE_H_ -#include #include #include #include @@ -28,20 +27,16 @@ namespace ae { class MapDomainStorage : public IDomainStorage { public: - using ObjKey = ObjId::Type; - using Data = std::optional; - using VersionData = std::unordered_map; - using ClassData = std::unordered_map; - using ObjClassData = std::unordered_map; - - std::unique_ptr Store( - DomainQuery const& query) override; - ClassList Enumerate(ObjId const& obj_id) override; - DomainLoad Load(DomainQuery const& query) override; - void Remove(ObjId const& obj_id) override; + using VersionData = std::unordered_map; + using ObjClassData = std::unordered_map>; + + std::unique_ptr Store(DataKey key, + std::uint8_t version) override; + DomainLoad Load(DataKey key, std::uint8_t version) override; + void Remove(DataKey key) override; void CleanUp() override; - void SaveData(DomainQuery const& query, ObjectData&& data); + void SaveData(DataKey key, std::uint8_t version, DataValue&& data); ObjClassData map; }; diff --git a/tests/test-object-system/test-obj-create.cpp b/tests/test-object-system/test-obj-create.cpp index 4a68eee3..38f39e7f 100644 --- a/tests/test-object-system/test-obj-create.cpp +++ b/tests/test-object-system/test-obj-create.cpp @@ -17,8 +17,7 @@ #include #include "aether/obj/domain.h" -#include "aether/obj/obj_ptr.h" -#include "aether/obj/registry.h" + #include "objects/foo.h" #include "objects/bob.h" #include "objects/bar.h" diff --git a/tests/test-tele-statistics/test-tele-statistics.cpp b/tests/test-tele-statistics/test-tele-statistics.cpp index 5149230d..11dcac5d 100644 --- a/tests/test-tele-statistics/test-tele-statistics.cpp +++ b/tests/test-tele-statistics/test-tele-statistics.cpp @@ -23,7 +23,6 @@ # include "aether/common.h" # include "aether/tele/tele.h" # include "aether/tele/sink.h" -# include "aether/ptr/rc_ptr.h" # include "aether/tele/traps/statistics_trap.h" # include "aether/tele/traps/tele_statistics.h" @@ -50,27 +49,26 @@ namespace ae::tele::test { void test_StatisticsRotation() { auto ram_ds = RamDomainStorage{}; ram_ds.CleanUp(); - auto domain = ae::Domain{ae::ClockType::now(), ram_ds}; + auto domain = ae::Domain{ram_ds}; - TeleStatistics::ptr tele_statistics = - domain.CreateObj(ObjId{1}); - tele_statistics->trap()->MergeStatistics(*statistics_trap); + TeleStatistics tele_statistics = TeleStatistics{&domain}; + tele_statistics.trap()->MergeStatistics(*statistics_trap); // set 100 byte - tele_statistics->trap()->statistics_store.SetSizeLimit(100); + tele_statistics.trap()->statistics_store.SetSizeLimit(100); - InitTeleSink(tele_statistics->trap()); + InitTeleSink(tele_statistics.trap()); { AE_TELED_DEBUG("12"); } auto statistics_size = std::get( - *tele_statistics->trap()->statistics_store.log_store()) + *tele_statistics.trap()->statistics_store.log_store()) .size; TEST_ASSERT_LESS_THAN(100, statistics_size); - tele_statistics->trap()->statistics_store.SetSizeLimit(1); + tele_statistics.trap()->statistics_store.SetSizeLimit(1); // rotation happened auto zero_size = std::get( - *tele_statistics->trap()->statistics_store.log_store()) + *tele_statistics.trap()->statistics_store.log_store()) .size; TEST_ASSERT_EQUAL(0, zero_size); } @@ -78,45 +76,41 @@ void test_StatisticsRotation() { void test_SaveLoadTeleStatistics() { auto ram_ds = RamDomainStorage{}; ram_ds.CleanUp(); - auto domain = ae::Domain{ae::ClockType::now(), ram_ds}; + auto domain = ae::Domain{ram_ds}; AE_TELE_ENV(); - TeleStatistics::ptr tele_statistics = - domain.CreateObj(ObjId{1}); - tele_statistics->trap()->MergeStatistics(*statistics_trap); - InitTeleSink(tele_statistics->trap()); + TeleStatistics tele_statistics = TeleStatistics{&domain}; + tele_statistics.trap()->MergeStatistics(*statistics_trap); + InitTeleSink(tele_statistics.trap()); { AE_TELED_DEBUG("12"); } auto statistics_size = std::get( - *tele_statistics->trap()->statistics_store.log_store()) + *tele_statistics.trap()->statistics_store.log_store()) .size; // use new trap to prevent statistics change while save auto temp_trap = std::make_shared(); InitTeleSink(temp_trap); - domain.SaveRoot(tele_statistics); + tele_statistics.Save(); // load stored object in new instance - auto domain2 = ae::Domain{ae::ClockType::now(), ram_ds}; - TeleStatistics::ptr tele_statistics2; - tele_statistics2.SetId(ObjId{1}); - domain2.LoadRoot(tele_statistics2); - TEST_ASSERT(static_cast(tele_statistics2)); + auto domain2 = ae::Domain{ram_ds}; + TeleStatistics tele_statistics2{&domain2}; auto statistics_size2 = std::get( - *tele_statistics2->trap()->statistics_store.log_store()) + *tele_statistics2.trap()->statistics_store.log_store()) .size; TEST_ASSERT_EQUAL(statistics_size, statistics_size2); auto& metrics1 = - tele_statistics->trap()->statistics_store.metrics_store().metrics; + tele_statistics.trap()->statistics_store.metrics_store().metrics; auto& metrics2 = - tele_statistics2->trap()->statistics_store.metrics_store().metrics; + tele_statistics2.trap()->statistics_store.metrics_store().metrics; TEST_ASSERT_EQUAL(metrics1.size(), metrics2.size()); if constexpr (_AE_MODULE_CONFIG(MLog.id, AE_TELE_METRICS_MODULES) && diff --git a/tests/test-transport/test-data-packet-collector.cpp b/tests/test-transport/test-data-packet-collector.cpp index fe4ecb23..284e6f97 100644 --- a/tests/test-transport/test-data-packet-collector.cpp +++ b/tests/test-transport/test-data-packet-collector.cpp @@ -61,7 +61,6 @@ inline void AssertPacket(std::vector const& data_packet) { int i; float f; is >> str >> i >> f; - TEST_ASSERT(data_was_read(is)); TEST_ASSERT_EQUAL_STRING("Hello", str.c_str()); TEST_ASSERT_EQUAL(12, i); TEST_ASSERT_EQUAL(12.42, f); From cf282992498ece5f0f64051889e79c82f286827a Mon Sep 17 00:00:00 2001 From: BartolomeyKant Date: Fri, 9 Jan 2026 11:13:32 +0500 Subject: [PATCH 06/12] remove file system init --- .github/workflows/ci-cd-multi-platforms.yml | 3 - config/file_system_init.h | 251 ------------------ .../aether-client-cpp/CMakeLists.txt | 3 - .../vscode/aether-client-cpp/CMakeLists.txt | 4 - .../aether-client-cpp/CMakeLists.txt | 4 - .../vscode/aether-client-cpp/CMakeLists.txt | 4 - 6 files changed, 269 deletions(-) delete mode 100644 config/file_system_init.h diff --git a/.github/workflows/ci-cd-multi-platforms.yml b/.github/workflows/ci-cd-multi-platforms.yml index 973d7f43..09750a70 100644 --- a/.github/workflows/ci-cd-multi-platforms.yml +++ b/.github/workflows/ci-cd-multi-platforms.yml @@ -149,7 +149,6 @@ jobs: - { name: "Optimized", user_config: "./config/user_config_optimized.h", - fs_init: "./config/file_system_init.h", } steps: @@ -167,8 +166,6 @@ jobs: command: idf.py build -DCOMPILE_EXAMPLE=${{ matrix.compile_example }} -DUSER_CONFIG=../../../../../${{ matrix.platforms.user_config }} - -DFS_INIT="../../../../../${{ matrix.platforms.fs_init }}" - -DAE_DISTILLATION=Off - name: Rename artifact run: | diff --git a/config/file_system_init.h b/config/file_system_init.h deleted file mode 100644 index 170249c8..00000000 --- a/config/file_system_init.h +++ /dev/null @@ -1,251 +0,0 @@ -/** - * This file is autogenerated by aether-registrator - */ - -#ifndef FILE_SYSTEM_STATE_H_ -#define FILE_SYSTEM_STATE_H_ - -#include "aether/domain_storage/static_object_types.h" -// clang-format off -static constexpr auto class_array_1 = std::array{2178182515, 3757268233, }; -static constexpr auto class_array_2 = std::array{207799855, 2178182515, 2967114514, }; -static constexpr auto class_array_3 = std::array{1105219716, 2178182515, }; -static constexpr auto class_array_1004 = std::array{698262047, 1232350972, 1402813048, 2178182515, }; -static constexpr auto class_array_2001 = std::array{1058537116, 2178182515, }; -static constexpr auto class_array_2004 = std::array{207799855, 712345007, 2178182515, }; -static constexpr auto class_array_2005 = std::array{1296832837, 2178182515, }; -static constexpr auto class_array_3000 = std::array{2178182515, 2424033868, }; -static constexpr auto class_array_4000 = std::array{217497168, 844107085, 2178182515, }; -static constexpr auto class_array_5000 = std::array{460694392, 733819916, 2178182515, }; -static constexpr auto class_array_89425 = std::array{2178182515, 2654162901, }; -static constexpr auto class_array_195897384 = std::array{2178182515, 2654162901, }; -static constexpr auto class_array_634705393 = std::array{2178182515, 2654162901, }; -static constexpr auto class_array_1152904477 = std::array{1058537116, 2178182515, }; -static constexpr auto class_array_1243226655 = std::array{2178182515, 2721984319, }; -static constexpr auto class_array_1403600181 = std::array{2178182515, 2461747236, }; -static constexpr auto class_array_1431526488 = std::array{2178182515, 2461747236, }; -static constexpr auto class_array_1519411631 = std::array{2178182515, 2654162901, }; -static constexpr auto class_array_1604682788 = std::array{2178182515, 2721984319, }; -static constexpr auto class_array_1652254447 = std::array{2178182515, 2721984319, }; -static constexpr auto class_array_1703468408 = std::array{2178182515, 2461747236, }; -static constexpr auto class_array_1874908864 = std::array{1058537116, 2178182515, }; -static constexpr auto class_array_2187029861 = std::array{2178182515, 2461747236, }; -static constexpr auto class_array_2286930707 = std::array{701908926, 2178182515, }; -static constexpr auto class_array_2517507214 = std::array{2178182515, 2461747236, }; -static constexpr auto class_array_2663262239 = std::array{2178182515, 2721984319, }; -static constexpr auto class_array_2724383112 = std::array{2178182515, 2654162901, }; -static constexpr auto class_array_2850465053 = std::array{207799855, 712345007, 2178182515, }; -static constexpr auto class_array_2998276279 = std::array{2178182515, 2721984319, }; -static constexpr auto class_array_3443994296 = std::array{207799855, 712345007, 2178182515, }; -static constexpr auto class_array_3554060643 = std::array{2178182515, 2461747236, }; -static constexpr auto class_array_3956468029 = std::array{701908926, 2178182515, }; -static constexpr auto class_array_4028423841 = std::array{698262047, 2178182515, 3658551669, }; -static constexpr auto class_array_4143624256 = std::array{2178182515, 2654162901, }; -static constexpr auto class_array_4225132580 = std::array{2178182515, 2721984319, }; - -static constexpr auto data_array_1_2178182515_0 = std::array{0x29, 0x18, 0xf2, 0x42, 0xa9, 0x36, 0x06, 0x00, }; -static constexpr auto data_array_1_3757268233_0 = std::array{0xd1, 0x07, 0x00, 0x00, 0x01, 0xd4, 0x07, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0xb8, 0x0b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x1d, 0xed, 0xb7, 0x44, 0x00, 0xc0, 0xd6, 0xc0, 0x6f, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x1f, 0x22, 0x1a, 0x4a, 0x01, 0x03, 0x00, 0x24, 0x68, 0xd6, 0xfb, 0x01, 0x04, 0x00, 0x24, 0x84, 0xa5, 0x5f, 0x01, 0x05, 0x00, 0xb7, 0x10, 0xb6, 0xb2, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x0f, 0x00, 0x00, 0x00, 0x88, 0x13, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0xec, 0x03, 0x00, 0x00, 0x01, }; -static constexpr auto data_array_2_207799855_0 = std::array{0x02, 0x00, 0x00, 0x00, 0x1f, 0x28, 0xbe, 0x9e, 0x01, 0xef, 0x66, 0x7b, 0x62, 0x01, 0xec, 0x03, 0x00, 0x00, 0x01, }; -static constexpr auto data_array_2_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_2_2967114514_0 = std::array{}; -static constexpr auto data_array_3_1105219716_0 = std::array{0x00, 0x02, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x30, 0x2e, 0x31, 0x2e, 0x30, 0x2e, 0x65, 0x37, 0x37, 0x64, 0x33, 0x32, 0x63, 0x32, 0x66, 0x34, 0x33, 0x65, 0x30, 0x32, 0x37, 0x62, 0x34, 0x62, 0x30, 0x32, 0x31, 0x32, 0x34, 0x66, 0x34, 0x61, 0x36, 0x31, 0x34, 0x30, 0x61, 0x36, 0x33, 0x62, 0x31, 0x38, 0x61, 0x63, 0x37, 0x61, 0x05, 0x00, 0x00, 0x00, 0x4c, 0x69, 0x6e, 0x75, 0x78, 0x05, 0x00, 0x00, 0x00, 0x63, 0x6c, 0x61, 0x6e, 0x67, 0x06, 0x00, 0x00, 0x00, 0x31, 0x39, 0x2e, 0x31, 0x2e, 0x37, 0x05, 0x00, 0x00, 0x00, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0x0a, 0x00, 0x00, 0x00, 0x41, 0x4d, 0x44, 0x20, 0x78, 0x38, 0x36, 0x2d, 0x36, 0x34, 0x01, 0x14, 0xe2, 0x01, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x31, 0x01, 0x01, 0x00, 0x00, 0x00, 0x31, 0x02, 0x01, 0x00, 0x00, 0x00, 0x31, 0x03, 0x01, 0x00, 0x00, 0x00, 0x31, 0x04, 0x01, 0x00, 0x00, 0x00, 0x31, 0x05, 0x01, 0x00, 0x00, 0x00, 0x31, 0x06, 0x01, 0x00, 0x00, 0x00, 0x31, 0x07, 0x01, 0x00, 0x00, 0x00, 0x31, 0x08, 0x01, 0x00, 0x00, 0x00, 0x31, 0x09, 0x01, 0x00, 0x00, 0x00, 0x31, 0x0a, 0x01, 0x00, 0x00, 0x00, 0x31, 0x0b, 0x01, 0x00, 0x00, 0x00, 0x31, 0x0c, 0x1c, 0x00, 0x00, 0x00, 0x41, 0x45, 0x5f, 0x53, 0x55, 0x50, 0x50, 0x4f, 0x52, 0x54, 0x5f, 0x44, 0x59, 0x4e, 0x41, 0x4d, 0x49, 0x43, 0x5f, 0x43, 0x4c, 0x4f, 0x55, 0x44, 0x5f, 0x44, 0x4e, 0x53, 0x0d, 0x01, 0x00, 0x00, 0x00, 0x31, 0x0e, 0x01, 0x00, 0x00, 0x00, 0x31, 0x0f, 0x01, 0x00, 0x00, 0x00, 0x31, 0x10, 0x01, 0x00, 0x00, 0x00, 0x31, 0x11, 0x04, 0x00, 0x00, 0x00, 0x35, 0x30, 0x30, 0x30, 0x12, 0x01, 0x00, 0x00, 0x00, 0x31, 0x13, 0x01, 0x00, 0x00, 0x00, 0x31, 0x14, 0x01, 0x00, 0x00, 0x00, 0x32, 0x15, 0x01, 0x00, 0x00, 0x00, 0x32, 0x16, 0x01, 0x00, 0x00, 0x00, 0x32, 0x17, 0x01, 0x00, 0x00, 0x00, 0x32, 0x18, 0x01, 0x00, 0x00, 0x00, 0x31, 0x19, 0x01, 0x00, 0x00, 0x00, 0x31, 0x1a, 0x01, 0x00, 0x00, 0x00, 0x30, 0x1b, 0x03, 0x00, 0x00, 0x00, 0x31, 0x2e, 0x35, 0x1c, 0x02, 0x00, 0x00, 0x00, 0x31, 0x30, 0x1d, 0x03, 0x00, 0x00, 0x00, 0x31, 0x30, 0x30, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x31, 0x1f, 0x01, 0x00, 0x00, 0x00, 0x31, 0x20, 0x01, 0x00, 0x00, 0x00, 0x30, 0x21, 0x0a, 0x00, 0x00, 0x00, 0x30, 0x78, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x22, 0x0c, 0x00, 0x00, 0x00, 0x7b, 0x30, 0x78, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x65, 0x7d, 0x23, 0x0a, 0x00, 0x00, 0x00, 0x30, 0x78, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x24, 0x0c, 0x00, 0x00, 0x00, 0x7b, 0x30, 0x78, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x65, 0x7d, 0x25, 0x0a, 0x00, 0x00, 0x00, 0x30, 0x78, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x26, 0x03, 0x00, 0x00, 0x00, 0x7b, 0x20, 0x7d, 0x27, 0x0a, 0x00, 0x00, 0x00, 0x30, 0x78, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x28, 0x03, 0x00, 0x00, 0x00, 0x7b, 0x20, 0x7d, 0x29, 0x0a, 0x00, 0x00, 0x00, 0x30, 0x78, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x2a, 0x03, 0x00, 0x00, 0x00, 0x7b, 0x20, 0x7d, 0x2b, 0x0a, 0x00, 0x00, 0x00, 0x30, 0x78, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x2c, 0x03, 0x00, 0x00, 0x00, 0x7b, 0x20, 0x7d, 0x2d, 0x0a, 0x00, 0x00, 0x00, 0x30, 0x78, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x2e, 0x03, 0x00, 0x00, 0x00, 0x7b, 0x20, 0x7d, 0x2f, 0x0c, 0x00, 0x00, 0x00, 0x7b, 0x30, 0x78, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x65, 0x7d, 0x30, 0x03, 0x00, 0x00, 0x00, 0x7b, 0x20, 0x7d, 0x31, 0x0a, 0x00, 0x00, 0x00, 0x30, 0x78, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x32, 0x0c, 0x00, 0x00, 0x00, 0x7b, 0x30, 0x78, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x65, 0x7d, 0x33, 0x0a, 0x00, 0x00, 0x00, 0x30, 0x78, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x34, 0x03, 0x00, 0x00, 0x00, 0x7b, 0x20, 0x7d, 0x35, 0x0a, 0x00, 0x00, 0x00, 0x30, 0x78, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x36, 0x03, 0x00, 0x00, 0x00, 0x7b, 0x20, 0x7d, 0x37, 0x01, 0x00, 0x00, 0x00, 0x31, 0x38, 0x01, 0x00, 0x00, 0x00, 0x31, 0x39, 0x01, 0x00, 0x00, 0x00, 0x31, 0x01, 0x3d, 0x02, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x5d, 0x00, 0x00, 0x00, 0xfb, 0x32, 0xe1, 0x9d, 0xe4, 0x81, 0x2d, 0x85, 0x45, 0x18, 0x08, 0x0a, 0x00, 0x00, 0x00, 0x0a, 0x44, 0x73, 0x4f, 0x62, 0x6a, 0x53, 0x61, 0x76, 0x65, 0x64, 0x42, 0x53, 0x61, 0x76, 0x65, 0x64, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x69, 0x64, 0x3d, 0x31, 0x38, 0x37, 0x34, 0x39, 0x30, 0x38, 0x38, 0x36, 0x34, 0x2c, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x69, 0x64, 0x3d, 0x32, 0x31, 0x37, 0x38, 0x31, 0x38, 0x32, 0x35, 0x31, 0x35, 0x2c, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x30, 0x2c, 0x20, 0x73, 0x69, 0x7a, 0x65, 0x3d, 0x38, 0x5d, 0x00, 0x00, 0x00, 0xfb, 0x32, 0xf7, 0x8c, 0xe5, 0x81, 0x2d, 0x85, 0x45, 0x18, 0x08, 0x0a, 0x00, 0x00, 0x00, 0x0a, 0x44, 0x73, 0x4f, 0x62, 0x6a, 0x53, 0x61, 0x76, 0x65, 0x64, 0x42, 0x53, 0x61, 0x76, 0x65, 0x64, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x69, 0x64, 0x3d, 0x33, 0x34, 0x34, 0x33, 0x39, 0x39, 0x34, 0x32, 0x39, 0x36, 0x2c, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x69, 0x64, 0x3d, 0x32, 0x31, 0x37, 0x38, 0x31, 0x38, 0x32, 0x35, 0x31, 0x35, 0x2c, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x30, 0x2c, 0x20, 0x73, 0x69, 0x7a, 0x65, 0x3d, 0x38, 0x5d, 0x00, 0x00, 0x00, 0xfb, 0x32, 0xe2, 0x76, 0xe6, 0x81, 0x2d, 0x85, 0x45, 0x18, 0x08, 0x0a, 0x00, 0x00, 0x00, 0x0a, 0x44, 0x73, 0x4f, 0x62, 0x6a, 0x53, 0x61, 0x76, 0x65, 0x64, 0x42, 0x53, 0x61, 0x76, 0x65, 0x64, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x69, 0x64, 0x3d, 0x33, 0x34, 0x34, 0x33, 0x39, 0x39, 0x34, 0x32, 0x39, 0x36, 0x2c, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x69, 0x64, 0x3d, 0x32, 0x30, 0x37, 0x37, 0x39, 0x39, 0x38, 0x35, 0x35, 0x2c, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x30, 0x2c, 0x20, 0x73, 0x69, 0x7a, 0x65, 0x3d, 0x32, 0x39, 0x5c, 0x00, 0x00, 0x00, 0xfb, 0x32, 0x5b, 0xf4, 0xe6, 0x81, 0x2d, 0x85, 0x45, 0x18, 0x08, 0x0a, 0x00, 0x00, 0x00, 0x0a, 0x44, 0x73, 0x4f, 0x62, 0x6a, 0x53, 0x61, 0x76, 0x65, 0x64, 0x41, 0x53, 0x61, 0x76, 0x65, 0x64, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x69, 0x64, 0x3d, 0x33, 0x34, 0x34, 0x33, 0x39, 0x39, 0x34, 0x32, 0x39, 0x36, 0x2c, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x69, 0x64, 0x3d, 0x37, 0x31, 0x32, 0x33, 0x34, 0x35, 0x30, 0x30, 0x37, 0x2c, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x30, 0x2c, 0x20, 0x73, 0x69, 0x7a, 0x65, 0x3d, 0x30, 0x5d, 0x00, 0x00, 0x00, 0xfb, 0x32, 0x05, 0x05, 0xe8, 0x81, 0x2d, 0x85, 0x45, 0x18, 0x08, 0x0a, 0x00, 0x00, 0x00, 0x0a, 0x44, 0x73, 0x4f, 0x62, 0x6a, 0x53, 0x61, 0x76, 0x65, 0x64, 0x42, 0x53, 0x61, 0x76, 0x65, 0x64, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x69, 0x64, 0x3d, 0x33, 0x39, 0x35, 0x36, 0x34, 0x36, 0x38, 0x30, 0x32, 0x39, 0x2c, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x69, 0x64, 0x3d, 0x32, 0x31, 0x37, 0x38, 0x31, 0x38, 0x32, 0x35, 0x31, 0x35, 0x2c, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x30, 0x2c, 0x20, 0x73, 0x69, 0x7a, 0x65, 0x3d, 0x38, 0x5d, 0x00, 0x00, 0x00, 0xfb, 0x32, 0x08, 0xca, 0xe8, 0x81, 0x2d, 0x85, 0x45, 0x18, 0x08, 0x0a, 0x00, 0x00, 0x00, 0x0a, 0x44, 0x73, 0x4f, 0x62, 0x6a, 0x53, 0x61, 0x76, 0x65, 0x64, 0x42, 0x53, 0x61, 0x76, 0x65, 0x64, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x69, 0x64, 0x3d, 0x33, 0x39, 0x35, 0x36, 0x34, 0x36, 0x38, 0x30, 0x32, 0x39, 0x2c, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x69, 0x64, 0x3d, 0x37, 0x30, 0x31, 0x39, 0x30, 0x38, 0x39, 0x32, 0x36, 0x2c, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x30, 0x2c, 0x20, 0x73, 0x69, 0x7a, 0x65, 0x3d, 0x33, 0x35, 0x01, 0x00, 0x00, 0x00, 0xfb, 0x32, 0x06, 0x24, 0xb1, 0x00, 0x01, 0xc3, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x00, 0xfb, 0x32, 0xfa, 0x4e, 0xe9, 0x81, 0x2d, 0x85, 0x45, 0x18, 0x08, 0x0a, 0x00, 0x00, 0x00, 0x0a, 0x44, 0x73, 0x4f, 0x62, 0x6a, 0x53, 0x61, 0x76, 0x65, 0x64, 0x44, 0x53, 0x61, 0x76, 0x65, 0x64, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x69, 0x64, 0x3d, 0x31, 0x38, 0x37, 0x34, 0x39, 0x30, 0x38, 0x38, 0x36, 0x34, 0x2c, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x69, 0x64, 0x3d, 0x31, 0x30, 0x35, 0x38, 0x35, 0x33, 0x37, 0x31, 0x31, 0x36, 0x2c, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x30, 0x2c, 0x20, 0x73, 0x69, 0x7a, 0x65, 0x3d, 0x35, 0x30, 0x30, 0x54, 0x00, 0x00, 0x00, 0xfb, 0x32, 0x6c, 0x62, 0xea, 0x81, 0x2d, 0x85, 0x45, 0x18, 0x08, 0x0a, 0x00, 0x00, 0x00, 0x0a, 0x44, 0x73, 0x4f, 0x62, 0x6a, 0x53, 0x61, 0x76, 0x65, 0x64, 0x39, 0x53, 0x61, 0x76, 0x65, 0x64, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x69, 0x64, 0x3d, 0x33, 0x2c, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x69, 0x64, 0x3d, 0x32, 0x31, 0x37, 0x38, 0x31, 0x38, 0x32, 0x35, 0x31, 0x35, 0x2c, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x30, 0x2c, 0x20, 0x73, 0x69, 0x7a, 0x65, 0x3d, 0x38, 0x01, 0x00, 0x00, 0x00, 0xfb, 0x32, 0x02, 0x1f, 0x3c, 0x00, }; -static constexpr auto data_array_3_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_1004_698262047_0 = std::array{0x00, 0x00, 0x00, 0x00, 0xd5, 0x07, 0x00, 0x00, 0x01, }; -static constexpr auto data_array_1004_1232350972_0 = std::array{0x01, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x0f, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x54, 0x65, 0x73, 0x74, 0x31, 0x32, 0x33, 0x07, 0x00, 0x00, 0x00, 0x54, 0x65, 0x73, 0x74, 0x31, 0x32, 0x33, }; -static constexpr auto data_array_1004_1402813048_0 = std::array{0xa1, 0xde, 0x1c, 0xf0, 0x00, }; -static constexpr auto data_array_1004_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_2001_1058537116_0 = std::array{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, }; -static constexpr auto data_array_2001_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_2004_207799855_0 = std::array{0x00, 0x00, 0x00, 0x00, 0xec, 0x03, 0x00, 0x00, 0x01, }; -static constexpr auto data_array_2004_712345007_0 = std::array{}; -static constexpr auto data_array_2004_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_2005_1296832837_0 = std::array{}; -static constexpr auto data_array_2005_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_3000_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_3000_2424033868_0 = std::array{0x01, 0x00, 0x00, 0x00, 0x01, 0x05, 0x88, 0x3b, 0x4d, 0x7e, 0x0f, 0xb0, 0x4a, 0x38, 0xca, 0x12, 0xb3, 0xa4, 0x51, 0xb0, 0x09, 0x42, 0x04, 0x88, 0x58, 0x26, 0x3e, 0xe6, 0xe6, 0xd6, 0x11, 0x50, 0xf2, 0xef, 0x15, 0xf4, 0x03, 0x43, }; -static constexpr auto data_array_4000_217497168_0 = std::array{}; -static constexpr auto data_array_4000_844107085_0 = std::array{}; -static constexpr auto data_array_4000_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_5000_460694392_0 = std::array{0x01, 0x00, 0x00, 0x00, 0x00, }; -static constexpr auto data_array_5000_733819916_0 = std::array{}; -static constexpr auto data_array_5000_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_89425_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_89425_2654162901_0 = std::array{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; -static constexpr auto data_array_195897384_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_195897384_2654162901_0 = std::array{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; -static constexpr auto data_array_634705393_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_634705393_2654162901_0 = std::array{0x02, 0x00, 0x00, 0x00, 0x40, 0xe4, 0x03, 0x00, 0x26, 0xe7, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, }; -static constexpr auto data_array_1152904477_1058537116_0 = std::array{0x01, 0x00, 0x00, 0x00, 0x00, 0xc1, 0x54, 0x5a, 0x79, 0xaa, 0x29, 0x4e, 0x59, 0xb9, 0x9d, 0x69, 0xaf, 0x17, 0xbf, 0x1f, 0x94, 0xd8, 0xfd, 0x51, 0x96, 0x3a, 0x04, 0x4c, 0xdc, 0xa2, 0xc5, 0x7e, 0x08, 0x37, 0xab, 0x55, 0xa5, 0x09, 0x38, 0xea, 0x31, 0xfd, 0x2e, 0x47, 0x64, 0xa6, 0xf6, 0xc3, 0xc2, 0x48, 0xcc, 0xe1, 0xb5, 0x98, 0x5c, 0xa2, 0xc2, 0x15, 0x31, 0x74, 0x11, 0x8e, 0xf5, 0x05, 0x0f, 0x5c, 0xdc, 0x04, 0x72, 0x55, 0x1d, 0xa5, 0xe6, 0xa9, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x09, 0x38, 0xea, 0x31, 0xfd, 0x2e, 0x47, 0x64, 0xa6, 0xf6, 0xc3, 0xc2, 0x48, 0xcc, 0xe1, 0xb5, 0x98, 0x5c, 0xa2, 0xc2, 0x15, 0x31, 0x74, 0x11, 0x8e, 0xf5, 0x05, 0x0f, 0x5c, 0xdc, 0x04, 0x72, 0x55, 0x00, 0x09, 0x82, 0x15, 0x98, 0xb4, 0x51, 0x7e, 0xc0, 0x58, 0x87, 0xf4, 0x83, 0x08, 0x3a, 0x4d, 0x3b, 0xdc, 0xec, 0x6b, 0xd1, 0x9d, 0xe4, 0x68, 0x77, 0xf0, 0x4f, 0xf2, 0x5d, 0xa6, 0x56, 0xfd, 0x1d, 0x56, 0x09, 0x99, 0x67, 0x5f, 0x1d, 0x89, 0x6f, 0x09, 0x3b, 0x82, 0xbb, 0x92, 0x0e, 0xe8, 0xf3, 0x8a, 0x70, 0x6e, 0xec, 0x95, 0x14, 0xd7, 0xd2, 0xf0, 0x91, 0xbc, 0x79, 0x80, 0x02, 0xc8, 0x88, 0xe1, 0x85, 0x03, 0x00, 0x03, 0x00, 0x09, 0x38, 0xea, 0x31, 0xfd, 0x2e, 0x47, 0x64, 0xa6, 0xf6, 0xc3, 0xc2, 0x48, 0xcc, 0xe1, 0xb5, 0x98, 0x5c, 0xa2, 0xc2, 0x15, 0x31, 0x74, 0x11, 0x8e, 0xf5, 0x05, 0x0f, 0x5c, 0xdc, 0x04, 0x72, 0x55, 0x00, 0x09, 0x71, 0x05, 0x6b, 0x5f, 0x83, 0x45, 0x28, 0x64, 0xf5, 0x7a, 0x28, 0xfb, 0x67, 0x42, 0x57, 0x08, 0x0a, 0x61, 0x09, 0xc0, 0x85, 0x24, 0x5e, 0xca, 0x76, 0x83, 0xa9, 0xb1, 0x41, 0x96, 0x35, 0x39, 0x09, 0x51, 0x70, 0x3a, 0xd0, 0x7e, 0x0d, 0xae, 0x79, 0x86, 0x93, 0xdb, 0x43, 0xa4, 0x3f, 0xbc, 0x39, 0xa1, 0x63, 0x3b, 0x4b, 0x88, 0x60, 0x75, 0x84, 0x2c, 0x35, 0x0b, 0xfa, 0x7d, 0xae, 0x9d, 0x50, 0x04, 0x00, 0x04, 0x00, 0x09, 0x38, 0xea, 0x31, 0xfd, 0x2e, 0x47, 0x64, 0xa6, 0xf6, 0xc3, 0xc2, 0x48, 0xcc, 0xe1, 0xb5, 0x98, 0x5c, 0xa2, 0xc2, 0x15, 0x31, 0x74, 0x11, 0x8e, 0xf5, 0x05, 0x0f, 0x5c, 0xdc, 0x04, 0x72, 0x55, 0x00, 0x09, 0x7b, 0x2f, 0x83, 0xbe, 0xfa, 0x27, 0x06, 0xb3, 0x8f, 0x3c, 0x1e, 0x82, 0x22, 0x30, 0x08, 0x03, 0x2a, 0xed, 0xd4, 0x95, 0x08, 0x03, 0x68, 0xaa, 0xa8, 0x36, 0x50, 0x24, 0x2f, 0xf6, 0x55, 0xdf, 0x09, 0xd8, 0xcd, 0xfa, 0x2d, 0xf5, 0x93, 0xec, 0x28, 0x6b, 0xb3, 0xf7, 0xfa, 0x24, 0xb1, 0x03, 0x9a, 0x3a, 0x59, 0xe9, 0x50, 0xa7, 0x18, 0x58, 0xaa, 0x65, 0x9c, 0x9a, 0x17, 0x0d, 0xfa, 0xe1, 0x0f, 0x05, 0x00, 0x05, 0x00, 0x09, 0x38, 0xea, 0x31, 0xfd, 0x2e, 0x47, 0x64, 0xa6, 0xf6, 0xc3, 0xc2, 0x48, 0xcc, 0xe1, 0xb5, 0x98, 0x5c, 0xa2, 0xc2, 0x15, 0x31, 0x74, 0x11, 0x8e, 0xf5, 0x05, 0x0f, 0x5c, 0xdc, 0x04, 0x72, 0x55, 0x00, 0x09, 0x97, 0xee, 0xbb, 0x02, 0x3b, 0xdb, 0xf3, 0x33, 0x90, 0x93, 0x75, 0xdc, 0x21, 0xc3, 0xb9, 0x99, 0xe5, 0x0f, 0x59, 0xd9, 0x6f, 0xd2, 0xa3, 0x10, 0x49, 0x71, 0xf4, 0xdd, 0x55, 0x96, 0x5e, 0x40, 0x09, 0x99, 0xd2, 0x71, 0x70, 0xa8, 0xaa, 0xde, 0x4c, 0x1a, 0x74, 0x19, 0xd6, 0x19, 0xa5, 0x24, 0x08, 0x6b, 0x43, 0xe4, 0xe0, 0x4b, 0xa8, 0xed, 0xa2, 0xb5, 0xd7, 0x7f, 0x83, 0xaf, 0x03, 0xe0, 0x45, 0x13, 0xcb, 0x4f, 0x88, 0x00, }; -static constexpr auto data_array_1152904477_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_1243226655_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_1243226655_2721984319_0 = std::array{0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x35, 0x3d, 0xa9, 0x53, 0x01, }; -static constexpr auto data_array_1403600181_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_1403600181_2461747236_0 = std::array{0x00, 0x00, 0x22, 0x3c, 0xf4, 0x94, 0x3c, 0x23, 0x00, 0x40, 0x4b, 0x4c, 0x00, 0x40, 0x42, 0x0f, 0x00, 0x51, 0x5d, 0x01, 0x00, 0x00, }; -static constexpr auto data_array_1431526488_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_1431526488_2461747236_0 = std::array{0x01, 0x19, 0x00, 0x00, 0x00, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x61, 0x65, 0x74, 0x68, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x69, 0x6f, 0x32, 0x23, 0x00, 0x40, 0x4b, 0x4c, 0x00, 0x40, 0x42, 0x0f, 0x00, 0xf1, 0xd5, 0xd4, 0x25, 0x00, }; -static constexpr auto data_array_1519411631_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_1519411631_2654162901_0 = std::array{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; -static constexpr auto data_array_1604682788_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_1604682788_2721984319_0 = std::array{0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x8e, 0x1c, 0x0e, 0x96, 0x01, }; -static constexpr auto data_array_1652254447_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_1652254447_2721984319_0 = std::array{0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x78, 0xdd, 0x88, 0x65, 0x01, }; -static constexpr auto data_array_1703468408_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_1703468408_2461747236_0 = std::array{0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x15, 0x5d, 0xff, 0xfe, 0x34, 0x83, 0x47, 0x32, 0x23, 0x00, 0x40, 0x4b, 0x4c, 0x00, 0x40, 0x42, 0x0f, 0x00, 0x40, 0xb0, 0xfa, 0xf6, 0x00, }; -static constexpr auto data_array_1874908864_1058537116_0 = std::array{0x01, 0x00, 0x00, 0x00, 0x00, 0xb1, 0x5e, 0x61, 0x10, 0x8e, 0x7b, 0x40, 0x2c, 0x96, 0x53, 0xf5, 0x49, 0x6b, 0xa7, 0x03, 0x05, 0xe6, 0x5c, 0x25, 0x00, 0x3b, 0x3b, 0x44, 0x67, 0xb8, 0x62, 0x26, 0xba, 0xb1, 0xe1, 0xa7, 0xcd, 0x09, 0x31, 0x9b, 0x27, 0x78, 0xe3, 0xae, 0x2f, 0x0f, 0xe7, 0xbd, 0x1c, 0x8d, 0x4f, 0x0e, 0x36, 0xef, 0xb2, 0x29, 0x9e, 0x40, 0x8d, 0x7c, 0xfa, 0xca, 0x8b, 0x89, 0xdc, 0xdd, 0x0c, 0x47, 0x33, 0xdf, 0xb8, 0x2e, 0x47, 0xcd, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x09, 0x31, 0x9b, 0x27, 0x78, 0xe3, 0xae, 0x2f, 0x0f, 0xe7, 0xbd, 0x1c, 0x8d, 0x4f, 0x0e, 0x36, 0xef, 0xb2, 0x29, 0x9e, 0x40, 0x8d, 0x7c, 0xfa, 0xca, 0x8b, 0x89, 0xdc, 0xdd, 0x0c, 0x47, 0x33, 0xdf, 0x00, 0x09, 0x99, 0xdf, 0x74, 0x93, 0x00, 0xa5, 0x4e, 0x56, 0x3f, 0xd3, 0x62, 0x80, 0xd8, 0x52, 0x3a, 0x8c, 0x42, 0x03, 0x5f, 0x0b, 0x13, 0xfc, 0xd4, 0xd0, 0x04, 0xcf, 0x6a, 0x42, 0x84, 0xd1, 0x1a, 0x2c, 0x09, 0x48, 0x04, 0xb3, 0x4d, 0x44, 0xc1, 0x9c, 0x15, 0x54, 0xbd, 0x4c, 0x89, 0x72, 0x79, 0xba, 0xf6, 0x9c, 0xea, 0xc1, 0x90, 0xfc, 0x16, 0x07, 0xf5, 0xe5, 0xbd, 0x43, 0x37, 0xf9, 0x05, 0x5b, 0x9c, 0x03, 0x00, 0x03, 0x00, 0x09, 0x31, 0x9b, 0x27, 0x78, 0xe3, 0xae, 0x2f, 0x0f, 0xe7, 0xbd, 0x1c, 0x8d, 0x4f, 0x0e, 0x36, 0xef, 0xb2, 0x29, 0x9e, 0x40, 0x8d, 0x7c, 0xfa, 0xca, 0x8b, 0x89, 0xdc, 0xdd, 0x0c, 0x47, 0x33, 0xdf, 0x00, 0x09, 0x52, 0xda, 0xcf, 0x1d, 0x57, 0x91, 0x64, 0xfa, 0x4a, 0x95, 0xb6, 0xdc, 0xe5, 0xbf, 0xac, 0x37, 0x5f, 0xe4, 0x13, 0x0e, 0xec, 0x7a, 0x9c, 0x16, 0x13, 0x3f, 0x83, 0xc2, 0xae, 0xa0, 0xd8, 0x87, 0x09, 0x2b, 0xa0, 0xe8, 0x36, 0x6d, 0x92, 0x6a, 0xde, 0x97, 0x0c, 0x27, 0x09, 0xd4, 0xe2, 0xb2, 0x7f, 0xaf, 0xfd, 0x30, 0xbd, 0x8b, 0xd2, 0x02, 0x12, 0xbb, 0x92, 0x2e, 0xf9, 0x79, 0x4d, 0xae, 0x21, 0x04, 0x00, 0x04, 0x00, 0x09, 0x31, 0x9b, 0x27, 0x78, 0xe3, 0xae, 0x2f, 0x0f, 0xe7, 0xbd, 0x1c, 0x8d, 0x4f, 0x0e, 0x36, 0xef, 0xb2, 0x29, 0x9e, 0x40, 0x8d, 0x7c, 0xfa, 0xca, 0x8b, 0x89, 0xdc, 0xdd, 0x0c, 0x47, 0x33, 0xdf, 0x00, 0x09, 0xfb, 0xe3, 0x7b, 0xb7, 0xb0, 0x12, 0x4b, 0x47, 0x9c, 0x31, 0x4c, 0x8b, 0x4e, 0xd7, 0xd1, 0xd7, 0x33, 0xaa, 0x14, 0x69, 0xab, 0xd6, 0xd1, 0x00, 0x3a, 0xdb, 0xab, 0xec, 0x02, 0xe7, 0x94, 0x97, 0x09, 0xfa, 0xea, 0xdf, 0x11, 0x2e, 0xed, 0x4d, 0xe3, 0x98, 0x03, 0x79, 0x10, 0xe0, 0x1b, 0x9a, 0xbe, 0x65, 0x2b, 0xf2, 0x27, 0xf5, 0x9c, 0x72, 0x64, 0xcf, 0xfa, 0xa1, 0xe0, 0x46, 0xbb, 0x07, 0xcd, 0x05, 0x00, 0x05, 0x00, 0x09, 0x31, 0x9b, 0x27, 0x78, 0xe3, 0xae, 0x2f, 0x0f, 0xe7, 0xbd, 0x1c, 0x8d, 0x4f, 0x0e, 0x36, 0xef, 0xb2, 0x29, 0x9e, 0x40, 0x8d, 0x7c, 0xfa, 0xca, 0x8b, 0x89, 0xdc, 0xdd, 0x0c, 0x47, 0x33, 0xdf, 0x00, 0x09, 0x71, 0xe9, 0xc7, 0x4c, 0xf9, 0xec, 0xe1, 0xa4, 0x94, 0x04, 0x4d, 0x3c, 0xbf, 0x54, 0xc0, 0x07, 0x98, 0x24, 0x8e, 0x4f, 0x09, 0x80, 0xa1, 0x1d, 0x90, 0x4f, 0x0b, 0xc8, 0xc9, 0x9b, 0x5b, 0x93, 0x09, 0xbb, 0x74, 0xd2, 0x9c, 0x8e, 0xd7, 0x11, 0xd1, 0x3b, 0x18, 0xa9, 0xe7, 0x70, 0x2c, 0xdd, 0xb9, 0x5d, 0xf6, 0x37, 0xe0, 0x77, 0x8d, 0x32, 0x97, 0xc5, 0x6d, 0x2a, 0x1b, 0x12, 0x85, 0x7e, 0xc0, 0x3d, 0xe9, 0xd2, 0xeb, 0x00, }; -static constexpr auto data_array_1874908864_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_2187029861_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_2187029861_2461747236_0 = std::array{0x00, 0x00, 0x22, 0x4e, 0x2f, 0xaf, 0x3c, 0x23, 0x00, 0x40, 0x4b, 0x4c, 0x00, 0x40, 0x42, 0x0f, 0x00, 0x88, 0xc9, 0x62, 0xa2, 0x00, }; -static constexpr auto data_array_2286930707_701908926_0 = std::array{0x01, 0x00, 0x00, 0x00, 0x00, 0x1d, 0xed, 0xb7, 0x44, 0x00, 0x01, 0x00, 0x00, 0x00, 0xc1, 0x54, 0x5a, 0x79, 0xaa, 0x29, 0x4e, 0x59, 0xb9, 0x9d, 0x69, 0xaf, 0x17, 0xbf, 0x1f, 0x94, 0x1d, 0xa5, 0xe6, 0xa9, 0x00, }; -static constexpr auto data_array_2286930707_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_2517507214_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_2517507214_2461747236_0 = std::array{0x00, 0x00, 0x23, 0xf5, 0x44, 0xb5, 0x3c, 0x23, 0x00, 0x40, 0x4b, 0x4c, 0x00, 0x40, 0x42, 0x0f, 0x00, 0x28, 0x28, 0xad, 0x0b, 0x00, }; -static constexpr auto data_array_2663262239_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_2663262239_2721984319_0 = std::array{0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x58, 0x5c, 0x53, 0x55, 0x01, }; -static constexpr auto data_array_2724383112_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_2724383112_2654162901_0 = std::array{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; -static constexpr auto data_array_2850465053_207799855_0 = std::array{0x04, 0x00, 0x00, 0x00, 0x24, 0x68, 0xd6, 0xfb, 0x01, 0x24, 0x84, 0xa5, 0x5f, 0x01, 0x1f, 0x22, 0x1a, 0x4a, 0x01, 0xb7, 0x10, 0xb6, 0xb2, 0x01, 0xec, 0x03, 0x00, 0x00, 0x01, }; -static constexpr auto data_array_2850465053_712345007_0 = std::array{}; -static constexpr auto data_array_2850465053_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_2998276279_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_2998276279_2721984319_0 = std::array{0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x63, 0xa9, 0xd6, 0xd3, 0x01, }; -static constexpr auto data_array_3443994296_207799855_0 = std::array{0x04, 0x00, 0x00, 0x00, 0x1f, 0x22, 0x1a, 0x4a, 0x01, 0xb7, 0x10, 0xb6, 0xb2, 0x01, 0x24, 0x68, 0xd6, 0xfb, 0x01, 0x24, 0x84, 0xa5, 0x5f, 0x01, 0xec, 0x03, 0x00, 0x00, 0x01, }; -static constexpr auto data_array_3443994296_712345007_0 = std::array{}; -static constexpr auto data_array_3443994296_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_3554060643_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_3554060643_2461747236_0 = std::array{0x00, 0x00, 0x23, 0xde, 0x6f, 0x47, 0x3c, 0x23, 0x00, 0x40, 0x4b, 0x4c, 0x00, 0x40, 0x42, 0x0f, 0x00, 0xaf, 0x61, 0x90, 0x5a, 0x00, }; -static constexpr auto data_array_3956468029_701908926_0 = std::array{0x01, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xd6, 0xc0, 0x6f, 0x00, 0x01, 0x00, 0x00, 0x00, 0xb1, 0x5e, 0x61, 0x10, 0x8e, 0x7b, 0x40, 0x2c, 0x96, 0x53, 0xf5, 0x49, 0x6b, 0xa7, 0x03, 0x05, 0xb8, 0x2e, 0x47, 0xcd, 0x00, }; -static constexpr auto data_array_3956468029_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_4028423841_698262047_0 = std::array{0x00, 0x00, 0x00, 0x00, 0xd5, 0x07, 0x00, 0x00, 0x01, }; -static constexpr auto data_array_4028423841_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_4028423841_3658551669_0 = std::array{0x01, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x0f, 0x00, 0x00, 0x00, }; -static constexpr auto data_array_4143624256_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_4143624256_2654162901_0 = std::array{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; -static constexpr auto data_array_4225132580_2178182515_0 = std::array{0x29, 0xf8, 0x05, 0xcf, 0x57, 0x53, 0x06, 0x00, }; -static constexpr auto data_array_4225132580_2721984319_0 = std::array{0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x65, 0x6d, 0x5b, 0x82, 0x01, }; - -static constexpr auto static_domain_data = ae::StaticDomainData{ - ae::StaticMap{{ - std::pair{ std::uint32_t{ 1 } , ae::Span{ class_array_1 }}, - std::pair{ std::uint32_t{ 2 } , ae::Span{ class_array_2 }}, - std::pair{ std::uint32_t{ 3 } , ae::Span{ class_array_3 }}, - std::pair{ std::uint32_t{ 1004 } , ae::Span{ class_array_1004 }}, - std::pair{ std::uint32_t{ 2001 } , ae::Span{ class_array_2001 }}, - std::pair{ std::uint32_t{ 2004 } , ae::Span{ class_array_2004 }}, - std::pair{ std::uint32_t{ 2005 } , ae::Span{ class_array_2005 }}, - std::pair{ std::uint32_t{ 3000 } , ae::Span{ class_array_3000 }}, - std::pair{ std::uint32_t{ 4000 } , ae::Span{ class_array_4000 }}, - std::pair{ std::uint32_t{ 5000 } , ae::Span{ class_array_5000 }}, - std::pair{ std::uint32_t{ 89425 } , ae::Span{ class_array_89425 }}, - std::pair{ std::uint32_t{ 195897384 } , ae::Span{ class_array_195897384 }}, - std::pair{ std::uint32_t{ 634705393 } , ae::Span{ class_array_634705393 }}, - std::pair{ std::uint32_t{ 1152904477 } , ae::Span{ class_array_1152904477 }}, - std::pair{ std::uint32_t{ 1243226655 } , ae::Span{ class_array_1243226655 }}, - std::pair{ std::uint32_t{ 1403600181 } , ae::Span{ class_array_1403600181 }}, - std::pair{ std::uint32_t{ 1431526488 } , ae::Span{ class_array_1431526488 }}, - std::pair{ std::uint32_t{ 1519411631 } , ae::Span{ class_array_1519411631 }}, - std::pair{ std::uint32_t{ 1604682788 } , ae::Span{ class_array_1604682788 }}, - std::pair{ std::uint32_t{ 1652254447 } , ae::Span{ class_array_1652254447 }}, - std::pair{ std::uint32_t{ 1703468408 } , ae::Span{ class_array_1703468408 }}, - std::pair{ std::uint32_t{ 1874908864 } , ae::Span{ class_array_1874908864 }}, - std::pair{ std::uint32_t{ 2187029861 } , ae::Span{ class_array_2187029861 }}, - std::pair{ std::uint32_t{ 2286930707 } , ae::Span{ class_array_2286930707 }}, - std::pair{ std::uint32_t{ 2517507214 } , ae::Span{ class_array_2517507214 }}, - std::pair{ std::uint32_t{ 2663262239 } , ae::Span{ class_array_2663262239 }}, - std::pair{ std::uint32_t{ 2724383112 } , ae::Span{ class_array_2724383112 }}, - std::pair{ std::uint32_t{ 2850465053 } , ae::Span{ class_array_2850465053 }}, - std::pair{ std::uint32_t{ 2998276279 } , ae::Span{ class_array_2998276279 }}, - std::pair{ std::uint32_t{ 3443994296 } , ae::Span{ class_array_3443994296 }}, - std::pair{ std::uint32_t{ 3554060643 } , ae::Span{ class_array_3554060643 }}, - std::pair{ std::uint32_t{ 3956468029 } , ae::Span{ class_array_3956468029 }}, - std::pair{ std::uint32_t{ 4028423841 } , ae::Span{ class_array_4028423841 }}, - std::pair{ std::uint32_t{ 4143624256 } , ae::Span{ class_array_4143624256 }}, - std::pair{ std::uint32_t{ 4225132580 } , ae::Span{ class_array_4225132580 }}, - }}, - - ae::StaticMap{{ - std::pair{ ae::ObjectPathKey{ 1, 2178182515, 0 }, ae::Span{ data_array_1_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 1, 3757268233, 0 }, ae::Span{ data_array_1_3757268233_0 }}, - std::pair{ ae::ObjectPathKey{ 2, 207799855, 0 }, ae::Span{ data_array_2_207799855_0 }}, - std::pair{ ae::ObjectPathKey{ 2, 2178182515, 0 }, ae::Span{ data_array_2_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 2, 2967114514, 0 }, ae::Span{ data_array_2_2967114514_0 }}, - std::pair{ ae::ObjectPathKey{ 3, 1105219716, 0 }, ae::Span{ data_array_3_1105219716_0 }}, - std::pair{ ae::ObjectPathKey{ 3, 2178182515, 0 }, ae::Span{ data_array_3_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 1004, 698262047, 0 }, ae::Span{ data_array_1004_698262047_0 }}, - std::pair{ ae::ObjectPathKey{ 1004, 1232350972, 0 }, ae::Span{ data_array_1004_1232350972_0 }}, - std::pair{ ae::ObjectPathKey{ 1004, 1402813048, 0 }, ae::Span{ data_array_1004_1402813048_0 }}, - std::pair{ ae::ObjectPathKey{ 1004, 2178182515, 0 }, ae::Span{ data_array_1004_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 2001, 1058537116, 0 }, ae::Span{ data_array_2001_1058537116_0 }}, - std::pair{ ae::ObjectPathKey{ 2001, 2178182515, 0 }, ae::Span{ data_array_2001_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 2004, 207799855, 0 }, ae::Span{ data_array_2004_207799855_0 }}, - std::pair{ ae::ObjectPathKey{ 2004, 712345007, 0 }, ae::Span{ data_array_2004_712345007_0 }}, - std::pair{ ae::ObjectPathKey{ 2004, 2178182515, 0 }, ae::Span{ data_array_2004_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 2005, 1296832837, 0 }, ae::Span{ data_array_2005_1296832837_0 }}, - std::pair{ ae::ObjectPathKey{ 2005, 2178182515, 0 }, ae::Span{ data_array_2005_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 3000, 2178182515, 0 }, ae::Span{ data_array_3000_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 3000, 2424033868, 0 }, ae::Span{ data_array_3000_2424033868_0 }}, - std::pair{ ae::ObjectPathKey{ 4000, 217497168, 0 }, ae::Span{ data_array_4000_217497168_0 }}, - std::pair{ ae::ObjectPathKey{ 4000, 844107085, 0 }, ae::Span{ data_array_4000_844107085_0 }}, - std::pair{ ae::ObjectPathKey{ 4000, 2178182515, 0 }, ae::Span{ data_array_4000_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 5000, 460694392, 0 }, ae::Span{ data_array_5000_460694392_0 }}, - std::pair{ ae::ObjectPathKey{ 5000, 733819916, 0 }, ae::Span{ data_array_5000_733819916_0 }}, - std::pair{ ae::ObjectPathKey{ 5000, 2178182515, 0 }, ae::Span{ data_array_5000_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 89425, 2178182515, 0 }, ae::Span{ data_array_89425_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 89425, 2654162901, 0 }, ae::Span{ data_array_89425_2654162901_0 }}, - std::pair{ ae::ObjectPathKey{ 195897384, 2178182515, 0 }, ae::Span{ data_array_195897384_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 195897384, 2654162901, 0 }, ae::Span{ data_array_195897384_2654162901_0 }}, - std::pair{ ae::ObjectPathKey{ 634705393, 2178182515, 0 }, ae::Span{ data_array_634705393_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 634705393, 2654162901, 0 }, ae::Span{ data_array_634705393_2654162901_0 }}, - std::pair{ ae::ObjectPathKey{ 1152904477, 1058537116, 0 }, ae::Span{ data_array_1152904477_1058537116_0 }}, - std::pair{ ae::ObjectPathKey{ 1152904477, 2178182515, 0 }, ae::Span{ data_array_1152904477_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 1243226655, 2178182515, 0 }, ae::Span{ data_array_1243226655_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 1243226655, 2721984319, 0 }, ae::Span{ data_array_1243226655_2721984319_0 }}, - std::pair{ ae::ObjectPathKey{ 1403600181, 2178182515, 0 }, ae::Span{ data_array_1403600181_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 1403600181, 2461747236, 0 }, ae::Span{ data_array_1403600181_2461747236_0 }}, - std::pair{ ae::ObjectPathKey{ 1431526488, 2178182515, 0 }, ae::Span{ data_array_1431526488_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 1431526488, 2461747236, 0 }, ae::Span{ data_array_1431526488_2461747236_0 }}, - std::pair{ ae::ObjectPathKey{ 1519411631, 2178182515, 0 }, ae::Span{ data_array_1519411631_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 1519411631, 2654162901, 0 }, ae::Span{ data_array_1519411631_2654162901_0 }}, - std::pair{ ae::ObjectPathKey{ 1604682788, 2178182515, 0 }, ae::Span{ data_array_1604682788_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 1604682788, 2721984319, 0 }, ae::Span{ data_array_1604682788_2721984319_0 }}, - std::pair{ ae::ObjectPathKey{ 1652254447, 2178182515, 0 }, ae::Span{ data_array_1652254447_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 1652254447, 2721984319, 0 }, ae::Span{ data_array_1652254447_2721984319_0 }}, - std::pair{ ae::ObjectPathKey{ 1703468408, 2178182515, 0 }, ae::Span{ data_array_1703468408_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 1703468408, 2461747236, 0 }, ae::Span{ data_array_1703468408_2461747236_0 }}, - std::pair{ ae::ObjectPathKey{ 1874908864, 1058537116, 0 }, ae::Span{ data_array_1874908864_1058537116_0 }}, - std::pair{ ae::ObjectPathKey{ 1874908864, 2178182515, 0 }, ae::Span{ data_array_1874908864_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 2187029861, 2178182515, 0 }, ae::Span{ data_array_2187029861_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 2187029861, 2461747236, 0 }, ae::Span{ data_array_2187029861_2461747236_0 }}, - std::pair{ ae::ObjectPathKey{ 2286930707, 701908926, 0 }, ae::Span{ data_array_2286930707_701908926_0 }}, - std::pair{ ae::ObjectPathKey{ 2286930707, 2178182515, 0 }, ae::Span{ data_array_2286930707_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 2517507214, 2178182515, 0 }, ae::Span{ data_array_2517507214_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 2517507214, 2461747236, 0 }, ae::Span{ data_array_2517507214_2461747236_0 }}, - std::pair{ ae::ObjectPathKey{ 2663262239, 2178182515, 0 }, ae::Span{ data_array_2663262239_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 2663262239, 2721984319, 0 }, ae::Span{ data_array_2663262239_2721984319_0 }}, - std::pair{ ae::ObjectPathKey{ 2724383112, 2178182515, 0 }, ae::Span{ data_array_2724383112_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 2724383112, 2654162901, 0 }, ae::Span{ data_array_2724383112_2654162901_0 }}, - std::pair{ ae::ObjectPathKey{ 2850465053, 207799855, 0 }, ae::Span{ data_array_2850465053_207799855_0 }}, - std::pair{ ae::ObjectPathKey{ 2850465053, 712345007, 0 }, ae::Span{ data_array_2850465053_712345007_0 }}, - std::pair{ ae::ObjectPathKey{ 2850465053, 2178182515, 0 }, ae::Span{ data_array_2850465053_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 2998276279, 2178182515, 0 }, ae::Span{ data_array_2998276279_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 2998276279, 2721984319, 0 }, ae::Span{ data_array_2998276279_2721984319_0 }}, - std::pair{ ae::ObjectPathKey{ 3443994296, 207799855, 0 }, ae::Span{ data_array_3443994296_207799855_0 }}, - std::pair{ ae::ObjectPathKey{ 3443994296, 712345007, 0 }, ae::Span{ data_array_3443994296_712345007_0 }}, - std::pair{ ae::ObjectPathKey{ 3443994296, 2178182515, 0 }, ae::Span{ data_array_3443994296_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 3554060643, 2178182515, 0 }, ae::Span{ data_array_3554060643_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 3554060643, 2461747236, 0 }, ae::Span{ data_array_3554060643_2461747236_0 }}, - std::pair{ ae::ObjectPathKey{ 3956468029, 701908926, 0 }, ae::Span{ data_array_3956468029_701908926_0 }}, - std::pair{ ae::ObjectPathKey{ 3956468029, 2178182515, 0 }, ae::Span{ data_array_3956468029_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 4028423841, 698262047, 0 }, ae::Span{ data_array_4028423841_698262047_0 }}, - std::pair{ ae::ObjectPathKey{ 4028423841, 2178182515, 0 }, ae::Span{ data_array_4028423841_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 4028423841, 3658551669, 0 }, ae::Span{ data_array_4028423841_3658551669_0 }}, - std::pair{ ae::ObjectPathKey{ 4143624256, 2178182515, 0 }, ae::Span{ data_array_4143624256_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 4143624256, 2654162901, 0 }, ae::Span{ data_array_4143624256_2654162901_0 }}, - std::pair{ ae::ObjectPathKey{ 4225132580, 2178182515, 0 }, ae::Span{ data_array_4225132580_2178182515_0 }}, - std::pair{ ae::ObjectPathKey{ 4225132580, 2721984319, 0 }, ae::Span{ data_array_4225132580_2721984319_0 }}, - -}}, -}; - -// clang-format on - -#endif // FILE_SYSTEM_STATE_H_ \ No newline at end of file diff --git a/projects/espressif_riscv/platformio/aether-client-cpp/CMakeLists.txt b/projects/espressif_riscv/platformio/aether-client-cpp/CMakeLists.txt index bd686574..dc3eeea2 100644 --- a/projects/espressif_riscv/platformio/aether-client-cpp/CMakeLists.txt +++ b/projects/espressif_riscv/platformio/aether-client-cpp/CMakeLists.txt @@ -29,9 +29,6 @@ if (NOT USER_CONFIG) set(USER_CONFIG "${CMAKE_CURRENT_LIST_DIR}/../../../../config/user_config_hydrogen.h" CACHE PATH "") endif() -if (NOT FS_INIT) - set(FS_INIT "${CMAKE_CURRENT_LIST_DIR}/../../../../config/file_system_init.h" CACHE PATH "") -endif() # enable doubles in unity tests add_compile_definitions("CONFIG_UNITY_ENABLE_DOUBLE") diff --git a/projects/espressif_riscv/vscode/aether-client-cpp/CMakeLists.txt b/projects/espressif_riscv/vscode/aether-client-cpp/CMakeLists.txt index a4a21681..41b026c1 100644 --- a/projects/espressif_riscv/vscode/aether-client-cpp/CMakeLists.txt +++ b/projects/espressif_riscv/vscode/aether-client-cpp/CMakeLists.txt @@ -33,10 +33,6 @@ if (NOT USER_CONFIG) set(USER_CONFIG "${CMAKE_CURRENT_LIST_DIR}/../../../../config/user_config_optimized.h" CACHE PATH "") endif() -if (NOT FS_INIT) - set(FS_INIT "${CMAKE_CURRENT_LIST_DIR}/../../../../config/file_system_init.h" CACHE PATH "") -endif() - # enable doubles in unity tests add_compile_definitions("CONFIG_UNITY_ENABLE_DOUBLE") diff --git a/projects/xtensa_lx6/platformio/aether-client-cpp/CMakeLists.txt b/projects/xtensa_lx6/platformio/aether-client-cpp/CMakeLists.txt index d2c9d8dc..c1497a57 100644 --- a/projects/xtensa_lx6/platformio/aether-client-cpp/CMakeLists.txt +++ b/projects/xtensa_lx6/platformio/aether-client-cpp/CMakeLists.txt @@ -29,10 +29,6 @@ if (NOT USER_CONFIG) set(USER_CONFIG "${CMAKE_CURRENT_LIST_DIR}/../../../../config/user_config_optimized.h" CACHE PATH "") endif() -if (NOT FS_INIT) - set(FS_INIT "${CMAKE_CURRENT_LIST_DIR}/../../../../config/file_system_init.h" CACHE PATH "") -endif() - # enable doubles in unity tests add_compile_definitions("CONFIG_UNITY_ENABLE_DOUBLE") diff --git a/projects/xtensa_lx6/vscode/aether-client-cpp/CMakeLists.txt b/projects/xtensa_lx6/vscode/aether-client-cpp/CMakeLists.txt index 2a98f088..711ce380 100644 --- a/projects/xtensa_lx6/vscode/aether-client-cpp/CMakeLists.txt +++ b/projects/xtensa_lx6/vscode/aether-client-cpp/CMakeLists.txt @@ -33,10 +33,6 @@ if (NOT USER_CONFIG) set(USER_CONFIG "${CMAKE_CURRENT_LIST_DIR}/../../../../config/user_config_optimized.h" CACHE PATH "") endif() -if (NOT FS_INIT) - set(FS_INIT "${CMAKE_CURRENT_LIST_DIR}/../../../../config/file_system_init.h" CACHE PATH "") -endif() - # enable doubles in unity tests add_compile_definitions("CONFIG_UNITY_ENABLE_DOUBLE") From 394611a8a01d5ee68b926ced83e072ce0baedf43 Mon Sep 17 00:00:00 2001 From: BartolomeyKant Date: Fri, 9 Jan 2026 11:15:18 +0500 Subject: [PATCH 07/12] fix test ds synchronization --- tests/test-domain-storage/test_ds_synchronization.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-domain-storage/test_ds_synchronization.cpp b/tests/test-domain-storage/test_ds_synchronization.cpp index 5dcf80a5..35913c1a 100644 --- a/tests/test-domain-storage/test_ds_synchronization.cpp +++ b/tests/test-domain-storage/test_ds_synchronization.cpp @@ -91,7 +91,7 @@ void TestSyncDataStorage(std::unique_ptr sds, writer_2_1->write(data_4.data(), data_4.size()); writer_2_1.reset(); - auto load_2_1 = data_storage.Load(2, 0); + auto load_2_1 = data_storage.Load(2, 1); TEST_ASSERT(load_2_1.result == DomainLoadResult::kLoaded); auto data_2_1 = DataGetter(load_2_1.reader); TEST_ASSERT_EQUAL_UINT8_ARRAY(data_4.data(), data_2_1.data(), From faaad3a7d9bdf40d17c957f5e792a89865b26c91 Mon Sep 17 00:00:00 2001 From: BartolomeyKant Date: Fri, 9 Jan 2026 11:15:32 +0500 Subject: [PATCH 08/12] fix data packet collector for now --- aether/transport/data_packet_collector.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/aether/transport/data_packet_collector.cpp b/aether/transport/data_packet_collector.cpp index 999a5cd6..1f057a18 100644 --- a/aether/transport/data_packet_collector.cpp +++ b/aether/transport/data_packet_collector.cpp @@ -86,7 +86,11 @@ std::pair StreamDataPacketCollector::GetPacketSize( ? sizeof(PacketSize::ValueType) : size; + // TODO: it's possible that there is maybe less data than max PacketSize temp_data_buffer_.insert(temp_data_buffer_.end(), data, data + use_max_size); + if (temp_data_buffer_.size() < sizeof(PacketSize::ValueType)) { + return {0, 0}; + } VectorReader reader(temp_data_buffer_); auto is = imstream{reader}; From 688caf3831fae19aa492b59c76dbe39b6c63971c Mon Sep 17 00:00:00 2001 From: BartolomeyKant Date: Fri, 9 Jan 2026 11:15:52 +0500 Subject: [PATCH 09/12] add try to load client, if not loaded --- aether/aether.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/aether/aether.cpp b/aether/aether.cpp index cabcef5a..e4e4cd35 100644 --- a/aether/aether.cpp +++ b/aether/aether.cpp @@ -77,7 +77,13 @@ ActionPtr Aether::SelectClient( if (client) { return MakeSelectClient(client); } -// register new client + // try load client + client = std::make_shared(*this, client_id, domain_); + if (!client->uid().empty()) { + StoreClient(client); + return MakeSelectClient(client); + } + // register new client #if AE_SUPPORT_REGISTRATION auto registration = RegisterClient(parent_uid); return MakeSelectClient(std::move(registration), client_id); From e2c8fc55a634548cc82fb2b2ca47223bb1d68314 Mon Sep 17 00:00:00 2001 From: BartolomeyKant Date: Fri, 9 Jan 2026 11:16:02 +0500 Subject: [PATCH 10/12] fix server logs --- aether/server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aether/server.cpp b/aether/server.cpp index f3eedb95..5b0cb3a5 100644 --- a/aether/server.cpp +++ b/aether/server.cpp @@ -30,7 +30,7 @@ Server::Server(ServerId server_id, adapter_registry_{std::move(adapter_registry)} { assert((server_id != 0) && "Server ID must be non-zero"); domain_->Load(*this, Hash(kTypeName, server_id)); - AE_TELED_DEBUG("Loaded server id={}, endpoints={}", server_id, endpoints); + AE_TELED_DEBUG("Loaded server id={}, endpoints=[{}]", server_id, endpoints); Register(); } From f73eef4faf568be82d49bb7fac54aefada5a0267 Mon Sep 17 00:00:00 2001 From: BartolomeyKant Date: Fri, 9 Jan 2026 11:16:20 +0500 Subject: [PATCH 11/12] fix cloed test construct adapters --- examples/cloud/aether_construct_esp_wifi.h | 21 ++++++++------------- examples/cloud/aether_construct_ethernet.h | 20 ++++++++------------ 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/examples/cloud/aether_construct_esp_wifi.h b/examples/cloud/aether_construct_esp_wifi.h index 9477eff8..d9a505d2 100644 --- a/examples/cloud/aether_construct_esp_wifi.h +++ b/examples/cloud/aether_construct_esp_wifi.h @@ -27,19 +27,14 @@ static constexpr std::string_view kWifiPass = "Test1234"; RcPtr construct_aether_app() { return AetherApp::Construct( - AetherAppContext{} -# if defined AE_DISTILLATION - .AdaptersFactory([](AetherAppContext const& context) { - auto adapter_registry = - context.domain().CreateObj(); - adapter_registry->Add(context.domain().CreateObj( - GlobalId::kWiFiAdapter, context.aether(), context.poller(), - context.dns_resolver(), std::string(kWifiSsid), - std::string(kWifiPass))); - return adapter_registry; - }) -# endif - ); + AetherAppContext{}.AdaptersFactory([](AetherAppContext const& context) { + auto adapter_registry = + std::make_shared(context.domain()); + adapter_registry->Add(std::make_shared( + *context.aether(), *context.poller(), *context.dns_resolver(), + std::string(kWifiSsid), std::string(kWifiPass), context.domain())); + return adapter_registry; + })); } } // namespace ae::cloud_test diff --git a/examples/cloud/aether_construct_ethernet.h b/examples/cloud/aether_construct_ethernet.h index c8374e57..de589bfd 100644 --- a/examples/cloud/aether_construct_ethernet.h +++ b/examples/cloud/aether_construct_ethernet.h @@ -23,18 +23,14 @@ namespace ae::cloud_test { static RcPtr construct_aether_app() { return AetherApp::Construct( - AetherAppContext{} -# if defined AE_DISTILLATION - .AdaptersFactory([](AetherAppContext const& context) { - auto adapter_registry = - std::make_shared(context.domain()); - adapter_registry->Add(std::make_shared( - *context.aether(), *context.poller(), *context.dns_resolver(), - context.domain())); - return adapter_registry; - }) -# endif - ); + AetherAppContext{}.AdaptersFactory([](AetherAppContext const& context) { + auto adapter_registry = + std::make_shared(context.domain()); + adapter_registry->Add(std::make_shared( + *context.aether(), *context.poller(), *context.dns_resolver(), + context.domain())); + return adapter_registry; + })); } } // namespace ae::cloud_test #endif From 391e08534926e7f493d3223c67c8d259456c0c8c Mon Sep 17 00:00:00 2001 From: BartolomeyKant Date: Fri, 9 Jan 2026 11:21:40 +0500 Subject: [PATCH 12/12] fix code style in hash --- aether/misc/hash.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/aether/misc/hash.h b/aether/misc/hash.h index ef25cca3..55509b58 100644 --- a/aether/misc/hash.h +++ b/aether/misc/hash.h @@ -14,9 +14,11 @@ * limitations under the License. */ -#ifndef AEHTER_MISC_HASH_H_ -#define AEHTER_MISC_HASH_H_ +#ifndef AETHER_MISC_HASH_H_ +#define AETHER_MISC_HASH_H_ +#include +#include #include #include "aether/crc.h" @@ -90,4 +92,4 @@ struct Hasher { } // namespace ae -#endif // AEHTER_MISC_HASH_H_ +#endif // AETHER_MISC_HASH_H_