diff --git a/source/RobotAPI/libraries/armem/CMakeLists.txt b/source/RobotAPI/libraries/armem/CMakeLists.txt index 4f9b5be30489e93151d9f4e5034b058bed520dc3..c004148924127bbcc2145def5a1e10ba160143d4 100644 --- a/source/RobotAPI/libraries/armem/CMakeLists.txt +++ b/source/RobotAPI/libraries/armem/CMakeLists.txt @@ -20,7 +20,9 @@ set(LIB_FILES segments/CoreSegment.cpp segments/Entity.cpp segments/EntityData.cpp + segments/EntitySnapshot.cpp segments/EntityStorage.cpp + segments/InternalCommit.cpp segments/Memory.cpp segments/ProviderSegment.cpp ) @@ -35,7 +37,9 @@ set(LIB_HEADERS segments/CoreSegment.h segments/Entity.h segments/EntityData.h + segments/EntitySnapshot.h segments/EntityStorage.h + segments/InternalCommit.h segments/Memory.h segments/ProviderSegment.h ) diff --git a/source/RobotAPI/libraries/armem/segments/CoreSegment.cpp b/source/RobotAPI/libraries/armem/segments/CoreSegment.cpp index dcfdb18e8228ccd1aa3eb7b6d7dc5f0969d624f5..3043abb4a4b1057c69d6b2b20cca05d700c1ac64 100644 --- a/source/RobotAPI/libraries/armem/segments/CoreSegment.cpp +++ b/source/RobotAPI/libraries/armem/segments/CoreSegment.cpp @@ -4,7 +4,7 @@ namespace armarx::armem { - void CoreSegment::update(const EntityUpdate& update) + void CoreSegment::update(const InternalEntityUpdate& update) { if (update.entityID.coreSegmentName != this->name) { diff --git a/source/RobotAPI/libraries/armem/segments/CoreSegment.h b/source/RobotAPI/libraries/armem/segments/CoreSegment.h index 6fbfba228308a1daf4e3a87880e56026632b541e..ce7f33555bf5aafccaff5fe948723386d11adbfb 100644 --- a/source/RobotAPI/libraries/armem/segments/CoreSegment.h +++ b/source/RobotAPI/libraries/armem/segments/CoreSegment.h @@ -20,7 +20,7 @@ namespace armarx::armem using EntityStorage::EntityStorage; - virtual void update(const EntityUpdate& update) override; + virtual void update(const InternalEntityUpdate& update) override; public: diff --git a/source/RobotAPI/libraries/armem/segments/Entity.cpp b/source/RobotAPI/libraries/armem/segments/Entity.cpp index 595679fa7d8d0697b8f376ad3679a1413adea61c..8ddd6dba27647aecb1f4796e20e3d816eb9c7590 100644 --- a/source/RobotAPI/libraries/armem/segments/Entity.cpp +++ b/source/RobotAPI/libraries/armem/segments/Entity.cpp @@ -12,7 +12,7 @@ namespace armarx::armem { } - void Entity::update(const EntityUpdate& update) + void Entity::update(const InternalEntityUpdate& update) { if (update.entityID.entityName != this->name) { @@ -30,17 +30,4 @@ namespace armarx::armem it->second->update(update); } - - void EntitySnapshot::update(const EntityUpdate& update) - { - id = update.timeCreated; - - instances.clear(); - for (int i = 0; i < int(update.instancesData.size()); ++i) - { - EntityDataPtr& data = instances.emplace_back(std::make_unique<EntityData>()); - data->update(update, i); - } - } - } diff --git a/source/RobotAPI/libraries/armem/segments/Entity.h b/source/RobotAPI/libraries/armem/segments/Entity.h index f21467acbb41335d3dea46dfd19ea7a0dca65e24..78d0625d91bfa282f5e7247f6d837ddd28a0c102 100644 --- a/source/RobotAPI/libraries/armem/segments/Entity.h +++ b/source/RobotAPI/libraries/armem/segments/Entity.h @@ -4,12 +4,9 @@ #include <memory> #include <string> -#include <RobotAPI/interface/aron.h> - #include "../core/Time.h" -#include "../core/MemoryID.h" -#include "EntityData.h" -#include "EntityStorage.h" + +#include "EntitySnapshot.h" namespace armarx::armem @@ -29,7 +26,7 @@ namespace armarx::armem Entity(); Entity(const std::string& name); - void update(const EntityUpdate& update); + void update(const InternalEntityUpdate& update); public: @@ -41,36 +38,4 @@ namespace armarx::armem using EntityPtr = std::unique_ptr<Entity>; - - /** - * @brief Data of an entity at one point in time. - */ - class EntitySnapshot - { - public: - - EntitySnapshot() = default; - - - void update(const EntityUpdate& update); - - - EntityData* getInstance(int index) - { - size_t si = size_t(index); - return (index >= 0 && si < instances.size()) ? instances[si].get() : nullptr; - } - EntityData* getInstance(MemoryID id) - { - return id.hasInstanceIndex() ? getInstance(id.instanceIndex) : nullptr; - } - - - public: - - Time id; - std::vector<EntityDataPtr> instances; - - }; - } diff --git a/source/RobotAPI/libraries/armem/segments/EntityData.cpp b/source/RobotAPI/libraries/armem/segments/EntityData.cpp index 0a2fd172bc52e04508f464af7165978829124803..b9f841c2c5d4258a22257045a8f9ea753e361bd7 100644 --- a/source/RobotAPI/libraries/armem/segments/EntityData.cpp +++ b/source/RobotAPI/libraries/armem/segments/EntityData.cpp @@ -6,7 +6,7 @@ namespace armarx::armem { - void EntityData::update(const EntityUpdate& update, int index) + void EntityData::update(const InternalEntityUpdate& update, int index) { ARMARX_CHECK_FITS_SIZE(index, update.instancesData.size()); @@ -14,9 +14,10 @@ namespace armarx::armem this->data = update.instancesData.at(size_t(index)); this->metadata.importance = update.importance; + this->metadata.timeCreated = update.timeCreated; this->metadata.timeSent = update.timeSent; - this->metadata.timeArrived = Time::now(); // todo; + this->metadata.timeArrived = update.timeArrived; } } diff --git a/source/RobotAPI/libraries/armem/segments/EntityData.h b/source/RobotAPI/libraries/armem/segments/EntityData.h index 4fa91a181a8ae1f9375c7058412466f9115000bd..c904a643a248a05189c316deb7e340945a62ca27 100644 --- a/source/RobotAPI/libraries/armem/segments/EntityData.h +++ b/source/RobotAPI/libraries/armem/segments/EntityData.h @@ -5,7 +5,8 @@ #include <RobotAPI/interface/aron.h> #include "../core/Time.h" -#include "../client/Commit.h" + +#include "InternalCommit.h" namespace armarx::armem @@ -38,7 +39,7 @@ namespace armarx::armem aron::AronDataPtr data; EntityMetadata metadata; - void update(const EntityUpdate& update, int index); + void update(const InternalEntityUpdate& update, int index); }; using EntityDataPtr = std::unique_ptr<EntityData>; diff --git a/source/RobotAPI/libraries/armem/segments/EntitySnapshot.cpp b/source/RobotAPI/libraries/armem/segments/EntitySnapshot.cpp new file mode 100644 index 0000000000000000000000000000000000000000..73eac93d18a30612deed6a08e37ea82289961a3e --- /dev/null +++ b/source/RobotAPI/libraries/armem/segments/EntitySnapshot.cpp @@ -0,0 +1,20 @@ +#include "EntitySnapshot.h" + + +namespace armarx::armem +{ + + + void EntitySnapshot::update(const InternalEntityUpdate& update) + { + id = update.timeCreated; + + instances.clear(); + for (int i = 0; i < int(update.instancesData.size()); ++i) + { + EntityDataPtr& data = instances.emplace_back(std::make_unique<EntityData>()); + data->update(update, i); + } + } + +} diff --git a/source/RobotAPI/libraries/armem/segments/EntitySnapshot.h b/source/RobotAPI/libraries/armem/segments/EntitySnapshot.h new file mode 100644 index 0000000000000000000000000000000000000000..dce6c4c0f1baf90b341f4bdc1f6bdcb35a90b033 --- /dev/null +++ b/source/RobotAPI/libraries/armem/segments/EntitySnapshot.h @@ -0,0 +1,49 @@ +#pragma once + +#include <memory> +#include <vector> + +#include "../core/Time.h" +#include "../core/MemoryID.h" + +#include "EntityData.h" + + +namespace armarx::armem +{ + + /** + * @brief Data of an entity at one point in time. + */ + class EntitySnapshot + { + public: + + EntitySnapshot() = default; + + + void update(const InternalEntityUpdate& update); + + + EntityData* getInstance(int index) + { + size_t si = size_t(index); + return (index >= 0 && si < instances.size()) ? instances[si].get() : nullptr; + } + EntityData* getInstance(MemoryID id) + { + return id.hasInstanceIndex() ? getInstance(id.instanceIndex) : nullptr; + } + + + public: + + Time id; + std::vector<EntityDataPtr> instances; + + }; + + using EntitySnapshotPtr = std::unique_ptr<EntitySnapshot>; + + +} diff --git a/source/RobotAPI/libraries/armem/segments/EntityStorage.cpp b/source/RobotAPI/libraries/armem/segments/EntityStorage.cpp index 8ed344d85132e6695b4b1de5555bab6900ace1b5..4cff8192604930f91a03ab04686981731098f537 100644 --- a/source/RobotAPI/libraries/armem/segments/EntityStorage.cpp +++ b/source/RobotAPI/libraries/armem/segments/EntityStorage.cpp @@ -12,7 +12,7 @@ namespace armarx::armem { } - void EntityStorage::update(const Commit& commit) + void EntityStorage::update(const InternalCommit& commit) { for (const auto& update : commit.updates) { diff --git a/source/RobotAPI/libraries/armem/segments/EntityStorage.h b/source/RobotAPI/libraries/armem/segments/EntityStorage.h index 9a50056942348f4db2b678eaad05f8f85dccd55e..960064a108aee9b6fadf7adddf0bf67466fbfa43 100644 --- a/source/RobotAPI/libraries/armem/segments/EntityStorage.h +++ b/source/RobotAPI/libraries/armem/segments/EntityStorage.h @@ -1,6 +1,6 @@ #pragma once -#include "../client/Commit.h" +#include "InternalCommit.h" namespace armarx::armem @@ -20,8 +20,8 @@ namespace armarx::armem virtual ~EntityStorage() = default; - void update(const Commit& commit); - virtual void update(const EntityUpdate& update) = 0; + void update(const InternalCommit& commit); + virtual void update(const InternalEntityUpdate& update) = 0; public: diff --git a/source/RobotAPI/libraries/armem/segments/InternalCommit.cpp b/source/RobotAPI/libraries/armem/segments/InternalCommit.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0f21876094199ba6dea13325683466efebed9d1b --- /dev/null +++ b/source/RobotAPI/libraries/armem/segments/InternalCommit.cpp @@ -0,0 +1,7 @@ +#include "InternalCommit.h" + + +namespace armarx::armem +{ + +} diff --git a/source/RobotAPI/libraries/armem/segments/InternalCommit.h b/source/RobotAPI/libraries/armem/segments/InternalCommit.h new file mode 100644 index 0000000000000000000000000000000000000000..07264dcbf2abd1303ec46841601cc856f5be4905 --- /dev/null +++ b/source/RobotAPI/libraries/armem/segments/InternalCommit.h @@ -0,0 +1,28 @@ +#pragma once + +#include <vector> + +#include "../client/Commit.h" + + +namespace armarx::armem +{ + + /** + * @brief An update received by a memory. + * + * For use inside a memory. + */ + struct InternalEntityUpdate : public EntityUpdate + { + Time timeArrived = Time::microSeconds(-1); + }; + + + struct InternalCommit + { + std::vector<InternalEntityUpdate> updates; + }; + + +} diff --git a/source/RobotAPI/libraries/armem/segments/Memory.cpp b/source/RobotAPI/libraries/armem/segments/Memory.cpp index cf6d5fb62831722e8c760990554e38fca0b7643e..7a30818c0ec313a19446765075ce6727fe009eea 100644 --- a/source/RobotAPI/libraries/armem/segments/Memory.cpp +++ b/source/RobotAPI/libraries/armem/segments/Memory.cpp @@ -4,7 +4,7 @@ namespace armarx::armem { - void Memory::update(const EntityUpdate& update) + void Memory::update(const InternalEntityUpdate& update) { if (update.entityID.memoryName != this->name) { diff --git a/source/RobotAPI/libraries/armem/segments/Memory.h b/source/RobotAPI/libraries/armem/segments/Memory.h index c436acfea7e964a58e1d45f44b6342725afa0c8c..4e1ad888ab573a17db74423fc725f298af6eb646 100644 --- a/source/RobotAPI/libraries/armem/segments/Memory.h +++ b/source/RobotAPI/libraries/armem/segments/Memory.h @@ -20,7 +20,7 @@ namespace armarx::armem using EntityStorage::EntityStorage; - virtual void update(const EntityUpdate& update) override; + virtual void update(const InternalEntityUpdate& update) override; public: diff --git a/source/RobotAPI/libraries/armem/segments/ProviderSegment.cpp b/source/RobotAPI/libraries/armem/segments/ProviderSegment.cpp index e30e617a13cdb37e395c65f926ae43353ca6067c..67dc198f50f3646c70e05707de63df51207aa00b 100644 --- a/source/RobotAPI/libraries/armem/segments/ProviderSegment.cpp +++ b/source/RobotAPI/libraries/armem/segments/ProviderSegment.cpp @@ -4,7 +4,7 @@ namespace armarx::armem { - void ProviderSegment::update(const EntityUpdate& update) + void ProviderSegment::update(const InternalEntityUpdate& update) { if (update.entityID.coreSegmentName != this->name) { diff --git a/source/RobotAPI/libraries/armem/segments/ProviderSegment.h b/source/RobotAPI/libraries/armem/segments/ProviderSegment.h index d0a111a5dd4b64afcdcbbeeacc345331662198d7..c85c8dc528a32120df0fbf91cc89d295f298c63a 100644 --- a/source/RobotAPI/libraries/armem/segments/ProviderSegment.h +++ b/source/RobotAPI/libraries/armem/segments/ProviderSegment.h @@ -20,7 +20,7 @@ namespace armarx::armem using EntityStorage::EntityStorage; - virtual void update(const EntityUpdate& update) override; + virtual void update(const InternalEntityUpdate& update) override; public: