From 4c162bdb351b3d8e1e450c0c7d5af3c91c517701 Mon Sep 17 00:00:00 2001 From: "fabian.peller-konrad@kit.edu" <fabian.peller-konrad@kit.edu> Date: Mon, 19 Apr 2021 18:11:10 +0200 Subject: [PATCH] WOrking Memory updates, new namespaces for wm and ltm, updated scenarios, adapted all dependent code. First compiling version --- scenarios/ArMemExample/ArMemExample.scx | 6 +- ...MemExampleMemory.cfg => ExampleMemory.cfg} | 132 ++++--- ...mpleClient.cfg => ExampleMemoryClient.cfg} | 114 +++--- ...oryNameSystem.cfg => MemoryNameSystem.cfg} | 70 ++-- .../components/armem/client/CMakeLists.txt | 2 +- .../test/ArMemExampleClientTest.cpp | 37 -- .../client/ExampleClient/test/CMakeLists.txt | 5 - .../CMakeLists.txt | 6 +- .../ExampleMemoryClient.cpp} | 64 ++-- .../ExampleMemoryClient.h} | 12 +- .../server/ExampleMemory/ExampleMemory.cpp | 10 +- .../ExampleMemory/test/ExampleMemoryTest.cpp | 8 +- .../GeneralPurposeMemory.cpp | 2 +- .../RobotSensorMemory/RobotSensorMemory.cpp | 6 +- .../server/SkillsMemory/SkillsMemory.cpp | 2 +- source/RobotAPI/interface/armem/io.ice | 2 - source/RobotAPI/interface/aron/Aron.ice | 2 +- .../RobotAPI/libraries/armem/CMakeLists.txt | 112 +++--- .../RobotAPI/libraries/armem/client/Query.cpp | 7 +- .../RobotAPI/libraries/armem/client/Query.h | 4 +- .../RobotAPI/libraries/armem/client/Reader.h | 4 +- source/RobotAPI/libraries/armem/core.h | 13 +- .../libraries/armem/core/CoreSegment.cpp | 173 --------- .../libraries/armem/core/CoreSegment.h | 93 ----- .../RobotAPI/libraries/armem/core/Entity.cpp | 216 ----------- source/RobotAPI/libraries/armem/core/Entity.h | 192 ---------- .../libraries/armem/core/EntitySnapshot.cpp | 166 --------- .../libraries/armem/core/EntitySnapshot.h | 103 ------ .../RobotAPI/libraries/armem/core/Memory.cpp | 174 --------- source/RobotAPI/libraries/armem/core/Memory.h | 83 ----- .../libraries/armem/core/ProviderSegment.cpp | 175 --------- .../libraries/armem/core/ProviderSegment.h | 97 ----- .../CoreSegment.cpp} | 0 .../libraries/armem/core/base/CoreSegment.h | 224 ++++++++++++ .../libraries/armem/core/base/Entity.cpp | 0 .../libraries/armem/core/base/Entity.h | 335 ++++++++++++++++++ .../armem/core/base/EntityInstance.cpp | 0 .../armem/core/base/EntityInstance.h | 86 +++++ .../armem/core/base/EntitySnapshot.cpp | 0 .../armem/core/base/EntitySnapshot.h | 221 ++++++++++++ .../libraries/armem/core/base/Memory.cpp | 0 .../libraries/armem/core/base/Memory.h | 218 ++++++++++++ .../armem/core/base/ProviderSegment.cpp | 0 .../armem/core/base/ProviderSegment.h | 222 ++++++++++++ .../{ => base}/detail/EntityContainer.cpp | 0 .../core/{ => base}/detail/EntityContainer.h | 79 ++--- .../core/{ => base}/detail/MaxHistorySize.cpp | 0 .../core/{ => base}/detail/MaxHistorySize.h | 0 .../{ => base}/detail/MemoryContainer.cpp | 0 .../armem/core/base/detail/MemoryContainer.h | 116 ++++++ .../armem/core/base/detail/MemoryItem.cpp | 0 .../armem/core/{ => base}/detail/MemoryItem.h | 35 +- .../core/base/detail/TypedEntityContainer.h | 81 +++++ .../armem/core/base/ice_conversions.cpp | 130 +++++++ .../armem/core/base/ice_conversions.h | 35 ++ .../armem/core/detail/MemoryContainer.h | 114 ------ .../armem/core/detail/MemoryItem.cpp | 19 - .../armem/core/detail/TypedEntityContainer.h | 63 ---- .../libraries/armem/core/ice_conversions.cpp | 129 +------ .../libraries/armem/core/ice_conversions.h | 27 +- .../armem/core/ice_conversions_templates.h | 11 +- .../armem/core/io/DiskCoreSegment.cpp | 112 ------ .../libraries/armem/core/io/DiskCoreSegment.h | 74 ---- .../libraries/armem/core/io/DiskEntity.cpp | 107 ------ .../libraries/armem/core/io/DiskEntity.h | 76 ---- .../armem/core/io/DiskEntityInstance.cpp | 57 --- .../armem/core/io/DiskEntityInstance.h | 67 ---- .../armem/core/io/DiskEntitySnapshot.cpp | 112 ------ .../armem/core/io/DiskEntitySnapshot.h | 75 ---- .../armem/core/io/DiskInstanceData.h | 48 --- .../libraries/armem/core/io/DiskMemory.cpp | 138 -------- .../libraries/armem/core/io/DiskMemory.h | 96 ----- .../armem/core/io/DiskProviderSegment.cpp | 113 ------ .../armem/core/io/DiskProviderSegment.h | 75 ---- .../core/io/MemoryFileSystemStorage_OLD.cpp | 291 --------------- .../core/io/MemoryFileSystemStorage_OLD.h | 77 ---- .../armem/core/io/detail/DiskMemoryItem.h | 70 ---- .../core/io/detail/DiskTypedEntityContainer.h | 52 --- .../armem/core/io/diskReader/DiskReader.cpp | 73 ---- .../armem/core/io/diskReader/DiskReader.h | 52 --- .../NlohmannJSON/NlohmannJSONDiskReader.cpp | 28 -- .../NlohmannJSON/NlohmannJSONDiskReader.h | 45 --- .../armem/core/io/diskWriter/DiskWriter.cpp | 90 ----- .../armem/core/io/diskWriter/DiskWriter.h | 54 --- .../NlohmannJSON/NlohmannJSONDiskWriter.cpp | 24 -- .../NlohmannJSON/NlohmannJSONDiskWriter.h | 51 --- .../armem/core/longtermMemory/CoreSegment.cpp | 45 +++ .../armem/core/longtermMemory/CoreSegment.h | 29 ++ .../armem/core/longtermMemory/Entity.cpp | 33 ++ .../armem/core/longtermMemory/Entity.h | 46 +++ .../core/longtermMemory/EntityInstance.cpp | 62 ++++ .../core/longtermMemory/EntityInstance.h | 72 ++++ .../core/longtermMemory/EntitySnapshot.cpp | 45 +++ .../core/longtermMemory/EntitySnapshot.h | 31 ++ .../armem/core/longtermMemory/Memory.cpp | 39 ++ .../armem/core/longtermMemory/Memory.h | 26 ++ .../core/longtermMemory/ProviderSegment.cpp | 45 +++ .../core/longtermMemory/ProviderSegment.h | 29 ++ .../longtermMemory/detail/EntityContainer.cpp | 10 + .../longtermMemory/detail/EntityContainer.h | 32 ++ .../longtermMemory/detail/MemoryContainer.cpp | 7 + .../longtermMemory/detail/MemoryContainer.h | 28 ++ .../detail/TypedEntityContainer.h | 26 ++ .../core/longtermMemory/ice_conversions.cpp | 0 .../core/longtermMemory/ice_conversions.h | 0 .../armem/core/workingMemory/CoreSegment.cpp | 47 +++ .../armem/core/workingMemory/CoreSegment.h | 31 ++ .../armem/core/workingMemory/Entity.cpp | 33 ++ .../armem/core/workingMemory/Entity.h | 48 +++ .../{ => workingMemory}/EntityInstance.cpp | 47 +-- .../core/{ => workingMemory}/EntityInstance.h | 47 +-- .../core/workingMemory/EntitySnapshot.cpp | 45 +++ .../armem/core/workingMemory/EntitySnapshot.h | 33 ++ .../armem/core/workingMemory/Memory.cpp | 40 +++ .../armem/core/workingMemory/Memory.h | 28 ++ .../core/workingMemory/ProviderSegment.cpp | 48 +++ .../core/workingMemory/ProviderSegment.h | 31 ++ .../workingMemory/detail/EntityContainer.cpp | 0 .../workingMemory/detail/EntityContainer.h | 32 ++ .../workingMemory/detail/MemoryContainer.cpp | 7 + .../workingMemory/detail/MemoryContainer.h | 35 ++ .../detail/TypedEntityContainer.h | 26 ++ .../core/workingMemory/ice_conversions.cpp | 126 +++++++ .../core/workingMemory/ice_conversions.h | 35 ++ .../armem/server/ComponentPlugin.cpp | 16 +- .../libraries/armem/server/ComponentPlugin.h | 14 +- .../armem/server/MemoryRemoteGui.cpp | 14 +- .../libraries/armem/server/MemoryRemoteGui.h | 14 +- .../armem/server/MemoryToIceAdapter.cpp | 52 +-- .../armem/server/MemoryToIceAdapter.h | 10 +- .../query_proc/CoreSegmentQueryProcessor.cpp | 18 +- .../query_proc/CoreSegmentQueryProcessor.h | 14 +- .../query_proc/EntityQueryProcessor.cpp | 27 +- .../server/query_proc/EntityQueryProcessor.h | 22 +- .../query_proc/MemoryQueryProcessor.cpp | 16 +- .../server/query_proc/MemoryQueryProcessor.h | 18 +- .../ProviderSegmentQueryProcessor.cpp | 18 +- .../ProviderSegmentQueryProcessor.h | 14 +- .../libraries/armem/test/ArMemLTMTest.cpp | 14 +- .../libraries/armem/test/ArMemMemoryTest.cpp | 16 +- .../libraries/armem/test/ArMemQueryTest.cpp | 36 +- source/RobotAPI/libraries/armem/util/util.h | 12 +- .../libraries/armem_gui/MemoryViewer.cpp | 14 +- .../libraries/armem_gui/MemoryViewer.h | 2 +- .../armem_gui/instance/InstanceView.cpp | 12 +- .../armem_gui/instance/InstanceView.h | 10 +- .../libraries/armem_gui/memory/TreeWidget.cpp | 94 ++--- .../libraries/armem_gui/memory/TreeWidget.h | 40 ++- .../TransformReader.cpp | 6 +- .../TransformReader.h | 6 +- .../TransformWriter.cpp | 6 +- 151 files changed, 3594 insertions(+), 4579 deletions(-) rename scenarios/ArMemExample/config/{ArMemExampleMemory.cfg => ExampleMemory.cfg} (77%) rename scenarios/ArMemExample/config/{ArMemExampleClient.cfg => ExampleMemoryClient.cfg} (81%) rename scenarios/ArMemExample/config/{ArMemMemoryNameSystem.cfg => MemoryNameSystem.cfg} (90%) delete mode 100644 source/RobotAPI/components/armem/client/ExampleClient/test/ArMemExampleClientTest.cpp delete mode 100644 source/RobotAPI/components/armem/client/ExampleClient/test/CMakeLists.txt rename source/RobotAPI/components/armem/client/{ExampleClient => ExampleMemoryClient}/CMakeLists.txt (84%) rename source/RobotAPI/components/armem/client/{ExampleClient/ExampleClient.cpp => ExampleMemoryClient/ExampleMemoryClient.cpp} (83%) rename source/RobotAPI/components/armem/client/{ExampleClient/ExampleClient.h => ExampleMemoryClient/ExampleMemoryClient.h} (91%) delete mode 100644 source/RobotAPI/libraries/armem/core/CoreSegment.cpp delete mode 100644 source/RobotAPI/libraries/armem/core/CoreSegment.h delete mode 100644 source/RobotAPI/libraries/armem/core/Entity.cpp delete mode 100644 source/RobotAPI/libraries/armem/core/Entity.h delete mode 100644 source/RobotAPI/libraries/armem/core/EntitySnapshot.cpp delete mode 100644 source/RobotAPI/libraries/armem/core/EntitySnapshot.h delete mode 100644 source/RobotAPI/libraries/armem/core/Memory.cpp delete mode 100644 source/RobotAPI/libraries/armem/core/Memory.h delete mode 100644 source/RobotAPI/libraries/armem/core/ProviderSegment.cpp delete mode 100644 source/RobotAPI/libraries/armem/core/ProviderSegment.h rename source/RobotAPI/libraries/armem/core/{io/detail/DiskMemoryContainer.h => base/CoreSegment.cpp} (100%) create mode 100644 source/RobotAPI/libraries/armem/core/base/CoreSegment.h create mode 100644 source/RobotAPI/libraries/armem/core/base/Entity.cpp create mode 100644 source/RobotAPI/libraries/armem/core/base/Entity.h create mode 100644 source/RobotAPI/libraries/armem/core/base/EntityInstance.cpp create mode 100644 source/RobotAPI/libraries/armem/core/base/EntityInstance.h create mode 100644 source/RobotAPI/libraries/armem/core/base/EntitySnapshot.cpp create mode 100644 source/RobotAPI/libraries/armem/core/base/EntitySnapshot.h create mode 100644 source/RobotAPI/libraries/armem/core/base/Memory.cpp create mode 100644 source/RobotAPI/libraries/armem/core/base/Memory.h create mode 100644 source/RobotAPI/libraries/armem/core/base/ProviderSegment.cpp create mode 100644 source/RobotAPI/libraries/armem/core/base/ProviderSegment.h rename source/RobotAPI/libraries/armem/core/{ => base}/detail/EntityContainer.cpp (100%) rename source/RobotAPI/libraries/armem/core/{ => base}/detail/EntityContainer.h (50%) rename source/RobotAPI/libraries/armem/core/{ => base}/detail/MaxHistorySize.cpp (100%) rename source/RobotAPI/libraries/armem/core/{ => base}/detail/MaxHistorySize.h (100%) rename source/RobotAPI/libraries/armem/core/{ => base}/detail/MemoryContainer.cpp (100%) create mode 100644 source/RobotAPI/libraries/armem/core/base/detail/MemoryContainer.h create mode 100644 source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.cpp rename source/RobotAPI/libraries/armem/core/{ => base}/detail/MemoryItem.h (52%) create mode 100644 source/RobotAPI/libraries/armem/core/base/detail/TypedEntityContainer.h create mode 100644 source/RobotAPI/libraries/armem/core/base/ice_conversions.cpp create mode 100644 source/RobotAPI/libraries/armem/core/base/ice_conversions.h delete mode 100644 source/RobotAPI/libraries/armem/core/detail/MemoryContainer.h delete mode 100644 source/RobotAPI/libraries/armem/core/detail/MemoryItem.cpp delete mode 100644 source/RobotAPI/libraries/armem/core/detail/TypedEntityContainer.h delete mode 100644 source/RobotAPI/libraries/armem/core/io/DiskCoreSegment.cpp delete mode 100644 source/RobotAPI/libraries/armem/core/io/DiskCoreSegment.h delete mode 100644 source/RobotAPI/libraries/armem/core/io/DiskEntity.cpp delete mode 100644 source/RobotAPI/libraries/armem/core/io/DiskEntity.h delete mode 100644 source/RobotAPI/libraries/armem/core/io/DiskEntityInstance.cpp delete mode 100644 source/RobotAPI/libraries/armem/core/io/DiskEntityInstance.h delete mode 100644 source/RobotAPI/libraries/armem/core/io/DiskEntitySnapshot.cpp delete mode 100644 source/RobotAPI/libraries/armem/core/io/DiskEntitySnapshot.h delete mode 100644 source/RobotAPI/libraries/armem/core/io/DiskInstanceData.h delete mode 100644 source/RobotAPI/libraries/armem/core/io/DiskMemory.cpp delete mode 100644 source/RobotAPI/libraries/armem/core/io/DiskMemory.h delete mode 100644 source/RobotAPI/libraries/armem/core/io/DiskProviderSegment.cpp delete mode 100644 source/RobotAPI/libraries/armem/core/io/DiskProviderSegment.h delete mode 100644 source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage_OLD.cpp delete mode 100644 source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage_OLD.h delete mode 100644 source/RobotAPI/libraries/armem/core/io/detail/DiskMemoryItem.h delete mode 100644 source/RobotAPI/libraries/armem/core/io/detail/DiskTypedEntityContainer.h delete mode 100644 source/RobotAPI/libraries/armem/core/io/diskReader/DiskReader.cpp delete mode 100644 source/RobotAPI/libraries/armem/core/io/diskReader/DiskReader.h delete mode 100644 source/RobotAPI/libraries/armem/core/io/diskReader/NlohmannJSON/NlohmannJSONDiskReader.cpp delete mode 100644 source/RobotAPI/libraries/armem/core/io/diskReader/NlohmannJSON/NlohmannJSONDiskReader.h delete mode 100644 source/RobotAPI/libraries/armem/core/io/diskWriter/DiskWriter.cpp delete mode 100644 source/RobotAPI/libraries/armem/core/io/diskWriter/DiskWriter.h delete mode 100644 source/RobotAPI/libraries/armem/core/io/diskWriter/NlohmannJSON/NlohmannJSONDiskWriter.cpp delete mode 100644 source/RobotAPI/libraries/armem/core/io/diskWriter/NlohmannJSON/NlohmannJSONDiskWriter.h create mode 100644 source/RobotAPI/libraries/armem/core/longtermMemory/CoreSegment.cpp create mode 100644 source/RobotAPI/libraries/armem/core/longtermMemory/CoreSegment.h create mode 100644 source/RobotAPI/libraries/armem/core/longtermMemory/Entity.cpp create mode 100644 source/RobotAPI/libraries/armem/core/longtermMemory/Entity.h create mode 100644 source/RobotAPI/libraries/armem/core/longtermMemory/EntityInstance.cpp create mode 100644 source/RobotAPI/libraries/armem/core/longtermMemory/EntityInstance.h create mode 100644 source/RobotAPI/libraries/armem/core/longtermMemory/EntitySnapshot.cpp create mode 100644 source/RobotAPI/libraries/armem/core/longtermMemory/EntitySnapshot.h create mode 100644 source/RobotAPI/libraries/armem/core/longtermMemory/Memory.cpp create mode 100644 source/RobotAPI/libraries/armem/core/longtermMemory/Memory.h create mode 100644 source/RobotAPI/libraries/armem/core/longtermMemory/ProviderSegment.cpp create mode 100644 source/RobotAPI/libraries/armem/core/longtermMemory/ProviderSegment.h create mode 100644 source/RobotAPI/libraries/armem/core/longtermMemory/detail/EntityContainer.cpp create mode 100644 source/RobotAPI/libraries/armem/core/longtermMemory/detail/EntityContainer.h create mode 100644 source/RobotAPI/libraries/armem/core/longtermMemory/detail/MemoryContainer.cpp create mode 100644 source/RobotAPI/libraries/armem/core/longtermMemory/detail/MemoryContainer.h create mode 100644 source/RobotAPI/libraries/armem/core/longtermMemory/detail/TypedEntityContainer.h create mode 100644 source/RobotAPI/libraries/armem/core/longtermMemory/ice_conversions.cpp create mode 100644 source/RobotAPI/libraries/armem/core/longtermMemory/ice_conversions.h create mode 100644 source/RobotAPI/libraries/armem/core/workingMemory/CoreSegment.cpp create mode 100644 source/RobotAPI/libraries/armem/core/workingMemory/CoreSegment.h create mode 100644 source/RobotAPI/libraries/armem/core/workingMemory/Entity.cpp create mode 100644 source/RobotAPI/libraries/armem/core/workingMemory/Entity.h rename source/RobotAPI/libraries/armem/core/{ => workingMemory}/EntityInstance.cpp (66%) rename source/RobotAPI/libraries/armem/core/{ => workingMemory}/EntityInstance.h (68%) create mode 100644 source/RobotAPI/libraries/armem/core/workingMemory/EntitySnapshot.cpp create mode 100644 source/RobotAPI/libraries/armem/core/workingMemory/EntitySnapshot.h create mode 100644 source/RobotAPI/libraries/armem/core/workingMemory/Memory.cpp create mode 100644 source/RobotAPI/libraries/armem/core/workingMemory/Memory.h create mode 100644 source/RobotAPI/libraries/armem/core/workingMemory/ProviderSegment.cpp create mode 100644 source/RobotAPI/libraries/armem/core/workingMemory/ProviderSegment.h create mode 100644 source/RobotAPI/libraries/armem/core/workingMemory/detail/EntityContainer.cpp create mode 100644 source/RobotAPI/libraries/armem/core/workingMemory/detail/EntityContainer.h create mode 100644 source/RobotAPI/libraries/armem/core/workingMemory/detail/MemoryContainer.cpp create mode 100644 source/RobotAPI/libraries/armem/core/workingMemory/detail/MemoryContainer.h create mode 100644 source/RobotAPI/libraries/armem/core/workingMemory/detail/TypedEntityContainer.h create mode 100644 source/RobotAPI/libraries/armem/core/workingMemory/ice_conversions.cpp create mode 100644 source/RobotAPI/libraries/armem/core/workingMemory/ice_conversions.h diff --git a/scenarios/ArMemExample/ArMemExample.scx b/scenarios/ArMemExample/ArMemExample.scx index fc00a0130..49d2a0a43 100644 --- a/scenarios/ArMemExample/ArMemExample.scx +++ b/scenarios/ArMemExample/ArMemExample.scx @@ -1,8 +1,8 @@ <?xml version="1.0" encoding="utf-8"?> <scenario name="ArMemExample" creation="2020-11-10.10:38:44" globalConfigName="./config/global.cfg" package="RobotAPI" deploymentType="local" nodeName="NodeMain"> - <application name="ArMemExampleMemory" instance="" package="RobotAPI" nodeName="" enabled="true" iceAutoRestart="false"/> - <application name="ArMemExampleClient" instance="" package="RobotAPI" nodeName="" enabled="true" iceAutoRestart="false"/> - <application name="ArMemMemoryNameSystem" instance="" package="RobotAPI" nodeName="" enabled="true" iceAutoRestart="false"/> + <application name="ExampleMemory" instance="" package="RobotAPI" nodeName="" enabled="true" iceAutoRestart="false"/> + <application name="ExampleMemoryClient" instance="" package="RobotAPI" nodeName="" enabled="true" iceAutoRestart="false"/> + <application name="MemoryNameSystem" instance="" package="RobotAPI" nodeName="" enabled="true" iceAutoRestart="false"/> <application name="RemoteGuiProviderApp" instance="" package="ArmarXGui" nodeName="" enabled="true" iceAutoRestart="false"/> <application name="DebugObserver" instance="" package="ArmarXCore" nodeName="" enabled="true" iceAutoRestart="false"/> </scenario> diff --git a/scenarios/ArMemExample/config/ArMemExampleMemory.cfg b/scenarios/ArMemExample/config/ExampleMemory.cfg similarity index 77% rename from scenarios/ArMemExample/config/ArMemExampleMemory.cfg rename to scenarios/ArMemExample/config/ExampleMemory.cfg index a7b234054..e59a680a2 100644 --- a/scenarios/ArMemExample/config/ArMemExampleMemory.cfg +++ b/scenarios/ArMemExample/config/ExampleMemory.cfg @@ -1,5 +1,5 @@ # ================================================================== -# ArMemExampleMemory properties +# ExampleMemory properties # ================================================================== # ArmarX.AdditionalPackages: List of additional ArmarX packages which should be in the list of default packages. If you have custom packages, which should be found by the gui or other apps, specify them here. Comma separated List. @@ -18,155 +18,171 @@ # ArmarX.ApplicationName = "" -# ArmarX.ArMemExampleMemory.EnableProfiling: enable profiler which is used for logging performance events +# ArmarX.ArMemExampleMemory.tpc.pub.MemoryListener: No Description # Attributes: -# - Default: false +# - Default: MemoryUpdates +# - Case sensitivity: no +# - Required: no +ArmarX.ArMemExampleMemory.tpc.pub.MemoryListener = MemoryUpdates + + +# ArmarX.CachePath: Path for cache files. If relative path AND env. variable ARMARX_USER_CONFIG_DIR is set, the cache path will be made relative to ARMARX_USER_CONFIG_DIR. Otherwise if relative it will be relative to the default ArmarX config dir (${HOME}/.armarx) +# Attributes: +# - Default: mongo/.cache # - Case sensitivity: yes # - Required: no -# - Possible values: {0, 1, false, no, true, yes} -# ArmarX.ArMemExampleMemory.EnableProfiling = false +# ArmarX.CachePath = mongo/.cache -# ArmarX.ArMemExampleMemory.MinimumLoggingLevel: Local logging level only for this component +# ArmarX.Config: Comma-separated list of configuration files # Attributes: -# - Default: Undefined +# - Default: "" # - Case sensitivity: yes # - Required: no -# - Possible values: {Debug, Error, Fatal, Important, Info, Undefined, Verbose, Warning} -# ArmarX.ArMemExampleMemory.MinimumLoggingLevel = Undefined +# ArmarX.Config = "" -# ArmarX.ArMemExampleMemory.ObjectName: Name of IceGrid well-known object +# ArmarX.DataPath: Semicolon-separated search list for data files # Attributes: # - Default: "" # - Case sensitivity: yes # - Required: no -# ArmarX.ArMemExampleMemory.ObjectName = "" +# ArmarX.DataPath = "" -# ArmarX.ArMemExampleMemory.RemoteGuiName: Name of the remote gui provider +# ArmarX.DefaultPackages: List of ArmarX packages which are accessible by default. Comma separated List. If you want to add your own packages and use all default ArmarX packages, use the property 'AdditionalPackages'. # Attributes: -# - Default: RemoteGuiProvider +# - Default: Default value not mapped. # - Case sensitivity: yes # - Required: no -# ArmarX.ArMemExampleMemory.RemoteGuiName = RemoteGuiProvider +# ArmarX.DefaultPackages = Default value not mapped. -# ArmarX.ArMemExampleMemory.core.AddOnUsage: If enabled, core segments are added when required by a new provider segment. +# ArmarX.DependenciesConfig: Path to the (usually generated) config file containing all data paths of all dependent projects. This property usually does not need to be edited. +# Attributes: +# - Default: ./config/dependencies.cfg +# - Case sensitivity: yes +# - Required: no +# ArmarX.DependenciesConfig = ./config/dependencies.cfg + + +# ArmarX.DisableLogging: Turn logging off in whole application # Attributes: # - Default: false # - Case sensitivity: yes # - Required: no # - Possible values: {0, 1, false, no, true, yes} -# ArmarX.ArMemExampleMemory.core.AddOnUsage = false +# ArmarX.DisableLogging = false -# ArmarX.ArMemExampleMemory.core.DefaultSegments: Core segments to add on start up. +# ArmarX.EnableProfiling: Enable profiling of CPU load produced by this application # Attributes: -# - Default: ExampleModality, ExampleConcept +# - Default: false # - Case sensitivity: yes # - Required: no -# ArmarX.ArMemExampleMemory.core.DefaultSegments = ExampleModality, ExampleConcept +# - Possible values: {0, 1, false, no, true, yes} +# ArmarX.EnableProfiling = false -# ArmarX.ArMemExampleMemory.memory.Name: Name of this memory. +# ArmarX.ExampleMemory.: # Attributes: -# - Default: Example +# - Default: "" # - Case sensitivity: yes # - Required: no -# ArmarX.ArMemExampleMemory.memory.Name = Example +# ArmarX.ExampleMemory. = "" -# ArmarX.ArMemExampleMemory.mns.MemoryNameSystemEnabled: Whether to use (and depend on) the Memory Name System (MNS). -# Set to false to use this memory as a stand-alone. +# ArmarX.ExampleMemory.EnableProfiling: enable profiler which is used for logging performance events # Attributes: -# - Default: true +# - Default: false # - Case sensitivity: yes # - Required: no # - Possible values: {0, 1, false, no, true, yes} -# ArmarX.ArMemExampleMemory.mns.MemoryNameSystemEnabled = true +# ArmarX.ExampleMemory.EnableProfiling = false -# ArmarX.ArMemExampleMemory.mns.MemoryNameSystemName: Name of the Memory Name System (MNS) component. +# ArmarX.ExampleMemory.MinimumLoggingLevel: Local logging level only for this component # Attributes: -# - Default: ArMemMemoryNameSystem +# - Default: Undefined # - Case sensitivity: yes # - Required: no -# ArmarX.ArMemExampleMemory.mns.MemoryNameSystemName = ArMemMemoryNameSystem +# - Possible values: {Debug, Error, Fatal, Important, Info, Undefined, Verbose, Warning} +# ArmarX.ExampleMemory.MinimumLoggingLevel = Undefined -# ArmarX.ArMemExampleMemory.tpc.pub.DebugObserver: Name of the `DebugObserver` topic to publish data to. +# ArmarX.ExampleMemory.ObjectName: Name of IceGrid well-known object # Attributes: -# - Default: DebugObserver +# - Default: "" # - Case sensitivity: yes # - Required: no -# ArmarX.ArMemExampleMemory.tpc.pub.DebugObserver = DebugObserver +# ArmarX.ExampleMemory.ObjectName = "" -# ArmarX.ArMemExampleMemory.tpc.pub.MemoryListener: Name of the `MemoryListener` topic to publish data to. +# ArmarX.ExampleMemory.RemoteGuiName: Name of the remote gui provider # Attributes: -# - Default: MemoryUpdates +# - Default: RemoteGuiProvider # - Case sensitivity: yes # - Required: no -ArmarX.ArMemExampleMemory.tpc.pub.MemoryListener = MemoryUpdates +# ArmarX.ExampleMemory.RemoteGuiName = RemoteGuiProvider -# ArmarX.CachePath: Path for cache files. If relative path AND env. variable ARMARX_USER_CONFIG_DIR is set, the cache path will be made relative to ARMARX_USER_CONFIG_DIR. Otherwise if relative it will be relative to the default ArmarX config dir (${HOME}/.armarx) +# ArmarX.ExampleMemory.core.AddOnUsage: If enabled, core segments are added when required by a new provider segment.This will usually be off for most memory servers. # Attributes: -# - Default: mongo/.cache +# - Default: false # - Case sensitivity: yes # - Required: no -# ArmarX.CachePath = mongo/.cache +# - Possible values: {0, 1, false, no, true, yes} +# ArmarX.ExampleMemory.core.AddOnUsage = false -# ArmarX.Config: Comma-separated list of configuration files +# ArmarX.ExampleMemory.core.DefaultSegments: Core segments to add on start up (just as example). # Attributes: -# - Default: "" +# - Default: ExampleModality, ExampleConcept # - Case sensitivity: yes # - Required: no -# ArmarX.Config = "" +# ArmarX.ExampleMemory.core.DefaultSegments = ExampleModality, ExampleConcept -# ArmarX.DataPath: Semicolon-separated search list for data files +# ArmarX.ExampleMemory.memory.Name: Name of this memory (server). # Attributes: -# - Default: "" +# - Default: Example # - Case sensitivity: yes # - Required: no -# ArmarX.DataPath = "" +# ArmarX.ExampleMemory.memory.Name = Example -# ArmarX.DefaultPackages: List of ArmarX packages which are accessible by default. Comma separated List. If you want to add your own packages and use all default ArmarX packages, use the property 'AdditionalPackages'. +# ArmarX.ExampleMemory.mns.MemoryNameSystemEnabled: Whether to use (and depend on) the Memory Name System (MNS). +# Set to false to use this memory as a stand-alone. # Attributes: -# - Default: Default value not mapped. +# - Default: true # - Case sensitivity: yes # - Required: no -# ArmarX.DefaultPackages = Default value not mapped. +# - Possible values: {0, 1, false, no, true, yes} +# ArmarX.ExampleMemory.mns.MemoryNameSystemEnabled = true -# ArmarX.DependenciesConfig: Path to the (usually generated) config file containing all data paths of all dependent projects. This property usually does not need to be edited. +# ArmarX.ExampleMemory.mns.MemoryNameSystemName: Name of the Memory Name System (MNS) component. # Attributes: -# - Default: ./config/dependencies.cfg +# - Default: ArMemMemoryNameSystem # - Case sensitivity: yes # - Required: no -# ArmarX.DependenciesConfig = ./config/dependencies.cfg +# ArmarX.ExampleMemory.mns.MemoryNameSystemName = ArMemMemoryNameSystem -# ArmarX.DisableLogging: Turn logging off in whole application +# ArmarX.ExampleMemory.tpc.pub.DebugObserver: Name of the `DebugObserver` topic to publish data to. # Attributes: -# - Default: false +# - Default: DebugObserver # - Case sensitivity: yes # - Required: no -# - Possible values: {0, 1, false, no, true, yes} -# ArmarX.DisableLogging = false +# ArmarX.ExampleMemory.tpc.pub.DebugObserver = DebugObserver -# ArmarX.EnableProfiling: Enable profiling of CPU load produced by this application +# ArmarX.ExampleMemory.tpc.pub.MemoryListener: Name of the `MemoryListener` topic to publish data to. # Attributes: -# - Default: false +# - Default: MemoryUpdates # - Case sensitivity: yes # - Required: no -# - Possible values: {0, 1, false, no, true, yes} -# ArmarX.EnableProfiling = false +# ArmarX.ExampleMemory.tpc.pub.MemoryListener = MemoryUpdates # ArmarX.LoadLibraries: Libraries to load at start up of the application. Must be enabled by the Application with enableLibLoading(). Format: PackageName:LibraryName;... or /absolute/path/to/library;... diff --git a/scenarios/ArMemExample/config/ArMemExampleClient.cfg b/scenarios/ArMemExample/config/ExampleMemoryClient.cfg similarity index 81% rename from scenarios/ArMemExample/config/ArMemExampleClient.cfg rename to scenarios/ArMemExample/config/ExampleMemoryClient.cfg index ceaa86ed3..76d3d8775 100644 --- a/scenarios/ArMemExample/config/ArMemExampleClient.cfg +++ b/scenarios/ArMemExample/config/ExampleMemoryClient.cfg @@ -1,5 +1,5 @@ # ================================================================== -# ArMemExampleClient properties +# ExampleMemoryClient properties # ================================================================== # ArmarX.AdditionalPackages: List of additional ArmarX packages which should be in the list of default packages. If you have custom packages, which should be found by the gui or other apps, specify them here. Comma separated List. @@ -18,138 +18,146 @@ # ArmarX.ApplicationName = "" -# ArmarX.ArMemExampleClient.EnableProfiling: enable profiler which is used for logging performance events +# ArmarX.ArMemExampleClient.tpc.sub.MemoryListener: No Description # Attributes: -# - Default: false +# - Default: MemoryUpdates +# - Case sensitivity: no +# - Required: no +ArmarX.ArMemExampleClient.tpc.sub.MemoryListener = MemoryUpdates + + +# ArmarX.CachePath: Path for cache files. If relative path AND env. variable ARMARX_USER_CONFIG_DIR is set, the cache path will be made relative to ARMARX_USER_CONFIG_DIR. Otherwise if relative it will be relative to the default ArmarX config dir (${HOME}/.armarx) +# Attributes: +# - Default: mongo/.cache # - Case sensitivity: yes # - Required: no -# - Possible values: {0, 1, false, no, true, yes} -# ArmarX.ArMemExampleClient.EnableProfiling = false +# ArmarX.CachePath = mongo/.cache -# ArmarX.ArMemExampleClient.MinimumLoggingLevel: Local logging level only for this component +# ArmarX.Config: Comma-separated list of configuration files # Attributes: -# - Default: Undefined +# - Default: "" # - Case sensitivity: yes # - Required: no -# - Possible values: {Debug, Error, Fatal, Important, Info, Undefined, Verbose, Warning} -# ArmarX.ArMemExampleClient.MinimumLoggingLevel = Undefined +# ArmarX.Config = "" -# ArmarX.ArMemExampleClient.ObjectName: Name of IceGrid well-known object +# ArmarX.DataPath: Semicolon-separated search list for data files # Attributes: # - Default: "" # - Case sensitivity: yes # - Required: no -# ArmarX.ArMemExampleClient.ObjectName = "" +# ArmarX.DataPath = "" -# ArmarX.ArMemExampleClient.RemoteGuiName: Name of the remote gui provider +# ArmarX.DefaultPackages: List of ArmarX packages which are accessible by default. Comma separated List. If you want to add your own packages and use all default ArmarX packages, use the property 'AdditionalPackages'. # Attributes: -# - Default: RemoteGuiProvider +# - Default: Default value not mapped. # - Case sensitivity: yes # - Required: no -# ArmarX.ArMemExampleClient.RemoteGuiName = RemoteGuiProvider +# ArmarX.DefaultPackages = Default value not mapped. -# ArmarX.ArMemExampleClient.mem.MemoryName: Name of the memory to use. +# ArmarX.DependenciesConfig: Path to the (usually generated) config file containing all data paths of all dependent projects. This property usually does not need to be edited. # Attributes: -# - Default: Example +# - Default: ./config/dependencies.cfg # - Case sensitivity: yes # - Required: no -# ArmarX.ArMemExampleClient.mem.MemoryName = Example +# ArmarX.DependenciesConfig = ./config/dependencies.cfg -# ArmarX.ArMemExampleClient.mns.MemoryNameSystemEnabled: Whether to use (and depend on) the Memory Name System (MNS). -# Set to false to use this memory as a stand-alone. +# ArmarX.DisableLogging: Turn logging off in whole application # Attributes: -# - Default: true +# - Default: false # - Case sensitivity: yes # - Required: no # - Possible values: {0, 1, false, no, true, yes} -# ArmarX.ArMemExampleClient.mns.MemoryNameSystemEnabled = true +# ArmarX.DisableLogging = false -# ArmarX.ArMemExampleClient.mns.MemoryNameSystemName: Name of the Memory Name System (MNS) component. +# ArmarX.EnableProfiling: Enable profiling of CPU load produced by this application # Attributes: -# - Default: ArMemMemoryNameSystem +# - Default: false # - Case sensitivity: yes # - Required: no -# ArmarX.ArMemExampleClient.mns.MemoryNameSystemName = ArMemMemoryNameSystem +# - Possible values: {0, 1, false, no, true, yes} +# ArmarX.EnableProfiling = false -# ArmarX.ArMemExampleClient.tpc.pub.DebugObserver: Name of the `DebugObserver` topic to publish data to. +# ArmarX.ExampleMemoryClient.EnableProfiling: enable profiler which is used for logging performance events # Attributes: -# - Default: DebugObserver +# - Default: false # - Case sensitivity: yes # - Required: no -# ArmarX.ArMemExampleClient.tpc.pub.DebugObserver = DebugObserver +# - Possible values: {0, 1, false, no, true, yes} +# ArmarX.ExampleMemoryClient.EnableProfiling = false -# ArmarX.ArMemExampleClient.tpc.sub.MemoryListener: Name of the `MemoryListener` topic to subscribe to. +# ArmarX.ExampleMemoryClient.MinimumLoggingLevel: Local logging level only for this component # Attributes: -# - Default: MemoryUpdates +# - Default: Undefined # - Case sensitivity: yes # - Required: no -ArmarX.ArMemExampleClient.tpc.sub.MemoryListener = MemoryUpdates +# - Possible values: {Debug, Error, Fatal, Important, Info, Undefined, Verbose, Warning} +# ArmarX.ExampleMemoryClient.MinimumLoggingLevel = Undefined -# ArmarX.CachePath: Path for cache files. If relative path AND env. variable ARMARX_USER_CONFIG_DIR is set, the cache path will be made relative to ARMARX_USER_CONFIG_DIR. Otherwise if relative it will be relative to the default ArmarX config dir (${HOME}/.armarx) +# ArmarX.ExampleMemoryClient.ObjectName: Name of IceGrid well-known object # Attributes: -# - Default: mongo/.cache +# - Default: "" # - Case sensitivity: yes # - Required: no -# ArmarX.CachePath = mongo/.cache +# ArmarX.ExampleMemoryClient.ObjectName = "" -# ArmarX.Config: Comma-separated list of configuration files +# ArmarX.ExampleMemoryClient.RemoteGuiName: Name of the remote gui provider # Attributes: -# - Default: "" +# - Default: RemoteGuiProvider # - Case sensitivity: yes # - Required: no -# ArmarX.Config = "" +# ArmarX.ExampleMemoryClient.RemoteGuiName = RemoteGuiProvider -# ArmarX.DataPath: Semicolon-separated search list for data files +# ArmarX.ExampleMemoryClient.mem.MemoryName: Name of the memory to use. # Attributes: -# - Default: "" +# - Default: Example # - Case sensitivity: yes # - Required: no -# ArmarX.DataPath = "" +# ArmarX.ExampleMemoryClient.mem.MemoryName = Example -# ArmarX.DefaultPackages: List of ArmarX packages which are accessible by default. Comma separated List. If you want to add your own packages and use all default ArmarX packages, use the property 'AdditionalPackages'. +# ArmarX.ExampleMemoryClient.mns.MemoryNameSystemEnabled: Whether to use (and depend on) the Memory Name System (MNS). +# Set to false to use this memory as a stand-alone. # Attributes: -# - Default: Default value not mapped. +# - Default: true # - Case sensitivity: yes # - Required: no -# ArmarX.DefaultPackages = Default value not mapped. +# - Possible values: {0, 1, false, no, true, yes} +# ArmarX.ExampleMemoryClient.mns.MemoryNameSystemEnabled = true -# ArmarX.DependenciesConfig: Path to the (usually generated) config file containing all data paths of all dependent projects. This property usually does not need to be edited. +# ArmarX.ExampleMemoryClient.mns.MemoryNameSystemName: Name of the Memory Name System (MNS) component. # Attributes: -# - Default: ./config/dependencies.cfg +# - Default: ArMemMemoryNameSystem # - Case sensitivity: yes # - Required: no -# ArmarX.DependenciesConfig = ./config/dependencies.cfg +# ArmarX.ExampleMemoryClient.mns.MemoryNameSystemName = ArMemMemoryNameSystem -# ArmarX.DisableLogging: Turn logging off in whole application +# ArmarX.ExampleMemoryClient.tpc.pub.DebugObserver: Name of the `DebugObserver` topic to publish data to. # Attributes: -# - Default: false +# - Default: DebugObserver # - Case sensitivity: yes # - Required: no -# - Possible values: {0, 1, false, no, true, yes} -# ArmarX.DisableLogging = false +# ArmarX.ExampleMemoryClient.tpc.pub.DebugObserver = DebugObserver -# ArmarX.EnableProfiling: Enable profiling of CPU load produced by this application +# ArmarX.ExampleMemoryClient.tpc.sub.MemoryListener: Name of the `MemoryListener` topic to subscribe to. # Attributes: -# - Default: false +# - Default: MemoryUpdates # - Case sensitivity: yes # - Required: no -# - Possible values: {0, 1, false, no, true, yes} -# ArmarX.EnableProfiling = false +# ArmarX.ExampleMemoryClient.tpc.sub.MemoryListener = MemoryUpdates # ArmarX.LoadLibraries: Libraries to load at start up of the application. Must be enabled by the Application with enableLibLoading(). Format: PackageName:LibraryName;... or /absolute/path/to/library;... diff --git a/scenarios/ArMemExample/config/ArMemMemoryNameSystem.cfg b/scenarios/ArMemExample/config/MemoryNameSystem.cfg similarity index 90% rename from scenarios/ArMemExample/config/ArMemMemoryNameSystem.cfg rename to scenarios/ArMemExample/config/MemoryNameSystem.cfg index 194953115..869022057 100644 --- a/scenarios/ArMemExample/config/ArMemMemoryNameSystem.cfg +++ b/scenarios/ArMemExample/config/MemoryNameSystem.cfg @@ -1,5 +1,5 @@ # ================================================================== -# ArMemMemoryNameSystem properties +# MemoryNameSystem properties # ================================================================== # ArmarX.AdditionalPackages: List of additional ArmarX packages which should be in the list of default packages. If you have custom packages, which should be found by the gui or other apps, specify them here. Comma separated List. @@ -18,40 +18,6 @@ # ArmarX.ApplicationName = "" -# ArmarX.ArMemMemoryNameSystem.EnableProfiling: enable profiler which is used for logging performance events -# Attributes: -# - Default: false -# - Case sensitivity: yes -# - Required: no -# - Possible values: {0, 1, false, no, true, yes} -# ArmarX.ArMemMemoryNameSystem.EnableProfiling = false - - -# ArmarX.ArMemMemoryNameSystem.MinimumLoggingLevel: Local logging level only for this component -# Attributes: -# - Default: Undefined -# - Case sensitivity: yes -# - Required: no -# - Possible values: {Debug, Error, Fatal, Important, Info, Undefined, Verbose, Warning} -# ArmarX.ArMemMemoryNameSystem.MinimumLoggingLevel = Undefined - - -# ArmarX.ArMemMemoryNameSystem.ObjectName: Name of IceGrid well-known object -# Attributes: -# - Default: "" -# - Case sensitivity: yes -# - Required: no -# ArmarX.ArMemMemoryNameSystem.ObjectName = "" - - -# ArmarX.ArMemMemoryNameSystem.RemoteGuiName: Name of the remote gui provider -# Attributes: -# - Default: RemoteGuiProvider -# - Case sensitivity: yes -# - Required: no -# ArmarX.ArMemMemoryNameSystem.RemoteGuiName = RemoteGuiProvider - - # ArmarX.CachePath: Path for cache files. If relative path AND env. variable ARMARX_USER_CONFIG_DIR is set, the cache path will be made relative to ARMARX_USER_CONFIG_DIR. Otherwise if relative it will be relative to the default ArmarX config dir (${HOME}/.armarx) # Attributes: # - Default: mongo/.cache @@ -126,6 +92,40 @@ # ArmarX.LoggingGroup = "" +# ArmarX.MemoryNameSystem.EnableProfiling: enable profiler which is used for logging performance events +# Attributes: +# - Default: false +# - Case sensitivity: yes +# - Required: no +# - Possible values: {0, 1, false, no, true, yes} +# ArmarX.MemoryNameSystem.EnableProfiling = false + + +# ArmarX.MemoryNameSystem.MinimumLoggingLevel: Local logging level only for this component +# Attributes: +# - Default: Undefined +# - Case sensitivity: yes +# - Required: no +# - Possible values: {Debug, Error, Fatal, Important, Info, Undefined, Verbose, Warning} +# ArmarX.MemoryNameSystem.MinimumLoggingLevel = Undefined + + +# ArmarX.MemoryNameSystem.ObjectName: Name of IceGrid well-known object +# Attributes: +# - Default: "" +# - Case sensitivity: yes +# - Required: no +ArmarX.MemoryNameSystem.ObjectName = "ArMemMemoryNameSystem" + + +# ArmarX.MemoryNameSystem.RemoteGuiName: Name of the remote gui provider +# Attributes: +# - Default: RemoteGuiProvider +# - Case sensitivity: yes +# - Required: no +# ArmarX.MemoryNameSystem.RemoteGuiName = RemoteGuiProvider + + # ArmarX.RedirectStdout: Redirect std::cout and std::cerr to ArmarXLog # Attributes: # - Default: true diff --git a/source/RobotAPI/components/armem/client/CMakeLists.txt b/source/RobotAPI/components/armem/client/CMakeLists.txt index a8e816bf2..4eda25283 100644 --- a/source/RobotAPI/components/armem/client/CMakeLists.txt +++ b/source/RobotAPI/components/armem/client/CMakeLists.txt @@ -1 +1 @@ -add_subdirectory(ExampleClient) +add_subdirectory(ExampleMemoryClient) diff --git a/source/RobotAPI/components/armem/client/ExampleClient/test/ArMemExampleClientTest.cpp b/source/RobotAPI/components/armem/client/ExampleClient/test/ArMemExampleClientTest.cpp deleted file mode 100644 index 67269fecc..000000000 --- a/source/RobotAPI/components/armem/client/ExampleClient/test/ArMemExampleClientTest.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * This file is part of ArmarX. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @package RobotAPI::ArmarXObjects::ArMemExampleClient - * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) - * @date 2020 - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#define BOOST_TEST_MODULE RobotAPI::ArmarXObjects::ArMemExampleClient - -#define ARMARX_BOOST_TEST - -#include <RobotAPI/Test.h> -#include "../ArMemExampleClient.h" - -#include <iostream> - -BOOST_AUTO_TEST_CASE(testExample) -{ - armarx::ArMemExampleClient instance; - - BOOST_CHECK_EQUAL(true, true); -} diff --git a/source/RobotAPI/components/armem/client/ExampleClient/test/CMakeLists.txt b/source/RobotAPI/components/armem/client/ExampleClient/test/CMakeLists.txt deleted file mode 100644 index 775fb5e2e..000000000 --- a/source/RobotAPI/components/armem/client/ExampleClient/test/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ - -# Libs required for the tests -SET(LIBS ${LIBS} ArmarXCore ArMemExampleClient) - -armarx_add_test(ArMemExampleClientTest ArMemExampleClientTest.cpp "${LIBS}") diff --git a/source/RobotAPI/components/armem/client/ExampleClient/CMakeLists.txt b/source/RobotAPI/components/armem/client/ExampleMemoryClient/CMakeLists.txt similarity index 84% rename from source/RobotAPI/components/armem/client/ExampleClient/CMakeLists.txt rename to source/RobotAPI/components/armem/client/ExampleMemoryClient/CMakeLists.txt index a6c8b9c63..d699638cd 100644 --- a/source/RobotAPI/components/armem/client/ExampleClient/CMakeLists.txt +++ b/source/RobotAPI/components/armem/client/ExampleMemoryClient/CMakeLists.txt @@ -1,4 +1,4 @@ -armarx_component_set_name("ExampleClient") +armarx_component_set_name("ExampleMemoryClient") find_package(IVT QUIET) armarx_build_if(IVT_FOUND "IVT not available") @@ -11,11 +11,11 @@ set(COMPONENT_LIBS ) set(SOURCES - ExampleClient.cpp + ExampleMemoryClient.cpp ) set(HEADERS - ExampleClient.h + ExampleMemoryClient.h ) armarx_add_component("${SOURCES}" "${HEADERS}") diff --git a/source/RobotAPI/components/armem/client/ExampleClient/ExampleClient.cpp b/source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.cpp similarity index 83% rename from source/RobotAPI/components/armem/client/ExampleClient/ExampleClient.cpp rename to source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.cpp index b69d0aa53..39e68a5ca 100644 --- a/source/RobotAPI/components/armem/client/ExampleClient/ExampleClient.cpp +++ b/source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.cpp @@ -13,14 +13,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * - * @package RobotAPI::ArmarXObjects::ExampleClient + * @package RobotAPI::ArmarXObjects::ExampleMemoryClient * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) * @date 2020 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt * GNU General Public License */ -#include "ExampleClient.h" +#include "ExampleMemoryClient.h" #include <SimoxUtility/color/cmaps.h> @@ -37,14 +37,14 @@ namespace armarx { - ExampleClientPropertyDefinitions::ExampleClientPropertyDefinitions(std::string prefix) : + ExampleMemoryClientPropertyDefinitions::ExampleMemoryClientPropertyDefinitions(std::string prefix) : armarx::ComponentPropertyDefinitions(prefix) { } - armarx::PropertyDefinitionsPtr ExampleClient::createPropertyDefinitions() + armarx::PropertyDefinitionsPtr ExampleMemoryClient::createPropertyDefinitions() { - armarx::PropertyDefinitionsPtr defs = new ExampleClientPropertyDefinitions(getConfigIdentifier()); + armarx::PropertyDefinitionsPtr defs = new ExampleMemoryClientPropertyDefinitions(getConfigIdentifier()); defs->topic(debugObserver); @@ -53,18 +53,18 @@ namespace armarx return defs; } - std::string ExampleClient::getDefaultName() const + std::string ExampleMemoryClient::getDefaultName() const { - return "ExampleClient"; + return "ExampleMemoryClient"; } - void ExampleClient::onInitComponent() + void ExampleMemoryClient::onInitComponent() { } - void ExampleClient::onConnectComponent() + void ExampleMemoryClient::onConnectComponent() { createRemoteGuiTab(); RemoteGui_startRunningTask(); @@ -90,26 +90,26 @@ namespace armarx ARMARX_INFO << "Entity " << entityID << " was updated by " << snapshotIDs.size() << " snapshots."; }); // Using a member function: - memoryReader.subscribe(entityID, this, &ExampleClient::example_entityUpdated); + memoryReader.subscribe(entityID, this, &ExampleMemoryClient::example_entityUpdated); - task = new RunningTask<ExampleClient>(this, &ExampleClient::run); + task = new RunningTask<ExampleMemoryClient>(this, &ExampleMemoryClient::run); task->start(); } - void ExampleClient::onDisconnectComponent() + void ExampleMemoryClient::onDisconnectComponent() { task->stop(); } - void ExampleClient::onExitComponent() + void ExampleMemoryClient::onExitComponent() { } - void ExampleClient::run() + void ExampleMemoryClient::run() { ARMARX_IMPORTANT << "Running example."; @@ -142,7 +142,7 @@ namespace armarx } - armem::MemoryID ExampleClient::addProviderSegment() + armem::MemoryID ExampleMemoryClient::addProviderSegment() { armem::data::AddSegmentInput input; input.coreSegmentName = "ExampleModality"; @@ -155,7 +155,7 @@ namespace armarx return armem::MemoryID(result.segmentID); } - armem::MemoryID ExampleClient::commitSingleSnapshot(const armem::MemoryID& entityID) + armem::MemoryID ExampleMemoryClient::commitSingleSnapshot(const armem::MemoryID& entityID) { // Prepare the update with some empty instances. armem::EntityUpdate update; @@ -178,7 +178,7 @@ namespace armarx return updateResult.snapshotID; } - void ExampleClient::commitMultipleSnapshots(const armem::MemoryID& entityID, int num) + void ExampleMemoryClient::commitMultipleSnapshots(const armem::MemoryID& entityID, int num) { // Commit a number of updates with different timestamps and number of instances. armem::Commit commit; @@ -202,7 +202,7 @@ namespace armarx } - void ExampleClient::queryLatestSnapshot(const armem::MemoryID& entityID) + void ExampleMemoryClient::queryLatestSnapshot(const armem::MemoryID& entityID) { ARMARX_IMPORTANT << "Querying latest snapshot: " @@ -221,19 +221,19 @@ namespace armarx if (qResult.success) { - armem::Memory& memory = qResult.memory; + armem::workingmemory::Memory& memory = qResult.memory; ARMARX_CHECK_EQUAL(memory.coreSegments.size(), 1); - armem::CoreSegment& coreSeg = memory.coreSegments.begin()->second; + armem::workingmemory::CoreSegment& coreSeg = memory.coreSegments.begin()->second; ARMARX_CHECK_EQUAL(coreSeg.providerSegments.size(), 1); - armem::ProviderSegment& provSeg = coreSeg.providerSegments.begin()->second; + armem::workingmemory::ProviderSegment& provSeg = coreSeg.providerSegments.begin()->second; ARMARX_CHECK_EQUAL(provSeg.entities.size(), 1); - armem::Entity& entity = provSeg.entities.begin()->second; + armem::workingmemory::Entity& entity = provSeg.entities.begin()->second; ARMARX_CHECK_GREATER_EQUAL(entity.history.size(), 1); - armem::EntitySnapshot& snapshot = entity.history.begin()->second; + armem::workingmemory::EntitySnapshot& snapshot = entity.history.begin()->second; ARMARX_INFO << "Result: " << "\n- memory: \t" << memory.name() @@ -245,7 +245,7 @@ namespace armarx ; ARMARX_IMPORTANT << "Getting entity via ID"; - const armem::Entity& e = memory.getEntity(entityID); + const armem::workingmemory::Entity& e = memory.getEntity(entityID); ARMARX_INFO << "Result: " << "\n- entity: \t" << e.name() << "\n- snapshot: \t" << e.getLatestSnapshot().time() @@ -262,7 +262,7 @@ namespace armarx } } - void ExampleClient::queryExactSnapshot(const armem::MemoryID& snapshotID) + void ExampleMemoryClient::queryExactSnapshot(const armem::MemoryID& snapshotID) { ARMARX_IMPORTANT << "Querying exact smapshot: " @@ -282,8 +282,8 @@ namespace armarx if (qResult.success) { - armem::Memory memory = std::move(qResult.memory); - armem::EntitySnapshot& entitySnapshot = memory.getEntity(snapshotID).getLatestSnapshot(); + armem::workingmemory::Memory memory = std::move(qResult.memory); + const armem::workingmemory::EntitySnapshot& entitySnapshot = memory.getEntity(snapshotID).getLatestSnapshot(); ARMARX_INFO << "Result snapshot: " << "\n- time: \t" << entitySnapshot.time() @@ -297,7 +297,7 @@ namespace armarx } - void ExampleClient::commitExampleData() + void ExampleMemoryClient::commitExampleData() { ARMARX_IMPORTANT << "Adding segment " << "ExampleData" << "/" << getName(); @@ -376,7 +376,7 @@ namespace armarx } } - void ExampleClient::queryExampleData() + void ExampleMemoryClient::queryExampleData() { // Query all entities from provider. armem::client::query::Builder qb; @@ -400,7 +400,7 @@ namespace armarx - void ExampleClient::example_entityUpdated(const armem::MemoryID& subscriptionID, const std::vector<armem::MemoryID>& snapshotIDs) + void ExampleMemoryClient::example_entityUpdated(const armem::MemoryID& subscriptionID, const std::vector<armem::MemoryID>& snapshotIDs) { std::stringstream ss; ss << "example_entity got updated: " << subscriptionID << "\n"; @@ -414,7 +414,7 @@ namespace armarx } - void ExampleClient::createRemoteGuiTab() + void ExampleMemoryClient::createRemoteGuiTab() { using namespace armarx::RemoteGui::Client; @@ -427,7 +427,7 @@ namespace armarx RemoteGui_createTab(getName(), root, &tab); } - void ExampleClient::RemoteGui_update() + void ExampleMemoryClient::RemoteGui_update() { if (tab.rebuild.exchange(false)) { diff --git a/source/RobotAPI/components/armem/client/ExampleClient/ExampleClient.h b/source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.h similarity index 91% rename from source/RobotAPI/components/armem/client/ExampleClient/ExampleClient.h rename to source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.h index 3ee6d82e4..ba4f67a4b 100644 --- a/source/RobotAPI/components/armem/client/ExampleClient/ExampleClient.h +++ b/source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.h @@ -34,7 +34,7 @@ #include <RobotAPI/interface/armem/server/MemoryInterface.h> #include <RobotAPI/interface/armem/mns/MemoryNameSystemInterface.h> #include <RobotAPI/libraries/armem/client/ComponentPlugin.h> -#include <RobotAPI/libraries/armem/core/Memory.h> +#include <RobotAPI/libraries/armem/core/workingMemory/Memory.h> namespace armarx @@ -43,11 +43,11 @@ namespace armarx * @class ExampleClientPropertyDefinitions * @brief Property definitions of `ExampleClient`. */ - class ExampleClientPropertyDefinitions : + class ExampleMemoryClientPropertyDefinitions : public armarx::ComponentPropertyDefinitions { public: - ExampleClientPropertyDefinitions(std::string prefix); + ExampleMemoryClientPropertyDefinitions(std::string prefix); }; @@ -62,7 +62,7 @@ namespace armarx * * Detailed description of class ExampleClient. */ - class ExampleClient : + class ExampleMemoryClient : virtual public armarx::Component, virtual public armarx::armem::client::ComponentPluginUser, virtual public LightweightRemoteGuiComponentPluginUser @@ -114,7 +114,7 @@ namespace armarx private: - armarx::RunningTask<ExampleClient>::pointer_type task; + armarx::RunningTask<ExampleMemoryClient>::pointer_type task; armarx::DebugObserverInterfacePrx debugObserver; @@ -124,7 +124,7 @@ namespace armarx { std::atomic_bool rebuild = false; - std::optional<armem::Memory> queryResult; + std::optional<armem::workingmemory::Memory> queryResult; RemoteGui::Client::GroupBox queryResultGroup; }; RemoteGuiTab tab; diff --git a/source/RobotAPI/components/armem/server/ExampleMemory/ExampleMemory.cpp b/source/RobotAPI/components/armem/server/ExampleMemory/ExampleMemory.cpp index 19b547583..a3c7f7bc8 100644 --- a/source/RobotAPI/components/armem/server/ExampleMemory/ExampleMemory.cpp +++ b/source/RobotAPI/components/armem/server/ExampleMemory/ExampleMemory.cpp @@ -60,16 +60,16 @@ namespace armarx void ExampleMemory::onInitComponent() { - memory.name() = p.memoryName; + workingmemory.name() = p.memoryName; // Usually, the memory server will specify a number of core segments with a specific aron type. - memory.addCoreSegment("ExampleData", armem::example::ExampleData::toInitialAronType()); + workingmemory.addCoreSegment("ExampleData", armem::example::ExampleData::toInitialAronType()); // For illustration purposes, we add more segments (without types). bool trim = true; p.core.defaultCoreSegments = simox::alg::split(p.core._defaultSegmentsStr, ",", trim); p.core._defaultSegmentsStr.clear(); - memory.addCoreSegments(p.core.defaultCoreSegments); + workingmemory.addCoreSegments(p.core.defaultCoreSegments); } void ExampleMemory::onConnectComponent() @@ -121,8 +121,8 @@ namespace armarx using namespace armarx::RemoteGui::Client; { - std::scoped_lock lock(memoryMutex); - tab.memoryGroup = armem::server::MemoryRemoteGui().makeGroupBox(memory); + std::scoped_lock lock(workingmemoryMutex); + tab.memoryGroup = armem::server::MemoryRemoteGui().makeGroupBox(workingmemory); } VBoxLayout root = {tab.memoryGroup, VSpacer()}; diff --git a/source/RobotAPI/components/armem/server/ExampleMemory/test/ExampleMemoryTest.cpp b/source/RobotAPI/components/armem/server/ExampleMemory/test/ExampleMemoryTest.cpp index 6cc169273..01ff68729 100644 --- a/source/RobotAPI/components/armem/server/ExampleMemory/test/ExampleMemoryTest.cpp +++ b/source/RobotAPI/components/armem/server/ExampleMemory/test/ExampleMemoryTest.cpp @@ -51,9 +51,9 @@ BOOST_AUTO_TEST_CASE(test_ExampleData_type) BOOST_CHECK_EQUAL(type->childrenSize(), 15); - armem::Memory memory; - armem::CoreSegment& core = memory.addCoreSegment("ExampleData", type); - armem::ProviderSegment& prov = core.addProviderSegment("Provider"); + armem::workingmemory::Memory memory; + armem::workingmemory::CoreSegment& core = memory.addCoreSegment("ExampleData", type); + armem::workingmemory::ProviderSegment& prov = core.addProviderSegment("Provider"); - BOOST_CHECK_EQUAL(core.aronType(), prov.aronType()); + BOOST_CHECK_EQUAL(core.aronType, prov.aronType); } diff --git a/source/RobotAPI/components/armem/server/GeneralPurposeMemory/GeneralPurposeMemory.cpp b/source/RobotAPI/components/armem/server/GeneralPurposeMemory/GeneralPurposeMemory.cpp index 7cc935683..8247ab6f9 100644 --- a/source/RobotAPI/components/armem/server/GeneralPurposeMemory/GeneralPurposeMemory.cpp +++ b/source/RobotAPI/components/armem/server/GeneralPurposeMemory/GeneralPurposeMemory.cpp @@ -50,7 +50,7 @@ namespace armarx void GeneralPurposeMemory::onInitComponent() { - memory.name() = memoryName; + workingmemory.name() = memoryName; } diff --git a/source/RobotAPI/components/armem/server/RobotSensorMemory/RobotSensorMemory.cpp b/source/RobotAPI/components/armem/server/RobotSensorMemory/RobotSensorMemory.cpp index fd1987ee7..cc09275e7 100644 --- a/source/RobotAPI/components/armem/server/RobotSensorMemory/RobotSensorMemory.cpp +++ b/source/RobotAPI/components/armem/server/RobotSensorMemory/RobotSensorMemory.cpp @@ -71,7 +71,7 @@ namespace armarx robotStateComponentMemoryBatchSize = std::max((unsigned int) 1, robotStateComponentMemoryBatchSize); robotStateComponentPollFrequency = std::clamp(robotStateComponentPollFrequency, 1, ROBOT_STATE_COMPONENT_MAXIMUM_FREQUENCY); - memory.name() = memoryName; + workingmemory.name() = memoryName; } @@ -114,7 +114,7 @@ namespace armarx void RobotSensorMemory::setupRobotUnitSegment() { ARMARX_INFO << "Adding core segment " << robotUnitCoreSegmentName; - memory.addCoreSegments({robotUnitCoreSegmentName}); + workingmemory.addCoreSegments({robotUnitCoreSegmentName}); ARMARX_INFO << "Adding provider segment " << robotUnitCoreSegmentName << "/" << robotUnitProviderSegmentName; armem::data::AddSegmentInput input; @@ -379,7 +379,7 @@ namespace armarx void RobotSensorMemory::setupRobotStateComponentSegment() { ARMARX_INFO << "Adding core segment " << robotStateComponentCoreSegmentName; - memory.addCoreSegments({robotStateComponentCoreSegmentName}); + workingmemory.addCoreSegments({robotStateComponentCoreSegmentName}); ARMARX_INFO << "Adding provider segment " << robotStateComponentCoreSegmentName << "/" << robotStateComponentProviderSegmentName; armem::data::AddSegmentInput input; diff --git a/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.cpp b/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.cpp index 14dd88879..4efdcbff7 100644 --- a/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.cpp +++ b/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.cpp @@ -50,7 +50,7 @@ namespace armarx void SkillsMemory::onInitComponent() { - memory.name() = memoryName; + workingmemory.name() = memoryName; } diff --git a/source/RobotAPI/interface/armem/io.ice b/source/RobotAPI/interface/armem/io.ice index 99917016b..853e8c1c8 100644 --- a/source/RobotAPI/interface/armem/io.ice +++ b/source/RobotAPI/interface/armem/io.ice @@ -34,8 +34,6 @@ module armarx { armarx::data::PackagePath packagePath; armem::query::data::Input query; - - bool createParentDirectories = false; }; struct StoreResult diff --git a/source/RobotAPI/interface/aron/Aron.ice b/source/RobotAPI/interface/aron/Aron.ice index 50e821e1b..d01b0d60a 100644 --- a/source/RobotAPI/interface/aron/Aron.ice +++ b/source/RobotAPI/interface/aron/Aron.ice @@ -51,7 +51,7 @@ module armarx class AronList extends AronType { AronType acceptedType; }; class AronTuple extends AronType { AronTypeList elementTypes; }; class AronPair extends AronType { AronType acceptedType1; AronType acceptedType2; }; - class AronObject extends AronType { AronObject parent; string objectName; AronTypeDict elementTypes;}; + class AronObject extends AronType { AronObject parent; string objectName; AronTypeDict elementTypes; }; class AronDict extends AronType { AronType acceptedType; }; // Complex Types (serialize to ndarray) diff --git a/source/RobotAPI/libraries/armem/CMakeLists.txt b/source/RobotAPI/libraries/armem/CMakeLists.txt index 57bbfbd6b..7551773bf 100644 --- a/source/RobotAPI/libraries/armem/CMakeLists.txt +++ b/source/RobotAPI/libraries/armem/CMakeLists.txt @@ -19,32 +19,39 @@ set(LIB_FILES core/MemoryID.cpp core/SuccessHeader.cpp core/Time.cpp - core/ice_conversions.cpp - core/CoreSegment.cpp - core/Entity.cpp - core/EntityInstance.cpp - core/EntitySnapshot.cpp core/ice_conversions.cpp - core/Memory.cpp - core/ProviderSegment.cpp - core/detail/MemoryItem.cpp - core/detail/MaxHistorySize.cpp + core/base/detail/MemoryItem.cpp + core/base/detail/MaxHistorySize.cpp + core/base/detail/MemoryContainer.cpp + core/base/detail/EntityContainer.cpp + + core/base/CoreSegment.cpp + core/base/Entity.cpp + core/base/EntityInstance.cpp + core/base/EntitySnapshot.cpp + core/base/Memory.cpp + core/base/ProviderSegment.cpp + + core/workingMemory/ice_conversions.cpp + core/workingMemory/CoreSegment.cpp + core/workingMemory/Entity.cpp + core/workingMemory/EntityInstance.cpp + core/workingMemory/EntitySnapshot.cpp + core/workingMemory/Memory.cpp + core/workingMemory/ProviderSegment.cpp + + core/longtermMemory/ice_conversions.cpp + core/longtermMemory/CoreSegment.cpp + core/longtermMemory/Entity.cpp + core/longtermMemory/EntityInstance.cpp + core/longtermMemory/EntitySnapshot.cpp + core/longtermMemory/Memory.cpp + core/longtermMemory/ProviderSegment.cpp core/error/ArMemError.cpp - core/io/DiskMemory.cpp - core/io/DiskCoreSegment.cpp - core/io/DiskProviderSegment.cpp - core/io/DiskEntity.cpp - core/io/DiskEntitySnapshot.cpp - core/io/DiskEntityInstance.cpp - core/io/diskWriter/DiskWriter.cpp - core/io/diskWriter/NlohmannJSON/NlohmannJSONDiskWriter.cpp - core/io/diskReader/DiskReader.cpp - core/io/diskReader/NlohmannJSON/NlohmannJSONDiskReader.cpp - client/ComponentPlugin.cpp client/Reader.cpp client/ReaderComponentPlugin.cpp @@ -86,35 +93,42 @@ set(LIB_HEADERS core/error.h core/error/ArMemError.h - core/CoreSegment.h - core/Entity.h - core/EntityInstance.h - core/EntitySnapshot.h - core/ice_conversions.h - core/Memory.h - core/ProviderSegment.h - - core/detail/EntityContainer.h - core/detail/MaxHistorySize.h - core/detail/MemoryContainer.h - core/detail/MemoryItem.h - core/detail/TypedEntityContainer.h - - core/io/DiskInstanceData.h - core/io/DiskMemory.h - core/io/DiskCoreSegment.h - core/io/DiskProviderSegment.h - core/io/DiskEntity.h - core/io/DiskEntitySnapshot.h - core/io/DiskEntityInstance.h - core/io/diskWriter/DiskWriter.h - core/io/diskWriter/NlohmannJSON/NlohmannJSONDiskWriter.h - core/io/diskReader/DiskReader.h - core/io/diskReader/NlohmannJSON/NlohmannJSONDiskReader.h - - core/io/detail/DiskMemoryItem.h - core/io/detail/DiskMemoryContainer.h - core/io/detail/DiskTypedEntityContainer.h + core/base/detail/MemoryItem.h + core/base/detail/MaxHistorySize.h + core/base/detail/MemoryContainer.h + core/base/detail/EntityContainer.h + core/base/detail/TypedEntityContainer.h + + core/base/CoreSegment.h + core/base/Entity.h + core/base/EntityInstance.h + core/base/EntitySnapshot.h + core/base/Memory.h + core/base/ProviderSegment.h + + core/workingMemory/detail/MemoryContainer.h + core/workingMemory/detail/EntityContainer.h + core/workingMemory/detail/TypedEntityContainer.h + + core/workingMemory/ice_conversions.h + core/workingMemory/CoreSegment.h + core/workingMemory/Entity.h + core/workingMemory/EntityInstance.h + core/workingMemory/EntitySnapshot.h + core/workingMemory/Memory.h + core/workingMemory/ProviderSegment.h + + core/longtermMemory/detail/MemoryContainer.h + core/longtermMemory/detail/EntityContainer.h + core/longtermMemory/detail/TypedEntityContainer.h + + core/longtermMemory/ice_conversions.h + core/longtermMemory/CoreSegment.h + core/longtermMemory/Entity.h + core/longtermMemory/EntityInstance.h + core/longtermMemory/EntitySnapshot.h + core/longtermMemory/Memory.h + core/longtermMemory/ProviderSegment.h client.h client/ComponentPlugin.h diff --git a/source/RobotAPI/libraries/armem/client/Query.cpp b/source/RobotAPI/libraries/armem/client/Query.cpp index 1c649e340..9830e11c4 100644 --- a/source/RobotAPI/libraries/armem/client/Query.cpp +++ b/source/RobotAPI/libraries/armem/client/Query.cpp @@ -1,7 +1,6 @@ #include "Query.h" -#include <RobotAPI/libraries/armem/core/ice_conversions.h> - +#include <RobotAPI/libraries/armem/core/workingMemory/ice_conversions.h> namespace armarx::armem::client { @@ -52,13 +51,13 @@ namespace armarx::armem void client::toIce(armem::query::data::Result& ice, const QueryResult& result) { toIce(ice, dynamic_cast<const detail::SuccessHeader&>(result)); - toIce(ice.memory, result.memory); + armarx::armem::toIce(ice.memory, result.memory); } void client::fromIce(const armem::query::data::Result& ice, QueryResult& result) { fromIce(ice, dynamic_cast<detail::SuccessHeader&>(result)); - fromIce(ice.memory, result.memory); + armarx::armem::fromIce(ice.memory, result.memory); } } diff --git a/source/RobotAPI/libraries/armem/client/Query.h b/source/RobotAPI/libraries/armem/client/Query.h index 06379aff7..842fdf55c 100644 --- a/source/RobotAPI/libraries/armem/client/Query.h +++ b/source/RobotAPI/libraries/armem/client/Query.h @@ -6,7 +6,7 @@ #include <RobotAPI/libraries/armem/core/ice_conversions.h> #include <RobotAPI/libraries/armem/core/SuccessHeader.h> #include <RobotAPI/libraries/armem/core/DataMode.h> -#include <RobotAPI/libraries/armem/core/Memory.h> +#include <RobotAPI/libraries/armem/core/workingMemory/Memory.h> namespace armarx::armem::client @@ -31,7 +31,7 @@ namespace armarx::armem::client */ struct QueryResult : public detail::SuccessHeader { - Memory memory; + workingmemory::Memory memory; static QueryResult fromIce(const armem::query::data::Result& ice); diff --git a/source/RobotAPI/libraries/armem/client/Reader.h b/source/RobotAPI/libraries/armem/client/Reader.h index bbae1f4b3..8fd5277e6 100644 --- a/source/RobotAPI/libraries/armem/client/Reader.h +++ b/source/RobotAPI/libraries/armem/client/Reader.h @@ -10,8 +10,8 @@ #include <RobotAPI/interface/armem/server/ReadingMemoryInterface.h> #include <RobotAPI/interface/armem/client/MemoryListenerInterface.h> #include <RobotAPI/libraries/armem/core/ice_conversions.h> -#include <RobotAPI/libraries/armem/core/Memory.h> -#include <RobotAPI/libraries/armem/core/io/DiskMemory.h> +#include <RobotAPI/libraries/armem/core/workingMemory/Memory.h> +#include <RobotAPI/libraries/armem/core/longtermMemory/Memory.h> #include "Query.h" diff --git a/source/RobotAPI/libraries/armem/core.h b/source/RobotAPI/libraries/armem/core.h index 8e0a1ea22..e4825918b 100644 --- a/source/RobotAPI/libraries/armem/core.h +++ b/source/RobotAPI/libraries/armem/core.h @@ -7,12 +7,13 @@ #include "core/MemoryID.h" #include "core/Time.h" -#include "core/Memory.h" -#include "core/CoreSegment.h" -#include "core/ProviderSegment.h" -#include "core/Entity.h" -#include "core/EntitySnapshot.h" -#include "core/EntityInstance.h" +#include "core/workingMemory/Memory.h" +#include "core/workingMemory/CoreSegment.h" +#include "core/workingMemory/ProviderSegment.h" +#include "core/workingMemory/Entity.h" +#include "core/workingMemory/EntitySnapshot.h" +#include "core/workingMemory/EntityInstance.h" +#include "core/workingMemory/ice_conversions.h" namespace armarx::armem diff --git a/source/RobotAPI/libraries/armem/core/CoreSegment.cpp b/source/RobotAPI/libraries/armem/core/CoreSegment.cpp deleted file mode 100644 index 92857a7bc..000000000 --- a/source/RobotAPI/libraries/armem/core/CoreSegment.cpp +++ /dev/null @@ -1,173 +0,0 @@ -#include "CoreSegment.h" - -#include <ArmarXCore/core/exceptions/local/ExpressionException.h> - -#include "error.h" - - -namespace armarx::armem -{ - - CoreSegment::CoreSegment() - { - } - - CoreSegment::CoreSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType) : - CoreSegment(name, MemoryID(), aronType) - { - } - - CoreSegment::CoreSegment(const std::string& name, const MemoryID& parentID, aron::typenavigator::ObjectNavigatorPtr aronType) : - CoreSegment(parentID.getMemoryID().withCoreSegmentName(name), aronType) - { - } - - CoreSegment::CoreSegment(const MemoryID& id, aron::typenavigator::ObjectNavigatorPtr aronType) : - Base(id, aronType) - { - } - - CoreSegment::CoreSegment(const CoreSegment& other) : Base(other) - { - *this = other; - } - - CoreSegment& CoreSegment::operator=(const CoreSegment& other) - { - other._copySelf(*this); - other._copyElements(*this, true); - return *this; - } - - bool CoreSegment::equalsDeep(const CoreSegment& other) const - { - //std::cout << "CoreSegment::equalsDeep" << std::endl; - if (size() != other.size()) - { - return false; - } - for (const auto& [key, provider] : providerSegments) - { - if (not other.hasProviderSegment(key)) - { - return false; - } - if (not provider.equalsDeep(other.getProviderSegment(key))) - { - return false; - } - } - return true; - } - - CoreSegment::~CoreSegment() - { - } - - const std::string& CoreSegment::name() const - { - return id().coreSegmentName; - } - - void CoreSegment::_copyElements(CoreSegment& other, bool withData) const - { - other.providerSegments.clear(); - for (const auto& [name, providerSegment] : this->providerSegments) - { - other.addProviderSegment(providerSegment.copy(withData)); - } - } - - - bool CoreSegment::hasProviderSegment(const std::string& name) const - { - return providerSegments.count(name) > 0; - } - - ProviderSegment& CoreSegment::getProviderSegment(const std::string& name) - { - return const_cast<ProviderSegment&>(const_cast<const CoreSegment*>(this)->getProviderSegment(name)); - } - - const ProviderSegment& CoreSegment::getProviderSegment(const std::string& name) const - { - auto it = this->providerSegments.find(name); - if (it != providerSegments.end()) - { - return it->second; - } - else - { - throw armem::error::MissingEntry("provider segment", name, getLevelName(), this->name()); - } - } - - const Entity& CoreSegment::getEntity(const MemoryID& id) const - { - _checkContainerName(id.coreSegmentName, this->name()); - return getProviderSegment(id.providerSegmentName).getEntity(id); - } - - - ProviderSegment& CoreSegment::addProviderSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr providerSegmentType) - { - aron::typenavigator::ObjectNavigatorPtr type = providerSegmentType ? providerSegmentType : this->aronType(); - return addProviderSegment(ProviderSegment(name, type)); - } - - ProviderSegment& CoreSegment::addProviderSegment(const ProviderSegment& providerSegment) - { - return addProviderSegment(ProviderSegment(providerSegment)); - } - - ProviderSegment& CoreSegment::addProviderSegment(ProviderSegment&& providerSegment) - { - if (hasProviderSegment(providerSegment.name())) - { - throw armem::error::ContainerEntryAlreadyExists( - providerSegment.getLevelName(), providerSegment.name(), getLevelName(), this->name()); - } - - auto it = providerSegments.emplace(providerSegment.name(), std::move(providerSegment)).first; - it->second.id().setCoreSegmentID(id()); - it->second.setMaxHistorySize(maxHistorySize); - return it->second; - } - - void CoreSegment::setMaxHistorySize(long maxSize) - { - MaxHistorySize::setMaxHistorySize(maxSize); - for (auto& [name, seg] : providerSegments) - { - seg.setMaxHistorySize(maxSize); - } - } - - std::string CoreSegment::getLevelName() const - { - return "core segment"; - } - - CoreSegment::ContainerT& CoreSegment::_underlyingContainer() - { - return providerSegments; - } - - - MemoryID CoreSegment::update(const EntityUpdate& update) - { - _checkContainerName(update.entityID.coreSegmentName, this->name()); - - auto it = this->providerSegments.find(update.entityID.providerSegmentName); - if (it != providerSegments.end()) - { - return it->second.update(update); - } - else - { - throw armem::error::MissingEntry("provider segment", update.entityID.providerSegmentName, - getLevelName(), name()); - } - } - -} diff --git a/source/RobotAPI/libraries/armem/core/CoreSegment.h b/source/RobotAPI/libraries/armem/core/CoreSegment.h deleted file mode 100644 index f492c0f1a..000000000 --- a/source/RobotAPI/libraries/armem/core/CoreSegment.h +++ /dev/null @@ -1,93 +0,0 @@ -#pragma once - -#include <map> -#include <string> - -#include "ProviderSegment.h" -#include "detail/TypedEntityContainer.h" -#include "detail/MaxHistorySize.h" - - -namespace armarx::armem -{ - - /** - * @brief Data of a core segment containing multiple provider segments. - */ - class CoreSegment : - public detail::TypedEntityContainer<ProviderSegment, CoreSegment> - , public detail::MaxHistorySize - { - using Base = detail::TypedEntityContainer<ProviderSegment, CoreSegment>; - - public: - - CoreSegment(); - CoreSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); - CoreSegment(const std::string& name, const MemoryID& parentID, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); - CoreSegment(const MemoryID& id, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); - - CoreSegment(const CoreSegment& other); - CoreSegment& operator=(const CoreSegment& other); - - ~CoreSegment() override; - - - using Base::name; - const std::string& name() const override; - - - bool hasProviderSegment(const std::string& name) const; - ProviderSegment& getProviderSegment(const std::string& name); - const ProviderSegment& getProviderSegment(const std::string& name) const; - - - using Base::getEntity; - const Entity& getEntity(const MemoryID& id) const override; - - - using Base::update; - virtual MemoryID update(const EntityUpdate& update) override; - - /** - * @brief Add an empty provider segment with the given name and optional provider segment type. - * @param name The segment name. - * @param providerSegmentType The provider type. If nullptr, the core segment type is used. - * @return The added provider segment. - */ - ProviderSegment& addProviderSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr providerSegmentType = nullptr); - /// Copy and insert a provider segment. - ProviderSegment& addProviderSegment(const ProviderSegment& providerSegment); - /// Move and insert a provider segment. - ProviderSegment& addProviderSegment(ProviderSegment&& providerSegment); - - - /** - * @brief Sets the maximum history size of entities in this segment. - * This affects all current entities as well as new ones. - * @see Entity::setMaxHistorySize() - */ - void setMaxHistorySize(long maxSize) override; - - - bool equalsDeep(const CoreSegment& other) const; - - - // MemoryItem interface - public: - std::string getLevelName() const override; - - // MemoryContainer interface - protected: - ContainerT& _underlyingContainer() override; - void _copyElements(CoreSegment& other, bool withData) const override; - - - public: - - /// The provider segments. - std::map<std::string, ProviderSegment> providerSegments; - - }; - -} diff --git a/source/RobotAPI/libraries/armem/core/Entity.cpp b/source/RobotAPI/libraries/armem/core/Entity.cpp deleted file mode 100644 index 9795ffdbe..000000000 --- a/source/RobotAPI/libraries/armem/core/Entity.cpp +++ /dev/null @@ -1,216 +0,0 @@ -#include "Entity.h" - -#include <SimoxUtility/algorithm/get_map_keys_values.h> - -#include <ArmarXCore/core/exceptions/local/ExpressionException.h> - -#include "error.h" - - -namespace armarx::armem -{ - - Entity::Entity() - { - } - - Entity::Entity(const std::string& name, const MemoryID& parentID) : - Entity(parentID.withEntityName(name)) - { - } - - Entity::Entity(const MemoryID& id) : Base(id) - { - } - - Entity::Entity(const Entity& other) : Base(other) - { - *this = other; - } - - Entity& Entity::operator=(const Entity& other) - { - other._copySelf(*this); - other._copyElements(*this, true); - return *this; - } - - bool Entity::equalsDeep(const Entity& other) const - { - //std::cout << "Entity::equalsDeep" << std::endl; - if (size() != other.size()) - { - return false; - } - for (const auto& [key, snapshot] : history) - { - if (not other.hasSnapshot(key)) - { - return false; - } - if (not snapshot.equalsDeep(other.getSnapshot(key))) - { - return false; - } - } - return true; - } - - - void Entity::_copySelf(Entity& other) const - { - Base::_copySelf(other); - other.maxHistorySize = this->maxHistorySize; - } - - void Entity::_copyElements(Entity& other, bool withData) const - { - other.history.clear(); - for (const auto& [time, snapshot] : this->history) - { - other.addSnapshot(snapshot.copy(withData)); - } - } - - - bool Entity::hasSnapshot(Time time) const - { - return history.count(time) > 0; - } - - bool Entity::hasSnapshotData(Time time) const - { - return history.count(time) > 0; - } - - EntitySnapshot& Entity::getSnapshot(Time time) - { - return const_cast<EntitySnapshot&>(const_cast<const Entity*>(this)->getSnapshot(time)); - } - - const EntitySnapshot& Entity::getSnapshot(Time time) const - { - auto it = history.find(time); - if (it != history.end()) - { - return it->second; - } - else - { - throw error::MissingEntry("entity snapshot", toDateTimeMilliSeconds(time), - getLevelName(), this->id().str()); - } - } - - EntitySnapshot& Entity::getSnapshot(const MemoryID& id) - { - return const_cast<EntitySnapshot&>(const_cast<const Entity*>(this)->getSnapshot(id)); - } - - const EntitySnapshot& Entity::getSnapshot(const MemoryID& id) const - { - checkEntityName(id.entityName); - return getSnapshot(id.timestamp); - } - - EntitySnapshot& Entity::getLatestSnapshot() - { - return const_cast<EntitySnapshot&>(const_cast<const Entity*>(this)->getLatestSnapshot()); - } - - const EntitySnapshot& Entity::getLatestSnapshot() const - { - return getLatestItem().second; - } - - Time Entity::getLatestTimestamp() const - { - return getLatestItem().first; - } - - std::vector<Time> Entity::getTimestamps() const - { - return simox::alg::get_keys(history); - } - - - EntitySnapshot& Entity::addSnapshot(const EntitySnapshot& snapshot) - { - return addSnapshot(EntitySnapshot(snapshot)); - } - - - EntitySnapshot& Entity::addSnapshot(EntitySnapshot&& snapshot) - { - auto it = history.emplace(snapshot.time(), std::move(snapshot)).first; - it->second.id().setEntityID(id()); - return it->second; - } - - EntitySnapshot& Entity::addSnapshot(const Time& timestamp) - { - return addSnapshot(EntitySnapshot(timestamp)); - } - - MemoryID Entity::update(const EntityUpdate& update) - { - checkEntityName(update.entityID.entityName); - id() = update.entityID; - - EntitySnapshot* snapshot; - - auto it = history.find(update.timeCreated); - if (it == history.end()) - { - // Insert into history. - snapshot = &addSnapshot(update.timeCreated); - truncateHistoryToSize(); - } - else - { - snapshot = &it->second; - } - // Update entry. - snapshot->update(update); - - return snapshot->id(); - } - - - void Entity::setMaxHistorySize(long maxSize) - { - this->maxHistorySize = maxSize; - truncateHistoryToSize(); - } - - - void Entity::truncateHistoryToSize() - { - if (maxHistorySize >= 0) - { - while (history.size() > size_t(maxHistorySize)) - { - history.erase(history.begin()); - } - ARMARX_CHECK_LESS_EQUAL(history.size(), maxHistorySize); - } - } - - void Entity::checkEntityName(const std::string& name) const - { - if (name != this->name()) - { - throw armem::error::ContainerNameMismatch(name, getLevelName(), this->name()); - } - } - - const std::map<Time, EntitySnapshot>::value_type& Entity::getLatestItem() const - { - if (history.empty()) - { - throw armem::error::EntityHistoryEmpty(name(), "when getting the latest snapshot."); - } - return *history.rbegin(); - } - -} diff --git a/source/RobotAPI/libraries/armem/core/Entity.h b/source/RobotAPI/libraries/armem/core/Entity.h deleted file mode 100644 index b81ffe761..000000000 --- a/source/RobotAPI/libraries/armem/core/Entity.h +++ /dev/null @@ -1,192 +0,0 @@ -#pragma once - -#include <map> -#include <string> - -#include "../core/Time.h" -#include "../core/MemoryID.h" - -#include "EntitySnapshot.h" -#include "detail/MemoryContainer.h" - - -namespace armarx::armem -{ - - /** - * @brief An entity over a period of time. - * - * An entity should be a physical thing or abstract concept existing - * (and potentially evolving) over some time. - * - * Examples are: - * - objects (the green box) - * - agents (robot, human) - * - locations (frige, sink) - * - grasp affordances (general, or for a specific object) - * - images - * - point clouds - * - other sensory values - * - * At each point in time (`EntitySnapshot`), the entity can have a - * (potentially variable) number of instances (`EntityInstance`), - * each containing a single `AronData` object of a specific `AronType`. - */ - class Entity : - public detail::MemoryContainer<std::map<Time, EntitySnapshot>, Entity> - { - using Base = detail::MemoryContainer<std::map<Time, EntitySnapshot>, Entity>; - - - public: - - Entity(); - Entity(const std::string& name, const MemoryID& parentID = {}); - Entity(const MemoryID& id); - - /// Copy the history from `other` to this. - Entity(const Entity& other); - /// Copy the history from `other` to this. - Entity& operator=(const Entity& other); - - - inline const std::string& name() const - { - return id().entityName; - } - inline std::string& name() - { - return id().entityName; - } - - - /** - * @brief Indicates whether a history entry for the given time exists. - */ - bool hasSnapshot(Time time) const; - /** - * @brief Indicates whether a history entry for the given time exists - * and its data is not null. - */ - bool hasSnapshotData(Time time) const; - - - /** - * @brief Get the latest timestamp. - * @throw `armem::error::EntityHistoryEmpty` If the history is empty. - */ - Time getLatestTimestamp() const; - /** - * @brief Get all timestamps in the history. - */ - std::vector<Time> getTimestamps() const; - - - /** - * @brief Get a snapshot. - * @param time The time. - * @return The snapshot, if it exists. - * - * @throws `armem::error::MissingEntry` If there is no such entry. - * @throws `armem::error::MissingData` If the entry has no data. - */ - EntitySnapshot& getSnapshot(Time time); - const EntitySnapshot& getSnapshot(Time time) const; - - EntitySnapshot& getSnapshot(const MemoryID& id); - const EntitySnapshot& getSnapshot(const MemoryID& id) const; - - /** - * @brief Return the snapshot with the most recent timestamp. - * @return The latest snapshot. - * @throw `armem::error::EntityHistoryEmpty` If the history is empty. - * @throw `armem::error::MissingData` If the latest snapshot has no data. - */ - EntitySnapshot& getLatestSnapshot(); - const EntitySnapshot& getLatestSnapshot() const; - - - /** - * @brief Add the given update to this entity's history. - * @param update The update. - * @return The snapshot ID of the update. - */ - MemoryID update(const EntityUpdate& update); - - /** - * @brief Add a single snapshot with data. - * @param snapshot The snapshot. - * @return The stored snapshot. - */ - EntitySnapshot& addSnapshot(const EntitySnapshot& snapshot); - EntitySnapshot& addSnapshot(EntitySnapshot&& snapshot); - EntitySnapshot& addSnapshot(const Time& timestamp); - - - /** - * @brief Sets the maximum history size. - * - * The current history is truncated if necessary. - */ - void setMaxHistorySize(long maxSize); - - - bool equalsDeep(const Entity& other) const; - - - protected: - - void _copySelf(Entity& other) const override; - void _copyElements(Entity& other, bool withData) const override; - - - - private: - - /// If maximum size is set, ensure `history`'s is not higher. - void truncateHistoryToSize(); - void checkEntityName(const std::string& name) const; - ContainerT::iterator _addSnapshot(); - - /** - * @brief Return the snapshot with the most recent timestamp. - * @return The latest snapshot. - * @throw `armem::error::EntityHistoryEmpty` If the history is empty. - */ - const std::map<Time, EntitySnapshot>::value_type& getLatestItem() const; - - - public: - - std::map<Time, EntitySnapshot> history; - - /** - * @brief Maximum size of `history` - * - * If negative, the size of `history` is not limited. - */ - long maxHistorySize = -1; - // ToDo: Add max age; - // ToDo in future: keep/remove predicate - - // MemoryItem interface - public: - std::string getKeyString() const override - { - return id().entityName; - } - std::string getLevelName() const override - { - return "entity"; - } - - // MemoryContainer interface - protected: - ContainerT& _underlyingContainer() override - { - return history; - } - - }; - -} diff --git a/source/RobotAPI/libraries/armem/core/EntitySnapshot.cpp b/source/RobotAPI/libraries/armem/core/EntitySnapshot.cpp deleted file mode 100644 index 9d9eac2a6..000000000 --- a/source/RobotAPI/libraries/armem/core/EntitySnapshot.cpp +++ /dev/null @@ -1,166 +0,0 @@ -#include "EntitySnapshot.h" - -#include <ArmarXCore/core/exceptions/local/ExpressionException.h> - -#include "error.h" - - -namespace armarx::armem -{ - - - EntitySnapshot::EntitySnapshot() - { - } - - EntitySnapshot::EntitySnapshot(Time time, const MemoryID& parentID) : - EntitySnapshot(parentID.withTimestamp(time)) - { - } - - EntitySnapshot::EntitySnapshot(const MemoryID& id) : Base(id) - { - } - - EntitySnapshot::EntitySnapshot(const EntitySnapshot& other) : Base(other) - { - *this = other; - } - - EntitySnapshot& EntitySnapshot::operator=(const EntitySnapshot& other) - { - other._copySelf(*this); - other._copyElements(*this, true); - return *this; - } - - bool EntitySnapshot::equalsDeep(const EntitySnapshot& other) const - { - //std::cout << "EntitySnapshot::equalsDeep" << std::endl; - if (size() != other.size()) - { - return false; - } - int i = 0; - for (const auto& instance : instances) - { - if (not instance.equalsDeep(other.getInstance(i))) - { - return false; - } - i++; - } - return true; - } - - - void EntitySnapshot::_copyElements(EntitySnapshot& other, bool withData) const - { - other.instances.clear(); - other.instances.reserve(this->instances.size()); - for (const auto& data : this->instances) - { - other.instances.emplace_back(data.copy(withData)); - } - } - - - void EntitySnapshot::update(const EntityUpdate& update, - std::optional<MemoryID> parentID) - { - if (parentID) - { - id() = *parentID; - } - time() = update.timeCreated; - - instances.clear(); - for (int i = 0; i < int(update.instancesData.size()); ++i) - { - EntityInstance& data = instances.emplace_back(i, id()); - data.update(update, i); - } - } - - bool EntitySnapshot::hasInstance(int index) const - { - size_t si = size_t(index); - return index >= 0 && si < instances.size(); - } - - - EntityInstance& EntitySnapshot::getInstance(int index) - { - return const_cast<EntityInstance&>(const_cast<const EntitySnapshot*>(this)->getInstance(index)); - } - - const EntityInstance& EntitySnapshot::getInstance(int index) const - { - if (hasInstance(index)) - { - size_t si = size_t(index); - return instances[si]; - } - else - { - throw armem::error::MissingEntry(EntityInstance().getLevelName(), std::to_string(index), - getLevelName(), toDateTimeMilliSeconds(time())); - } - } - - - EntityInstance& EntitySnapshot::getInstance(const MemoryID& id) - { - return const_cast<EntityInstance&>(const_cast<const EntitySnapshot*>(this)->getInstance(id)); - } - - const EntityInstance& EntitySnapshot::getInstance(const MemoryID& id) const - { - if (!id.hasInstanceIndex()) - { - throw armem::error::InvalidMemoryID(id, "ID has no instance index."); - } - return getInstance(id.instanceIndex); - } - - EntityInstance& EntitySnapshot::addInstance(const EntityInstance& instance) - { - return addInstance(EntityInstance(instance)); - } - - - EntityInstance& EntitySnapshot::addInstance(EntityInstance&& instance) - { - if (instance.index() > 0 && (size_t) instance.index() < instances.size()) - { - throw error::InvalidArgument(std::to_string(instance.index()), "EntitySnapshot::addInstance", - "Cannot add an EntityInstance because its index already exists."); - } - if (instance.index() > 0 && (size_t) instance.index() > instances.size()) - { - throw error::InvalidArgument(std::to_string(instance.index()), "EntitySnapshot::addInstance", - "Cannot add an EntityInstance because its index is too big."); - } - - int new_index = instances.size(); - auto& it = instances.emplace_back(std::move(instance)); - it.index() = new_index; - return it; - } - - std::string EntitySnapshot::getKeyString() const - { - return toDateTimeMilliSeconds(this->time()); - } - - std::string EntitySnapshot::getLevelName() const - { - return "entity snapshot"; - } - - EntitySnapshot::ContainerT& EntitySnapshot::_underlyingContainer() - { - return instances; - } - -} diff --git a/source/RobotAPI/libraries/armem/core/EntitySnapshot.h b/source/RobotAPI/libraries/armem/core/EntitySnapshot.h deleted file mode 100644 index da1301ccf..000000000 --- a/source/RobotAPI/libraries/armem/core/EntitySnapshot.h +++ /dev/null @@ -1,103 +0,0 @@ -#pragma once - -#include <memory> -#include <vector> - -#include "../core/MemoryID.h" -#include "../core/Time.h" - -#include "EntityInstance.h" -#include "detail/MemoryItem.h" -#include "detail/MemoryContainer.h" - - -namespace armarx::armem -{ - - /** - * @brief Data of an entity at one point in time. - */ - class EntitySnapshot : - public detail::MemoryContainer<std::vector<EntityInstance>, EntitySnapshot> - { - using Base = detail::MemoryContainer<std::vector<EntityInstance>, EntitySnapshot>; - - public: - - EntitySnapshot(); - EntitySnapshot(Time time, const MemoryID& parentID = {}); - EntitySnapshot(const MemoryID& id); - - /// Copy the instances from `other` to this. - EntitySnapshot(const EntitySnapshot& other); - /// Copy the instances from `other` to this. - EntitySnapshot& operator=(const EntitySnapshot& other); - - - inline Time& time() - { - return id().timestamp; - } - inline const Time& time() const - { - return id().timestamp; - } - - - void update(const EntityUpdate& update, - std::optional<MemoryID> parentID = std::nullopt); - - - bool hasInstance(int index) const; - - /** - * @brief Get the given instance. - * @param index The instance's index. - * @return The instance. - * @throw `armem::error::MissingEntry` If the given index is invalid. - */ - EntityInstance& getInstance(int index); - const EntityInstance& getInstance(int index) const; - /** - * @brief Get the given instance. - * @param index The instance's index. - * @return The instance. - * @throw `armem::error::MissingEntry` If the given index is invalid. - * @throw `armem::error::InvalidMemoryID` If memory ID does not have an instance index. - */ - EntityInstance& getInstance(const MemoryID& id); - const EntityInstance& getInstance(const MemoryID& id) const; - - - /** - * @brief Add a single instance with data. - * @param instance The instance. - * @return The stored instance. - * @throw `armem::error::InvalidArgument` If the given index is invalid. Must be equal to instances.size() or -1 (meaning push_back) - */ - EntityInstance& addInstance(const EntityInstance& instance); - EntityInstance& addInstance(EntityInstance&& instance); - - - bool equalsDeep(const EntitySnapshot& other) const; - - - // MemoryItem interface - public: - std::string getKeyString() const override; - std::string getLevelName() const override; - - - // MemoryContainer interface - protected: - ContainerT& _underlyingContainer() override; - void _copyElements(EntitySnapshot& other, bool withData) const override; - - - public: - - std::vector<EntityInstance> instances; - - }; - -} diff --git a/source/RobotAPI/libraries/armem/core/Memory.cpp b/source/RobotAPI/libraries/armem/core/Memory.cpp deleted file mode 100644 index 748e47495..000000000 --- a/source/RobotAPI/libraries/armem/core/Memory.cpp +++ /dev/null @@ -1,174 +0,0 @@ -#include "Memory.h" - -#include <ArmarXCore/core/logging/Logging.h> -#include <ArmarXCore/core/exceptions/local/ExpressionException.h> - -#include "error.h" - - -namespace armarx::armem -{ - - Memory::Memory() - { - } - - Memory::Memory(const std::string& name) : Memory(MemoryID().withMemoryName(name)) - { - } - - Memory::Memory(const MemoryID& id) : EntityContainer(id) - { - } - - Memory::Memory(const Memory& other) : EntityContainer(other) - { - *this = other; - } - - Memory& Memory::operator=(const Memory& other) - { - other._copySelf(*this); - other._copyElements(*this, true); - return *this; - } - - Memory::~Memory() - { - } - - - const std::string& Memory::name() const - { - return id().memoryName; - } - - void Memory::_copyElements(Memory& other, bool withData) const - { - other.coreSegments.clear(); - for (const auto& [name, coreSegment] : this->coreSegments) - { - other.coreSegments.emplace(name, coreSegment.copy(withData)); - } - } - - - bool Memory::hasCoreSegment(const std::string& name) const - { - return coreSegments.count(name) > 0; - } - - CoreSegment& Memory::getCoreSegment(const std::string& name) - { - return const_cast<CoreSegment&>(const_cast<const Memory*>(this)->getCoreSegment(name)); - } - const CoreSegment& Memory::getCoreSegment(const std::string& name) const - { - auto it = this->coreSegments.find(name); - if (it != coreSegments.end()) - { - return it->second; - } - else - { - throw armem::error::MissingEntry(CoreSegment().getLevelName(), name, getLevelName(), this->name()); - } - } - - - const Entity& Memory::getEntity(const MemoryID& id) const - { - _checkContainerName(id.memoryName, this->name()); - return getCoreSegment(id.coreSegmentName).getEntity(id); - } - - - CoreSegment& Memory::addCoreSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr coreSegmentType) - { - return addCoreSegment(CoreSegment(name, coreSegmentType)); - } - - CoreSegment& Memory::addCoreSegment(const CoreSegment& coreSegment) - { - return addCoreSegment(CoreSegment(coreSegment)); - } - - CoreSegment& Memory::addCoreSegment(CoreSegment&& coreSegment) - { - if (coreSegments.count(coreSegment.name()) > 0) - { - throw armem::error::ContainerEntryAlreadyExists(coreSegment.getLevelName(), coreSegment.name(), - this->getLevelName(), this->name()); - } - auto it = coreSegments.emplace(coreSegment.name(), std::move(coreSegment)).first; - it->second.id().setMemoryID(id()); - return it->second; - } - - std::vector<CoreSegment*> Memory::addCoreSegments(const std::vector<std::string>& names) - { - std::vector<CoreSegment*> segments; - for (const auto& name : names) - { - try - { - segments.push_back(&addCoreSegment(name)); - } - catch (const armem::error::ContainerEntryAlreadyExists& e) - { - ARMARX_INFO << e.what() << "\nIgnoring multiple addition."; - } - } - return segments; - } - - - MemoryID Memory::update(const EntityUpdate& update) - { - _checkContainerName(update.entityID.memoryName, this->name()); - - auto it = this->coreSegments.find(update.entityID.coreSegmentName); - if (it != coreSegments.end()) - { - return it->second.update(update); - } - else - { - throw armem::error::MissingEntry(CoreSegment().getLevelName(), update.entityID.coreSegmentName, - getLevelName(), this->name()); - } - } - - std::string Memory::getLevelName() const - { - return "memory"; - } - - Memory::ContainerT& Memory::_underlyingContainer() - { - return coreSegments; - } - - - bool Memory::equalsDeep(const Memory& other) const - { - //std::cout << "Memory::equalsDeep" << std::endl; - if (size() != other.size()) - { - return false; - } - for (const auto& [key, core] : coreSegments) - { - if (not other.hasCoreSegment(key)) - { - return false; - } - if (not core.equalsDeep(other.getCoreSegment(key))) - { - return false; - } - } - return true; - } - -} diff --git a/source/RobotAPI/libraries/armem/core/Memory.h b/source/RobotAPI/libraries/armem/core/Memory.h deleted file mode 100644 index 2059d0c0d..000000000 --- a/source/RobotAPI/libraries/armem/core/Memory.h +++ /dev/null @@ -1,83 +0,0 @@ -#pragma once - -#include <map> -#include <string> - -#include "CoreSegment.h" -#include "detail/EntityContainer.h" - -namespace armarx::armem -{ - - /** - * @brief Data of a memory consisting of multiple core segments. - */ - class Memory : public detail::EntityContainer<CoreSegment, Memory> - { - using Base = detail::EntityContainer<CoreSegment, Memory>; - - public: - - Memory(); - Memory(const std::string& name); - Memory(const MemoryID& id); - - Memory(const Memory& other); - Memory& operator=(const Memory& other); - - ~Memory() override; - - - using Base::name; - const std::string& name() const override; - - - bool hasCoreSegment(const std::string& name) const; - - CoreSegment& getCoreSegment(const std::string& name); - const CoreSegment& getCoreSegment(const std::string& name) const; - - - using Base::getEntity; - const Entity& getEntity(const MemoryID& id) const override; - - /** - * @brief Add an empty core segment with the given name. - * @param name The core segment name. - * @param coreSegmentType The core segment type (optional). - * @return The added core segment. - */ - CoreSegment& addCoreSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr coreSegmentType = nullptr); - /// Copy and insert a core segment. - CoreSegment& addCoreSegment(const CoreSegment& coreSegment); - /// Move and insert a core segment. - CoreSegment& addCoreSegment(CoreSegment&& coreSegment); - - /** - * @brief Add multiple core segments. - * @param The core segment names. - * @return The core segments. The contained pointers are never null. - */ - std::vector<CoreSegment*> addCoreSegments(const std::vector<std::string>& names); - - virtual MemoryID update(const EntityUpdate& update) override; - using Base::update; - - - bool equalsDeep(const Memory& other) const; - - - // MemoryItem interface - public: - std::string getLevelName() const override; - - // MemoryContainer interface - protected: - ContainerT& _underlyingContainer() override; - void _copyElements(Memory& other, bool withData) const override; - - - public: - std::map<std::string, CoreSegment> coreSegments; - }; -} diff --git a/source/RobotAPI/libraries/armem/core/ProviderSegment.cpp b/source/RobotAPI/libraries/armem/core/ProviderSegment.cpp deleted file mode 100644 index 1eabd5ecf..000000000 --- a/source/RobotAPI/libraries/armem/core/ProviderSegment.cpp +++ /dev/null @@ -1,175 +0,0 @@ -#include "ProviderSegment.h" - -#include <ArmarXCore/core/exceptions/local/ExpressionException.h> - -#include "error.h" - - -namespace armarx::armem -{ - - ProviderSegment::ProviderSegment() - { - } - - ProviderSegment::ProviderSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType) : - ProviderSegment(name, MemoryID(), aronType) - { - } - - ProviderSegment::ProviderSegment(const std::string& name, const MemoryID parentID, aron::typenavigator::ObjectNavigatorPtr aronType) : - ProviderSegment(parentID.withProviderSegmentName(name), aronType) - { - } - - ProviderSegment::ProviderSegment(const MemoryID id, aron::typenavigator::ObjectNavigatorPtr aronType) : - Base(id, aronType) - { - } - - ProviderSegment::ProviderSegment(const ProviderSegment& other) : Base(other) - { - *this = other; - } - - ProviderSegment& ProviderSegment::operator=(const ProviderSegment& other) - { - other._copySelf(*this); - other._copyElements(*this, true); - return *this; - } - - bool ProviderSegment::equalsDeep(const ProviderSegment& other) const - { - //std::cout << "ProviderSegment::equalsDeep" << std::endl; - if (size() != other.size()) - { - return false; - } - for (const auto& [key, value] : entities) - { - if (not other.hasEntity(key)) - { - return false; - } - - if (not value.equalsDeep(other.getEntity(key))) - { - return false; - } - } - return true; - } - - ProviderSegment::~ProviderSegment() - { - } - - const std::string& ProviderSegment::name() const - { - return id().providerSegmentName; - } - - - void ProviderSegment::_copySelf(ProviderSegment& other) const - { - Base::_copySelf(other); - other.maxHistorySize = this->maxHistorySize; - } - - void ProviderSegment::_copyElements(ProviderSegment& other, bool withData) const - { - other.entities.clear(); - for (const auto& [name, entity] : this->entities) - { - other.addEntity(entity.copy(withData)); - } - } - - - bool ProviderSegment::hasEntity(const std::string& name) const - { - return entities.count(name) > 0; - } - - Entity& ProviderSegment::getEntity(const std::string& name) - { - return const_cast<Entity&>(const_cast<const ProviderSegment*>(this)->getEntity(name)); - } - - const Entity& ProviderSegment::getEntity(const std::string& name) const - { - auto it = this->entities.find(name); - if (it != entities.end()) - { - return it->second; - } - else - { - throw error::MissingEntry("entity", name, getLevelName(), this->name()); - } - } - - const Entity& ProviderSegment::getEntity(const MemoryID& id) const - { - _checkContainerName(id.providerSegmentName, this->name()); - return getEntity(id.entityName); - } - - MemoryID ProviderSegment::update(const EntityUpdate& update) - { - _checkContainerName(update.entityID.providerSegmentName, this->name()); - - Entity* entity; - auto it = this->entities.find(update.entityID.providerSegmentName); - if (it == entities.end()) - { - // Add entity entry. - entity = &addEntity(update.entityID.entityName); - entity->setMaxHistorySize(maxHistorySize); - } - else - { - entity = &it->second; - } - // Update entity. - return entity->update(update); - } - - Entity& ProviderSegment::addEntity(const std::string& name) - { - return addEntity(Entity(name)); - } - - Entity& ProviderSegment::addEntity(const Entity& entity) - { - return addEntity(Entity(entity)); - } - - Entity& ProviderSegment::addEntity(Entity&& entity) - { - auto it = entities.emplace(entity.name(), std::move(entity)).first; - it->second.id().setProviderSegmentID(id()); - return it->second; - } - - void ProviderSegment::setMaxHistorySize(long maxSize) - { - MaxHistorySize::setMaxHistorySize(maxSize); - for (auto& [name, entity] : entities) - { - entity.setMaxHistorySize(maxSize); - } - } - - std::string ProviderSegment::getLevelName() const - { - return "provider segment"; - } - - ProviderSegment::ContainerT& ProviderSegment::_underlyingContainer() - { - return entities; - } - -} diff --git a/source/RobotAPI/libraries/armem/core/ProviderSegment.h b/source/RobotAPI/libraries/armem/core/ProviderSegment.h deleted file mode 100644 index cbb2080de..000000000 --- a/source/RobotAPI/libraries/armem/core/ProviderSegment.h +++ /dev/null @@ -1,97 +0,0 @@ -#pragma once - -#include <map> -#include <string> - -#include "Entity.h" -#include "detail/TypedEntityContainer.h" -#include "detail/MaxHistorySize.h" - - -namespace armarx::armem -{ - - /** - * @brief Data of a provider segment containing multiple entities. - */ - class ProviderSegment : - public detail::TypedEntityContainer<Entity, ProviderSegment> - , public detail::MaxHistorySize - - { - using Base = detail::TypedEntityContainer<Entity, ProviderSegment>; - - - public: - - ProviderSegment(); - ProviderSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); - ProviderSegment(const std::string& name, const MemoryID parentID, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); - ProviderSegment(const MemoryID id, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); - - ProviderSegment(const ProviderSegment& other); - ProviderSegment& operator=(const ProviderSegment& other); - - ~ProviderSegment() override; - - - using Base::name; - const std::string& name() const override; - - - bool hasEntity(const std::string& name) const; - - using Base::getEntity; - const Entity& getEntity(const MemoryID& id) const override; - - Entity& getEntity(const std::string& name); - const Entity& getEntity(const std::string& name) const; - - - - using Base::update; - /** - * @brief Updates an entity's history. - * - * Missing entity entries are added before updating. - */ - virtual MemoryID update(const EntityUpdate& update) override; - - /// Add an empty entity with the given name. - Entity& addEntity(const std::string& name); - /// Copy and insert an entity. - Entity& addEntity(const Entity& entity); - /// Move and insert an entity. - Entity& addEntity(Entity&& entity); - - - /** - * @brief Sets the maximum history size of entities in this segment. - * This affects all current entities as well as new ones. - * @see Entity::setMaxHistorySize() - */ - void setMaxHistorySize(long maxSize) override; - - - bool equalsDeep(const ProviderSegment& other) const; - - - // MemoryItem interface - public: - std::string getLevelName() const override; - - // MemoryContainer interface - protected: - ContainerT& _underlyingContainer() override; - void _copySelf(ProviderSegment& other) const override; - void _copyElements(ProviderSegment& other, bool withData) const override; - - - public: - - /// The entities. - std::map<std::string, Entity> entities; - - }; - -} diff --git a/source/RobotAPI/libraries/armem/core/io/detail/DiskMemoryContainer.h b/source/RobotAPI/libraries/armem/core/base/CoreSegment.cpp similarity index 100% rename from source/RobotAPI/libraries/armem/core/io/detail/DiskMemoryContainer.h rename to source/RobotAPI/libraries/armem/core/base/CoreSegment.cpp diff --git a/source/RobotAPI/libraries/armem/core/base/CoreSegment.h b/source/RobotAPI/libraries/armem/core/base/CoreSegment.h new file mode 100644 index 000000000..75f604a82 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/base/CoreSegment.h @@ -0,0 +1,224 @@ +#pragma once + +#include <map> +#include <string> + +#include "ProviderSegment.h" +#include "detail/TypedEntityContainer.h" +#include "detail/MaxHistorySize.h" + + +namespace armarx::armem +{ + + /** + * @brief Data of a core segment containing multiple provider segments. + */ + template <class _ProviderSegmentT, class _EntityT, class _EntitySnapshotT, class _EntityInstanceT, class Derived> + class CoreSegmentBase : + virtual public detail::TypedEntityContainerBase<_ProviderSegmentT, _EntityT, _EntitySnapshotT, _EntityInstanceT, Derived>, + virtual public armarx::armem::detail::MaxHistorySize + { + using Base = detail::TypedEntityContainerBase<_ProviderSegmentT, _EntityT, _EntitySnapshotT, _EntityInstanceT, Derived>; + + public: + using ProviderSegmentT = _ProviderSegmentT; + using EntityT = _EntityT; + + public: + /*CoreSegmentBase(); + CoreSegmentBase(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr) : + CoreSegmentBase(name, MemoryID(), aronType) + { + } + + CoreSegmentBase(const std::string& name, const MemoryID& parentID, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr) : + CoreSegmentBase(parentID.getMemoryID().withCoreSegmentName(name), aronType) + { + } + + CoreSegmentBase(const MemoryID& id, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr) : + Base(id, aronType) + { + } + + CoreSegmentBase(const CoreSegmentBase& other) : Base(other) + { + // *this = other; + }*/ + + CoreSegmentBase& operator=(const CoreSegmentBase& other) + { + other._copySelf(*this); + return *this; + } + + using Base::id; + inline const std::string& name() const + { + return id.coreSegmentName; + } + inline std::string& name() + { + return const_cast<std::string&>(const_cast<const CoreSegmentBase*>(this)->name()); + } + + bool hasProviderSegment(const std::string& name) const + { + return providerSegments.count(name) > 0; + } + + ProviderSegmentT& getProviderSegment(const std::string& name) + { + return const_cast<ProviderSegmentT&>(const_cast<const CoreSegmentBase*>(this)->getProviderSegment(name)); + } + + const ProviderSegmentT& getProviderSegment(const std::string& name) const + { + auto it = this->providerSegments.find(name); + if (it != providerSegments.end()) + { + return it->second; + } + else + { + throw armem::error::MissingEntry("provider segment", name, getLevelName(), this->getKeyString()); + } + } + + using Base::_checkContainerName; + const EntityT& getEntity(const MemoryID& id) const override + { + _checkContainerName(id.coreSegmentName, this->getKeyString()); + return getProviderSegment(id.providerSegmentName).getEntity(id); + } + + virtual MemoryID update(const EntityUpdate& update) override + { + _checkContainerName(update.entityID.coreSegmentName, this->name()); + + auto it = this->providerSegments.find(update.entityID.providerSegmentName); + if (it != providerSegments.end()) + { + return it->second.update(update); + } + else + { + throw armem::error::MissingEntry("provider segment", update.entityID.providerSegmentName, getLevelName(), this->getKeyString()); + } + } + + /** + * @brief Add an empty provider segment with the given name and optional provider segment type. + * @param name The segment name. + * @param providerSegmentType The provider type. If nullptr, the core segment type is used. + * @return The added provider segment. + */ + ProviderSegmentT& addProviderSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr providerSegmentType = nullptr) + { + aron::typenavigator::ObjectNavigatorPtr type = providerSegmentType ? providerSegmentType : this->aronType; + return addProviderSegment(ProviderSegmentT(name, type)); + } + + /// Copy and insert a provider segment. + ProviderSegmentT& addProviderSegment(const ProviderSegmentT& providerSegment) + { + return addProviderSegment(ProviderSegment(providerSegment)); + } + + /// Move and insert a provider segment. + ProviderSegmentT& addProviderSegment(ProviderSegmentT&& providerSegment) + { + if (hasProviderSegment(providerSegment.name())) + { + throw armem::error::ContainerEntryAlreadyExists( + providerSegment.getLevelName(), providerSegment.name(), getLevelName(), this->getKeyString()); + } + + auto it = providerSegments.emplace(providerSegment.name(), std::move(providerSegment)).first; + it->second.id.setCoreSegmentID(id); + it->second.setMaxHistorySize(maxHistorySize); + return it->second; + } + + + /** + * @brief Sets the maximum history size of entities in this segment. + * This affects all current entities as well as new ones. + * @see Entity::setMaxHistorySize() + */ + void setMaxHistorySize(long maxSize) override + { + MaxHistorySize::setMaxHistorySize(maxSize); + for (auto& [name, seg] : providerSegments) + { + seg.setMaxHistorySize(maxSize); + } + } + + using Base::size; + virtual bool equalsDeep(const CoreSegmentBase& other) const + { + //std::cout << "CoreSegment::equalsDeep" << std::endl; + if (size() != other.size()) + { + return false; + } + for (const auto& [key, provider] : providerSegments) + { + if (not other.hasProviderSegment(key)) + { + return false; + } + if (not provider.equalsDeep(other.getProviderSegment(key))) + { + return false; + } + } + return true; + } + + std::string getLevelName() const override + { + return "core segment"; + } + + std::string getKeyString() const override + { + return this->name(); + } + + virtual Derived copy() const override + { + Derived d; + this->_copySelf(d); + return d; + } + + virtual Derived copyEmpty() const override + { + Derived d; + this->_copySelfEmpty(d); + return d; + } + + protected: + virtual void _copySelf(Derived& other) const override + { + Base::_copySelf(other); + providerSegments = other.providerSegments; + } + + virtual void _copySelfEmpty(Derived& other) const override + { + Base::_copySelfEmpty(other); + providerSegments = other.providerSegments; + } + + public: + /// The provider segments. + std::map<std::string, ProviderSegmentT>& providerSegments = Base::container; + + }; + +} diff --git a/source/RobotAPI/libraries/armem/core/base/Entity.cpp b/source/RobotAPI/libraries/armem/core/base/Entity.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/source/RobotAPI/libraries/armem/core/base/Entity.h b/source/RobotAPI/libraries/armem/core/base/Entity.h new file mode 100644 index 000000000..70bda50c0 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/base/Entity.h @@ -0,0 +1,335 @@ +#pragma once + +#include <map> +#include <string> + +#include <SimoxUtility/algorithm/get_map_keys_values.h> + +#include "../../core/Time.h" +#include "../../core/MemoryID.h" + +#include "EntitySnapshot.h" +#include "detail/MemoryContainer.h" + + +namespace armarx::armem +{ + + /** + * @brief An entity over a period of time. + * + * An entity should be a physical thing or abstract concept existing + * (and potentially evolving) over some time. + * + * Examples are: + * - objects (the green box) + * - agents (robot, human) + * - locations (frige, sink) + * - grasp affordances (general, or for a specific object) + * - images + * - point clouds + * - other sensory values + * + * At each point in time (`EntitySnapshot`), the entity can have a + * (potentially variable) number of instances (`EntityInstance`), + * each containing a single `AronData` object of a specific `AronType`. + */ + template <class _EntitySnapshotT, class Derived> + class EntityBase : + virtual public detail::MemoryContainerBase<std::map<Time, _EntitySnapshotT>, Derived> + { + using Base = detail::MemoryContainerBase<std::map<Time, _EntitySnapshotT>, Derived>; + + public: + using EntitySnapshotT = _EntitySnapshotT; + + + public: + + /*EntityBase() + {} + + EntityBase(const std::string& name, const MemoryID& parentID = {}) : + EntityBase(parentID.withEntityName(name)) + {} + + EntityBase(const MemoryID& id) : + Base(id) + {} + + /// Copy the history from `other` to this. + EntityBase(const EntityBase& other) : + Base(id) + { + // *this = other; + }*/ + + EntityBase& operator=(const EntityBase& other) + { + other._copySelf(*this); + return *this; + } + + using Base::size; + virtual bool equalsDeep(const EntityBase& other) const + { + //std::cout << "Entity::equalsDeep" << std::endl; + if (size() != other.size()) + { + return false; + } + for (const auto& [key, snapshot] : history) + { + if (not other.hasSnapshot(key)) + { + return false; + } + if (not snapshot.equalsDeep(other.getSnapshot(key))) + { + return false; + } + } + return true; + } + + + using Base::id; + const std::string& name() const + { + return id.entityName; + } + std::string& name() + { + return const_cast<std::string&>(const_cast<const EntityBase*>(this)->name()); + } + + + /** + * @brief Indicates whether a history entry for the given time exists. + */ + bool hasSnapshot(Time time) const + { + return history.count(time) > 0; + } + + /** + * @brief Get the latest timestamp. + * @throw `armem::error::EntityHistoryEmpty` If the history is empty. + */ + Time getLatestTimestamp() const + { + return getLatestItem().first; + } + + /** + * @brief Get all timestamps in the history. + */ + std::vector<Time> getTimestamps() const + { + return simox::alg::get_keys(history); + } + + + /** + * @brief Get a snapshot. + * @param time The time. + * @return The snapshot, if it exists. + * + * @throws `armem::error::MissingEntry` If there is no such entry. + * @throws `armem::error::MissingData` If the entry has no data. + */ + EntitySnapshotT& getSnapshot(Time time) + { + return const_cast<EntitySnapshotT&>(const_cast<const EntityBase*>(this)->getSnapshot(time)); + } + + const EntitySnapshotT& getSnapshot(Time time) const + { + auto it = history.find(time); + if (it != history.end()) + { + return it->second; + } + else + { + throw error::MissingEntry("entity snapshot", toDateTimeMilliSeconds(time), getLevelName(), this->id.str()); + } + } + + EntitySnapshotT& getSnapshot(const MemoryID& id) + { + return const_cast<EntitySnapshotT&>(const_cast<const EntityBase*>(this)->getSnapshot(id)); + } + + const EntitySnapshotT& getSnapshot(const MemoryID& id) const + { + checkEntityName(id.entityName); + return getSnapshot(id.timestamp); + } + + /** + * @brief Return the snapshot with the most recent timestamp. + * @return The latest snapshot. + * @throw `armem::error::EntityHistoryEmpty` If the history is empty. + * @throw `armem::error::MissingData` If the latest snapshot has no data. + */ + EntitySnapshotT& getLatestSnapshot() + { + return const_cast<EntitySnapshotT&>(const_cast<const EntityBase*>(this)->getLatestSnapshot()); + } + + const EntitySnapshotT& getLatestSnapshot() const + { + return getLatestItem().second; + } + + + /** + * @brief Add the given update to this entity's history. + * @param update The update. + * @return The snapshot ID of the update. + */ + virtual MemoryID update(const EntityUpdate& update) + { + checkEntityName(update.entityID.entityName); + id = update.entityID; + + EntitySnapshotT* snapshot; + + auto it = history.find(update.timeCreated); + if (it == history.end()) + { + // Insert into history. + snapshot = &addSnapshot(update.timeCreated); + truncateHistoryToSize(); + } + else + { + snapshot = &it->second; + } + // Update entry. + snapshot->update(update); + + return snapshot->id; + } + + /** + * @brief Add a single snapshot with data. + * @param snapshot The snapshot. + * @return The stored snapshot. + */ + EntitySnapshotT& addSnapshot(const EntitySnapshotT& snapshot) + { + return addSnapshot(EntitySnapshotT(snapshot)); + } + + EntitySnapshotT& addSnapshot(EntitySnapshotT&& snapshot) + { + auto it = history.emplace(snapshot.time(), std::move(snapshot)).first; + it->second.id.setEntityID(id); + return it->second; + } + + EntitySnapshotT& addSnapshot(const Time& timestamp) + { + return addSnapshot(EntitySnapshotT(timestamp)); + } + + + /** + * @brief Sets the maximum history size. + * + * The current history is truncated if necessary. + */ + void setMaxHistorySize(long maxSize) + { + this->maxHistorySize = maxSize; + truncateHistoryToSize(); + } + + std::string getKeyString() const override + { + return id.entityName; + } + std::string getLevelName() const override + { + return "entity"; + } + + virtual Derived copy() const override + { + Derived d; + this->_copySelf(d); + return d; + } + + virtual Derived copyEmpty() const override + { + Derived d; + this->_copySelfEmpty(d); + return d; + } + + protected: + virtual void _copySelf(Derived& other) const override + { + Base::_copySelf(other); + history = other.history; + } + + virtual void _copySelfEmpty(Derived& other) const override + { + Base::_copySelfEmpty(other); + history = other.history; + } + + private: + /// If maximum size is set, ensure `history`'s is not higher. + void truncateHistoryToSize() + { + if (maxHistorySize >= 0) + { + while (history.size() > size_t(maxHistorySize)) + { + history.erase(history.begin()); + } + ARMARX_CHECK_LESS_EQUAL(history.size(), maxHistorySize); + } + } + + void checkEntityName(const std::string& name) const + { + if (name != this->name()) + { + throw armem::error::ContainerNameMismatch(name, getLevelName(), getKeyString()); + } + } + + /** + * @brief Return the snapshot with the most recent timestamp. + * @return The latest snapshot. + * @throw `armem::error::EntityHistoryEmpty` If the history is empty. + */ + const typename std::map<Time, EntitySnapshotT>::value_type& getLatestItem() const + { + if (history.empty()) + { + throw armem::error::EntityHistoryEmpty(name(), "when getting the latest snapshot."); + } + return *history.rbegin(); + } + + public: + std::map<Time, EntitySnapshotT>& history = Base::container; + + /** + * @brief Maximum size of `history` + * + * If negative, the size of `history` is not limited. + */ + long maxHistorySize = -1; + // ToDo: Add max age; + // ToDo in future: keep/remove predicate + }; + +} diff --git a/source/RobotAPI/libraries/armem/core/base/EntityInstance.cpp b/source/RobotAPI/libraries/armem/core/base/EntityInstance.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/source/RobotAPI/libraries/armem/core/base/EntityInstance.h b/source/RobotAPI/libraries/armem/core/base/EntityInstance.h new file mode 100644 index 000000000..f6d3e3baa --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/base/EntityInstance.h @@ -0,0 +1,86 @@ +#pragma once + +#include <RobotAPI/interface/aron.h> +#include <RobotAPI/libraries/aron/core/navigator/data/container/Dict.h> + +#include "../../core/Time.h" + +#include "../Commit.h" +#include "detail/MemoryItem.h" + + +namespace armarx::armem +{ + /** + * @brief Data of a single entity instance. + */ + template <class Derived> + class EntityInstanceBase : + virtual public armarx::armem::detail::MemoryItem + { + using Base = armarx::armem::detail::MemoryItem; + + public: + + /*EntityInstanceBase() + {} + + EntityInstanceBase(int index, const MemoryID& parentID = {}) : + EntityInstanceBase(parentID.withInstanceIndex(index)) + {} + + EntityInstanceBase(const MemoryID& id) : + Base(id) + {}*/ + + EntityInstanceBase& operator=(const EntityInstanceBase& other) + { + //other._copySelf(*this); + return *this; + } + + using Base::id; + inline int& index() + { + return id.instanceIndex; + } + inline int index() const + { + return id.instanceIndex; + } + + // Copying + virtual Derived copy() const + { + Derived d; + this->_copySelf(d); + return d; + } + + /** + * @brief Fill `*this` with the update's values. + * @param update The update. + * @param index The instances index. + */ + virtual void update(const EntityUpdate& update, int index) = 0; + + virtual bool equalsDeep(const Derived& other) const = 0; + + std::string getLevelName() const override + { + return "entity instance"; + } + + std::string getKeyString() const override + { + return std::to_string(index()); + } + + protected: + virtual void _copySelf(Derived& other) const + { + Base::_copySelf(other); + } + }; + +} diff --git a/source/RobotAPI/libraries/armem/core/base/EntitySnapshot.cpp b/source/RobotAPI/libraries/armem/core/base/EntitySnapshot.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/source/RobotAPI/libraries/armem/core/base/EntitySnapshot.h b/source/RobotAPI/libraries/armem/core/base/EntitySnapshot.h new file mode 100644 index 000000000..7ad3680cd --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/base/EntitySnapshot.h @@ -0,0 +1,221 @@ +#pragma once + +#include <memory> +#include <vector> + +#include "../MemoryID.h" +#include "../Time.h" + +#include "EntityInstance.h" +#include "detail/MemoryContainer.h" + + +namespace armarx::armem +{ + /** + * @brief Data of an entity at one point in time. + */ + template <class _EntityInstanceT, class Derived> + class EntitySnapshotBase : + virtual public detail::MemoryContainerBase<std::vector<_EntityInstanceT>, Derived> + { + using Base = detail::MemoryContainerBase<std::vector<_EntityInstanceT>, Derived>; + + public: + using EntityInstanceT = _EntityInstanceT; + + public: + /*EntitySnapshotBase() + {} + + EntitySnapshotBase(Time time, const MemoryID& parentID = {}) : + EntitySnapshotBase(parentID.withTimestamp(time)) + {} + + EntitySnapshotBase(const MemoryID& id) : Base(id) + {} + + /// Copy the instances from `other` to this. + EntitySnapshotBase(const EntitySnapshotBase& other) : Base(other) + { + // *this = other; + }*/ + + EntitySnapshotBase& operator=(const EntitySnapshotBase& other) + { + other._copySelf(*this); + return *this; + } + + using Base::size; + virtual bool equalsDeep(const EntitySnapshotBase& other) const + { + //std::cout << "EntitySnapshot::equalsDeep" << std::endl; + if (size() != other.size()) + { + return false; + } + int i = 0; + for (const auto& instance : instances) + { + if (not instance.equalsDeep(other.getInstance(i))) + { + return false; + } + i++; + } + return true; + } + + using Base::id; + inline Time& time() + { + return id.timestamp; + } + + inline const Time& time() const + { + return id.timestamp; + } + + void update(const EntityUpdate& update, std::optional<MemoryID> parentID = std::nullopt) + { + if (parentID) + { + id = *parentID; + } + time() = update.timeCreated; + + instances.clear(); + for (int i = 0; i < int(update.instancesData.size()); ++i) + { + EntityInstanceT& data = instances.emplace_back(i, id); + data.update(update, i); + } + } + + + bool hasInstance(int index) const + { + size_t si = size_t(index); + return index >= 0 && si < instances.size(); + } + + /** + * @brief Get the given instance. + * @param index The instance's index. + * @return The instance. + * @throw `armem::error::MissingEntry` If the given index is invalid. + */ + EntityInstanceT& getInstance(int index) + { + return const_cast<EntityInstanceT&>(const_cast<const EntitySnapshotBase*>(this)->getInstance(index)); + } + + const EntityInstanceT& getInstance(int index) const + { + if (hasInstance(index)) + { + size_t si = size_t(index); + return instances[si]; + } + else + { + throw armem::error::MissingEntry(EntityInstanceT().getLevelName(), std::to_string(index), getLevelName(), toDateTimeMilliSeconds(time())); + } + } + + /** + * @brief Get the given instance. + * @param index The instance's index. + * @return The instance. + * @throw `armem::error::MissingEntry` If the given index is invalid. + * @throw `armem::error::InvalidMemoryID` If memory ID does not have an instance index. + */ + EntityInstanceT& getInstance(const MemoryID& id) + { + return const_cast<EntityInstanceT&>(const_cast<const EntitySnapshotBase*>(this)->getInstance(id)); + } + + const EntityInstanceT& getInstance(const MemoryID& id) const + { + if (!id.hasInstanceIndex()) + { + throw armem::error::InvalidMemoryID(id, "ID has no instance index."); + } + return getInstance(id.instanceIndex); + } + + + /** + * @brief Add a single instance with data. + * @param instance The instance. + * @return The stored instance. + * @throw `armem::error::InvalidArgument` If the given index is invalid. Must be equal to instances.size() or -1 (meaning push_back) + */ + EntityInstanceT& addInstance(const EntityInstanceT& instance) + { + return addInstance(EntityInstanceT(instance)); + } + + EntityInstanceT& addInstance(EntityInstanceT&& instance) + { + if (instance.index() > 0 && (size_t) instance.index() < instances.size()) + { + throw error::InvalidArgument(std::to_string(instance.index()), "EntitySnapshot::addInstance", + "Cannot add an EntityInstance because its index already exists."); + } + if (instance.index() > 0 && (size_t) instance.index() > instances.size()) + { + throw error::InvalidArgument(std::to_string(instance.index()), "EntitySnapshot::addInstance", + "Cannot add an EntityInstance because its index is too big."); + } + + int new_index = instances.size(); + auto& it = instances.emplace_back(std::move(instance)); + it.index() = new_index; + return it; + } + + std::string getKeyString() const override + { + return toDateTimeMilliSeconds(this->time()); + } + + std::string getLevelName() const override + { + return "entity snapshot"; + } + + virtual Derived copy() const override + { + Derived d; + this->_copySelf(d); + return d; + } + + virtual Derived copyEmpty() const override + { + Derived d; + this->_copySelfEmpty(d); + return d; + } + + protected: + virtual void _copySelf(Derived& other) const override + { + Base::_copySelf(other); + instances = other.instances; + } + + virtual void _copySelfEmpty(Derived& other) const override + { + Base::_copySelfEmpty(other); + instances = other.instances; + } + + public: + std::vector<_EntityInstanceT>& instances = Base::container; + }; + +} diff --git a/source/RobotAPI/libraries/armem/core/base/Memory.cpp b/source/RobotAPI/libraries/armem/core/base/Memory.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/source/RobotAPI/libraries/armem/core/base/Memory.h b/source/RobotAPI/libraries/armem/core/base/Memory.h new file mode 100644 index 000000000..717927b97 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/base/Memory.h @@ -0,0 +1,218 @@ +#pragma once + +#include <map> +#include <string> + +#include "ProviderSegment.h" +#include "detail/EntityContainer.h" + +namespace armarx::armem +{ + + /** + * @brief Data of a memory consisting of multiple core segments. + */ + template <class _CoreSegmentT, class _EntityT, class _EntitySnapshotT, class _EntityInstanceT, class Derived> + class MemoryBase : + virtual public detail::EntityContainerBase<_CoreSegmentT, _EntityT, _EntitySnapshotT, _EntityInstanceT, Derived> + { + using Base = detail::EntityContainerBase<_CoreSegmentT, _EntityT, _EntitySnapshotT, _EntityInstanceT, Derived>; + + public: + using CoreSegmentT = _CoreSegmentT; + using EntityT = _EntityT; + + public: + /*MemoryBase() + {} + + MemoryBase(const std::string& name) : + MemoryBase(MemoryID().withMemoryName(name)) + { + } + + MemoryBase(const MemoryID& id) : + Base(id) + { + } + + MemoryBase(const MemoryBase& other) : + Base(other) + { + // *this = other; + }*/ + + MemoryBase& operator=(const MemoryBase& other) + { + other._copySelf(*this); + return *this; + } + + using Base::id; + inline const std::string& name() const + { + return id.memoryName; + } + inline std::string& name() + { + return const_cast<std::string&>(const_cast<const MemoryBase*>(this)->name()); + } + + bool hasCoreSegment(const std::string& name) const + { + return coreSegments.count(name) > 0; + } + + CoreSegmentT& getCoreSegment(const std::string& name) + { + return const_cast<CoreSegmentT&>(const_cast<const MemoryBase*>(this)->getCoreSegment(name)); + } + + const CoreSegmentT& getCoreSegment(const std::string& name) const + { + auto it = this->coreSegments.find(name); + if (it != coreSegments.end()) + { + return it->second; + } + else + { + throw armem::error::MissingEntry(CoreSegmentT().getLevelName(), name, getLevelName(), this->name()); + } + } + + using Base::_checkContainerName; + const EntityT& getEntity(const MemoryID& id) const override + { + _checkContainerName(id.memoryName, this->name()); + return getCoreSegment(id.coreSegmentName).getEntity(id); + } + + /** + * @brief Add an empty core segment with the given name. + * @param name The core segment name. + * @param coreSegmentType The core segment type (optional). + * @return The added core segment. + */ + CoreSegmentT& addCoreSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr coreSegmentType = nullptr) + { + return addCoreSegment(CoreSegmentT(name, coreSegmentType)); + } + /// Copy and insert a core segment. + CoreSegmentT& addCoreSegment(const CoreSegmentT& coreSegment) + { + return addCoreSegment(CoreSegmentT(coreSegment)); + } + /// Move and insert a core segment. + CoreSegmentT& addCoreSegment(CoreSegmentT&& coreSegment) + { + if (coreSegments.count(coreSegment.name()) > 0) + { + throw armem::error::ContainerEntryAlreadyExists(coreSegment.getLevelName(), coreSegment.name(), + this->getLevelName(), this->name()); + } + auto it = coreSegments.emplace(coreSegment.name(), std::move(coreSegment)).first; + it->second.id.setMemoryID(id); + return it->second; + } + + /** + * @brief Add multiple core segments. + * @param The core segment names. + * @return The core segments. The contained pointers are never null. + */ + std::vector<CoreSegmentT*> addCoreSegments(const std::vector<std::string>& names) + { + std::vector<CoreSegmentT*> segments; + for (const auto& name : names) + { + try + { + segments.push_back(&addCoreSegment(name)); + } + catch (const armem::error::ContainerEntryAlreadyExists& e) + { + ARMARX_INFO << e.what() << "\nIgnoring multiple addition."; + } + } + return segments; + } + + virtual MemoryID update(const EntityUpdate& update) override + { + _checkContainerName(update.entityID.memoryName, this->name()); + + auto it = this->coreSegments.find(update.entityID.coreSegmentName); + if (it != coreSegments.end()) + { + return it->second.update(update); + } + else + { + throw armem::error::MissingEntry(CoreSegmentT().getLevelName(), update.entityID.coreSegmentName, getLevelName(), this->name()); + } + } + + using Base::size; + virtual bool equalsDeep(const MemoryBase& other) const + { + //std::cout << "Memory::equalsDeep" << std::endl; + if (size() != other.size()) + { + return false; + } + for (const auto& [key, core] : coreSegments) + { + if (not other.hasCoreSegment(key)) + { + return false; + } + if (not core.equalsDeep(other.getCoreSegment(key))) + { + return false; + } + } + return true; + } + + std::string getLevelName() const override + { + return "memory"; + } + + std::string getKeyString() const override + { + return this->name(); + } + + virtual Derived copy() const override + { + Derived d; + this->_copySelf(d); + return d; + } + + virtual Derived copyEmpty() const override + { + Derived d; + this->_copySelfEmpty(d); + return d; + } + + protected: + virtual void _copySelf(Derived& other) const override + { + Base::_copySelf(other); + coreSegments = other.coreSegments; + } + + virtual void _copySelfEmpty(Derived& other) const override + { + Base::_copySelfEmpty(other); + coreSegments = other.coreSegments; + } + + public: + std::map<std::string, CoreSegmentT>& coreSegments = Base::container; + }; +} diff --git a/source/RobotAPI/libraries/armem/core/base/ProviderSegment.cpp b/source/RobotAPI/libraries/armem/core/base/ProviderSegment.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/source/RobotAPI/libraries/armem/core/base/ProviderSegment.h b/source/RobotAPI/libraries/armem/core/base/ProviderSegment.h new file mode 100644 index 000000000..26f22688d --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/base/ProviderSegment.h @@ -0,0 +1,222 @@ +#pragma once + +#include <map> +#include <string> + +#include "Entity.h" +#include "detail/TypedEntityContainer.h" +#include "detail/MaxHistorySize.h" + + +namespace armarx::armem +{ + + /** + * @brief Data of a provider segment containing multiple entities. + */ + template <class _EntityT, class _EntitySnapshotT, class _EntityInstanceT, class Derived> + class ProviderSegmentBase : + virtual public detail::TypedEntityContainerBase<_EntityT, _EntityT, _EntitySnapshotT, _EntityInstanceT, Derived>, + virtual public armarx::armem::detail::MaxHistorySize + { + using Base = detail::TypedEntityContainerBase<_EntityT, _EntityT, _EntitySnapshotT, _EntityInstanceT, Derived>; + + public: + using EntityT = _EntityT; + + public: + /*ProviderSegmentBase() + {} + + ProviderSegmentBase(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr) : + ProviderSegmentBase(name, MemoryID(), aronType) + { + } + ProviderSegmentBase(const std::string& name, const MemoryID parentID, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr) : + ProviderSegmentBase(parentID.withProviderSegmentName(name), aronType) + { + } + ProviderSegmentBase(const MemoryID id, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr) : + Base(id, aronType) + { + } + + ProviderSegmentBase(const ProviderSegmentBase& other) : Base(other) + { + // *this = other; + }*/ + + ProviderSegmentBase& operator=(const ProviderSegmentBase& other) + { + other._copySelf(*this); + return *this; + } + + using Base::id; + inline const std::string& name() const + { + return id.providerSegmentName; + } + inline std::string& name() + { + return const_cast<std::string&>(const_cast<const ProviderSegmentBase*>(this)->name()); + } + + + bool hasEntity(const std::string& name) const + { + return entities.count(name) > 0; + } + + using Base::_checkContainerName; + const EntityT& getEntity(const MemoryID& id) const override + { + _checkContainerName(id.providerSegmentName, this->getKeyString()); + return getEntity(id.entityName); + } + + EntityT& getEntity(const std::string& name) + { + return const_cast<EntityT&>(const_cast<const ProviderSegmentBase*>(this)->getEntity(name)); + } + + const EntityT& getEntity(const std::string& name) const + { + auto it = this->entities.find(name); + if (it != entities.end()) + { + return it->second; + } + else + { + throw error::MissingEntry("entity", name, getLevelName(), this->name()); + } + } + + /** + * @brief Updates an entity's history. + * + * Missing entity entries are added before updating. + */ + virtual MemoryID update(const EntityUpdate& update) override + { + _checkContainerName(update.entityID.providerSegmentName, this->name()); + + EntityT* entity; + auto it = this->entities.find(update.entityID.providerSegmentName); + if (it == entities.end()) + { + // Add entity entry. + entity = &addEntity(update.entityID.entityName); + entity->setMaxHistorySize(maxHistorySize); + } + else + { + entity = &it->second; + } + // Update entity. + return entity->update(update); + } + + /// Add an empty entity with the given name. + EntityT& addEntity(const std::string& name) + { + return addEntity(EntityT(name)); + } + /// Copy and insert an entity. + EntityT& addEntity(const EntityT& entity) + { + return addEntity(EntityT(entity)); + } + /// Move and insert an entity. + EntityT& addEntity(EntityT&& entity) + { + auto it = entities.emplace(entity.name(), std::move(entity)).first; + it->second.id.setProviderSegmentID(id); + return it->second; + } + + + /** + * @brief Sets the maximum history size of entities in this segment. + * This affects all current entities as well as new ones. + * @see Entity::setMaxHistorySize() + */ + void setMaxHistorySize(long maxSize) override + { + MaxHistorySize::setMaxHistorySize(maxSize); + for (auto& [name, entity] : entities) + { + entity.setMaxHistorySize(maxSize); + } + } + + + using Base::size; + virtual bool equalsDeep(const ProviderSegmentBase& other) const + { + //std::cout << "ProviderSegment::equalsDeep" << std::endl; + if (size() != other.size()) + { + return false; + } + for (const auto& [key, value] : entities) + { + if (not other.hasEntity(key)) + { + return false; + } + + if (not value.equalsDeep(other.getEntity(key))) + { + return false; + } + } + return true; + } + + std::string getLevelName() const override + { + return "provider segment"; + } + + std::string getKeyString() const override + { + return this->name(); + } + + virtual Derived copy() const override + { + Derived d; + this->_copySelf(d); + return d; + } + + virtual Derived copyEmpty() const override + { + Derived d; + this->_copySelfEmpty(d); + return d; + } + + protected: + virtual void _copySelf(Derived& other) const override + { + Base::_copySelf(other); + entities = other.entities; + } + + virtual void _copySelfEmpty(Derived& other) const override + { + Base::_copySelfEmpty(other); + entities = other.entities; + } + + + public: + /// The entities. + std::map<std::string, EntityT>& entities = Base::container; + + }; + +} diff --git a/source/RobotAPI/libraries/armem/core/detail/EntityContainer.cpp b/source/RobotAPI/libraries/armem/core/base/detail/EntityContainer.cpp similarity index 100% rename from source/RobotAPI/libraries/armem/core/detail/EntityContainer.cpp rename to source/RobotAPI/libraries/armem/core/base/detail/EntityContainer.cpp diff --git a/source/RobotAPI/libraries/armem/core/detail/EntityContainer.h b/source/RobotAPI/libraries/armem/core/base/detail/EntityContainer.h similarity index 50% rename from source/RobotAPI/libraries/armem/core/detail/EntityContainer.h rename to source/RobotAPI/libraries/armem/core/base/detail/EntityContainer.h index 873a15e6e..f241353a5 100644 --- a/source/RobotAPI/libraries/armem/core/detail/EntityContainer.h +++ b/source/RobotAPI/libraries/armem/core/base/detail/EntityContainer.h @@ -1,12 +1,13 @@ #pragma once -#include "../Commit.h" -#include "../Entity.h" -#include "../EntitySnapshot.h" -#include "../error/ArMemError.h" +#include "../../Commit.h" +#include "../../error/ArMemError.h" #include "MemoryContainer.h" +#include "../Entity.h" +#include "../EntitySnapshot.h" + namespace armarx::armem::detail { @@ -16,30 +17,25 @@ namespace armarx::armem::detail * * Can be updated by multiple entity updates. */ - template <class ValueT, class Derived> - class EntityContainer : public MemoryContainer<std::map<std::string, ValueT>, Derived> + template <class _ValueT, class _EntityT, class _EntitySnapshotT, class _EntityInstanceT, class Derived> + class EntityContainerBase : + virtual public MemoryContainerBase<std::map<std::string, _ValueT>, Derived> { - using Base = MemoryContainer<std::map<std::string, ValueT>, Derived>; + using Base = MemoryContainerBase<std::map<std::string, _ValueT>, Derived>; public: - - EntityContainer() - {} - EntityContainer(const MemoryID& id) : - MemoryContainer<std::map<std::string, ValueT>, Derived> (id) + /*EntityContainerBase() {} + EntityContainerBase(const MemoryID& id) : + MemoryItem(id) + {}*/ - virtual ~EntityContainer() override - {} - - - virtual const std::string& name() const = 0; - virtual std::string& name() + EntityContainerBase& operator=(const EntityContainerBase& other) { - return const_cast<std::string&>(const_cast<const EntityContainer*>(this)->name()); + other._copySelf(*this); + return *this; } - /** * @brief Store all updates in `commit`. * @param commit The commit. @@ -68,11 +64,11 @@ namespace armarx::armem::detail * @return The entity. * @throw An exception deriving from `armem::error::ArMemError` if the entity is missing. */ - virtual Entity& getEntity(const MemoryID& id) + virtual _EntityT& getEntity(const MemoryID& id) { - return const_cast<Entity&>(const_cast<const EntityContainer*>(this)->getEntity(id)); + return const_cast<_EntityT&>(const_cast<const EntityContainerBase*>(this)->getEntity(id)); } - virtual const Entity& getEntity(const MemoryID& id) const = 0; + virtual const _EntityT& getEntity(const MemoryID& id) const = 0; /** * @brief Retrieve an entity snapshot. @@ -83,13 +79,14 @@ namespace armarx::armem::detail * @return The entity snapshot. * @throw An exception deriving from `armem::error::ArMemError` if the snapshot is missing. */ - virtual EntitySnapshot& getEntitySnapshot(const MemoryID& id) + virtual _EntitySnapshotT& getEntitySnapshot(const MemoryID& id) { - return const_cast<EntitySnapshot&>(const_cast<const EntityContainer*>(this)->getEntitySnapshot(id)); + return const_cast<_EntitySnapshotT&>(const_cast<const EntityContainerBase*>(this)->getEntitySnapshot(id)); } - virtual const EntitySnapshot& getEntitySnapshot(const MemoryID& id) const + + virtual const _EntitySnapshotT& getEntitySnapshot(const MemoryID& id) const { - const Entity& entity = getEntity(id); + const _EntityT& entity = getEntity(id); if (id.hasTimestamp()) { @@ -101,37 +98,15 @@ namespace armarx::armem::detail } } - - virtual EntityInstance& getEntityInstance(const MemoryID& id) - { - return getEntitySnapshot(id).getInstance(id); - } - virtual const EntityInstance& getEntityInstance(const MemoryID& id) const + virtual _EntityInstanceT& getEntityInstance(const MemoryID& id) { return getEntitySnapshot(id).getInstance(id); } - - // MemoryLevel interface - public: - /// Return `name`. - virtual std::string getKeyString() const override + virtual const _EntityInstanceT& getEntityInstance(const MemoryID& id) const { - return name(); - } - - - protected: - - /// @throw `armem::error::ContainerNameMismatch` Of `expectedName != actualName`. - void _checkContainerName(const std::string& expectedName, const std::string& actualName) const - { - if (expectedName != actualName) - { - throw armem::error::ContainerNameMismatch(expectedName, this->getLevelName(), actualName); - } + return getEntitySnapshot(id).getInstance(id); } - }; } diff --git a/source/RobotAPI/libraries/armem/core/detail/MaxHistorySize.cpp b/source/RobotAPI/libraries/armem/core/base/detail/MaxHistorySize.cpp similarity index 100% rename from source/RobotAPI/libraries/armem/core/detail/MaxHistorySize.cpp rename to source/RobotAPI/libraries/armem/core/base/detail/MaxHistorySize.cpp diff --git a/source/RobotAPI/libraries/armem/core/detail/MaxHistorySize.h b/source/RobotAPI/libraries/armem/core/base/detail/MaxHistorySize.h similarity index 100% rename from source/RobotAPI/libraries/armem/core/detail/MaxHistorySize.h rename to source/RobotAPI/libraries/armem/core/base/detail/MaxHistorySize.h diff --git a/source/RobotAPI/libraries/armem/core/detail/MemoryContainer.cpp b/source/RobotAPI/libraries/armem/core/base/detail/MemoryContainer.cpp similarity index 100% rename from source/RobotAPI/libraries/armem/core/detail/MemoryContainer.cpp rename to source/RobotAPI/libraries/armem/core/base/detail/MemoryContainer.cpp diff --git a/source/RobotAPI/libraries/armem/core/base/detail/MemoryContainer.h b/source/RobotAPI/libraries/armem/core/base/detail/MemoryContainer.h new file mode 100644 index 000000000..bb53d6556 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/base/detail/MemoryContainer.h @@ -0,0 +1,116 @@ +#pragma once + +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + +#include "../../error.h" + +#include "MemoryItem.h" + + +namespace armarx::armem::detail +{ + + /** + * @class Provides default implmentations of `MemoryContainer`, as well as + * iterators (which requires a template). + */ + template <class _ContainerT, class Derived> + class MemoryContainerBase : + virtual public armarx::armem::detail::MemoryItem + { + using Base = armarx::armem::detail::MemoryItem; + + public: + using ContainerT = _ContainerT; + + public: + MemoryContainerBase() + {} + /*MemoryContainerBase(const MemoryID& id) : + Base(id) + {}*/ + MemoryContainerBase(const MemoryContainerBase<ContainerT, Derived>& o) : + MemoryItem(o.id), + container(o.container) + {} + + MemoryContainerBase& operator=(const MemoryContainerBase& other) + { + other._copySelf(*this); + return *this; + } + + // Container methods + virtual bool empty() const + { + return container.empty(); + } + virtual std::size_t size() const + { + return container.size(); + } + virtual void clear() + { + return container.clear(); + } + + typename ContainerT::const_iterator begin() const + { + return container.begin(); + } + typename ContainerT::iterator begin() + { + return container.begin(); + } + typename ContainerT::const_iterator end() const + { + return container.end(); + } + typename ContainerT::iterator end() + { + return container.end(); + } + + + // Copying + virtual Derived copy() const + { + Derived d; + this->_copySelf(d); + return d; + } + + /// Make a copy not containing any elements. + virtual Derived copyEmpty() const + { + Derived d; + this->_copySelfEmpty(d); + return d; + } + + protected: + /// @throw `armem::error::ContainerNameMismatch` Of `expectedName != actualName`. + void _checkContainerName(const std::string& expectedName, const std::string& actualName) const + { + if (expectedName != actualName) + { + throw armem::error::ContainerNameMismatch(expectedName, this->getLevelName(), actualName); + } + } + + virtual void _copySelf(Derived& other) const + { + Base::_copySelf(other); + other.container = container; + } + + virtual void _copySelfEmpty(Derived& other) const + { + Base::_copySelf(other); + } + + public: + ContainerT container; + }; + +} diff --git a/source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.cpp b/source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/source/RobotAPI/libraries/armem/core/detail/MemoryItem.h b/source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.h similarity index 52% rename from source/RobotAPI/libraries/armem/core/detail/MemoryItem.h rename to source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.h index 534b63127..e60f42dc1 100644 --- a/source/RobotAPI/libraries/armem/core/detail/MemoryItem.h +++ b/source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.h @@ -2,7 +2,7 @@ #include <string> -#include "../../core/MemoryID.h" +#include "../../MemoryID.h" namespace armarx::armem::detail @@ -14,37 +14,40 @@ namespace armarx::armem::detail class MemoryItem { public: + MemoryItem() + { + } - MemoryItem(); - MemoryItem(const MemoryID& id); - - virtual ~MemoryItem(); - + MemoryItem(const MemoryItem& other) : + id(other.id) + {} - inline MemoryID& id() + MemoryItem(const MemoryID& id) : + id(id) { - return _id; } - inline const MemoryID& id() const + + MemoryItem& operator=(const MemoryItem& other) { - return _id; + other._copySelf(*this); + return *this; } - // Introspection - /// Get a string version of `*this`' key. virtual std::string getKeyString() const = 0; /// Get a readable name of this level for messages, errors etc. virtual std::string getLevelName() const = 0; - protected: + virtual void _copySelf(MemoryItem& other) const + { + other.id = id; + } - /// The memory ID. - MemoryID _id; - + public: + MemoryID id; }; } diff --git a/source/RobotAPI/libraries/armem/core/base/detail/TypedEntityContainer.h b/source/RobotAPI/libraries/armem/core/base/detail/TypedEntityContainer.h new file mode 100644 index 000000000..f9860959f --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/base/detail/TypedEntityContainer.h @@ -0,0 +1,81 @@ +#pragma once + +#include "EntityContainer.h" + +#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> + +namespace armarx::armem::detail +{ + + /** + * @brief An entity container with a specific (Aron) type. + */ + template <class _ValueT, class _EntityT, class _EntitySnapshotT, class _EntityInstanceT, class Derived> + class TypedEntityContainerBase : + virtual public EntityContainerBase<_ValueT, _EntityT, _EntitySnapshotT, _EntityInstanceT, Derived> + { + using Base = EntityContainerBase<_ValueT, _EntityT, _EntitySnapshotT, _EntityInstanceT, Derived>; + + public: + + TypedEntityContainerBase(aron::typenavigator::ObjectNavigatorPtr aronType = nullptr) : + aronType(aronType) + {} + + TypedEntityContainerBase(const TypedEntityContainerBase<_ValueT, _EntityT, _EntitySnapshotT, _EntityInstanceT, Derived>& other) : + MemoryItem(other), + MemoryContainerBase<std::map<std::string, _ValueT>, Derived>(other), + aronType(other.aronType) + {} + + TypedEntityContainerBase(const MemoryID& id, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr) : + MemoryItem(id), + aronType(aronType) + {} + + TypedEntityContainerBase& operator=(const TypedEntityContainerBase& other) + { + other._copySelf(*this); + return *this; + } + + bool hasAronType() const + { + return aronType != nullptr; + } + + virtual Derived copy() const override + { + Derived d; + this->_copySelf(d); + return d; + } + + virtual Derived copyEmpty() const override + { + Derived d; + this->_copySelfEmpty(d); + return d; + } + + protected: + virtual void _copySelf(Derived& other) const override + { + Base::_copySelf(other); + other.aronType = aronType; + } + + virtual void _copySelfEmpty(Derived& other) const override + { + Base::_copySelfEmpty(other); + other.aronType = aronType; + } + + public: + /// The expected Aron type. May be nullptr, in which case no type information is available. + aron::typenavigator::ObjectNavigatorPtr aronType; + + }; + + +} diff --git a/source/RobotAPI/libraries/armem/core/base/ice_conversions.cpp b/source/RobotAPI/libraries/armem/core/base/ice_conversions.cpp new file mode 100644 index 000000000..6de4d6e59 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/base/ice_conversions.cpp @@ -0,0 +1,130 @@ +#include "ice_conversions.h" + +using namespace armarx::armem::workingmemory; + +namespace armarx +{ + void armem::toIce(data::EntityInstanceMetadata& ice, const EntityInstanceMetadata& metadata) + { + ice.confidence = metadata.confidence; + toIce(ice.timeArrivedMicroSeconds, metadata.timeArrived); + toIce(ice.timeCreatedMicroSeconds, metadata.timeCreated); + toIce(ice.timeSentMicroSeconds, metadata.timeSent); + } + void armem::fromIce(const data::EntityInstanceMetadata& ice, EntityInstanceMetadata& metadata) + { + metadata.confidence = ice.confidence; + fromIce(ice.timeArrivedMicroSeconds, metadata.timeArrived); + fromIce(ice.timeCreatedMicroSeconds, metadata.timeCreated); + fromIce(ice.timeSentMicroSeconds, metadata.timeSent); + } + + void armem::toIce(data::EntityInstance& ice, const EntityInstance& data) + { + detail::toIceItem(ice, data); + + if (data.data()) + { + ice.data = data.data()->toAronDictPtr(); + } + toIce(ice.metadata, data.metadata()); + } + void armem::fromIce(const data::EntityInstance& ice, EntityInstance& data) + { + detail::fromIceItem(ice, data); + + if (ice.data) + { + data.setData(aron::datanavigator::DictNavigator::FromAronDictPtr(ice.data)); + } + fromIce(ice.metadata, data.metadata()); + } + + + void armem::toIce(data::EntitySnapshot& ice, const EntitySnapshot& snapshot) + { + detail::toIceItem(ice, snapshot); + + toIce(ice.instances, snapshot.instances); + } + void armem::fromIce(const data::EntitySnapshot& ice, EntitySnapshot& snapshot) + { + detail::fromIceItem(ice, snapshot); + + fromIce(ice.instances, snapshot.instances); + } + + void armem::toIce(data::Entity& ice, const Entity& entity) + { + detail::toIceItem(ice, entity); + + toIce(ice.history, entity.history); + } + void armem::fromIce(const data::Entity& ice, Entity& entity) + { + detail::fromIceItem(ice, entity); + + fromIce(ice.history, entity.history); + } + + + void armem::toIce(data::ProviderSegment& ice, const ProviderSegment& providerSegment) + { + detail::toIceItem(ice, providerSegment); + + if (providerSegment.hasAronType()) + { + ice.aronType = providerSegment.aronType()->getResult(); + } + toIce(ice.entities, providerSegment.entities); + } + void armem::fromIce(const data::ProviderSegment& ice, ProviderSegment& providerSegment) + { + detail::fromIceItem(ice, providerSegment); + + if (ice.aronType) + { + providerSegment.aronType() = aron::typenavigator::ObjectNavigator::DynamicCastAndCheck( + aron::typenavigator::Navigator::FromAronType(ice.aronType) + ); + } + fromIce(ice.entities, providerSegment.entities); + } + + void armem::toIce(data::CoreSegment& ice, const CoreSegment& coreSegment) + { + detail::toIceItem(ice, coreSegment); + + if (coreSegment.hasAronType()) + { + ice.aronType = coreSegment.aronType()->getResult(); + } + toIce(ice.providerSegments, coreSegment.providerSegments); + } + void armem::fromIce(const data::CoreSegment& ice, CoreSegment& coreSegment) + { + detail::fromIceItem(ice, coreSegment); + + if (ice.aronType) + { + coreSegment.aronType() = aron::typenavigator::ObjectNavigator::DynamicCastAndCheck( + aron::typenavigator::Navigator::FromAronType(ice.aronType) + ); + } + fromIce(ice.providerSegments, coreSegment.providerSegments); + } + + void armem::toIce(data::Memory& ice, const Memory& memory) + { + detail::toIceItem(ice, memory); + + toIce(ice.coreSegments, memory.coreSegments); + } + void armem::fromIce(const data::Memory& ice, Memory& memory) + { + detail::fromIceItem(ice, memory); + + fromIce(ice.coreSegments, memory.coreSegments); + } + +} diff --git a/source/RobotAPI/libraries/armem/core/base/ice_conversions.h b/source/RobotAPI/libraries/armem/core/base/ice_conversions.h new file mode 100644 index 000000000..e5996b001 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/base/ice_conversions.h @@ -0,0 +1,35 @@ +#pragma once + +#include <RobotAPI/interface/armem/commit.h> +#include <RobotAPI/interface/armem/memory.h> + +#include "../ice_conversions.h" + +#include "Memory.h" + + +namespace armarx::armem +{ + void toIce(data::EntityInstanceMetadata& ice, const workingmemory::EntityInstanceMetadata& metadata); + void fromIce(const data::EntityInstanceMetadata& ice, workingmemory::EntityInstanceMetadata& metadata); + + void toIce(data::EntityInstance& ice, const workingmemory::EntityInstance& data); + void fromIce(const data::EntityInstance& ice, workingmemory::EntityInstance& data); + + + void toIce(data::EntitySnapshot& ice, const workingmemory::EntitySnapshot& snapshot); + void fromIce(const data::EntitySnapshot& ice, workingmemory::EntitySnapshot& snapshot); + + void toIce(data::Entity& ice, const workingmemory::Entity& entity); + void fromIce(const data::Entity& ice, workingmemory::Entity& entity); + + + void toIce(data::ProviderSegment& ice, const workingmemory::ProviderSegment& providerSegment); + void fromIce(const data::ProviderSegment& ice, workingmemory::ProviderSegment& providerSegment); + + void toIce(data::CoreSegment& ice, const workingmemory::CoreSegment& coreSegment); + void fromIce(const data::CoreSegment& ice, workingmemory::CoreSegment& coreSegment); + + void toIce(data::Memory& ice, const workingmemory::Memory& memory); + void fromIce(const data::Memory& ice, workingmemory::Memory& memory); +} diff --git a/source/RobotAPI/libraries/armem/core/detail/MemoryContainer.h b/source/RobotAPI/libraries/armem/core/detail/MemoryContainer.h deleted file mode 100644 index 6b64db1dd..000000000 --- a/source/RobotAPI/libraries/armem/core/detail/MemoryContainer.h +++ /dev/null @@ -1,114 +0,0 @@ -#pragma once - -#include <ArmarXCore/core/exceptions/local/ExpressionException.h> - -#include "../../error.h" - -#include "MemoryItem.h" - - -namespace armarx::armem::detail -{ - - /** - * @class Provides default implmentations of `MemoryContainer`, as well as - * iterators (which requires a template). - */ - template <class _ContainerT, class _Derived> - class MemoryContainer : public MemoryItem - { - public: - using ContainerT = _ContainerT; - using Derived = _Derived; - - public: - - MemoryContainer() - {} - MemoryContainer(const MemoryID& id) : MemoryItem(id) - {} - - virtual ~MemoryContainer() - {} - - - // Container methods - - virtual bool empty() const - { - return _underlyingContainer().empty(); - } - virtual std::size_t size() const - { - return _underlyingContainer().size(); - } - virtual void clear() - { - return _underlyingContainer().clear(); - } - - typename ContainerT::const_iterator begin() const - { - return _underlyingContainer().begin(); - } - typename ContainerT::iterator begin() - { - return _underlyingContainer().begin(); - } - typename ContainerT::const_iterator end() const - { - return _underlyingContainer().end(); - } - typename ContainerT::iterator end() - { - return _underlyingContainer().end(); - } - - - // Copying - - virtual Derived copy(bool withData = true) const - { - auto cast = dynamic_cast<const Derived*>(this); - ARMARX_CHECK_NOT_NULL(cast); - - Derived other; - this->_copySelf(other); - this->_copyElements(other, withData); - return other; - } - - /// Make a copy not containing any elements. - virtual Derived copyEmpty() const - { - auto cast = dynamic_cast<const Derived*>(this); - ARMARX_CHECK_NOT_NULL(cast); - - Derived other; - this->_copySelf(other); - return other; - } - - - protected: - - - virtual ContainerT& _underlyingContainer() = 0; - virtual const ContainerT& _underlyingContainer() const - { - return const_cast<const ContainerT&>(const_cast<MemoryContainer*>(this)->_underlyingContainer()); - } - - virtual void _copySelf(Derived& other) const - { - other.id() = this->id(); - (void) other; - } - virtual void _copyElements(Derived& other, bool withData) const - { - (void) other, (void) withData; - } - - }; - -} diff --git a/source/RobotAPI/libraries/armem/core/detail/MemoryItem.cpp b/source/RobotAPI/libraries/armem/core/detail/MemoryItem.cpp deleted file mode 100644 index 32640023b..000000000 --- a/source/RobotAPI/libraries/armem/core/detail/MemoryItem.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "MemoryItem.h" - - -namespace armarx::armem::detail -{ - - MemoryItem::MemoryItem() - { - } - - MemoryItem::MemoryItem(const MemoryID& id) : _id(id) - { - } - - MemoryItem::~MemoryItem() - { - } - -} diff --git a/source/RobotAPI/libraries/armem/core/detail/TypedEntityContainer.h b/source/RobotAPI/libraries/armem/core/detail/TypedEntityContainer.h deleted file mode 100644 index f932b7229..000000000 --- a/source/RobotAPI/libraries/armem/core/detail/TypedEntityContainer.h +++ /dev/null @@ -1,63 +0,0 @@ -#pragma once - -#include "EntityContainer.h" - -#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> - -namespace armarx::armem::detail -{ - - /** - * @brief An entity container with a specific (Aron) type. - */ - template <class _ValueT, class Derived> - class TypedEntityContainer : public EntityContainer<_ValueT, Derived> - { - using ValueT = _ValueT; - // using Base = EntityContainer<ValueT, Derived>; - - public: - - TypedEntityContainer(aron::typenavigator::ObjectNavigatorPtr aronType = nullptr) : _aronType(aronType) - {} - TypedEntityContainer(const MemoryID& id, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr) : - EntityContainer<ValueT, Derived>(id), _aronType(aronType) - {} - - virtual ~TypedEntityContainer() override - {} - - - bool hasAronType() const - { - return _aronType != nullptr; - } - aron::typenavigator::ObjectNavigatorPtr& aronType() - { - return _aronType; - } - aron::typenavigator::ObjectNavigatorPtr aronType() const - { - return _aronType; - } - - - - // MemoryContainer interface - protected: - virtual void _copySelf(Derived& other) const override - { - EntityContainer<ValueT, Derived>::_copySelf(other); - other._aronType = this->_aronType; - } - - - private: - - /// The expected Aron type. May be nullptr, in which case no type information is available. - aron::typenavigator::ObjectNavigatorPtr _aronType; - - }; - - -} diff --git a/source/RobotAPI/libraries/armem/core/ice_conversions.cpp b/source/RobotAPI/libraries/armem/core/ice_conversions.cpp index 684028ae6..32c881951 100644 --- a/source/RobotAPI/libraries/armem/core/ice_conversions.cpp +++ b/source/RobotAPI/libraries/armem/core/ice_conversions.cpp @@ -147,136 +147,11 @@ namespace armarx void armem::detail::toIceItem(data::detail::MemoryItem& ice, const MemoryItem& item) { - toIce(ice.id, item.id()); + toIce(ice.id, item.id); } void armem::detail::fromIceItem(const data::detail::MemoryItem& ice, MemoryItem& item) { - fromIce(ice.id, item.id()); + fromIce(ice.id, item.id); } - - - void armem::toIce(data::EntityInstanceMetadata& ice, const EntityInstanceMetadata& metadata) - { - ice.confidence = metadata.confidence; - toIce(ice.timeArrivedMicroSeconds, metadata.timeArrived); - toIce(ice.timeCreatedMicroSeconds, metadata.timeCreated); - toIce(ice.timeSentMicroSeconds, metadata.timeSent); - } - void armem::fromIce(const data::EntityInstanceMetadata& ice, EntityInstanceMetadata& metadata) - { - metadata.confidence = ice.confidence; - fromIce(ice.timeArrivedMicroSeconds, metadata.timeArrived); - fromIce(ice.timeCreatedMicroSeconds, metadata.timeCreated); - fromIce(ice.timeSentMicroSeconds, metadata.timeSent); - } - - void armem::toIce(data::EntityInstance& ice, const EntityInstance& data) - { - detail::toIceItem(ice, data); - - if (data.data()) - { - ice.data = data.data()->toAronDictPtr(); - } - toIce(ice.metadata, data.metadata()); - } - void armem::fromIce(const data::EntityInstance& ice, EntityInstance& data) - { - detail::fromIceItem(ice, data); - - if (ice.data) - { - data.setData(aron::datanavigator::DictNavigator::FromAronDictPtr(ice.data)); - } - fromIce(ice.metadata, data.metadata()); - } - - - void armem::toIce(data::EntitySnapshot& ice, const EntitySnapshot& snapshot) - { - detail::toIceItem(ice, snapshot); - - toIce(ice.instances, snapshot.instances); - } - void armem::fromIce(const data::EntitySnapshot& ice, EntitySnapshot& snapshot) - { - detail::fromIceItem(ice, snapshot); - - fromIce(ice.instances, snapshot.instances); - } - - void armem::toIce(data::Entity& ice, const Entity& entity) - { - detail::toIceItem(ice, entity); - - toIce(ice.history, entity.history); - } - void armem::fromIce(const data::Entity& ice, Entity& entity) - { - detail::fromIceItem(ice, entity); - - fromIce(ice.history, entity.history); - } - - - void armem::toIce(data::ProviderSegment& ice, const ProviderSegment& providerSegment) - { - detail::toIceItem(ice, providerSegment); - - if (providerSegment.hasAronType()) - { - ice.aronType = providerSegment.aronType()->getResult(); - } - toIce(ice.entities, providerSegment.entities); - } - void armem::fromIce(const data::ProviderSegment& ice, ProviderSegment& providerSegment) - { - detail::fromIceItem(ice, providerSegment); - - if (ice.aronType) - { - providerSegment.aronType() = aron::typenavigator::ObjectNavigator::DynamicCastAndCheck( - aron::typenavigator::Navigator::FromAronType(ice.aronType) - ); - } - fromIce(ice.entities, providerSegment.entities); - } - - void armem::toIce(data::CoreSegment& ice, const CoreSegment& coreSegment) - { - detail::toIceItem(ice, coreSegment); - - if (coreSegment.hasAronType()) - { - ice.aronType = coreSegment.aronType()->getResult(); - } - toIce(ice.providerSegments, coreSegment.providerSegments); - } - void armem::fromIce(const data::CoreSegment& ice, CoreSegment& coreSegment) - { - detail::fromIceItem(ice, coreSegment); - - if (ice.aronType) - { - coreSegment.aronType() = aron::typenavigator::ObjectNavigator::DynamicCastAndCheck( - aron::typenavigator::Navigator::FromAronType(ice.aronType) - ); - } - fromIce(ice.providerSegments, coreSegment.providerSegments); - } - - void armem::toIce(data::Memory& ice, const Memory& memory) - { - detail::toIceItem(ice, memory); - - toIce(ice.coreSegments, memory.coreSegments); - } - void armem::fromIce(const data::Memory& ice, Memory& memory) - { - detail::fromIceItem(ice, memory); - - fromIce(ice.coreSegments, memory.coreSegments); - } - } diff --git a/source/RobotAPI/libraries/armem/core/ice_conversions.h b/source/RobotAPI/libraries/armem/core/ice_conversions.h index f615e7c3b..6aa4ac524 100644 --- a/source/RobotAPI/libraries/armem/core/ice_conversions.h +++ b/source/RobotAPI/libraries/armem/core/ice_conversions.h @@ -6,7 +6,7 @@ #include "ice_conversions_templates.h" #include "Commit.h" -#include "Memory.h" +#include "base/detail/MemoryItem.h" namespace IceUtil @@ -52,31 +52,6 @@ namespace armarx::armem void fromIce(const data::EntityUpdate& ice, EntityUpdate& update, Time timeArrived); - - void toIce(data::EntityInstanceMetadata& ice, const EntityInstanceMetadata& metadata); - void fromIce(const data::EntityInstanceMetadata& ice, EntityInstanceMetadata& metadata); - - void toIce(data::EntityInstance& ice, const EntityInstance& data); - void fromIce(const data::EntityInstance& ice, EntityInstance& data); - - - void toIce(data::EntitySnapshot& ice, const EntitySnapshot& snapshot); - void fromIce(const data::EntitySnapshot& ice, EntitySnapshot& snapshot); - - void toIce(data::Entity& ice, const Entity& entity); - void fromIce(const data::Entity& ice, Entity& entity); - - - void toIce(data::ProviderSegment& ice, const ProviderSegment& providerSegment); - void fromIce(const data::ProviderSegment& ice, ProviderSegment& providerSegment); - - void toIce(data::CoreSegment& ice, const CoreSegment& coreSegment); - void fromIce(const data::CoreSegment& ice, CoreSegment& coreSegment); - - void toIce(data::Memory& ice, const Memory& memory); - void fromIce(const data::Memory& ice, Memory& memory); - - namespace detail { void toIceItem(data::detail::MemoryItem& ice, const MemoryItem& item); diff --git a/source/RobotAPI/libraries/armem/core/ice_conversions_templates.h b/source/RobotAPI/libraries/armem/core/ice_conversions_templates.h index 2f729f202..1cc826f45 100644 --- a/source/RobotAPI/libraries/armem/core/ice_conversions_templates.h +++ b/source/RobotAPI/libraries/armem/core/ice_conversions_templates.h @@ -27,19 +27,18 @@ namespace armarx::armem template <class IceT, class CppT> IceT toIce(const CppT& cpp) { - IceT ice; - toIce(ice, cpp); + IceT ice = {}; + //toIce(ice, cpp); return ice; } template <class CppT, class IceT> CppT fromIce(const IceT& ice) { CppT cpp; - fromIce(ice, cpp); + //fromIce(ice, cpp); return cpp; } - // std::unique_ptr template <class IceT, class CppT> @@ -64,14 +63,14 @@ namespace armarx::armem void toIce(::IceInternal::Handle<IceT>& ice, const CppT& cpp) { ice = new IceT(); - toIce(*ice, cpp); + //toIce(*ice, cpp); } template <class IceT, class CppT> void fromIce(const ::IceInternal::Handle<IceT>& ice, CppT& cpp) { if (ice) { - fromIce(*ice, cpp); + //fromIce(*ice, cpp); } } diff --git a/source/RobotAPI/libraries/armem/core/io/DiskCoreSegment.cpp b/source/RobotAPI/libraries/armem/core/io/DiskCoreSegment.cpp deleted file mode 100644 index 7020c28c7..000000000 --- a/source/RobotAPI/libraries/armem/core/io/DiskCoreSegment.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include "DiskCoreSegment.h" - -namespace armarx::armem::io::intern -{ - // copy - DiskCoreSegment::DiskCoreSegment(const DiskCoreSegment& x): - DiskMemoryItem(x.getMemoryID()), - DiskTypedEntityContainer(x.getMemoryID()), - diskProviderSegments(x.diskProviderSegments) - { - //std::cout << "Copy DiskCoreSegment" << std::endl; - } - - // load - DiskCoreSegment::DiskCoreSegment(const MemoryID& id) : - DiskMemoryItem(id.getCoreSegmentID()), - DiskTypedEntityContainer(id.getCoreSegmentID()) - { - - } - - // store - DiskCoreSegment::DiskCoreSegment(const CoreSegment& c) : - DiskCoreSegment(c.id()) - { - append(c); - } - - // operators - std::string DiskCoreSegment::toString() const - { - std::string endl = "\n"; - std::string tab = " "; - - std::stringstream ss; - ss << "{" << std::endl; - for (const auto& [key, p] : diskProviderSegments) - { - ss << tab << key << ":" << endl; - for (const auto& l : simox::alg::split(p.toString(), endl, false)) - { - ss << tab << l << endl; - } - } - ss << "}" << endl; - return ss.str(); - } - - bool DiskCoreSegment::hasProviderSegment(const std::string& key) const - { - return diskProviderSegments.find(key) != diskProviderSegments.end(); - } - - DiskProviderSegment DiskCoreSegment::getProviderSegment(const std::string& key) const - { - if (!hasProviderSegment(key)) - { - throw error::InvalidArgument("key", "DiskCoreSegment::getProviderSegment", "The providersegment does not exist."); - } - return diskProviderSegments.at(key); - } - - const std::map<std::string, DiskProviderSegment>& DiskCoreSegment::getProviderSegments() const - { - return diskProviderSegments; - } - - void DiskCoreSegment::append(const CoreSegment& c) - { - for (const auto& [key, p] : c.providerSegments) - { - if (hasProviderSegment(key)) - { - diskProviderSegments.at(key).append(p); - } - else - { - // also create new collection in db - std::string typeJSON = ""; - if (c.aronType() != nullptr) - { - //typeJSON = WRITER->getTypeAsString(WRITER->wrapType(c.aronType())); - } - - auto d = DiskProviderSegment(p); - diskProviderSegments.insert(std::pair<std::string, DiskProviderSegment>(key, d)); - } - } - } - - CoreSegment DiskCoreSegment::toCoreSegment(const aron::typenavigator::ObjectNavigatorPtr& expectedType) const - { - CoreSegment s; - for (const auto& [key, p] : diskProviderSegments) - { - auto x = p.toProviderSegment(expectedType); - x.name() = key; - s.addProviderSegment(x); - } - return s; - } - - aron::typenavigator::ObjectNavigatorPtr DiskCoreSegment::getAttachedType() const - { - return nullptr; - } - - bool DiskCoreSegment::hasData() const - { - return diskProviderSegments.size() > 0; - } -} diff --git a/source/RobotAPI/libraries/armem/core/io/DiskCoreSegment.h b/source/RobotAPI/libraries/armem/core/io/DiskCoreSegment.h deleted file mode 100644 index 510955d64..000000000 --- a/source/RobotAPI/libraries/armem/core/io/DiskCoreSegment.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -* This file is part of ArmarX. -* -* ArmarX is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* ArmarX is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* @author Fabian Peller (fabian dot peller at kit dot edu) -* @copyright http://www.gnu.org/licenses/gpl-2.0.txt -* GNU General Public License -*/ - -#pragma once - -// STD/STL -#include <map> -#include <string> -#include <vector> - -// BaseClass -#include "detail/DiskTypedEntityContainer.h" - -// ArmarX -#include "../CoreSegment.h" -#include "DiskProviderSegment.h" - - -namespace armarx::armem::io::intern -{ - class DiskCoreSegment : - virtual public detail::DiskTypedEntityContainer - { - - public: - DiskCoreSegment() = delete; - - // copy - DiskCoreSegment(const DiskCoreSegment&); - - // load - DiskCoreSegment(const MemoryID& id); - - // store - DiskCoreSegment(const CoreSegment&); - - // operators - std::string toString() const; - - // virtual - virtual aron::typenavigator::ObjectNavigatorPtr getAttachedType() const override; - bool hasData() const override; - - // public methods - bool hasProviderSegment(const std::string& key) const; - - DiskProviderSegment getProviderSegment(const std::string& key) const; - const std::map<std::string, DiskProviderSegment>& getProviderSegments() const; - - CoreSegment toCoreSegment(const aron::typenavigator::ObjectNavigatorPtr& expectedType = nullptr) const; - - void append(const CoreSegment&); - - private: - std::map<std::string, DiskProviderSegment> diskProviderSegments; - }; -} diff --git a/source/RobotAPI/libraries/armem/core/io/DiskEntity.cpp b/source/RobotAPI/libraries/armem/core/io/DiskEntity.cpp deleted file mode 100644 index 6c5a14caa..000000000 --- a/source/RobotAPI/libraries/armem/core/io/DiskEntity.cpp +++ /dev/null @@ -1,107 +0,0 @@ -#include "DiskEntity.h" - -namespace armarx::armem::io::intern -{ - // copy - DiskEntity::DiskEntity(const DiskEntity& x): - DiskMemoryItem(x.getMemoryID()), - DiskTypedEntityContainer(x.getMemoryID()), - diskEntityHistory(x.diskEntityHistory) - { - } - - // load - DiskEntity::DiskEntity(const MemoryID& id) : - DiskMemoryItem(id.getEntityID()), - DiskTypedEntityContainer(id.getEntityID()) - { - } - - // store - DiskEntity::DiskEntity(const Entity& c) : - DiskEntity(c.id()) - { - append(c); - } - - // operators - std::string DiskEntity::toString() const - { - std::string endl = "\n"; - std::string tab = " "; - - std::stringstream ss; - ss << "{" << std::endl; - for (const auto& [key, p] : diskEntityHistory) - { - ss << tab << std::to_string(key.toMicroSeconds()) << ":" << endl; - for (const auto& l : simox::alg::split(p.toString(), endl, false)) - { - ss << tab << l << endl; - } - } - ss << "}" << endl; - return ss.str(); - } - - bool DiskEntity::hasEntitySnapshot(const armem::Time& key) const - { - return diskEntityHistory.find(key) != diskEntityHistory.end(); - } - - DiskEntitySnapshot DiskEntity::getEntitySnapshot(const armem::Time& key) const - { - if (!hasEntitySnapshot(key)) - { - throw error::InvalidArgument("key", "DiskEntity::getEntitySnapshot", "The Entity does not exist."); - } - return diskEntityHistory.at(key); - } - - const std::map<armem::Time, DiskEntitySnapshot>& DiskEntity::getEntitySnapshots() const - { - return diskEntityHistory; - } - - void DiskEntity::append(const Entity& c) - { - for (const auto& [key, p] : c.history) - { - - if (hasEntitySnapshot(key)) - { - return; // if an entry at a specific time already exists we simply ignore it - // TODO: perhaps check for equality - } - else - { - // also create new collection in db - - auto d = DiskEntitySnapshot(p); - diskEntityHistory.insert(std::pair<armem::Time, DiskEntitySnapshot>(key, d)); - } - } - } - - aron::typenavigator::ObjectNavigatorPtr DiskEntity::getAttachedType() const - { - return nullptr; - } - - bool DiskEntity::hasData() const - { - return diskEntityHistory.size() > 0; - } - - Entity DiskEntity::toEntity(const aron::typenavigator::ObjectNavigatorPtr& expectedType) const - { - Entity s; - for (const auto& [key, p] : diskEntityHistory) - { - auto x = p.toEntitySnapshot(expectedType); - x.time() = key; - s.addSnapshot(x); - } - return s; - } -} diff --git a/source/RobotAPI/libraries/armem/core/io/DiskEntity.h b/source/RobotAPI/libraries/armem/core/io/DiskEntity.h deleted file mode 100644 index 454ba26cd..000000000 --- a/source/RobotAPI/libraries/armem/core/io/DiskEntity.h +++ /dev/null @@ -1,76 +0,0 @@ -/* -* This file is part of ArmarX. -* -* ArmarX is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* ArmarX is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* @author Fabian Peller (fabian dot peller at kit dot edu) -* @copyright http://www.gnu.org/licenses/gpl-2.0.txt -* GNU General Public License -*/ - -#pragma once - -// STD/STL -#include <map> -#include <string> -#include <vector> - -// BaseClass -#include "detail/DiskTypedEntityContainer.h" - -// ArmarX -#include "../Entity.h" -#include "../../core/Time.h" -#include "DiskEntitySnapshot.h" - - -namespace armarx::armem::io::intern -{ - - class DiskEntity : - virtual public detail::DiskTypedEntityContainer - { - - public: - DiskEntity() = delete; - - // copy - DiskEntity(const DiskEntity&); - - // load - DiskEntity(const MemoryID& id); - - // store - DiskEntity(const Entity&); - - // operators - std::string toString() const; - - // virtual - virtual aron::typenavigator::ObjectNavigatorPtr getAttachedType() const override; - bool hasData() const override; - - // public methods - bool hasEntitySnapshot(const armem::Time&) const; - - DiskEntitySnapshot getEntitySnapshot(const armem::Time&) const; - const std::map<armem::Time, DiskEntitySnapshot>& getEntitySnapshots() const; - - Entity toEntity(const aron::typenavigator::ObjectNavigatorPtr& expectedType = nullptr) const; - - void append(const Entity&); - - private: - std::map<armem::Time, DiskEntitySnapshot> diskEntityHistory; - }; -} diff --git a/source/RobotAPI/libraries/armem/core/io/DiskEntityInstance.cpp b/source/RobotAPI/libraries/armem/core/io/DiskEntityInstance.cpp deleted file mode 100644 index 21658ec88..000000000 --- a/source/RobotAPI/libraries/armem/core/io/DiskEntityInstance.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "DiskEntityInstance.h" - -namespace armarx::armem::io::intern -{ - // copy - DiskEntityInstance::DiskEntityInstance(const DiskEntityInstance& x): - DiskMemoryItem(x.getMemoryID()), - DiskTypedEntityContainer(x.getMemoryID()) - { - } - - // load - DiskEntityInstance::DiskEntityInstance(const MemoryID& id) : - DiskMemoryItem(id.getEntityInstanceID()), - DiskTypedEntityContainer(id.getEntityInstanceID()) - { - } - - // store - DiskEntityInstance::DiskEntityInstance(const EntityInstance& c) : - DiskEntityInstance(c.id()) - { - } - - // operators - std::string DiskEntityInstance::toString() const - { - std::string endl = "\n"; - std::string tab = " "; - - std::stringstream ss; - ss << "{" << std::endl; - ss << tab << "ID: " << _id.str() << endl; - ss << "}" << endl; - return ss.str(); - } - - aron::typenavigator::ObjectNavigatorPtr DiskEntityInstance::getAttachedType() const - { - return nullptr; - } - - bool DiskEntityInstance::hasData() const - { - return true; - } - - EntityInstance DiskEntityInstance::toEntityInstance(const aron::typenavigator::ObjectNavigatorPtr& expectedType) const - { - // get string from db - std::string entry_content = ""; - - //aron::datanavigator::DictNavigatorPtr dictdata = READER->getStringAsDataNavigator(entry_content, expectedType); - //return READER->unwrapData(dictdata); - return EntityInstance(); - } -} diff --git a/source/RobotAPI/libraries/armem/core/io/DiskEntityInstance.h b/source/RobotAPI/libraries/armem/core/io/DiskEntityInstance.h deleted file mode 100644 index 86cbd8122..000000000 --- a/source/RobotAPI/libraries/armem/core/io/DiskEntityInstance.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -* This file is part of ArmarX. -* -* ArmarX is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* ArmarX is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* @author Fabian Peller (fabian dot peller at kit dot edu) -* @copyright http://www.gnu.org/licenses/gpl-2.0.txt -* GNU General Public License -*/ - -#pragma once - -// STD/STL -#include <map> -#include <string> -#include <vector> -#include <filesystem> - -// BaseClass -#include "detail/DiskTypedEntityContainer.h" - -// ArmarX -#include "../EntityInstance.h" -#include "../MemoryID.h" -#include "../error.h" - -namespace armarx::armem::io::intern -{ - class DiskEntityInstance : - virtual public detail::DiskTypedEntityContainer - { - - public: - DiskEntityInstance() = delete; - - // copy - DiskEntityInstance(const DiskEntityInstance&); - - // load - DiskEntityInstance(const MemoryID& id); - - // store - DiskEntityInstance(const EntityInstance&); - - // operators - std::string toString() const; - - // virtual - virtual aron::typenavigator::ObjectNavigatorPtr getAttachedType() const override; - bool hasData() const override; - - // public methods - EntityInstance toEntityInstance(const aron::typenavigator::ObjectNavigatorPtr& expectedType = nullptr) const; - - private: - }; -} diff --git a/source/RobotAPI/libraries/armem/core/io/DiskEntitySnapshot.cpp b/source/RobotAPI/libraries/armem/core/io/DiskEntitySnapshot.cpp deleted file mode 100644 index bf673cc77..000000000 --- a/source/RobotAPI/libraries/armem/core/io/DiskEntitySnapshot.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include "DiskEntitySnapshot.h" - -#include "DiskEntity.h" - -namespace armarx::armem::io::intern -{ - // copy - DiskEntitySnapshot::DiskEntitySnapshot(const DiskEntitySnapshot& x): - DiskMemoryItem(x.getMemoryID()), - DiskTypedEntityContainer(x.getMemoryID()), - diskEntityInstances(x.diskEntityInstances) - { - } - - // load - DiskEntitySnapshot::DiskEntitySnapshot(const MemoryID& id) : - DiskMemoryItem(id.getEntitySnapshotID()), - DiskTypedEntityContainer(id.getEntitySnapshotID()) - { - - } - - // store - DiskEntitySnapshot::DiskEntitySnapshot(const EntitySnapshot& c) : - DiskEntitySnapshot(c.id()) - { - //std::cout << "Create DiskEntitySnapshot" << std::endl; - append(c); - } - - // operators - std::string DiskEntitySnapshot::toString() const - { - std::string endl = "\n"; - std::string tab = " "; - - std::stringstream ss; - ss << "{" << std::endl; - - unsigned int i = 0; - for (const auto& p : diskEntityInstances) - { - ss << tab << std::to_string(i++) << ":" << endl; - for (const auto& l : simox::alg::split(p.toString(), endl, false)) - { - ss << tab << l << endl; - } - } - ss << "}" << endl; - return ss.str(); - } - - aron::typenavigator::ObjectNavigatorPtr DiskEntitySnapshot::getAttachedType() const - { - return nullptr; - } - - bool DiskEntitySnapshot::hasData() const - { - return diskEntityInstances.size() > 0; - } - - bool DiskEntitySnapshot::hasEntityInstance(const unsigned int key) const - { - return diskEntityInstances.size() > key; - } - - DiskEntityInstance DiskEntitySnapshot::getEntityInstance(const unsigned int key) const - { - if (!hasEntityInstance(key)) - { - throw error::InvalidArgument("key", "DiskEntitySnapshot::getEntityInstance", "The entitysnapshot does not exist."); - } - return diskEntityInstances.at(key); - } - - const std::vector<DiskEntityInstance>& DiskEntitySnapshot::getEntityInstances() const - { - return diskEntityInstances; - } - - void DiskEntitySnapshot::append(const EntitySnapshot& c) - { - unsigned int i = 0; - for (const auto& p : c.instances) - { - if (i < diskEntityInstances.size()) - { - // WARNING: The snapshot already has values in its managed container. Ignoring - continue; - } - - auto d = DiskEntityInstance(p); - diskEntityInstances.push_back(d); - - std::cout << "Received trigger to store: " << d.getMemoryID().str() << std::endl; - } - } - - EntitySnapshot DiskEntitySnapshot::toEntitySnapshot(const aron::typenavigator::ObjectNavigatorPtr& expectedType) const - { - EntitySnapshot s; - unsigned int i = 0; - for (const auto& p : diskEntityInstances) - { - auto x = p.toEntityInstance(expectedType); - x.index() = i; - s.addInstance(x); - } - return s; - } -} diff --git a/source/RobotAPI/libraries/armem/core/io/DiskEntitySnapshot.h b/source/RobotAPI/libraries/armem/core/io/DiskEntitySnapshot.h deleted file mode 100644 index 7efd0a260..000000000 --- a/source/RobotAPI/libraries/armem/core/io/DiskEntitySnapshot.h +++ /dev/null @@ -1,75 +0,0 @@ -/* -* This file is part of ArmarX. -* -* ArmarX is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* ArmarX is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* @author Fabian Peller (fabian dot peller at kit dot edu) -* @copyright http://www.gnu.org/licenses/gpl-2.0.txt -* GNU General Public License -*/ - -#pragma once - -// STD/STL -#include <map> -#include <string> -#include <vector> - -// BaseClass -#include "detail/DiskTypedEntityContainer.h" - -// ArmarX -#include "../EntitySnapshot.h" -#include "DiskEntityInstance.h" - - -namespace armarx::armem::io::intern -{ - - class DiskEntitySnapshot : - virtual public detail::DiskTypedEntityContainer - { - - public: - DiskEntitySnapshot() = delete; - - // copy - DiskEntitySnapshot(const DiskEntitySnapshot&); - - // load - DiskEntitySnapshot(const MemoryID& id); - - // store - DiskEntitySnapshot(const EntitySnapshot&); - - // operators - std::string toString() const; - - // virtual - aron::typenavigator::ObjectNavigatorPtr getAttachedType() const override; - bool hasData() const override; - - // public methods - bool hasEntityInstance(const unsigned int) const; - - DiskEntityInstance getEntityInstance(const unsigned int) const; - const std::vector<DiskEntityInstance>& getEntityInstances() const; - - EntitySnapshot toEntitySnapshot(const aron::typenavigator::ObjectNavigatorPtr& expectedType = nullptr) const; - - void append(const EntitySnapshot&); - - private: - std::vector<DiskEntityInstance> diskEntityInstances; - }; -} diff --git a/source/RobotAPI/libraries/armem/core/io/DiskInstanceData.h b/source/RobotAPI/libraries/armem/core/io/DiskInstanceData.h deleted file mode 100644 index f871aff98..000000000 --- a/source/RobotAPI/libraries/armem/core/io/DiskInstanceData.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -* This file is part of ArmarX. -* -* ArmarX is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* ArmarX is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* @author Fabian Peller (fabian dot peller at kit dot edu) -* @copyright http://www.gnu.org/licenses/gpl-2.0.txt -* GNU General Public License -*/ - -#pragma once - -// STD/STL -#include <string> -#include <filesystem> - -// ArmarX -#include <RobotAPI/interface/aron.h> - -#include <RobotAPI/libraries/armem/core/Time.h> - - -namespace armarx::armem::io -{ - class DiskInstanceData - { - // static use only - DiskInstanceData() = delete; - - public: - static constexpr const char* DISK_READER_WRITER_DATA_FIELD = "__ARON_DATA"; - static constexpr const char* DISK_READER_WRITER_TIME_STORED_FIELD = "__WRITER_METADATA__TIME_STORED"; - static constexpr const char* DISK_READER_WRITER_TIME_CREATED_FIELD = "__ENTITY_METADATA__TIME_CREATED"; - static constexpr const char* DISK_READER_WRITER_TIME_SENT_FIELD = "__ENTITY_METADATA__TIME_SENT"; - static constexpr const char* DISK_READER_WRITER_TIME_ARRIVED_FIELD = "__ENTITY_METADATA__TIME_ARRIVED"; - static constexpr const char* DISK_READER_WRITER_CONFIDENCE_FIELD = "__ENTITY_METADATA__CONFIDENCE"; - }; -} diff --git a/source/RobotAPI/libraries/armem/core/io/DiskMemory.cpp b/source/RobotAPI/libraries/armem/core/io/DiskMemory.cpp deleted file mode 100644 index 48ce12dea..000000000 --- a/source/RobotAPI/libraries/armem/core/io/DiskMemory.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* -* This file is part of ArmarX. -* -* ArmarX is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* ArmarX is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* @author Fabian Peller (fabian dot peller at kit dot edu) -* @copyright http://www.gnu.org/licenses/gpl-2.0.txt -* GNU General Public License -*/ - -#include "DiskMemory.h" - -#include "diskWriter/NlohmannJSON/NlohmannJSONDiskWriter.h" - - -namespace armarx::armem::io -{ - DiskMemory::DiskMemory() : - detail::DiskMemoryItem(MemoryID()), - detail::DiskTypedEntityContainer(MemoryID()) - { - } - - - // copy - DiskMemory::DiskMemory(const DiskMemory& x) : - detail::DiskMemoryItem(x.getMemoryID()), - detail::DiskTypedEntityContainer(x.getMemoryID()), - _databaseUrl(x._databaseUrl), - _databaseUser(x._databaseUser), - _databasePassword(x._databasePassword), - diskCoreSegments(x.diskCoreSegments) - { - } - - // load on startup - DiskMemory::DiskMemory(const MemoryID& id) : - detail::DiskMemoryItem(id.getMemoryID()), - detail::DiskTypedEntityContainer(id.getMemoryID()) - { - } - - // write and load on startup - DiskMemory::DiskMemory(const Memory& m) : - DiskMemory(m.id()) - { - } - - // operators - std::string DiskMemory::toString() const - { - std::string endl = "\n"; - std::string tab = " "; - - std::stringstream ss; - ss << "{" << std::endl; - for (const auto& [key, p] : diskCoreSegments) - { - ss << tab << key << ":" << endl; - for (const auto& l : simox::alg::split(p.toString(), endl, false)) - { - ss << tab << l << endl; - } - } - ss << "}" << endl; - return ss.str(); - } - - aron::typenavigator::ObjectNavigatorPtr DiskMemory::getAttachedType() const - { - return nullptr; - } - - bool DiskMemory::hasData() const - { - return diskCoreSegments.size() > 0; - } - - bool DiskMemory::hasCoreSegment(const std::string& key) const - { - return diskCoreSegments.find(key) != diskCoreSegments.end(); - } - - intern::DiskCoreSegment DiskMemory::getCoreSegment(const std::string& key) const - { - if (!hasCoreSegment(key)) - { - throw error::InvalidArgument("key", "DiskMemory::getCoreSegment", "The coresegment does not exist."); - } - return diskCoreSegments.at(key); - } - - const std::map<std::string, intern::DiskCoreSegment>& DiskMemory::getCoreSegments() const - { - return diskCoreSegments; - } - - void DiskMemory::append(const Memory& m) - { - for (const auto& [key, p] : m.coreSegments) - { - if (hasCoreSegment(key)) - { - diskCoreSegments.at(key).append(p); - } - else - { - // also create new collection in db - auto d = intern::DiskCoreSegment(p); - diskCoreSegments.insert(std::make_pair(key, d)); - } - } - } - - Memory DiskMemory::toMemory() const - { - // converts the stored references to a real Memory - //std::cout << "toMemory" << std::endl; - Memory s; - for (const auto& [key, p] : diskCoreSegments) - { - auto x = p.toCoreSegment(); - x.name() = key; - s.addCoreSegment(x); - } - return s; - } -} diff --git a/source/RobotAPI/libraries/armem/core/io/DiskMemory.h b/source/RobotAPI/libraries/armem/core/io/DiskMemory.h deleted file mode 100644 index 6036bf29e..000000000 --- a/source/RobotAPI/libraries/armem/core/io/DiskMemory.h +++ /dev/null @@ -1,96 +0,0 @@ -/* -* This file is part of ArmarX. -* -* ArmarX is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* ArmarX is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* @author Fabian Peller (fabian dot peller at kit dot edu) -* @copyright http://www.gnu.org/licenses/gpl-2.0.txt -* GNU General Public License -*/ - -#pragma once - -// STD/STL -#include <filesystem> -#include <map> -#include <string> -#include <vector> - -// BaseClass -#include "detail/DiskTypedEntityContainer.h" - -// ArmarX -#include "../Memory.h" -#include "DiskCoreSegment.h" - -namespace armarx::armem::io -{ - class DiskMemory : - virtual public detail::DiskTypedEntityContainer - { - - public: - DiskMemory(); - - // copy - DiskMemory(const DiskMemory&); - - // load on startup - DiskMemory(const MemoryID&); - - // write on startup - DiskMemory(const Memory&); - - // operators - std::string toString() const; - - // virtual - aron::typenavigator::ObjectNavigatorPtr getAttachedType() const override; - bool hasData() const override; - - // public methods - bool hasCoreSegment(const std::string&) const; - - intern::DiskCoreSegment getCoreSegment(const std::string&) const; - const std::map<std::string, intern::DiskCoreSegment>& getCoreSegments() const; - - // WM conversion - Memory toMemory() const; - - // add information to LTM - void append(const Memory&); - - // database operators - void setDatabaseURL(const std::string& url) - { - _databaseUrl = url; - } - - void setDatabaseUser(const std::string& user) - { - _databaseUser = user; - } - - void setDatabasePassword(const std::string& pw) - { - _databasePassword = pw; - } - - private: - std::string _databaseUrl = ""; - std::string _databaseUser = ""; - std::string _databasePassword = ""; - - std::map<std::string, intern::DiskCoreSegment> diskCoreSegments; - }; -} diff --git a/source/RobotAPI/libraries/armem/core/io/DiskProviderSegment.cpp b/source/RobotAPI/libraries/armem/core/io/DiskProviderSegment.cpp deleted file mode 100644 index d175263f1..000000000 --- a/source/RobotAPI/libraries/armem/core/io/DiskProviderSegment.cpp +++ /dev/null @@ -1,113 +0,0 @@ -#include "DiskProviderSegment.h" - -namespace armarx::armem::io::intern -{ - // copy - DiskProviderSegment::DiskProviderSegment(const DiskProviderSegment& x): - DiskMemoryItem(x.getMemoryID()), - DiskTypedEntityContainer(x.getMemoryID()), - diskEntities(x.diskEntities) - { - } - - // load - DiskProviderSegment::DiskProviderSegment(const MemoryID& id) : - DiskMemoryItem(id.getProviderSegmentID()), - DiskTypedEntityContainer(id.getProviderSegmentID()) - { - } - - // store - DiskProviderSegment::DiskProviderSegment(const ProviderSegment& c) : - DiskProviderSegment(c.id()) - { - //std::cout << "Create DiskProviderSegment" << std::endl; - append(c); - } - - // operators - std::string DiskProviderSegment::toString() const - { - std::string endl = "\n"; - std::string tab = " "; - - std::stringstream ss; - ss << "{" << std::endl; - for (const auto& [key, p] : diskEntities) - { - ss << tab << key << ":" << endl; - for (const auto& l : simox::alg::split(p.toString(), endl, false)) - { - ss << tab << l << endl; - } - } - ss << "}" << endl; - return ss.str(); - } - - bool DiskProviderSegment::hasEntity(const std::string& key) const - { - return diskEntities.find(key) != diskEntities.end(); - } - - DiskEntity DiskProviderSegment::getEntity(const std::string& key) const - { - if (!hasEntity(key)) - { - throw error::InvalidArgument("key", "DiskProviderSegment::getEntity", "The entity does not exist."); - } - return diskEntities.at(key); - } - - const std::map<std::string, DiskEntity>& DiskProviderSegment::getEntities() const - { - return diskEntities; - } - - void DiskProviderSegment::append(const ProviderSegment& c) - { - for (const auto& [key, p] : c.entities) - { - if (hasEntity(key)) - { - diskEntities.at(key).append(p); - } - else - { - // also create new collection in db - std::string typeJSON = ""; - if (c.aronType() != nullptr) - { - //typeJSON = WRITER->getTypeAsString(WRITER->wrapType(c.aronType())); - } - - auto d = DiskEntity(p); - diskEntities.insert(std::pair<std::string, DiskEntity>(key, d)); - } - } - } - - ProviderSegment DiskProviderSegment::toProviderSegment(const aron::typenavigator::ObjectNavigatorPtr& expectedType) const - { - // converts the stored references to a real ProviderSegment - //std::cout << "toProviderSegment" << std::endl; - ProviderSegment s; - for (const auto& [key, p] : diskEntities) - { - auto x = p.toEntity(expectedType); - x.name() = key; - s.addEntity(x); - } - return s; - } - - aron::typenavigator::ObjectNavigatorPtr DiskProviderSegment::getAttachedType() const - { - return nullptr; - } - - bool DiskProviderSegment::hasData() const - { - return diskEntities.size() > 0; - } -} diff --git a/source/RobotAPI/libraries/armem/core/io/DiskProviderSegment.h b/source/RobotAPI/libraries/armem/core/io/DiskProviderSegment.h deleted file mode 100644 index 3b0fb2e60..000000000 --- a/source/RobotAPI/libraries/armem/core/io/DiskProviderSegment.h +++ /dev/null @@ -1,75 +0,0 @@ -/* -* This file is part of ArmarX. -* -* ArmarX is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* ArmarX is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* @author Fabian Peller (fabian dot peller at kit dot edu) -* @copyright http://www.gnu.org/licenses/gpl-2.0.txt -* GNU General Public License -*/ - -#pragma once - -// STD/STL -#include <map> -#include <string> -#include <vector> - -// BaseClass -#include "detail/DiskTypedEntityContainer.h" - -// ArmarX -#include "../ProviderSegment.h" -#include "DiskEntity.h" - - -namespace armarx::armem::io::intern -{ - - class DiskProviderSegment : - virtual public detail::DiskTypedEntityContainer - { - - public: - DiskProviderSegment() = delete; - - // copy - DiskProviderSegment(const DiskProviderSegment&); - - // load - DiskProviderSegment(const MemoryID& id); - - // store - DiskProviderSegment(const ProviderSegment&); - - // operators - std::string toString() const; - - // virtual - virtual aron::typenavigator::ObjectNavigatorPtr getAttachedType() const override; - bool hasData() const override; - - // public methods - bool hasEntity(const std::string&) const; - - DiskEntity getEntity(const std::string&) const; - const std::map<std::string, DiskEntity>& getEntities() const; - - ProviderSegment toProviderSegment(const aron::typenavigator::ObjectNavigatorPtr& expectedType = nullptr) const; - - void append(const ProviderSegment&); - - private: - std::map<std::string, DiskEntity> diskEntities; - }; -} diff --git a/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage_OLD.cpp b/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage_OLD.cpp deleted file mode 100644 index d39acab1a..000000000 --- a/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage_OLD.cpp +++ /dev/null @@ -1,291 +0,0 @@ -#include "MemoryFileSystemStorage.h" - -#include <RobotAPI/libraries/aron/core/Debug.h> -#include <RobotAPI/libraries/armem/core/error.h> - - -namespace armarx::armem::io -{ - FileSystemMemoryManager::FileSystemMemoryManager(const std::filesystem::path& rootPath, bool createFolder) : - FileSystemMemoryManager(std::make_shared<io::NlohmannJSONDiskWriter>(rootPath, createFolder), - std::make_shared<io::NlohmannJSONDiskReader>(rootPath, createFolder)) - { - } - - FileSystemMemoryManager::FileSystemMemoryManager(const io::DiskWriterPtr& w, const io::DiskReaderPtr& r) : - writer(w), - reader(r) - { - } - - void FileSystemMemoryManager::writeOnDisk(const Memory& m) - { - io::DiskWriterReturnInformation info = writer->writeOnDisk(m); - merge(info.storedElements); - } - - void FileSystemMemoryManager::writeOnDisk(const MemoryID& id, const CoreSegment& s) - { - io::DiskWriterReturnInformation info = writer->writeOnDisk(id, s); - merge(info.storedElements); - } - - void FileSystemMemoryManager::writeOnDisk(const MemoryID& id, const ProviderSegment& s) - { - io::DiskWriterReturnInformation info = writer->writeOnDisk(id, s); - merge(info.storedElements); - } - - void FileSystemMemoryManager::writeOnDisk(const MemoryID& id, const Entity& s) - { - io::DiskWriterReturnInformation info = writer->writeOnDisk(id, s); - merge(info.storedElements); - } - - void FileSystemMemoryManager::writeOnDisk(const MemoryID& id, const EntitySnapshot& s) - { - io::DiskWriterReturnInformation info = writer->writeOnDisk(id, s); - merge(info.storedElements); - } - - Memory FileSystemMemoryManager::readMemoryFromDisk(const std::string& n) const - { - MemoryID id; - id.memoryName = n; - return readMemoryFromDisk(id); - } - - Memory FileSystemMemoryManager::readMemoryFromDisk(const MemoryID& _id) const - { - if (!_id.hasMemoryName()) - { - throw error::InvalidMemoryID(_id, "MemoryName is missing."); - } - Memory ret(_id.memoryName); - if (internalMemory.hasMemory(_id)) - { - MemoryID id = _id.getMemoryID(); - for (const auto& [coreKey, _] : internalMemory.getDiskMemory(_id)) - { - id.coreSegmentName = coreKey; - CoreSegment s = readCoreSegmentFromDisk(id); - ret.addCoreSegment(s); - } - } - return ret; - } - - CoreSegment FileSystemMemoryManager::readCoreSegmentFromDisk(const MemoryID& _id) const - { - if (!_id.hasCoreSegmentName()) - { - throw error::InvalidMemoryID(_id, "CoreSegmentName is missing."); - } - - CoreSegment ret(_id.coreSegmentName); - if (internalMemory.hasCoreSegment(_id)) - { - MemoryID id = _id.getCoreSegmentID(); - for (const auto& [providerKey, _] : internalMemory.getDiskCoreSegment(_id)) - { - id.providerSegmentName = providerKey; - ProviderSegment s = readProviderSegmentFromDisk(id); - ret.addProviderSegment(s); - } - } - return ret; - } - - ProviderSegment FileSystemMemoryManager::readProviderSegmentFromDisk(const MemoryID& _id) const - { - if (!_id.hasProviderSegmentName()) - { - throw error::InvalidMemoryID(_id, "ProviderSegmentName is missing."); - } - - ProviderSegment ret(_id.providerSegmentName); - if (internalMemory.hasProviderSegment(_id)) - { - MemoryID id = _id.getProviderSegmentID(); - for (const auto& [entityKey, _] : internalMemory.getDiskProviderSegment(_id)) - { - id.entityName = entityKey; - Entity s = readEntityFromDisk(id); - ret.addEntity(s); - } - } - return ret; - } - - Entity FileSystemMemoryManager::readEntityFromDisk(const MemoryID& _id) const - { - if (!_id.hasEntityName()) - { - throw error::InvalidMemoryID(_id, "EntityName is missing."); - } - - Entity ret(_id.entityName); - if (internalMemory.hasEntity(_id)) - { - MemoryID id = _id.getEntityID(); - for (const auto& [ts, _] : internalMemory.getDiskEntity(_id)) - { - id.timestamp = ts; - EntitySnapshot s = readEntitySnapshotFromDisk(id); - ret.addSnapshot(s); - } - } - return ret; - } - - EntitySnapshot FileSystemMemoryManager::readEntitySnapshotFromDisk(const MemoryID& _id) const - { - if (!_id.hasTimestamp()) - { - throw error::InvalidMemoryID(_id, "Timestamp is missing."); - } - - EntitySnapshot ret(_id.timestamp); - if (internalMemory.hasEntitySnapshot(_id)) - { - MemoryID id = _id.getEntitySnapshotID(); - for (unsigned int i = 0; i < internalMemory.getDiskEntitySnapshot(_id).size(); ++i) - { - id.instanceIndex = static_cast<int>(i); - EntityInstance s = readEntityInstanceFromDisk(id); - ret.addInstance(s); - } - } - return ret; - } - - EntityInstance FileSystemMemoryManager::readEntityInstanceFromDisk(const MemoryID& _id) const - { - if (!_id.hasInstanceIndex()) - { - throw error::InvalidMemoryID(_id, "InstanceIndex is missing."); - } - - EntityInstance ret(_id.instanceIndex); - if (internalMemory.hasEntityInstance(_id)) - { - aron::typenavigator::ObjectNavigatorPtr typeInformation = readClosestTypeInformation(_id); - const DiskEntityInstance& path = internalMemory.getDiskEntityInstance(_id); - return reader->readSingleInstanceFromDisk(path, typeInformation); - } - return ret; - } - - aron::typenavigator::ObjectNavigatorPtr FileSystemMemoryManager::readClosestTypeInformation(const MemoryID& _id) const - { - if (_id.hasInstanceIndex()) - { - aron::typenavigator::ObjectNavigatorPtr t = reader->readSingleTypeInformationFromDisk(_id); - if (t != nullptr) - { - return t; - } - } - if (_id.hasTimestamp()) - { - MemoryID id = _id.getEntitySnapshotID(); - aron::typenavigator::ObjectNavigatorPtr t = reader->readSingleTypeInformationFromDisk(id); - if (t != nullptr) - { - return t; - } - } - if (_id.hasEntityName()) - { - MemoryID id = _id.getEntityID(); - aron::typenavigator::ObjectNavigatorPtr t = reader->readSingleTypeInformationFromDisk(id); - if (t != nullptr) - { - return t; - } - } - if (_id.hasProviderSegmentName()) - { - MemoryID id = _id.getProviderSegmentID(); - aron::typenavigator::ObjectNavigatorPtr t = reader->readSingleTypeInformationFromDisk(id); - if (t != nullptr) - { - return t; - } - } - if (_id.hasCoreSegmentName()) - { - MemoryID id = _id.getCoreSegmentID(); - aron::typenavigator::ObjectNavigatorPtr t = reader->readSingleTypeInformationFromDisk(id); - if (t != nullptr) - { - return t; - } - } - if (_id.hasMemoryName()) - { - MemoryID id = _id.getMemoryID(); - aron::typenavigator::ObjectNavigatorPtr t = reader->readSingleTypeInformationFromDisk(id); - if (t != nullptr) - { - return t; - } - } - - return nullptr; - } - - void FileSystemMemoryManager::update() - { - FileSystemLookupMemory up = reader->readMemoryStructureFromDisk(); - merge(up); - } - - std::string FileSystemMemoryManager::toString() - { - std::stringstream ss; - std::string tabs = ""; - for (const auto& [memoryName, memory] : internalMemory.memoryLookupTable) - { - ss << memoryName << ": " << std::endl; - std::string tabs = "\t"; - for (const auto& [coreKey, coreSegment] : memory) - { - ss << tabs << coreKey << ": " << std::endl; - std::string tabs = "\t\t"; - for (const auto& [providerKey, providerSegment] : coreSegment) - { - ss << tabs << providerKey << ": " << std::endl; - std::string tabs = "\t\t\t"; - for (const auto& [entityKey, entity] : providerSegment) - { - ss << tabs << entityKey << ": " << std::endl; - std::string tabs = "\t\t\t\t"; - for (const auto& [entityHistoryTimestamp, entitySnapshot] : entity) - { - ss << tabs << entityHistoryTimestamp.toMicroSeconds() << ":" << std::endl; - ss << tabs << "[" << std::endl; - for (unsigned int i = 0; i < entitySnapshot.size(); ++i) - { - const std::string& newlyGenerate = entitySnapshot[i]; - ss << tabs << "\t(" << i << " => " << newlyGenerate << ")"; - if (i < entitySnapshot.size() - 1) - { - ss << ", "; - } - ss << std::endl; - } - ss << tabs << "]" << std::endl; - } - } - } - } - } - return ss.str(); - } - - void FileSystemMemoryManager::merge(const FileSystemLookupMemory& info) - { - internalMemory.merge(info); - } -} diff --git a/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage_OLD.h b/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage_OLD.h deleted file mode 100644 index 9f44bb7a0..000000000 --- a/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage_OLD.h +++ /dev/null @@ -1,77 +0,0 @@ -/* -* This file is part of ArmarX. -* -* ArmarX is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* ArmarX is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* @author Fabian Peller (fabian dot peller at kit dot edu) -* @copyright http://www.gnu.org/licenses/gpl-2.0.txt -* GNU General Public License -*/ - -#pragma once - -// STD/STL -#include <filesystem> -#include <string> -#include <utility> // std::pair - -// ArmarX -#include <RobotAPI/interface/aron.h> - -#include "DiskWriter/DiskWriter.h" -#include "DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.h" -#include "DiskReader/DiskReader.h" -#include "DiskReader/NlohmannJSONDiskReader/NlohmannJSONDiskReader.h" - - -namespace armarx::armem::io -{ - class FileSystemMemoryManager - { - public: - FileSystemMemoryManager() = delete; - FileSystemMemoryManager(const std::filesystem::path& rootPath, bool createFolder = false); - FileSystemMemoryManager(const io::DiskWriterPtr&, const io::DiskReaderPtr&); - - void writeOnDisk(const Memory& memory); - void writeOnDisk(const MemoryID& coreSegmentID, const CoreSegment& coreSegment); - void writeOnDisk(const MemoryID& providerSegmentID, const ProviderSegment& providerSegment); - void writeOnDisk(const MemoryID& entityID, const Entity& entity); - // void writeOnDisk(const MemoryID&, const Entity&, aron::typenavigator::ObjectNavigatorPtr = nullptr); - void writeOnDisk(const MemoryID& entitySnapshotID, const EntitySnapshot& entitySnapshot); - - void update(); - void merge(const FileSystemLookupMemory& info); - - Memory readMemoryFromDisk(const std::string& memoryName) const; - Memory readMemoryFromDisk(const MemoryID& memoryID) const; - CoreSegment readCoreSegmentFromDisk(const MemoryID& coreSegmentID) const; - ProviderSegment readProviderSegmentFromDisk(const MemoryID& providerSegmentID) const; - Entity readEntityFromDisk(const MemoryID& entityID) const; - EntitySnapshot readEntitySnapshotFromDisk(const MemoryID& entitySnapshotID) const; - EntityInstance readEntityInstanceFromDisk(const MemoryID& entityInstanceID) const; - - aron::typenavigator::ObjectNavigatorPtr readClosestTypeInformation(const MemoryID&) const; - - //std::pair<Entity, aron::typenavigator::ObjectNavigatorPtr> readTypedEntityFromDisk(); - //std::pair<EntitySnapshot, aron::typenavigator::ObjectNavigatorPtr> readTypedEntitySnapshotFromDisk(); - - std::string toString(); - - private: - FileSystemLookupMemory internalMemory; - - DiskWriterPtr writer; - DiskReaderPtr reader; - }; -} diff --git a/source/RobotAPI/libraries/armem/core/io/detail/DiskMemoryItem.h b/source/RobotAPI/libraries/armem/core/io/detail/DiskMemoryItem.h deleted file mode 100644 index 7c4700b12..000000000 --- a/source/RobotAPI/libraries/armem/core/io/detail/DiskMemoryItem.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -* This file is part of ArmarX. -* -* ArmarX is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* ArmarX is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* @author Fabian Peller (fabian dot peller at kit dot edu) -* @copyright http://www.gnu.org/licenses/gpl-2.0.txt -* GNU General Public License -*/ - -#pragma once - -// STD/STL -#include <map> -#include <string> -#include <vector> -#include <filesystem> - -// ArmarX -#include "../diskReader/DiskReader.h" -#include "../diskWriter/DiskWriter.h" -#include "../diskWriter/NlohmannJSON/NlohmannJSONDiskWriter.h" -#include "../diskReader/NlohmannJSON/NlohmannJSONDiskReader.h" - -namespace armarx::armem::io::detail -{ - class DiskMemoryItem - { - - public: - DiskMemoryItem(const MemoryID& id) : - _id(id) - { - } - - // virtual definitions - virtual bool hasData() const = 0; - - // public member functions - void setMemoryID(const MemoryID& id) - { - _id = id; - } - - MemoryID getMemoryID() const - { - return _id; - } - - protected: - MemoryID _id; - - //static const DiskReaderPtr READER; - //static const DiskWriterPtr WRITER; - }; - - // initialize reader and writers (accessible to any memory item due to types) - //const DiskReaderPtr DiskMemoryItem::READER = std::make_shared<NlohmannJSONDiskReader>(); - //const DiskWriterPtr DiskMemoryItem::WRITER = std::make_shared<NlohmannJSONDiskWriter>(); -} diff --git a/source/RobotAPI/libraries/armem/core/io/detail/DiskTypedEntityContainer.h b/source/RobotAPI/libraries/armem/core/io/detail/DiskTypedEntityContainer.h deleted file mode 100644 index 36ec186b0..000000000 --- a/source/RobotAPI/libraries/armem/core/io/detail/DiskTypedEntityContainer.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -* This file is part of ArmarX. -* -* ArmarX is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* ArmarX is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* @author Fabian Peller (fabian dot peller at kit dot edu) -* @copyright http://www.gnu.org/licenses/gpl-2.0.txt -* GNU General Public License -*/ - -#pragma once - -// STD/STL -#include <map> -#include <string> -#include <vector> - -// BaseClass -#include "DiskMemoryItem.h" - -namespace armarx::armem::io::detail -{ - - class DiskTypedEntityContainer : - virtual public DiskMemoryItem - { - public: - DiskTypedEntityContainer(const MemoryID& id) : - DiskMemoryItem(id) - { - } - - // operators - DiskTypedEntityContainer& operator=(DiskTypedEntityContainer&&) - { - return *this; - } - - // virtual defainition - virtual aron::typenavigator::ObjectNavigatorPtr getAttachedType() const = 0; - }; -} diff --git a/source/RobotAPI/libraries/armem/core/io/diskReader/DiskReader.cpp b/source/RobotAPI/libraries/armem/core/io/diskReader/DiskReader.cpp deleted file mode 100644 index d25227d5d..000000000 --- a/source/RobotAPI/libraries/armem/core/io/diskReader/DiskReader.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* -* This file is part of ArmarX. -* -* ArmarX is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* ArmarX is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* @author Fabian Peller (fabian dot peller at kit dot edu) -* @copyright http://www.gnu.org/licenses/gpl-2.0.txt -* GNU General Public License -*/ - -#include "DiskReader.h" - -#include <sstream> -#include <fstream> -#include <iostream> - -// ArmarX -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h> -#include <RobotAPI/libraries/aron/core/navigator/type/AllNavigators.h> - -#include <RobotAPI/libraries/aron/core/io/dataIO/converter/Converter.h> -#include <RobotAPI/libraries/aron/core/io/dataIO/writer/navigator/NavigatorWriter.h> - -#include <RobotAPI/libraries/aron/core/io/typeIO/converter/Converter.h> -#include <RobotAPI/libraries/aron/core/io/typeIO/writer/navigator/NavigatorWriter.h> - -#include <RobotAPI/libraries/armem/core/error.h> - - -namespace armarx::armem::io -{ - EntityInstance DiskReader::unwrapData(const aron::datanavigator::DictNavigatorPtr& dataWrapped) const - { - EntityInstance e; - EntityInstanceMetadata& metadata = e.metadata(); - - aron::datanavigator::DictNavigatorPtr data = aron::datanavigator::DictNavigator::DynamicCastAndCheck(dataWrapped->getElement(DiskInstanceData::DISK_READER_WRITER_DATA_FIELD)); - e.setData(data); - - // not used right now - //aron::datanavigator::LongNavigatorPtr timeWrapped = aron::datanavigator::LongNavigator::DynamicCastAndCheck(dataWrapped->getElement(DiskInstanceData::DISK_READER_WRITER_TIME_WRAPPED_FIELD)); - - auto timeCreated = aron::datanavigator::LongNavigator::DynamicCastAndCheck(dataWrapped->getElement(DiskInstanceData::DISK_READER_WRITER_TIME_CREATED_FIELD)); - metadata.timeCreated = Time::microSeconds(timeCreated->toAronLongPtr()->value); - - auto timeSent = aron::datanavigator::LongNavigator::DynamicCastAndCheck(dataWrapped->getElement(DiskInstanceData::DISK_READER_WRITER_TIME_SENT_FIELD)); - metadata.timeSent = Time::microSeconds(timeSent->toAronLongPtr()->value); - - auto timeArrived = aron::datanavigator::LongNavigator::DynamicCastAndCheck(dataWrapped->getElement(DiskInstanceData::DISK_READER_WRITER_TIME_ARRIVED_FIELD)); - metadata.timeArrived = Time::microSeconds(timeArrived->toAronLongPtr()->value); - - auto confidence = aron::datanavigator::DoubleNavigator::DynamicCastAndCheck(dataWrapped->getElement(DiskInstanceData::DISK_READER_WRITER_CONFIDENCE_FIELD)); - metadata.confidence = static_cast<float>(confidence->toAronDoublePtr()->value); - - return e; - } - - aron::typenavigator::ObjectNavigatorPtr DiskReader::unwrapType(const aron::typenavigator::ObjectNavigatorPtr& t) const - { - return aron::typenavigator::ObjectNavigator::DynamicCastAndCheck(t->getMemberType(DiskInstanceData::DISK_READER_WRITER_DATA_FIELD)); - } -} diff --git a/source/RobotAPI/libraries/armem/core/io/diskReader/DiskReader.h b/source/RobotAPI/libraries/armem/core/io/diskReader/DiskReader.h deleted file mode 100644 index 843643c8f..000000000 --- a/source/RobotAPI/libraries/armem/core/io/diskReader/DiskReader.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -* This file is part of ArmarX. -* -* ArmarX is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* ArmarX is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* @author Fabian Peller (fabian dot peller at kit dot edu) -* @copyright http://www.gnu.org/licenses/gpl-2.0.txt -* GNU General Public License -*/ - -#pragma once - -// STD/STL -#include <filesystem> -#include <memory> -#include <string> - -// ArmarX -#include <RobotAPI/libraries/aron/core/navigator/data/container/Dict.h> -#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> -#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> -#include <RobotAPI/libraries/armem/core/EntityInstance.h> - -#include "../../Memory.h" -#include "../DiskInstanceData.h" - - -namespace armarx::armem::io -{ - class DiskReader; - using DiskReaderPtr = std::shared_ptr<DiskReader>; - - class DiskReader - { - public: - EntityInstance unwrapData(const aron::datanavigator::DictNavigatorPtr&) const; - aron::typenavigator::ObjectNavigatorPtr unwrapType(const aron::typenavigator::ObjectNavigatorPtr&) const; - - virtual aron::datanavigator::DictNavigatorPtr getStringAsDataNavigator(const std::string&, const aron::typenavigator::NavigatorPtr&) const = 0; - virtual aron::typenavigator::ObjectNavigatorPtr getStringAsTypeNavigator(const std::string& s) const = 0; - }; -} diff --git a/source/RobotAPI/libraries/armem/core/io/diskReader/NlohmannJSON/NlohmannJSONDiskReader.cpp b/source/RobotAPI/libraries/armem/core/io/diskReader/NlohmannJSON/NlohmannJSONDiskReader.cpp deleted file mode 100644 index aedc1f42d..000000000 --- a/source/RobotAPI/libraries/armem/core/io/diskReader/NlohmannJSON/NlohmannJSONDiskReader.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "NlohmannJSONDiskReader.h" - -#include <RobotAPI/libraries/aron/core/io/dataIO/converter/Converter.h> -#include <RobotAPI/libraries/aron/core/io/dataIO/reader/nlohmannJSON/NlohmannJSONReader.h> -#include <RobotAPI/libraries/aron/core/io/dataIO/writer/navigator/NavigatorWriter.h> -#include <RobotAPI/libraries/aron/core/io/typeIO/converter/Converter.h> -#include <RobotAPI/libraries/aron/core/io/typeIO/reader/nlohmannJSON/NlohmannJSONReader.h> -#include <RobotAPI/libraries/aron/core/io/typeIO/writer/navigator/NavigatorWriter.h> - - -namespace armarx::armem::io -{ - aron::datanavigator::DictNavigatorPtr NlohmannJSONDiskReader::getStringAsDataNavigator(const std::string& s, const aron::typenavigator::NavigatorPtr& expectedStructure) const - { - aron::dataIO::reader::NlohmannJSONReader dataReader(s); - aron::dataIO::writer::NavigatorWriter navWriter; - aron::dataIO::Converter::ReadAndConvert(dataReader, navWriter, expectedStructure); - return aron::datanavigator::DictNavigator::DynamicCastAndCheck(navWriter.getResult()); - } - - aron::typenavigator::ObjectNavigatorPtr NlohmannJSONDiskReader::getStringAsTypeNavigator(const std::string& s) const - { - aron::typeIO::reader::NlohmannJSONReader typeReader(s); - aron::typeIO::writer::NavigatorWriter navWriter; - aron::typeIO::Converter::ReadAndConvert(typeReader, navWriter); - return aron::typenavigator::ObjectNavigator::DynamicCastAndCheck(navWriter.getResult()); - } -} diff --git a/source/RobotAPI/libraries/armem/core/io/diskReader/NlohmannJSON/NlohmannJSONDiskReader.h b/source/RobotAPI/libraries/armem/core/io/diskReader/NlohmannJSON/NlohmannJSONDiskReader.h deleted file mode 100644 index 1a84b3303..000000000 --- a/source/RobotAPI/libraries/armem/core/io/diskReader/NlohmannJSON/NlohmannJSONDiskReader.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -* This file is part of ArmarX. -* -* ArmarX is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* ArmarX is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* @author Fabian Peller (fabian dot peller at kit dot edu) -* @copyright http://www.gnu.org/licenses/gpl-2.0.txt -* GNU General Public License -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// Base Class -#include "../DiskReader.h" - - -namespace armarx::armem::io -{ - class NlohmannJSONDiskReader; - using NlohmannJSONDiskReaderPtr = std::shared_ptr<NlohmannJSONDiskReader>; - - class NlohmannJSONDiskReader : virtual public DiskReader - { - public: - NlohmannJSONDiskReader() = default; - - protected: - aron::datanavigator::DictNavigatorPtr getStringAsDataNavigator(const std::string&, const aron::typenavigator::NavigatorPtr& expectedStructure = nullptr) const override; - aron::typenavigator::ObjectNavigatorPtr getStringAsTypeNavigator(const std::string& s) const override; - }; -} diff --git a/source/RobotAPI/libraries/armem/core/io/diskWriter/DiskWriter.cpp b/source/RobotAPI/libraries/armem/core/io/diskWriter/DiskWriter.cpp deleted file mode 100644 index f6d18cb29..000000000 --- a/source/RobotAPI/libraries/armem/core/io/diskWriter/DiskWriter.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* -* This file is part of ArmarX. -* -* ArmarX is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* ArmarX is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* @author Fabian Peller (fabian dot peller at kit dot edu) -* @copyright http://www.gnu.org/licenses/gpl-2.0.txt -* GNU General Public License -*/ - -// STD/STL -#include "DiskWriter.h" - -#include <fstream> -#include <iostream> - -// ArmarX -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h> -#include <RobotAPI/libraries/aron/core/navigator/type/AllNavigators.h> - -#include <RobotAPI/libraries/aron/core/io/dataIO/visitor/Visitor.h> -#include <RobotAPI/libraries/aron/core/io/dataIO/Writer.h> -#include <RobotAPI/libraries/aron/core/io/typeIO/visitor/Visitor.h> -#include <RobotAPI/libraries/aron/core/io/typeIO/Writer.h> - - -// BaseClass -#include <RobotAPI/libraries/armem/core/Memory.h> -#include <RobotAPI/libraries/armem/core/CoreSegment.h> -#include <RobotAPI/libraries/armem/core/Entity.h> - - -namespace armarx::armem::io -{ - aron::datanavigator::DictNavigatorPtr DiskWriter::wrapData(const EntityInstance& e) const - { - auto dataWrapped = std::make_shared<aron::datanavigator::DictNavigator>(); - dataWrapped->addElement(DiskInstanceData::DISK_READER_WRITER_DATA_FIELD, e.data()); - - auto timeWrapped = std::make_shared<aron::datanavigator::LongNavigator>(); - timeWrapped->setValue(Time::now().toMicroSeconds()); - dataWrapped->addElement(DiskInstanceData::DISK_READER_WRITER_TIME_STORED_FIELD, timeWrapped); - - - const EntityInstanceMetadata& metadata = e.metadata(); - auto timeCreated = std::make_shared<aron::datanavigator::LongNavigator>(); - timeCreated->setValue(metadata.timeCreated.toMicroSeconds()); - dataWrapped->addElement(DiskInstanceData::DISK_READER_WRITER_TIME_CREATED_FIELD, timeCreated); - - auto timeSent = std::make_shared<aron::datanavigator::LongNavigator>(); - timeSent->setValue(metadata.timeSent.toMicroSeconds()); - dataWrapped->addElement(DiskInstanceData::DISK_READER_WRITER_TIME_SENT_FIELD, timeSent); - - auto timeArrived = std::make_shared<aron::datanavigator::LongNavigator>(); - timeArrived->setValue(metadata.timeArrived.toMicroSeconds()); - dataWrapped->addElement(DiskInstanceData::DISK_READER_WRITER_TIME_ARRIVED_FIELD, timeArrived); - - auto confidence = std::make_shared<aron::datanavigator::DoubleNavigator>(); - confidence->setValue(metadata.confidence); - dataWrapped->addElement(DiskInstanceData::DISK_READER_WRITER_CONFIDENCE_FIELD, confidence); - - return dataWrapped; - } - - aron::typenavigator::ObjectNavigatorPtr DiskWriter::wrapType(const aron::typenavigator::ObjectNavigatorPtr& t) const - { - aron::typenavigator::ObjectNavigatorPtr typeWrapped(new aron::typenavigator::ObjectNavigator()); - typeWrapped->setObjectName(t->getObjectName() + "__ltm_type_export"); - typeWrapped->addMemberType(DiskInstanceData::DISK_READER_WRITER_DATA_FIELD, t); - - typeWrapped->addMemberType(DiskInstanceData::DISK_READER_WRITER_TIME_STORED_FIELD, std::make_shared<aron::typenavigator::LongNavigator>()); - typeWrapped->addMemberType(DiskInstanceData::DISK_READER_WRITER_TIME_CREATED_FIELD, std::make_shared<aron::typenavigator::LongNavigator>()); - typeWrapped->addMemberType(DiskInstanceData::DISK_READER_WRITER_TIME_SENT_FIELD, std::make_shared<aron::typenavigator::LongNavigator>()); - typeWrapped->addMemberType(DiskInstanceData::DISK_READER_WRITER_TIME_ARRIVED_FIELD, std::make_shared<aron::typenavigator::LongNavigator>()); - typeWrapped->addMemberType(DiskInstanceData::DISK_READER_WRITER_CONFIDENCE_FIELD, std::make_shared<aron::typenavigator::DoubleNavigator>()); - - return typeWrapped; - } -} diff --git a/source/RobotAPI/libraries/armem/core/io/diskWriter/DiskWriter.h b/source/RobotAPI/libraries/armem/core/io/diskWriter/DiskWriter.h deleted file mode 100644 index c75ff114b..000000000 --- a/source/RobotAPI/libraries/armem/core/io/diskWriter/DiskWriter.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -* This file is part of ArmarX. -* -* ArmarX is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* ArmarX is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* @author Fabian Peller (fabian dot peller at kit dot edu) -* @copyright http://www.gnu.org/licenses/gpl-2.0.txt -* GNU General Public License -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> -#include <filesystem> - -// ArmarX -#include <RobotAPI/libraries/aron/core/navigator/data/container/Dict.h> -#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> -#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> - -#include "../../Memory.h" -#include "../diskReader/DiskReader.h" -#include "../DiskInstanceData.h" - - -namespace armarx::armem::io -{ - class DiskWriter; - using DiskWriterPtr = std::shared_ptr<DiskWriter>; - - class DiskWriter - { - public: - virtual DiskReaderPtr getCorrespondingDiskReader() const = 0; - - aron::datanavigator::DictNavigatorPtr wrapData(const EntityInstance& e) const; - aron::typenavigator::ObjectNavigatorPtr wrapType(const aron::typenavigator::ObjectNavigatorPtr&) const; - - virtual std::string getDataAsString(const aron::datanavigator::DictNavigatorPtr&) const = 0; - virtual std::string getTypeAsString(const aron::typenavigator::ObjectNavigatorPtr&) const = 0; - }; -} diff --git a/source/RobotAPI/libraries/armem/core/io/diskWriter/NlohmannJSON/NlohmannJSONDiskWriter.cpp b/source/RobotAPI/libraries/armem/core/io/diskWriter/NlohmannJSON/NlohmannJSONDiskWriter.cpp deleted file mode 100644 index 22fe7a5a2..000000000 --- a/source/RobotAPI/libraries/armem/core/io/diskWriter/NlohmannJSON/NlohmannJSONDiskWriter.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "NlohmannJSONDiskWriter.h" - -#include <RobotAPI/libraries/aron/core/io/dataIO/visitor/Visitor.h> -#include <RobotAPI/libraries/aron/core/io/typeIO/visitor/Visitor.h> -#include <RobotAPI/libraries/aron/core/io/dataIO/writer/nlohmannJSON/NlohmannJSONWriter.h> -#include <RobotAPI/libraries/aron/core/io/typeIO/writer/nlohmannJSON/NlohmannJSONWriter.h> - - -namespace armarx::armem::io -{ - std::string NlohmannJSONDiskWriter::getDataAsString(const aron::datanavigator::DictNavigatorPtr& aronDataNav) const - { - aron::dataIO::writer::NlohmannJSONWriter dataWriter; - aron::dataIO::Visitor::VisitAndSetup(dataWriter, aronDataNav); - return dataWriter.getResult().dump(2); - } - - std::string NlohmannJSONDiskWriter::getTypeAsString(const aron::typenavigator::ObjectNavigatorPtr& aronTypeNav) const - { - aron::typeIO::writer::NlohmannJSONWriter typeWriter; - aron::typeIO::Visitor::VisitAndSetup(typeWriter, aronTypeNav); - return typeWriter.getResult().dump(2); - } -} diff --git a/source/RobotAPI/libraries/armem/core/io/diskWriter/NlohmannJSON/NlohmannJSONDiskWriter.h b/source/RobotAPI/libraries/armem/core/io/diskWriter/NlohmannJSON/NlohmannJSONDiskWriter.h deleted file mode 100644 index c68e6d2eb..000000000 --- a/source/RobotAPI/libraries/armem/core/io/diskWriter/NlohmannJSON/NlohmannJSONDiskWriter.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -* This file is part of ArmarX. -* -* ArmarX is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* ArmarX is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* @author Fabian Peller (fabian dot peller at kit dot edu) -* @copyright http://www.gnu.org/licenses/gpl-2.0.txt -* GNU General Public License -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// Base Class -#include "../DiskWriter.h" - -// ArmarX -#include "../../diskReader/NlohmannJSON/NlohmannJSONDiskReader.h" - -namespace armarx::armem::io -{ - class NlohmannJSONDiskWriter; - using NlohmannJSONDiskWriterPtr = std::shared_ptr<NlohmannJSONDiskWriter>; - - class NlohmannJSONDiskWriter : virtual public DiskWriter - { - public: - NlohmannJSONDiskWriter() = default; - - std::string getDataAsString(const aron::datanavigator::DictNavigatorPtr&) const override; - std::string getTypeAsString(const aron::typenavigator::ObjectNavigatorPtr&) const override; - - virtual DiskReaderPtr getCorrespondingDiskReader() const override - { - return std::make_shared<NlohmannJSONDiskReader>(); - } - }; -} diff --git a/source/RobotAPI/libraries/armem/core/longtermMemory/CoreSegment.cpp b/source/RobotAPI/libraries/armem/core/longtermMemory/CoreSegment.cpp new file mode 100644 index 000000000..76d86ba9f --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/longtermMemory/CoreSegment.cpp @@ -0,0 +1,45 @@ +#include "CoreSegment.h" + +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + +#include "error.h" + + +namespace armarx::armem::longtermmemory +{ + + CoreSegment::CoreSegment() + { + } + + CoreSegment::CoreSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType) : + CoreSegment(name, MemoryID(), aronType) + { + } + + CoreSegment::CoreSegment(const std::string& name, const MemoryID& parentID, aron::typenavigator::ObjectNavigatorPtr aronType) : + CoreSegment(parentID.getMemoryID().withCoreSegmentName(name), aronType) + { + } + + CoreSegment::CoreSegment(const MemoryID& id, aron::typenavigator::ObjectNavigatorPtr aronType) : + armarx::armem::detail::MemoryItem(id), + armarx::armem::detail::TypedEntityContainerBase<ProviderSegment, Entity, EntitySnapshot, EntityInstance, CoreSegment>(id, aronType) + { + } + + CoreSegment::CoreSegment(const CoreSegment& other) : + armarx::armem::detail::MemoryItem(other), + MemoryContainerBase<std::map<std::string, ProviderSegment>, CoreSegment>(other), + armarx::armem::detail::TypedEntityContainerBase<ProviderSegment, Entity, EntitySnapshot, EntityInstance, CoreSegment>(other) + { + // *this = other; + } + + CoreSegment& CoreSegment::operator=(const CoreSegment& other) + { + other._copySelf(*this); + //other._copyElements(*this, true); + return *this; + } +} diff --git a/source/RobotAPI/libraries/armem/core/longtermMemory/CoreSegment.h b/source/RobotAPI/libraries/armem/core/longtermMemory/CoreSegment.h new file mode 100644 index 000000000..d41c7288f --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/longtermMemory/CoreSegment.h @@ -0,0 +1,29 @@ +#pragma once + +#include "../base/CoreSegment.h" + +#include "ProviderSegment.h" +#include "detail/TypedEntityContainer.h" + + +namespace armarx::armem::longtermmemory +{ + + /** + * @brief Data of a core segment containing multiple provider segments. + */ + class CoreSegment : + virtual public CoreSegmentBase<ProviderSegment, Entity, EntitySnapshot, EntityInstance, CoreSegment>, + virtual public detail::TypedEntityContainer<ProviderSegment, CoreSegment> + { + public: + CoreSegment(); + CoreSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); + CoreSegment(const std::string& name, const MemoryID& parentID, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); + CoreSegment(const MemoryID& id, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); + + CoreSegment(const CoreSegment& other); + CoreSegment& operator=(const CoreSegment& other); + }; + +} diff --git a/source/RobotAPI/libraries/armem/core/longtermMemory/Entity.cpp b/source/RobotAPI/libraries/armem/core/longtermMemory/Entity.cpp new file mode 100644 index 000000000..2ed158416 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/longtermMemory/Entity.cpp @@ -0,0 +1,33 @@ +#include "Entity.h" + +namespace armarx::armem::longtermmemory +{ + + Entity::Entity() + { + } + + Entity::Entity(const std::string& name, const MemoryID& parentID) : + Entity(parentID.withEntityName(name)) + { + } + + Entity::Entity(const MemoryID& id) : + armarx::armem::detail::MemoryItem(id) + { + } + + Entity::Entity(const Entity& other) : + armarx::armem::detail::MemoryItem(other), + armarx::armem::detail::MemoryContainerBase<std::map<Time, EntitySnapshot>, Entity>(other) + { + // *this = other; + } + + Entity& Entity::operator=(const Entity& other) + { + other._copySelf(*this); + //other._copyElements(*this, true); + return *this; + } +} diff --git a/source/RobotAPI/libraries/armem/core/longtermMemory/Entity.h b/source/RobotAPI/libraries/armem/core/longtermMemory/Entity.h new file mode 100644 index 000000000..7d25e3fc8 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/longtermMemory/Entity.h @@ -0,0 +1,46 @@ +#pragma once + +#include "../base/Entity.h" + +#include "EntitySnapshot.h" +#include "detail/MemoryContainer.h" + + +namespace armarx::armem::longtermmemory +{ + /** + * @brief An entity over a period of time. + * + * An entity should be a physical thing or abstract concept existing + * (and potentially evolving) over some time. + * + * Examples are: + * - objects (the green box) + * - agents (robot, human) + * - locations (frige, sink) + * - grasp affordances (general, or for a specific object) + * - images + * - point clouds + * - other sensory values + * + * At each point in time (`EntitySnapshot`), the entity can have a + * (potentially variable) number of instances (`EntityInstance`), + * each containing a single `AronData` object of a specific `AronType`. + */ + class Entity : + virtual public EntityBase<EntitySnapshot, Entity>, + virtual public detail::MemoryContainer<std::map<Time, EntitySnapshot>, Entity> + { + + public: + Entity(); + Entity(const std::string& name, const MemoryID& parentID = {}); + Entity(const MemoryID& id); + + /// Copy the history from `other` to this. + Entity(const Entity& other); + /// Copy the history from `other` to this. + Entity& operator=(const Entity& other); + }; + +} diff --git a/source/RobotAPI/libraries/armem/core/longtermMemory/EntityInstance.cpp b/source/RobotAPI/libraries/armem/core/longtermMemory/EntityInstance.cpp new file mode 100644 index 000000000..6b2a6898f --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/longtermMemory/EntityInstance.cpp @@ -0,0 +1,62 @@ +#include "EntityInstance.h" + +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + + +namespace armarx::armem::longtermmemory +{ + + bool EntityInstanceMetadata::operator==(const EntityInstanceMetadata& other) const + { + return timeCreated == other.timeCreated + && timeSent == other.timeSent + && timeArrived == other.timeArrived + && std::abs(confidence - other.confidence) < 1e-6f; + } + + EntityInstance::EntityInstance() + { + } + + EntityInstance::EntityInstance(int index, const MemoryID& parentID) : + EntityInstance(parentID.withInstanceIndex(index)) + { + } + + EntityInstance::EntityInstance(const MemoryID& id) : + MemoryItem(id) + { + } + + + bool EntityInstance::equalsDeep(const EntityInstance& other) const + { + return id == other.id && _metadata == other.metadata(); + } + + void EntityInstance::update(const EntityUpdate& update, int index) + { + ARMARX_CHECK_FITS_SIZE(index, update.instancesData.size()); + + this->index() = index; + + this->_metadata.confidence = update.confidence; + + this->_metadata.timeCreated = update.timeCreated; + this->_metadata.timeSent = update.timeSent; + this->_metadata.timeArrived = update.timeArrived; + } + + EntityInstance EntityInstance::copy() const + { + EntityInstance d; + this->_copySelf(d); + return d; + } + + void EntityInstance::_copySelf(EntityInstance& other) const + { + EntityInstanceBase<EntityInstance>::_copySelf(other); + other._metadata = _metadata; + } +} diff --git a/source/RobotAPI/libraries/armem/core/longtermMemory/EntityInstance.h b/source/RobotAPI/libraries/armem/core/longtermMemory/EntityInstance.h new file mode 100644 index 000000000..764d941ed --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/longtermMemory/EntityInstance.h @@ -0,0 +1,72 @@ +#pragma once + +#include "../base/EntityInstance.h" + +namespace armarx::armem::longtermmemory +{ + + /** + * @brief Metadata of an entity instance. + */ + struct EntityInstanceMetadata + { + /// Time when this value was created. + Time timeCreated; + /// Time when this value was sent to the memory. + Time timeSent; + /// Time when this value has arrived at the memory. + Time timeArrived; + + /// An optional confidence, may be used for things like decay. + float confidence = 1.0; + + + bool operator==(const EntityInstanceMetadata& other) const; + inline bool operator!=(const EntityInstanceMetadata& other) const + { + return !(*this == other); + } + }; + + /** + * @brief Data of a single entity instance. + */ + class EntityInstance : + virtual public EntityInstanceBase<EntityInstance> + { + + public: + EntityInstance(); + EntityInstance(int index, const MemoryID& parentID = {}); + EntityInstance(const MemoryID& id); + + EntityInstanceMetadata& metadata() + { + return _metadata; + } + inline const EntityInstanceMetadata& metadata() const + { + return _metadata; + } + + + /** + * @brief Fill `*this` with the update's values. + * @param update The update. + * @param index The instances index. + */ + virtual void update(const EntityUpdate& update, int index) override; + + virtual bool equalsDeep(const EntityInstance& other) const override; + + virtual EntityInstance copy() const override; + + protected: + virtual void _copySelf(EntityInstance& other) const override; + + + private: + /// The metadata. + EntityInstanceMetadata _metadata; + }; +} diff --git a/source/RobotAPI/libraries/armem/core/longtermMemory/EntitySnapshot.cpp b/source/RobotAPI/libraries/armem/core/longtermMemory/EntitySnapshot.cpp new file mode 100644 index 000000000..f82a54ca7 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/longtermMemory/EntitySnapshot.cpp @@ -0,0 +1,45 @@ +#include "EntitySnapshot.h" + +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + +#include "error.h" + + +namespace armarx::armem::longtermmemory +{ + + + EntitySnapshot::EntitySnapshot() + { + } + + EntitySnapshot::EntitySnapshot(Time time, const MemoryID& parentID) : + EntitySnapshot(parentID.withTimestamp(time)) + { + } + + EntitySnapshot::EntitySnapshot(const MemoryID& id) : + MemoryItem(id) + { + } + + EntitySnapshot::EntitySnapshot(const EntitySnapshot& other) : + armarx::armem::detail::MemoryItem(other), + armarx::armem::detail::MemoryContainerBase<std::vector<EntityInstance>, EntitySnapshot>(other) + { + // *this = other; + } + + EntitySnapshot& EntitySnapshot::operator=(const EntitySnapshot& other) + { + other._copySelf(*this); + //other._copyElements(*this, true); + return *this; + } + + /*EntitySnapshot EntitySnapshot::copy(bool withData) const + { + //auto cast = dynamic_cast<const Derived*>(this); + return Base2::copy(withData); + }*/ +} diff --git a/source/RobotAPI/libraries/armem/core/longtermMemory/EntitySnapshot.h b/source/RobotAPI/libraries/armem/core/longtermMemory/EntitySnapshot.h new file mode 100644 index 000000000..b357f4e52 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/longtermMemory/EntitySnapshot.h @@ -0,0 +1,31 @@ +#pragma once + +#include "../base/EntitySnapshot.h" + +#include "EntityInstance.h" +#include "detail/MemoryContainer.h" + + +namespace armarx::armem::longtermmemory +{ + + /** + * @brief Data of an entity at one point in time. + */ + class EntitySnapshot : + virtual public EntitySnapshotBase<EntityInstance, EntitySnapshot>, + virtual public detail::MemoryContainer<std::vector<EntityInstance>, EntitySnapshot> + { + + public: + EntitySnapshot(); + EntitySnapshot(Time time, const MemoryID& parentID = {}); + EntitySnapshot(const MemoryID& id); + + /// Copy the instances from `other` to this. + EntitySnapshot(const EntitySnapshot& other); + + /// Copy the instances from `other` to this. + EntitySnapshot& operator=(const EntitySnapshot& other); + }; +} diff --git a/source/RobotAPI/libraries/armem/core/longtermMemory/Memory.cpp b/source/RobotAPI/libraries/armem/core/longtermMemory/Memory.cpp new file mode 100644 index 000000000..9ad01dec5 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/longtermMemory/Memory.cpp @@ -0,0 +1,39 @@ +#include "Memory.h" + +#include <ArmarXCore/core/logging/Logging.h> +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + +#include "error.h" + + +namespace armarx::armem::longtermmemory +{ + + Memory::Memory() + { + } + + Memory::Memory(const std::string& name) : + Memory(MemoryID().withMemoryName(name)) + { + } + + Memory::Memory(const MemoryID& id) : + MemoryItem(id) + { + } + + Memory::Memory(const Memory& other) : + armarx::armem::detail::MemoryItem(other), + MemoryContainerBase<std::map<std::string, CoreSegment>, Memory>(other) + { + *this = other; + } + + Memory& Memory::operator=(const Memory& other) + { + other._copySelf(*this); + //other._copyElements(*this, true); + return *this; + } +} diff --git a/source/RobotAPI/libraries/armem/core/longtermMemory/Memory.h b/source/RobotAPI/libraries/armem/core/longtermMemory/Memory.h new file mode 100644 index 000000000..dae9522a6 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/longtermMemory/Memory.h @@ -0,0 +1,26 @@ +#pragma once + +#include "../base/Memory.h" + +#include "CoreSegment.h" +#include "detail/EntityContainer.h" + +namespace armarx::armem::longtermmemory +{ + + /** + * @brief Data of a memory consisting of multiple core segments. + */ + class Memory : + virtual public MemoryBase<CoreSegment, Entity, EntitySnapshot, EntityInstance, Memory>, + virtual public detail::EntityContainer<CoreSegment, Memory> + { + public: + Memory(); + Memory(const std::string& name); + Memory(const MemoryID& id); + + Memory(const Memory& other); + Memory& operator=(const Memory& other); + }; +} diff --git a/source/RobotAPI/libraries/armem/core/longtermMemory/ProviderSegment.cpp b/source/RobotAPI/libraries/armem/core/longtermMemory/ProviderSegment.cpp new file mode 100644 index 000000000..b53148e18 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/longtermMemory/ProviderSegment.cpp @@ -0,0 +1,45 @@ +#include "ProviderSegment.h" + +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + +#include "error.h" + + +namespace armarx::armem::longtermmemory +{ + + ProviderSegment::ProviderSegment() + { + } + + ProviderSegment::ProviderSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType) : + ProviderSegment(name, MemoryID(), aronType) + { + } + + ProviderSegment::ProviderSegment(const std::string& name, const MemoryID parentID, aron::typenavigator::ObjectNavigatorPtr aronType) : + ProviderSegment(parentID.withProviderSegmentName(name), aronType) + { + } + + ProviderSegment::ProviderSegment(const MemoryID id, aron::typenavigator::ObjectNavigatorPtr aronType) : + armarx::armem::detail::MemoryItem(id), + armarx::armem::detail::TypedEntityContainerBase<Entity, Entity, EntitySnapshot, EntityInstance, ProviderSegment>(id, aronType) + { + } + + ProviderSegment::ProviderSegment(const ProviderSegment& other) : + armarx::armem::detail::MemoryItem(other), + MemoryContainerBase<std::map<std::string, Entity>, ProviderSegment>(other), + armarx::armem::detail::TypedEntityContainerBase<Entity, Entity, EntitySnapshot, EntityInstance, ProviderSegment>(other) + { + // *this = other; + } + + ProviderSegment& ProviderSegment::operator=(const ProviderSegment& other) + { + other._copySelf(*this); + //other._copyElements(*this, true); + return *this; + } +} diff --git a/source/RobotAPI/libraries/armem/core/longtermMemory/ProviderSegment.h b/source/RobotAPI/libraries/armem/core/longtermMemory/ProviderSegment.h new file mode 100644 index 000000000..c204c40eb --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/longtermMemory/ProviderSegment.h @@ -0,0 +1,29 @@ +#pragma once + +#include "../base/ProviderSegment.h" + +#include "Entity.h" +#include "detail/TypedEntityContainer.h" + + +namespace armarx::armem::longtermmemory +{ + + /** + * @brief Data of a provider segment containing multiple entities. + */ + class ProviderSegment : + virtual public ProviderSegmentBase<Entity, EntitySnapshot, EntityInstance, ProviderSegment>, + virtual public detail::TypedEntityContainer<Entity, ProviderSegment> + { + public: + ProviderSegment(); + ProviderSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); + ProviderSegment(const std::string& name, const MemoryID parentID, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); + ProviderSegment(const MemoryID id, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); + + ProviderSegment(const ProviderSegment& other); + ProviderSegment& operator=(const ProviderSegment& other); + }; + +} diff --git a/source/RobotAPI/libraries/armem/core/longtermMemory/detail/EntityContainer.cpp b/source/RobotAPI/libraries/armem/core/longtermMemory/detail/EntityContainer.cpp new file mode 100644 index 000000000..43ade411e --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/longtermMemory/detail/EntityContainer.cpp @@ -0,0 +1,10 @@ +#include "EntityContainer.h" + +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + + +namespace armarx::armem::detail +{ + + +} diff --git a/source/RobotAPI/libraries/armem/core/longtermMemory/detail/EntityContainer.h b/source/RobotAPI/libraries/armem/core/longtermMemory/detail/EntityContainer.h new file mode 100644 index 000000000..155b00912 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/longtermMemory/detail/EntityContainer.h @@ -0,0 +1,32 @@ +#pragma once + +#include "../../base/detail/EntityContainer.h" +#include "MemoryContainer.h" + +#include "../Entity.h" +#include "../EntitySnapshot.h" +#include "../EntityInstance.h" + + +namespace armarx::armem::longtermmemory::detail +{ + + /** + * @brief A container of entities at some point in the hierarchy. + * + * Can be updated by multiple entity updates. + */ + template <class _ValueT, class Derived> + class EntityContainer : + virtual public armarx::armem::detail::EntityContainerBase<_ValueT, Entity, EntitySnapshot, EntityInstance, Derived>, + virtual public MemoryContainer<std::map<std::string, _ValueT>, Derived> + { + public: + EntityContainer& operator=(const EntityContainer& other) + { + other._copySelf(*this); + return *this; + } + }; + +} diff --git a/source/RobotAPI/libraries/armem/core/longtermMemory/detail/MemoryContainer.cpp b/source/RobotAPI/libraries/armem/core/longtermMemory/detail/MemoryContainer.cpp new file mode 100644 index 000000000..9fd73048f --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/longtermMemory/detail/MemoryContainer.cpp @@ -0,0 +1,7 @@ +#include "MemoryContainer.h" + + +namespace armarx::armem::detail +{ + +} diff --git a/source/RobotAPI/libraries/armem/core/longtermMemory/detail/MemoryContainer.h b/source/RobotAPI/libraries/armem/core/longtermMemory/detail/MemoryContainer.h new file mode 100644 index 000000000..5913d50db --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/longtermMemory/detail/MemoryContainer.h @@ -0,0 +1,28 @@ +#pragma once + +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + +#include "../../error.h" + +#include "../../base/detail/MemoryContainer.h" + + +namespace armarx::armem::longtermmemory::detail +{ + + /** + * @class Provides default implmentations of `MemoryContainer`, as well as + * iterators (which requires a template). + */ + template <class _ContainerT, class Derived> + class MemoryContainer : + virtual public armarx::armem::detail::MemoryContainerBase<_ContainerT, Derived> + { + public: + MemoryContainer& operator=(const MemoryContainer& other) + { + other._copySelf(*this); + return *this; + } + }; +} diff --git a/source/RobotAPI/libraries/armem/core/longtermMemory/detail/TypedEntityContainer.h b/source/RobotAPI/libraries/armem/core/longtermMemory/detail/TypedEntityContainer.h new file mode 100644 index 000000000..da5c96c10 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/longtermMemory/detail/TypedEntityContainer.h @@ -0,0 +1,26 @@ +#pragma once + +#include "../../base/detail/TypedEntityContainer.h" +#include "EntityContainer.h" + +#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> + +namespace armarx::armem::longtermmemory::detail +{ + + /** + * @brief An entity container with a specific (Aron) type. + */ + template <class _ValueT, class Derived> + class TypedEntityContainer : + virtual public armarx::armem::detail::TypedEntityContainerBase<_ValueT, Entity, EntitySnapshot, EntityInstance, Derived>, + virtual public EntityContainer<_ValueT, Derived> + { + public: + TypedEntityContainer& operator=(const TypedEntityContainer& other) + { + other._copySelf(*this); + return *this; + } + }; +} diff --git a/source/RobotAPI/libraries/armem/core/longtermMemory/ice_conversions.cpp b/source/RobotAPI/libraries/armem/core/longtermMemory/ice_conversions.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/source/RobotAPI/libraries/armem/core/longtermMemory/ice_conversions.h b/source/RobotAPI/libraries/armem/core/longtermMemory/ice_conversions.h new file mode 100644 index 000000000..e69de29bb diff --git a/source/RobotAPI/libraries/armem/core/workingMemory/CoreSegment.cpp b/source/RobotAPI/libraries/armem/core/workingMemory/CoreSegment.cpp new file mode 100644 index 000000000..9310d7963 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/workingMemory/CoreSegment.cpp @@ -0,0 +1,47 @@ +#include "CoreSegment.h" + +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + +#include "error.h" + + +namespace armarx::armem::workingmemory +{ + + CoreSegment::CoreSegment() + { + } + + CoreSegment::CoreSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType) : + armarx::armem::detail::MemoryItem(MemoryID().withCoreSegmentName(name)), + armarx::armem::detail::TypedEntityContainerBase<ProviderSegment, Entity, EntitySnapshot, EntityInstance, CoreSegment>(MemoryID().withCoreSegmentName(name), aronType) + { + } + + CoreSegment::CoreSegment(const std::string& name, const MemoryID& parentID, aron::typenavigator::ObjectNavigatorPtr aronType) : + armarx::armem::detail::MemoryItem(MemoryID().withCoreSegmentName(name)), + armarx::armem::detail::TypedEntityContainerBase<ProviderSegment, Entity, EntitySnapshot, EntityInstance, CoreSegment>(parentID.withCoreSegmentName(name), aronType) + { + } + + CoreSegment::CoreSegment(const MemoryID& id, aron::typenavigator::ObjectNavigatorPtr aronType) : + armarx::armem::detail::MemoryItem(id), + armarx::armem::detail::TypedEntityContainerBase<ProviderSegment, Entity, EntitySnapshot, EntityInstance, CoreSegment>(id, aronType) + { + } + + CoreSegment::CoreSegment(const CoreSegment& other) : + armarx::armem::detail::MemoryItem(other), + MemoryContainerBase<std::map<std::string, ProviderSegment>, CoreSegment>(other), + armarx::armem::detail::TypedEntityContainerBase<ProviderSegment, Entity, EntitySnapshot, EntityInstance, CoreSegment>(other) + { + // *this = other; + } + + CoreSegment& CoreSegment::operator=(const CoreSegment& other) + { + other._copySelf(*this); + //other._copyElements(*this, true); + return *this; + } +} diff --git a/source/RobotAPI/libraries/armem/core/workingMemory/CoreSegment.h b/source/RobotAPI/libraries/armem/core/workingMemory/CoreSegment.h new file mode 100644 index 000000000..1da46fbf3 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/workingMemory/CoreSegment.h @@ -0,0 +1,31 @@ +#pragma once + +#include "../base/CoreSegment.h" + +#include "ProviderSegment.h" +#include "detail/TypedEntityContainer.h" + + +namespace armarx::armem::workingmemory +{ + + /** + * @brief Data of a core segment containing multiple provider segments. + */ + class CoreSegment : + virtual public CoreSegmentBase<ProviderSegment, Entity, EntitySnapshot, EntityInstance, CoreSegment>, + virtual public detail::TypedEntityContainer<ProviderSegment, CoreSegment> + { + public: + CoreSegment(); + CoreSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); + CoreSegment(const std::string& name, const MemoryID& parentID, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); + CoreSegment(const MemoryID& id, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); + + CoreSegment(const CoreSegment& other); + CoreSegment& operator=(const CoreSegment& other); + + //CoreSegment copyWithoutData() const override; + }; + +} diff --git a/source/RobotAPI/libraries/armem/core/workingMemory/Entity.cpp b/source/RobotAPI/libraries/armem/core/workingMemory/Entity.cpp new file mode 100644 index 000000000..8308070cf --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/workingMemory/Entity.cpp @@ -0,0 +1,33 @@ +#include "Entity.h" + +namespace armarx::armem::workingmemory +{ + + Entity::Entity() + { + } + + Entity::Entity(const std::string& name, const MemoryID& parentID) : + armarx::armem::detail::MemoryItem(parentID.withEntityName(name)) + { + } + + Entity::Entity(const MemoryID& id) : + armarx::armem::detail::MemoryItem(id) + { + } + + Entity::Entity(const Entity& other) : + armarx::armem::detail::MemoryItem(other), + armarx::armem::detail::MemoryContainerBase<std::map<Time, EntitySnapshot>, Entity>(other) + { + // *this = other; + } + + Entity& Entity::operator=(const Entity& other) + { + other._copySelf(*this); + //other._copyElements(*this, true); + return *this; + } +} diff --git a/source/RobotAPI/libraries/armem/core/workingMemory/Entity.h b/source/RobotAPI/libraries/armem/core/workingMemory/Entity.h new file mode 100644 index 000000000..571f02fbd --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/workingMemory/Entity.h @@ -0,0 +1,48 @@ +#pragma once + +#include "../base/Entity.h" + +#include "EntitySnapshot.h" +#include "detail/MemoryContainer.h" + + +namespace armarx::armem::workingmemory +{ + /** + * @brief An entity over a period of time. + * + * An entity should be a physical thing or abstract concept existing + * (and potentially evolving) over some time. + * + * Examples are: + * - objects (the green box) + * - agents (robot, human) + * - locations (frige, sink) + * - grasp affordances (general, or for a specific object) + * - images + * - point clouds + * - other sensory values + * + * At each point in time (`EntitySnapshot`), the entity can have a + * (potentially variable) number of instances (`EntityInstance`), + * each containing a single `AronData` object of a specific `AronType`. + */ + class Entity : + virtual public EntityBase<EntitySnapshot, Entity>, + virtual public detail::MemoryContainer<std::map<Time, EntitySnapshot>, Entity> + { + + public: + Entity(); + Entity(const std::string& name, const MemoryID& parentID = {}); + Entity(const MemoryID& id); + + /// Copy the history from `other` to this. + Entity(const Entity& other); + /// Copy the history from `other` to this. + Entity& operator=(const Entity& other); + + //Entity copyWithoutData() const override; + }; + +} diff --git a/source/RobotAPI/libraries/armem/core/EntityInstance.cpp b/source/RobotAPI/libraries/armem/core/workingMemory/EntityInstance.cpp similarity index 66% rename from source/RobotAPI/libraries/armem/core/EntityInstance.cpp rename to source/RobotAPI/libraries/armem/core/workingMemory/EntityInstance.cpp index c498216cf..624b8ee9a 100644 --- a/source/RobotAPI/libraries/armem/core/EntityInstance.cpp +++ b/source/RobotAPI/libraries/armem/core/workingMemory/EntityInstance.cpp @@ -3,9 +3,17 @@ #include <ArmarXCore/core/exceptions/local/ExpressionException.h> -namespace armarx::armem +namespace armarx::armem::workingmemory { + bool EntityInstanceMetadata::operator==(const EntityInstanceMetadata& other) const + { + return timeCreated == other.timeCreated + && timeSent == other.timeSent + && timeArrived == other.timeArrived + && std::abs(confidence - other.confidence) < 1e-6f; + } + EntityInstance::EntityInstance() { } @@ -15,14 +23,14 @@ namespace armarx::armem { } - EntityInstance::EntityInstance(const MemoryID& id) : MemoryItem(id) + EntityInstance::EntityInstance(const MemoryID& id) : + MemoryItem(id) { } bool EntityInstance::equalsDeep(const EntityInstance& other) const { - //std::cout << "EntityInstance::equalsDeep" << std::endl; return _metadata == other.metadata() && _data->equalsDeep(other.data()); } @@ -40,34 +48,29 @@ namespace armarx::armem this->_metadata.timeArrived = update.timeArrived; } - EntityInstance EntityInstance::copy(bool withData) const + EntityInstance EntityInstance::copy() const { - EntityInstance other(id()); - other._metadata = _metadata; - if (withData) - { - other.setData(_data); - } - return other; + EntityInstance d; + this->_copySelf(d); + return d; } - std::string EntityInstance::getKeyString() const + EntityInstance EntityInstance::copyWithoutData() const { - return std::to_string(index()); + EntityInstance d; + this->_copySelfWithoutData(d); + return d; } - std::string EntityInstance::getLevelName() const + void EntityInstance::_copySelf(EntityInstance& other) const { - return "entity instance"; + EntityInstanceBase<EntityInstance>::_copySelf(other); + other._metadata = _metadata; + other._data = _data; } - - bool EntityInstanceMetadata::operator==(const EntityInstanceMetadata& other) const + void EntityInstance::_copySelfWithoutData(EntityInstance& other) const { - return timeCreated == other.timeCreated - && timeSent == other.timeSent - && timeArrived == other.timeArrived - && std::abs(confidence - other.confidence) < 1e-6f; + EntityInstanceBase<EntityInstance>::_copySelf(other); } - } diff --git a/source/RobotAPI/libraries/armem/core/EntityInstance.h b/source/RobotAPI/libraries/armem/core/workingMemory/EntityInstance.h similarity index 68% rename from source/RobotAPI/libraries/armem/core/EntityInstance.h rename to source/RobotAPI/libraries/armem/core/workingMemory/EntityInstance.h index 25311339e..45a1c3e76 100644 --- a/source/RobotAPI/libraries/armem/core/EntityInstance.h +++ b/source/RobotAPI/libraries/armem/core/workingMemory/EntityInstance.h @@ -1,15 +1,8 @@ #pragma once -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/core/navigator/data/container/Dict.h> +#include "../base/EntityInstance.h" -#include "../core/Time.h" - -#include "Commit.h" -#include "detail/MemoryItem.h" - - -namespace armarx::armem +namespace armarx::armem::workingmemory { /** @@ -35,28 +28,18 @@ namespace armarx::armem } }; - /** * @brief Data of a single entity instance. */ - class EntityInstance : public detail::MemoryItem + class EntityInstance : + virtual public EntityInstanceBase<EntityInstance> { - public: + public: EntityInstance(); EntityInstance(int index, const MemoryID& parentID = {}); EntityInstance(const MemoryID& id); - - inline int& index() - { - return id().instanceIndex; - } - inline int index() const - { - return id().instanceIndex; - } - EntityInstanceMetadata& metadata() { return _metadata; @@ -70,6 +53,7 @@ namespace armarx::armem { return _data; } + void setData(const aron::datanavigator::DictNavigatorPtr& data) { this->_data = data; @@ -81,28 +65,23 @@ namespace armarx::armem * @param update The update. * @param index The instances index. */ - void update(const EntityUpdate& update, int index); + virtual void update(const EntityUpdate& update, int index) override; + virtual bool equalsDeep(const EntityInstance& other) const override; - EntityInstance copy(bool withData = true) const; + virtual EntityInstance copy() const override; + virtual EntityInstance copyWithoutData() const; - bool equalsDeep(const EntityInstance& other) const; - - - // MemoryItem interface - public: - std::string getKeyString() const override; - std::string getLevelName() const override; + protected: + virtual void _copySelf(EntityInstance& other) const override; + virtual void _copySelfWithoutData(EntityInstance& other) const; private: - /// The metadata. EntityInstanceMetadata _metadata; /// The data. May be nullptr. armarx::aron::datanavigator::DictNavigatorPtr _data; - }; - } diff --git a/source/RobotAPI/libraries/armem/core/workingMemory/EntitySnapshot.cpp b/source/RobotAPI/libraries/armem/core/workingMemory/EntitySnapshot.cpp new file mode 100644 index 000000000..ad4bc9ef6 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/workingMemory/EntitySnapshot.cpp @@ -0,0 +1,45 @@ +#include "EntitySnapshot.h" + +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + +#include "error.h" + + +namespace armarx::armem::workingmemory +{ + + + EntitySnapshot::EntitySnapshot() + { + } + + EntitySnapshot::EntitySnapshot(Time time, const MemoryID& parentID) : + EntitySnapshot(parentID.withTimestamp(time)) + { + } + + EntitySnapshot::EntitySnapshot(const MemoryID& id) : + MemoryItem(id) + { + } + + EntitySnapshot::EntitySnapshot(const EntitySnapshot& other) : + armarx::armem::detail::MemoryItem(other), + armarx::armem::detail::MemoryContainerBase<std::vector<EntityInstance>, EntitySnapshot>(other) + { + // *this = other; + } + + EntitySnapshot& EntitySnapshot::operator=(const EntitySnapshot& other) + { + other._copySelf(*this); + //other._copyElements(*this, true); + return *this; + } + + /*EntitySnapshot EntitySnapshot::copy(bool withData) const + { + //auto cast = dynamic_cast<const Derived*>(this); + return Base2::copy(withData); + }*/ +} diff --git a/source/RobotAPI/libraries/armem/core/workingMemory/EntitySnapshot.h b/source/RobotAPI/libraries/armem/core/workingMemory/EntitySnapshot.h new file mode 100644 index 000000000..b5671aaaf --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/workingMemory/EntitySnapshot.h @@ -0,0 +1,33 @@ +#pragma once + +#include "../base/EntitySnapshot.h" + +#include "EntityInstance.h" +#include "detail/MemoryContainer.h" + + +namespace armarx::armem::workingmemory +{ + + /** + * @brief Data of an entity at one point in time. + */ + class EntitySnapshot : + virtual public EntitySnapshotBase<EntityInstance, EntitySnapshot>, + virtual public detail::MemoryContainer<std::vector<EntityInstance>, EntitySnapshot> + { + + public: + EntitySnapshot(); + EntitySnapshot(Time time, const MemoryID& parentID = {}); + EntitySnapshot(const MemoryID& id); + + /// Copy the instances from `other` to this. + EntitySnapshot(const EntitySnapshot& other); + + /// Copy the instances from `other` to this. + EntitySnapshot& operator=(const EntitySnapshot& other); + + //EntitySnapshot copyWithoutData() const override; + }; +} diff --git a/source/RobotAPI/libraries/armem/core/workingMemory/Memory.cpp b/source/RobotAPI/libraries/armem/core/workingMemory/Memory.cpp new file mode 100644 index 000000000..250649091 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/workingMemory/Memory.cpp @@ -0,0 +1,40 @@ +#include "Memory.h" + +#include <ArmarXCore/core/logging/Logging.h> +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + +#include "error.h" + + +namespace armarx::armem::workingmemory +{ + + Memory::Memory() + { + } + + Memory::Memory(const std::string& name) : + armarx::armem::detail::MemoryItem(MemoryID().withMemoryName(name)) + { + std::cout << "Memory: My name is: " << this->name() << std::endl; + } + + Memory::Memory(const MemoryID& id) : + MemoryItem(id) + { + } + + Memory::Memory(const Memory& other) : + armarx::armem::detail::MemoryItem(other), + MemoryContainerBase<std::map<std::string, CoreSegment>, Memory>(other) + { + *this = other; + } + + Memory& Memory::operator=(const Memory& other) + { + other._copySelf(*this); + //other._copyElements(*this, true); + return *this; + } +} diff --git a/source/RobotAPI/libraries/armem/core/workingMemory/Memory.h b/source/RobotAPI/libraries/armem/core/workingMemory/Memory.h new file mode 100644 index 000000000..18e748cbb --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/workingMemory/Memory.h @@ -0,0 +1,28 @@ +#pragma once + +#include "../base/Memory.h" + +#include "CoreSegment.h" +#include "detail/EntityContainer.h" + +namespace armarx::armem::workingmemory +{ + + /** + * @brief Data of a memory consisting of multiple core segments. + */ + class Memory : + virtual public MemoryBase<CoreSegment, Entity, EntitySnapshot, EntityInstance, Memory>, + virtual public detail::EntityContainer<CoreSegment, Memory> + { + public: + Memory(); + Memory(const std::string& name); + Memory(const MemoryID& id); + + Memory(const Memory& other); + Memory& operator=(const Memory& other); + + //CoreSegment copyWithoutData() const override; + }; +} diff --git a/source/RobotAPI/libraries/armem/core/workingMemory/ProviderSegment.cpp b/source/RobotAPI/libraries/armem/core/workingMemory/ProviderSegment.cpp new file mode 100644 index 000000000..2e43d2ceb --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/workingMemory/ProviderSegment.cpp @@ -0,0 +1,48 @@ +#include "ProviderSegment.h" + +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + +#include "error.h" + + +namespace armarx::armem::workingmemory +{ + + ProviderSegment::ProviderSegment() + { + } + + ProviderSegment::ProviderSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType) : + armarx::armem::detail::MemoryItem(MemoryID().withProviderSegmentName(name)), + armarx::armem::detail::TypedEntityContainerBase<Entity, Entity, EntitySnapshot, EntityInstance, ProviderSegment>(MemoryID().withProviderSegmentName(name), aronType) + { + } + + ProviderSegment::ProviderSegment(const std::string& name, const MemoryID parentID, aron::typenavigator::ObjectNavigatorPtr aronType) : + armarx::armem::detail::MemoryItem(parentID.withProviderSegmentName(name)), + armarx::armem::detail::TypedEntityContainerBase<Entity, Entity, EntitySnapshot, EntityInstance, ProviderSegment>(parentID.withProviderSegmentName(name), aronType) + { + } + + ProviderSegment::ProviderSegment(const MemoryID id, aron::typenavigator::ObjectNavigatorPtr aronType) : + armarx::armem::detail::MemoryItem(id), + armarx::armem::detail::TypedEntityContainerBase<Entity, Entity, EntitySnapshot, EntityInstance, ProviderSegment>(id, aronType) + { + } + + ProviderSegment::ProviderSegment(const ProviderSegment& other) : + armarx::armem::detail::MemoryItem(other), + MemoryContainerBase<std::map<std::string, Entity>, ProviderSegment>(other), + armarx::armem::detail::TypedEntityContainerBase<Entity, Entity, EntitySnapshot, EntityInstance, ProviderSegment>(other) + { + // *this = other; + } + + ProviderSegment& ProviderSegment::operator=(const ProviderSegment& other) + { + other._copySelf(*this); + //other._copyElements(*this, true); + return *this; + } + +} diff --git a/source/RobotAPI/libraries/armem/core/workingMemory/ProviderSegment.h b/source/RobotAPI/libraries/armem/core/workingMemory/ProviderSegment.h new file mode 100644 index 000000000..482e189be --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/workingMemory/ProviderSegment.h @@ -0,0 +1,31 @@ +#pragma once + +#include "../base/ProviderSegment.h" + +#include "Entity.h" +#include "detail/TypedEntityContainer.h" + + +namespace armarx::armem::workingmemory +{ + + /** + * @brief Data of a provider segment containing multiple entities. + */ + class ProviderSegment : + virtual public ProviderSegmentBase<Entity, EntitySnapshot, EntityInstance, ProviderSegment>, + virtual public detail::TypedEntityContainer<Entity, ProviderSegment> + { + public: + ProviderSegment(); + ProviderSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); + ProviderSegment(const std::string& name, const MemoryID parentID, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); + ProviderSegment(const MemoryID id, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); + + ProviderSegment(const ProviderSegment& other); + ProviderSegment& operator=(const ProviderSegment& other); + + //ProviderSegment copyWithoutData() const override; + }; + +} diff --git a/source/RobotAPI/libraries/armem/core/workingMemory/detail/EntityContainer.cpp b/source/RobotAPI/libraries/armem/core/workingMemory/detail/EntityContainer.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/source/RobotAPI/libraries/armem/core/workingMemory/detail/EntityContainer.h b/source/RobotAPI/libraries/armem/core/workingMemory/detail/EntityContainer.h new file mode 100644 index 000000000..a4ccb8ffc --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/workingMemory/detail/EntityContainer.h @@ -0,0 +1,32 @@ +#pragma once + +#include "../../base/detail/EntityContainer.h" +#include "MemoryContainer.h" + +#include "../Entity.h" +#include "../EntitySnapshot.h" +#include "../EntityInstance.h" + + +namespace armarx::armem::workingmemory::detail +{ + + /** + * @brief A container of entities at some point in the hierarchy. + * + * Can be updated by multiple entity updates. + */ + template <class _ValueT, class Derived> + class EntityContainer : + virtual public armarx::armem::detail::EntityContainerBase<_ValueT, Entity, EntitySnapshot, EntityInstance, Derived>, + virtual public MemoryContainer<std::map<std::string, _ValueT>, Derived> + { + public: + EntityContainer& operator=(const EntityContainer& other) + { + other._copySelf(*this); + return *this; + } + }; + +} diff --git a/source/RobotAPI/libraries/armem/core/workingMemory/detail/MemoryContainer.cpp b/source/RobotAPI/libraries/armem/core/workingMemory/detail/MemoryContainer.cpp new file mode 100644 index 000000000..9fd73048f --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/workingMemory/detail/MemoryContainer.cpp @@ -0,0 +1,7 @@ +#include "MemoryContainer.h" + + +namespace armarx::armem::detail +{ + +} diff --git a/source/RobotAPI/libraries/armem/core/workingMemory/detail/MemoryContainer.h b/source/RobotAPI/libraries/armem/core/workingMemory/detail/MemoryContainer.h new file mode 100644 index 000000000..06d98823e --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/workingMemory/detail/MemoryContainer.h @@ -0,0 +1,35 @@ +#pragma once + +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + +#include "../../error.h" + +#include "../../base/detail/MemoryContainer.h" + + +namespace armarx::armem::workingmemory::detail +{ + + /** + * @class Provides default implmentations of `MemoryContainer`, as well as + * iterators (which requires a template). + */ + template <class _ContainerT, class Derived> + class MemoryContainer : + virtual public armarx::armem::detail::MemoryContainerBase<_ContainerT, Derived> + { + public: + MemoryContainer& operator=(const MemoryContainer& other) + { + other._copySelf(*this); + return *this; + } + + // Copying + virtual Derived copyWithoutData() const + { + //auto cast = dynamic_cast<const Derived*>(this); + return armarx::armem::detail::MemoryContainerBase<_ContainerT, Derived>::copy(); + } + }; +} diff --git a/source/RobotAPI/libraries/armem/core/workingMemory/detail/TypedEntityContainer.h b/source/RobotAPI/libraries/armem/core/workingMemory/detail/TypedEntityContainer.h new file mode 100644 index 000000000..ce775841c --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/workingMemory/detail/TypedEntityContainer.h @@ -0,0 +1,26 @@ +#pragma once + +#include "../../base/detail/TypedEntityContainer.h" +#include "EntityContainer.h" + +#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> + +namespace armarx::armem::workingmemory::detail +{ + + /** + * @brief An entity container with a specific (Aron) type. + */ + template <class _ValueT, class Derived> + class TypedEntityContainer : + virtual public armarx::armem::detail::TypedEntityContainerBase<_ValueT, Entity, EntitySnapshot, EntityInstance, Derived>, + virtual public EntityContainer<_ValueT, Derived> + { + public: + TypedEntityContainer& operator=(const TypedEntityContainer& other) + { + other._copySelf(*this); + return *this; + } + }; +} diff --git a/source/RobotAPI/libraries/armem/core/workingMemory/ice_conversions.cpp b/source/RobotAPI/libraries/armem/core/workingMemory/ice_conversions.cpp new file mode 100644 index 000000000..03c0e1f84 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/workingMemory/ice_conversions.cpp @@ -0,0 +1,126 @@ +#include "ice_conversions.h" + +using namespace armarx::armem::workingmemory; + +namespace armarx +{ + void armem::toIce(data::EntityInstanceMetadata& ice, const EntityInstanceMetadata& metadata) + { + ice.confidence = metadata.confidence; + toIce(ice.timeArrivedMicroSeconds, metadata.timeArrived); + toIce(ice.timeCreatedMicroSeconds, metadata.timeCreated); + toIce(ice.timeSentMicroSeconds, metadata.timeSent); + } + void armem::fromIce(const data::EntityInstanceMetadata& ice, EntityInstanceMetadata& metadata) + { + metadata.confidence = ice.confidence; + fromIce(ice.timeArrivedMicroSeconds, metadata.timeArrived); + fromIce(ice.timeCreatedMicroSeconds, metadata.timeCreated); + fromIce(ice.timeSentMicroSeconds, metadata.timeSent); + } + + void armem::toIce(data::EntityInstance& ice, const EntityInstance& data) + { + detail::toIceItem(ice, data); + + if (data.data()) + { + ice.data = data.data()->toAronDictPtr(); + } + toIce(ice.metadata, data.metadata()); + } + void armem::fromIce(const data::EntityInstance& ice, EntityInstance& data) + { + detail::fromIceItem(ice, data); + + if (ice.data) + { + data.setData(aron::datanavigator::DictNavigator::FromAronDictPtr(ice.data)); + } + fromIce(ice.metadata, data.metadata()); + } + + + void armem::toIce(data::EntitySnapshot& ice, const EntitySnapshot& snapshot) + { + detail::toIceItem(ice, snapshot); + + toIce(ice.instances, snapshot.instances); + } + void armem::fromIce(const data::EntitySnapshot& ice, EntitySnapshot& snapshot) + { + detail::fromIceItem(ice, snapshot); + + fromIce(ice.instances, snapshot.instances); + } + + void armem::toIce(data::Entity& ice, const Entity& entity) + { + detail::toIceItem(ice, entity); + + toIce(ice.history, entity.history); + } + void armem::fromIce(const data::Entity& ice, Entity& entity) + { + detail::fromIceItem(ice, entity); + + fromIce(ice.history, entity.history); + } + + + void armem::toIce(data::ProviderSegment& ice, const ProviderSegment& providerSegment) + { + detail::toIceItem(ice, providerSegment); + + if (providerSegment.hasAronType()) + { + ice.aronType = providerSegment.aronType->getResult(); + } + toIce(ice.entities, providerSegment.entities); + } + void armem::fromIce(const data::ProviderSegment& ice, ProviderSegment& providerSegment) + { + detail::fromIceItem(ice, providerSegment); + + if (ice.aronType) + { + providerSegment.aronType = aron::typenavigator::ObjectNavigator::DynamicCastAndCheck(aron::typenavigator::Navigator::FromAronType(ice.aronType)); + } + fromIce(ice.entities, providerSegment.entities); + } + + void armem::toIce(data::CoreSegment& ice, const CoreSegment& coreSegment) + { + detail::toIceItem(ice, coreSegment); + + if (coreSegment.hasAronType()) + { + ice.aronType = coreSegment.aronType->getResult(); + } + toIce(ice.providerSegments, coreSegment.providerSegments); + } + void armem::fromIce(const data::CoreSegment& ice, CoreSegment& coreSegment) + { + detail::fromIceItem(ice, coreSegment); + + if (ice.aronType) + { + coreSegment.aronType = aron::typenavigator::ObjectNavigator::DynamicCastAndCheck(aron::typenavigator::Navigator::FromAronType(ice.aronType)); + } + fromIce(ice.providerSegments, coreSegment.providerSegments); + } + + void armem::toIce(data::Memory& ice, const Memory& memory) + { + detail::toIceItem(ice, memory); + + toIce(ice.coreSegments, memory.coreSegments); + } + void armem::fromIce(const data::Memory& ice, Memory& memory) + { + detail::fromIceItem(ice, memory); + + fromIce(ice.coreSegments, memory.coreSegments); + } + +} diff --git a/source/RobotAPI/libraries/armem/core/workingMemory/ice_conversions.h b/source/RobotAPI/libraries/armem/core/workingMemory/ice_conversions.h new file mode 100644 index 000000000..e5996b001 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/workingMemory/ice_conversions.h @@ -0,0 +1,35 @@ +#pragma once + +#include <RobotAPI/interface/armem/commit.h> +#include <RobotAPI/interface/armem/memory.h> + +#include "../ice_conversions.h" + +#include "Memory.h" + + +namespace armarx::armem +{ + void toIce(data::EntityInstanceMetadata& ice, const workingmemory::EntityInstanceMetadata& metadata); + void fromIce(const data::EntityInstanceMetadata& ice, workingmemory::EntityInstanceMetadata& metadata); + + void toIce(data::EntityInstance& ice, const workingmemory::EntityInstance& data); + void fromIce(const data::EntityInstance& ice, workingmemory::EntityInstance& data); + + + void toIce(data::EntitySnapshot& ice, const workingmemory::EntitySnapshot& snapshot); + void fromIce(const data::EntitySnapshot& ice, workingmemory::EntitySnapshot& snapshot); + + void toIce(data::Entity& ice, const workingmemory::Entity& entity); + void fromIce(const data::Entity& ice, workingmemory::Entity& entity); + + + void toIce(data::ProviderSegment& ice, const workingmemory::ProviderSegment& providerSegment); + void fromIce(const data::ProviderSegment& ice, workingmemory::ProviderSegment& providerSegment); + + void toIce(data::CoreSegment& ice, const workingmemory::CoreSegment& coreSegment); + void fromIce(const data::CoreSegment& ice, workingmemory::CoreSegment& coreSegment); + + void toIce(data::Memory& ice, const workingmemory::Memory& memory); + void fromIce(const data::Memory& ice, workingmemory::Memory& memory); +} diff --git a/source/RobotAPI/libraries/armem/server/ComponentPlugin.cpp b/source/RobotAPI/libraries/armem/server/ComponentPlugin.cpp index 6d045663f..f39e7a2df 100644 --- a/source/RobotAPI/libraries/armem/server/ComponentPlugin.cpp +++ b/source/RobotAPI/libraries/armem/server/ComponentPlugin.cpp @@ -6,7 +6,7 @@ #include "MemoryToIceAdapter.h" -#include <RobotAPI/libraries/armem/core/io/diskWriter/NlohmannJSON/NlohmannJSONDiskWriter.h> +//#include <RobotAPI/libraries/armem/core/io/diskWriter/NlohmannJSON/NlohmannJSONDiskWriter.h> namespace armarx::armem::server::plugins { @@ -50,7 +50,7 @@ namespace armarx::armem::server::plugins data::RegisterMemoryResult ComponentPlugin::registerMemory(ComponentPluginUser& parent) { data::RegisterMemoryInput input; - input.name = parent.memory.name(); + input.name = parent.workingmemory.name(); input.proxy = MemoryInterfacePrx::checkedCast(parent.getProxy()); ARMARX_CHECK_NOT_NULL(input.proxy); data::RegisterMemoryResult result = parent.memoryNameSystem->registerMemory(input); @@ -73,7 +73,7 @@ namespace armarx::armem::server::plugins try { data::RemoveMemoryInput input; - input.name = parent.memory.name(); + input.name = parent.workingmemory.name(); result = parent.memoryNameSystem->removeMemory(input); if (result.success) { @@ -114,7 +114,7 @@ namespace armarx::armem::server data::AddSegmentsResult ComponentPluginUser::addSegments(const data::AddSegmentsInput& input, bool addCoreSegments) { - std::scoped_lock lock(memoryMutex); + std::scoped_lock lock(workingmemoryMutex); data::AddSegmentsResult result = iceMemory.addSegments(input, addCoreSegments); return result; } @@ -122,7 +122,7 @@ namespace armarx::armem::server data::CommitResult ComponentPluginUser::commit(const data::Commit& commitIce, const Ice::Current&) { - std::scoped_lock lock(memoryMutex); + std::scoped_lock lock(workingmemoryMutex); return iceMemory.commit(commitIce); } @@ -130,14 +130,14 @@ namespace armarx::armem::server // READING armem::query::data::Result ComponentPluginUser::query(const armem::query::data::Input& input, const Ice::Current&) { - std::scoped_lock lock(memoryMutex); + std::scoped_lock lock(workingmemoryMutex); return iceMemory.query(input); } // LTM LOADING data::StoreResult ComponentPluginUser::store(const data::StoreInput& input, const Ice::Current&) { - std::scoped_lock lock(memoryMutex); + std::scoped_lock lock(workingmemoryMutex); return iceMemory.store(input); } @@ -145,7 +145,7 @@ namespace armarx::armem::server // LTM STORING data::LoadResult ComponentPluginUser::load(const data::LoadInput& input, const Ice::Current&) { - std::scoped_lock lock(memoryMutex); + std::scoped_lock lock(workingmemoryMutex); return iceMemory.load(input); } diff --git a/source/RobotAPI/libraries/armem/server/ComponentPlugin.h b/source/RobotAPI/libraries/armem/server/ComponentPlugin.h index 6f69c2f41..12db6a741 100644 --- a/source/RobotAPI/libraries/armem/server/ComponentPlugin.h +++ b/source/RobotAPI/libraries/armem/server/ComponentPlugin.h @@ -8,7 +8,9 @@ #include <RobotAPI/interface/armem/client/MemoryListenerInterface.h> #include <RobotAPI/interface/armem/mns/MemoryNameSystemInterface.h> -#include "../core/Memory.h" +#include "../core/workingMemory/Memory.h" +#include "../core/longtermMemory/Memory.h" + #include "../mns/ClientPlugin.h" #include "MemoryToIceAdapter.h" @@ -94,11 +96,11 @@ namespace armarx::armem::server public: /// The actual memory. - Memory memory; - std::mutex memoryMutex; + workingmemory::Memory workingmemory; + std::mutex workingmemoryMutex; - io::DiskMemory diskMemory; - std::mutex diskMemoryMutex; + longtermmemory::Memory longtermmemory; + std::mutex longtermmemoryMutex; /// property defaults std::string memoryListenerDefaultName = "MemoryUpdates"; @@ -107,7 +109,7 @@ namespace armarx::armem::server std::string longTermMemoryDatabasePasswordDefault = ""; /// Helps connecting `memory` to ice. Used to handle Ice callbacks. - MemoryToIceAdapter iceMemory { &memory, &diskMemory}; + MemoryToIceAdapter iceMemory { &workingmemory, &longtermmemory}; private: diff --git a/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.cpp b/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.cpp index b2ada310d..b6a1ffc5d 100644 --- a/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.cpp +++ b/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.cpp @@ -13,7 +13,7 @@ namespace armarx::armem::server { - MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const Memory& memory) const + MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const workingmemory::Memory& memory) const { GroupBox group; group.setLabel(makeGroupLabel("Memory", memory.name(), memory.coreSegments.size())); @@ -32,7 +32,7 @@ namespace armarx::armem::server - MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const CoreSegment& coreSegment) const + MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const workingmemory::CoreSegment& coreSegment) const { GroupBox group; group.setLabel(makeGroupLabel("Core Segment", coreSegment.name(), coreSegment.providerSegments.size())); @@ -51,7 +51,7 @@ namespace armarx::armem::server - MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const ProviderSegment& providerSegment) const + MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const workingmemory::ProviderSegment& providerSegment) const { GroupBox group; group.setLabel(makeGroupLabel("Provider Segment", providerSegment.name(), providerSegment.entities.size())); @@ -70,7 +70,7 @@ namespace armarx::armem::server - MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const Entity& entity) const + MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const workingmemory::Entity& entity) const { GroupBox group; group.setLabel(makeGroupLabel("Entity", entity.name(), entity.history.size())); @@ -110,7 +110,7 @@ namespace armarx::armem::server - MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const EntitySnapshot& snapshot) const + MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const workingmemory::EntitySnapshot& snapshot) const { GroupBox group; group.setLabel(makeGroupLabel("t", armem::toDateTimeMilliSeconds(snapshot.time()), @@ -120,7 +120,7 @@ namespace armarx::armem::server { group.addChild(Label(makeNoItemsMessage("instances"))); } - for (const EntityInstance& instance : snapshot.instances) + for (const workingmemory::EntityInstance& instance : snapshot.instances) { group.addChild(makeGroupBox(instance)); } @@ -129,7 +129,7 @@ namespace armarx::armem::server return group; } - MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const EntityInstance& instance) const + MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const workingmemory::EntityInstance& instance) const { GroupBox group; diff --git a/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.h b/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.h index 4ce866f15..59ebb3128 100644 --- a/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.h +++ b/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.h @@ -2,7 +2,7 @@ #include <ArmarXGui/libraries/RemoteGui/Client/Widgets.h> -#include "../core/Memory.h" +#include "../core/workingMemory/Memory.h" namespace armarx::armem::server @@ -17,12 +17,12 @@ namespace armarx::armem::server using GroupBox = armarx::RemoteGui::Client::GroupBox; using Label = armarx::RemoteGui::Client::Label; - GroupBox makeGroupBox(const Memory& memory) const; - GroupBox makeGroupBox(const CoreSegment& coreSegment) const; - GroupBox makeGroupBox(const ProviderSegment& providerSegment) const; - GroupBox makeGroupBox(const Entity& entity) const; - GroupBox makeGroupBox(const EntitySnapshot& entitySnapshot) const; - GroupBox makeGroupBox(const EntityInstance& instance) const; + GroupBox makeGroupBox(const workingmemory::Memory& memory) const; + GroupBox makeGroupBox(const workingmemory::CoreSegment& coreSegment) const; + GroupBox makeGroupBox(const workingmemory::ProviderSegment& providerSegment) const; + GroupBox makeGroupBox(const workingmemory::Entity& entity) const; + GroupBox makeGroupBox(const workingmemory::EntitySnapshot& entitySnapshot) const; + GroupBox makeGroupBox(const workingmemory::EntityInstance& instance) const; std::string makeGroupLabel(const std::string& term, const std::string& name, size_t size, diff --git a/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp b/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp index 99650473a..955fb203f 100644 --- a/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp +++ b/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp @@ -6,13 +6,13 @@ #include "../core/ice_conversions.h" #include "query_proc/MemoryQueryProcessor.h" -#include "../core/io/diskWriter/NlohmannJSON/NlohmannJSONDiskWriter.h" -#include "../core/io/diskReader/NlohmannJSON/NlohmannJSONDiskReader.h" +//#include "../core/io/diskWriter/NlohmannJSON/NlohmannJSONDiskWriter.h" +//#include "../core/io/diskReader/NlohmannJSON/NlohmannJSONDiskReader.h" namespace armarx::armem::server { - MemoryToIceAdapter::MemoryToIceAdapter(Memory* memory, io::DiskMemory* diskMemory) : memory(memory), diskMemory(diskMemory) + MemoryToIceAdapter::MemoryToIceAdapter(workingmemory::Memory* workingmemory, longtermmemory::Memory* longtermmemory) : workingmemory(workingmemory), longtermmemory(longtermmemory) { } @@ -29,20 +29,20 @@ namespace armarx::armem::server MemoryToIceAdapter::addSegment(const data::AddSegmentInput& input, bool addCoreSegments) { ARMARX_DEBUG << "Adding segment '" << input.coreSegmentName << "/" << input.providerSegmentName << "'."; - ARMARX_CHECK_NOT_NULL(memory); + ARMARX_CHECK_NOT_NULL(workingmemory); data::AddSegmentResult output; - armem::CoreSegment* coreSegment = nullptr; + armem::workingmemory::CoreSegment* coreSegment = nullptr; try { - coreSegment = &memory->getCoreSegment(input.coreSegmentName); + coreSegment = &workingmemory->getCoreSegment(input.coreSegmentName); } catch (const armem::error::MissingEntry& e) { if (addCoreSegments) { - coreSegment = &memory->addCoreSegment(input.coreSegmentName); + coreSegment = &workingmemory->addCoreSegment(input.coreSegmentName); } else { @@ -64,14 +64,14 @@ namespace armarx::armem::server // This is ok. if (input.clearWhenExists) { - ProviderSegment& provider = coreSegment->getProviderSegment(input.providerSegmentName); + workingmemory::ProviderSegment& provider = coreSegment->getProviderSegment(input.providerSegmentName); provider.clear(); } } } armem::MemoryID segmentID; - segmentID.memoryName = memory->name(); + segmentID.memoryName = workingmemory->name(); segmentID.coreSegmentName = input.coreSegmentName; segmentID.providerSegmentName = input.providerSegmentName; @@ -84,7 +84,7 @@ namespace armarx::armem::server data::AddSegmentsResult MemoryToIceAdapter::addSegments(const data::AddSegmentsInput& input, bool addCoreSegments) { - ARMARX_CHECK_NOT_NULL(memory); + ARMARX_CHECK_NOT_NULL(workingmemory); data::AddSegmentsResult output; for (const auto& i : input) @@ -97,7 +97,7 @@ namespace armarx::armem::server data::CommitResult MemoryToIceAdapter::commit(const data::Commit& commitIce, Time timeArrived) { - ARMARX_CHECK_NOT_NULL(memory); + ARMARX_CHECK_NOT_NULL(workingmemory); armem::Commit commit; armem::fromIce(commitIce, commit, timeArrived); @@ -129,7 +129,7 @@ namespace armarx::armem::server EntityUpdateResult& result = commitResult.results.emplace_back(); try { - MemoryID snapshotID = memory->update(update); + MemoryID snapshotID = workingmemory->update(update); result.success = true; result.snapshotID = snapshotID; @@ -161,23 +161,20 @@ namespace armarx::armem::server armem::query::data::Result MemoryToIceAdapter::query(const armem::query::data::Input& input) { - ARMARX_CHECK_NOT_NULL(memory); + ARMARX_CHECK_NOT_NULL(workingmemory); armem::query_proc::MemoryQueryProcessor processor( input.withData ? armem::DataMode::WithData : armem::DataMode::NoData); - return processor.process(input, *memory); + return processor.process(input, *workingmemory); } // LTM LOADING data::LoadResult MemoryToIceAdapter::load(const armem::data::LoadInput& input) { - ARMARX_CHECK_NOT_NULL(diskMemory); + ARMARX_CHECK_NOT_NULL(longtermmemory); data::LoadResult output; - // read full memory. TODO: only read part of memory - std::filesystem::path x; - output.success = true; return output; } @@ -185,15 +182,22 @@ namespace armarx::armem::server // LTM STORING data::StoreResult MemoryToIceAdapter::store(const armem::data::StoreInput& input) { - ARMARX_CHECK_NOT_NULL(memory); - ARMARX_CHECK_NOT_NULL(diskMemory); + ARMARX_CHECK_NOT_NULL(workingmemory); + ARMARX_CHECK_NOT_NULL(longtermmemory); data::StoreResult output; - // Write full memory. TODO: only write part of memory - std::filesystem::path x; - diskMemory->append(*memory); + // query workingMemory + armem::query::data::Result queryResult = this->query(input.query); + + if (queryResult.success) + { + + } + else + { + output.success = false; + } - output.success = true; return output; } diff --git a/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.h b/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.h index 0bee460e6..1d74fbb5b 100644 --- a/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.h +++ b/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.h @@ -3,8 +3,8 @@ #include <RobotAPI/interface/armem/server/MemoryInterface.h> #include <RobotAPI/interface/armem/client/MemoryListenerInterface.h> -#include "../core/Memory.h" -#include "../core/io/DiskMemory.h" +#include "../core/workingMemory/Memory.h" +#include "../core/longtermMemory/Memory.h" namespace armarx::armem::server @@ -22,7 +22,7 @@ namespace armarx::armem::server public: /// Construct an MemoryToIceAdapter from an existing Memory. - MemoryToIceAdapter(Memory* memory = nullptr, io::DiskMemory* diskMemory = nullptr); + MemoryToIceAdapter(workingmemory::Memory* workingmemory = nullptr, longtermmemory::Memory* longtermmemory = nullptr); void setMemoryListener(client::MemoryListenerInterfacePrx memoryListener); @@ -50,8 +50,8 @@ namespace armarx::armem::server public: - Memory* memory; - io::DiskMemory* diskMemory; + workingmemory::Memory* workingmemory; + longtermmemory::Memory* longtermmemory; client::MemoryListenerInterfacePrx memoryListener; diff --git a/source/RobotAPI/libraries/armem/server/query_proc/CoreSegmentQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/CoreSegmentQueryProcessor.cpp index 9cdb90508..77c0cadab 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/CoreSegmentQueryProcessor.cpp +++ b/source/RobotAPI/libraries/armem/server/query_proc/CoreSegmentQueryProcessor.cpp @@ -12,7 +12,7 @@ namespace armarx::armem::query_proc { - void CoreSegmentQueryProcessor::process(CoreSegment& result, const armem::query::data::CoreSegmentQuery& query, const CoreSegment& coreSegment) const + void CoreSegmentQueryProcessor::process(workingmemory::CoreSegment& result, const armem::query::data::CoreSegmentQuery& query, const workingmemory::CoreSegment& coreSegment) const { if (auto q = dynamic_cast<const armem::query::data::core::All*>(&query)) { @@ -33,8 +33,8 @@ namespace armarx::armem::query_proc } - void CoreSegmentQueryProcessor::process(CoreSegment& result, - const armem::query::data::core::All& query, const CoreSegment& coreSegment) const + void CoreSegmentQueryProcessor::process(workingmemory::CoreSegment& result, + const armem::query::data::core::All& query, const workingmemory::CoreSegment& coreSegment) const { for (const auto& [name, providerSegment] : coreSegment.providerSegments) { @@ -42,12 +42,12 @@ namespace armarx::armem::query_proc } } - void CoreSegmentQueryProcessor::process(CoreSegment& result, - const armem::query::data::core::Single& query, const CoreSegment& coreSegment) const + void CoreSegmentQueryProcessor::process(workingmemory::CoreSegment& result, + const armem::query::data::core::Single& query, const workingmemory::CoreSegment& coreSegment) const { try { - const ProviderSegment& providerSegment = coreSegment.getProviderSegment(query.providerSegmentName); + const workingmemory::ProviderSegment& providerSegment = coreSegment.getProviderSegment(query.providerSegmentName); result.addProviderSegment(providerSegmentProcessor.process(query.providerSegmentQueries, providerSegment)); } catch (const error::MissingEntry&) @@ -56,8 +56,8 @@ namespace armarx::armem::query_proc } } - void CoreSegmentQueryProcessor::process(CoreSegment& result, - const armem::query::data::core::Regex& query, const CoreSegment& coreSegment) const + void CoreSegmentQueryProcessor::process(workingmemory::CoreSegment& result, + const armem::query::data::core::Regex& query, const workingmemory::CoreSegment& coreSegment) const { std::regex regex(query.providerSegmentNameRegex); for (const auto& [name, providerSegment] : coreSegment.providerSegments) @@ -71,7 +71,7 @@ namespace armarx::armem::query_proc data::CoreSegment CoreSegmentQueryProcessor::processToIce( - const armem::query::data::CoreSegmentQuery& query, const CoreSegment& coreSegment) const + const armem::query::data::CoreSegmentQuery& query, const workingmemory::CoreSegment& coreSegment) const { return toIce<data::CoreSegment>(process(query, coreSegment)); } diff --git a/source/RobotAPI/libraries/armem/server/query_proc/CoreSegmentQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/CoreSegmentQueryProcessor.h index 4a59e546d..2806875cf 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/CoreSegmentQueryProcessor.h +++ b/source/RobotAPI/libraries/armem/server/query_proc/CoreSegmentQueryProcessor.h @@ -2,7 +2,7 @@ #include <RobotAPI/interface/armem/query.h> -#include <RobotAPI/libraries/armem/core/Memory.h> +#include <RobotAPI/libraries/armem/core/workingMemory/Memory.h> #include "BaseQueryProcessor.h" #include "ProviderSegmentQueryProcessor.h" @@ -15,7 +15,7 @@ namespace armarx::armem::query_proc /** * @brief Handles memory queries. */ - class CoreSegmentQueryProcessor : public BaseQueryProcessor<CoreSegment, armem::query::data::CoreSegmentQuery> + class CoreSegmentQueryProcessor : public BaseQueryProcessor<workingmemory::CoreSegment, armem::query::data::CoreSegmentQuery> { public: @@ -26,14 +26,14 @@ namespace armarx::armem::query_proc using BaseQueryProcessor::process; - void process(CoreSegment& result, const armem::query::data::CoreSegmentQuery& query, const CoreSegment& coreSegment) const; + void process(workingmemory::CoreSegment& result, const armem::query::data::CoreSegmentQuery& query, const workingmemory::CoreSegment& coreSegment) const; - void process(CoreSegment& result, const armem::query::data::core::All& query, const CoreSegment& coreSegment) const; - void process(CoreSegment& result, const armem::query::data::core::Single& query, const CoreSegment& coreSegment) const; - void process(CoreSegment& result, const armem::query::data::core::Regex& query, const CoreSegment& coreSegment) const; + void process(workingmemory::CoreSegment& result, const armem::query::data::core::All& query, const workingmemory::CoreSegment& coreSegment) const; + void process(workingmemory::CoreSegment& result, const armem::query::data::core::Single& query, const workingmemory::CoreSegment& coreSegment) const; + void process(workingmemory::CoreSegment& result, const armem::query::data::core::Regex& query, const workingmemory::CoreSegment& coreSegment) const; - data::CoreSegment processToIce(const armem::query::data::CoreSegmentQuery& query, const CoreSegment& coreSegment) const; + data::CoreSegment processToIce(const armem::query::data::CoreSegmentQuery& query, const workingmemory::CoreSegment& coreSegment) const; private: diff --git a/source/RobotAPI/libraries/armem/server/query_proc/EntityQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/EntityQueryProcessor.cpp index c062c089e..48d40fb05 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/EntityQueryProcessor.cpp +++ b/source/RobotAPI/libraries/armem/server/query_proc/EntityQueryProcessor.cpp @@ -10,7 +10,7 @@ namespace armarx::armem::query_proc { - void EntityQueryProcessor::process(Entity& result, const armem::query::data::EntityQuery& query, const Entity& entity) const + void EntityQueryProcessor::process(workingmemory::Entity& result, const armem::query::data::EntityQuery& query, const workingmemory::Entity& entity) const { if (auto q = dynamic_cast<const armem::query::data::entity::All*>(&query)) { @@ -34,7 +34,7 @@ namespace armarx::armem::query_proc } } - void EntityQueryProcessor::process(Entity& result, const armem::query::data::entity::All& query, const Entity& entity) const + void EntityQueryProcessor::process(workingmemory::Entity& result, const armem::query::data::entity::All& query, const workingmemory::Entity& entity) const { (void) query; // Copy this entitiy and its contents. @@ -45,7 +45,7 @@ namespace armarx::armem::query_proc } } - void EntityQueryProcessor::process(Entity& result, const armem::query::data::entity::Single& query, const Entity& entity) const + void EntityQueryProcessor::process(workingmemory::Entity& result, const armem::query::data::entity::Single& query, const workingmemory::Entity& entity) const { if (query.timestamp < 0) { @@ -72,7 +72,7 @@ namespace armarx::armem::query_proc } } - void EntityQueryProcessor::process(Entity& result, const armem::query::data::entity::IndexRange& query, const Entity& entity) const + void EntityQueryProcessor::process(workingmemory::Entity& result, const armem::query::data::entity::IndexRange& query, const workingmemory::Entity& entity) const { if (entity.empty()) { @@ -95,7 +95,7 @@ namespace armarx::armem::query_proc } } - void EntityQueryProcessor::process(Entity& result, const armem::query::data::entity::TimeRange& query, const Entity& entity) const + void EntityQueryProcessor::process(workingmemory::Entity& result, const armem::query::data::entity::TimeRange& query, const workingmemory::Entity& entity) const { if (query.minTimestamp <= query.maxTimestamp || query.minTimestamp < 0 || query.maxTimestamp < 0) { @@ -105,7 +105,7 @@ namespace armarx::armem::query_proc } } - void EntityQueryProcessor::process(Entity& result, const Time& min, const Time& max, const Entity& entity, + void EntityQueryProcessor::process(workingmemory::Entity& result, const Time& min, const Time& max, const workingmemory::Entity& entity, const armem::query::data::EntityQuery& query) const { (void) query; @@ -121,7 +121,7 @@ namespace armarx::armem::query_proc } } - data::Entity EntityQueryProcessor::processToIce(const armem::query::data::EntityQuery& query, const Entity& entity) const + data::Entity EntityQueryProcessor::processToIce(const armem::query::data::EntityQuery& query, const workingmemory::Entity& entity) const { return toIce<data::Entity>(process(query, entity)); } @@ -139,14 +139,21 @@ namespace armarx::armem::query_proc } } - void EntityQueryProcessor::addResultSnapshot(Entity& result, Entity::ContainerT::const_iterator it) const + void EntityQueryProcessor::addResultSnapshot(workingmemory::Entity& result, workingmemory::Entity::ContainerT::const_iterator it) const { addResultSnapshot(result, it->second); } - void EntityQueryProcessor::addResultSnapshot(Entity& result, const EntitySnapshot& snapshot) const + void EntityQueryProcessor::addResultSnapshot(workingmemory::Entity& result, const workingmemory::EntitySnapshot& snapshot) const { bool withData = (dataMode == DataMode::WithData); - result.addSnapshot(snapshot.copy(withData)); + if (withData) + { + result.addSnapshot(snapshot.copy()); + } + else + { + result.addSnapshot(snapshot.copyWithoutData()); + } } } diff --git a/source/RobotAPI/libraries/armem/server/query_proc/EntityQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/EntityQueryProcessor.h index 594022ffb..52ded22bb 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/EntityQueryProcessor.h +++ b/source/RobotAPI/libraries/armem/server/query_proc/EntityQueryProcessor.h @@ -2,7 +2,7 @@ #include <RobotAPI/interface/armem/query.h> -#include <RobotAPI/libraries/armem/core/Memory.h> +#include <RobotAPI/libraries/armem/core/workingMemory/Memory.h> #include "BaseQueryProcessor.h" @@ -13,7 +13,7 @@ namespace armarx::armem::query_proc /** * @brief Handles memory queries. */ - class EntityQueryProcessor : public BaseQueryProcessor<Entity, armem::query::data::EntityQuery> + class EntityQueryProcessor : public BaseQueryProcessor<workingmemory::Entity, armem::query::data::EntityQuery> { public: @@ -24,26 +24,26 @@ namespace armarx::armem::query_proc using BaseQueryProcessor::process; - void process(Entity& result, const armem::query::data::EntityQuery& query, const Entity& entity) const override; + void process(workingmemory::Entity& result, const armem::query::data::EntityQuery& query, const workingmemory::Entity& entity) const override; - void process(Entity& result, const armem::query::data::entity::All& query, const Entity& entity) const; - void process(Entity& result, const armem::query::data::entity::Single& query, const Entity& entity) const; - void process(Entity& result, const armem::query::data::entity::TimeRange& query, const Entity& entity) const; - void process(Entity& result, const armem::query::data::entity::IndexRange& query, const Entity& entity) const; + void process(workingmemory::Entity& result, const armem::query::data::entity::All& query, const workingmemory::Entity& entity) const; + void process(workingmemory::Entity& result, const armem::query::data::entity::Single& query, const workingmemory::Entity& entity) const; + void process(workingmemory::Entity& result, const armem::query::data::entity::TimeRange& query, const workingmemory::Entity& entity) const; + void process(workingmemory::Entity& result, const armem::query::data::entity::IndexRange& query, const workingmemory::Entity& entity) const; - void process(Entity& result, const Time& min, const Time& max, const Entity& entity, + void process(workingmemory::Entity& result, const Time& min, const Time& max, const workingmemory::Entity& entity, const armem::query::data::EntityQuery& query) const; - data::Entity processToIce(const armem::query::data::EntityQuery& query, const Entity& entity) const; + data::Entity processToIce(const armem::query::data::EntityQuery& query, const workingmemory::Entity& entity) const; static size_t negativeIndexSemantics(long index, size_t size); private: - void addResultSnapshot(Entity& result, Entity::ContainerT::const_iterator it) const; - void addResultSnapshot(Entity& result, const EntitySnapshot& snapshot) const; + void addResultSnapshot(workingmemory::Entity& result, workingmemory::Entity::ContainerT::const_iterator it) const; + void addResultSnapshot(workingmemory::Entity& result, const workingmemory::EntitySnapshot& snapshot) const; }; diff --git a/source/RobotAPI/libraries/armem/server/query_proc/MemoryQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/MemoryQueryProcessor.cpp index 129892339..c239b6c8b 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/MemoryQueryProcessor.cpp +++ b/source/RobotAPI/libraries/armem/server/query_proc/MemoryQueryProcessor.cpp @@ -12,7 +12,7 @@ namespace armarx::armem::query_proc { - armem::query::data::Result MemoryQueryProcessor::process(const armem::query::data::Input& input, const Memory& memory) const + armem::query::data::Result MemoryQueryProcessor::process(const armem::query::data::Input& input, const workingmemory::Memory& memory) const { armem::query::data::Result result; result.memory = processToIce(input.memoryQueries, memory); @@ -21,17 +21,17 @@ namespace armarx::armem::query_proc } data::MemoryPtr MemoryQueryProcessor::processToIce( - const armem::query::data::MemoryQuery& query, const Memory& memory) const + const armem::query::data::MemoryQuery& query, const workingmemory::Memory& memory) const { return toIce<data::MemoryPtr>(process(query, memory)); } - data::MemoryPtr MemoryQueryProcessor::processToIce(const armem::query::data::MemoryQuerySeq& queries, const Memory& memory) const + data::MemoryPtr MemoryQueryProcessor::processToIce(const armem::query::data::MemoryQuerySeq& queries, const workingmemory::Memory& memory) const { return toIce<data::MemoryPtr>(process(queries, memory)); } - void MemoryQueryProcessor::process(Memory& result, const armem::query::data::MemoryQuery& query, const Memory& memory) const + void MemoryQueryProcessor::process(workingmemory::Memory& result, const armem::query::data::MemoryQuery& query, const workingmemory::Memory& memory) const { if (auto q = dynamic_cast<const armem::query::data::memory::All*>(&query)) { @@ -52,7 +52,7 @@ namespace armarx::armem::query_proc } - void MemoryQueryProcessor::process(Memory& result, const armem::query::data::memory::All& query, const Memory& memory) const + void MemoryQueryProcessor::process(workingmemory::Memory& result, const armem::query::data::memory::All& query, const workingmemory::Memory& memory) const { for (const auto& [name, coreSegment] : memory.coreSegments) { @@ -60,11 +60,11 @@ namespace armarx::armem::query_proc } } - void MemoryQueryProcessor::process(Memory& result, const armem::query::data::memory::Single& query, const Memory& memory) const + void MemoryQueryProcessor::process(workingmemory::Memory& result, const armem::query::data::memory::Single& query, const workingmemory::Memory& memory) const { try { - const CoreSegment& coreSegment = memory.getCoreSegment(query.coreSegmentName); + const workingmemory::CoreSegment& coreSegment = memory.getCoreSegment(query.coreSegmentName); result.addCoreSegment(coreSegmentProcessor.process(query.coreSegmentQueries, coreSegment)); } catch (const error::MissingEntry&) @@ -73,7 +73,7 @@ namespace armarx::armem::query_proc } } - void MemoryQueryProcessor::process(Memory& result, const armem::query::data::memory::Regex& query, const Memory& memory) const + void MemoryQueryProcessor::process(workingmemory::Memory& result, const armem::query::data::memory::Regex& query, const workingmemory::Memory& memory) const { std::regex regex(query.coreSegmentNameRegex); for (const auto& [name, coreSegment] : memory.coreSegments) diff --git a/source/RobotAPI/libraries/armem/server/query_proc/MemoryQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/MemoryQueryProcessor.h index de16c9433..b32b5afa2 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/MemoryQueryProcessor.h +++ b/source/RobotAPI/libraries/armem/server/query_proc/MemoryQueryProcessor.h @@ -2,7 +2,7 @@ #include <RobotAPI/interface/armem/query.h> -#include <RobotAPI/libraries/armem/core/Memory.h> +#include <RobotAPI/libraries/armem/core/workingMemory/Memory.h> #include "BaseQueryProcessor.h" #include "CoreSegmentQueryProcessor.h" @@ -15,7 +15,7 @@ namespace armarx::armem::query_proc /** * @brief Handles memory queries. */ - class MemoryQueryProcessor : public BaseQueryProcessor<Memory, armem::query::data::MemoryQuery> + class MemoryQueryProcessor : public BaseQueryProcessor<workingmemory::Memory, armem::query::data::MemoryQuery> { public: @@ -26,18 +26,18 @@ namespace armarx::armem::query_proc using BaseQueryProcessor::process; - armem::query::data::Result process(const armem::query::data::Input& input, const Memory& memory) const; + armem::query::data::Result process(const armem::query::data::Input& input, const workingmemory::Memory& memory) const; - void process(Memory& result, const armem::query::data::MemoryQuery& query, const Memory& memory) const; + void process(workingmemory::Memory& result, const armem::query::data::MemoryQuery& query, const workingmemory::Memory& memory) const; - void process(Memory& result, const armem::query::data::memory::All& query, const Memory& memory) const; - void process(Memory& result, const armem::query::data::memory::Single& query, const Memory& memory) const; - void process(Memory& result, const armem::query::data::memory::Regex& query, const Memory& memory) const; + void process(workingmemory::Memory& result, const armem::query::data::memory::All& query, const workingmemory::Memory& memory) const; + void process(workingmemory::Memory& result, const armem::query::data::memory::Single& query, const workingmemory::Memory& memory) const; + void process(workingmemory::Memory& result, const armem::query::data::memory::Regex& query, const workingmemory::Memory& memory) const; - data::MemoryPtr processToIce(const armem::query::data::MemoryQuery& query, const Memory& memory) const; - data::MemoryPtr processToIce(const armem::query::data::MemoryQuerySeq& query, const Memory& memory) const; + data::MemoryPtr processToIce(const armem::query::data::MemoryQuery& query, const workingmemory::Memory& memory) const; + data::MemoryPtr processToIce(const armem::query::data::MemoryQuerySeq& query, const workingmemory::Memory& memory) const; private: diff --git a/source/RobotAPI/libraries/armem/server/query_proc/ProviderSegmentQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/ProviderSegmentQueryProcessor.cpp index 36bfe8765..8a07b2116 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/ProviderSegmentQueryProcessor.cpp +++ b/source/RobotAPI/libraries/armem/server/query_proc/ProviderSegmentQueryProcessor.cpp @@ -12,7 +12,7 @@ namespace armarx::armem::query_proc { - void ProviderSegmentQueryProcessor::process(ProviderSegment& result, const armem::query::data::ProviderSegmentQuery& query, const ProviderSegment& providerSegment) const + void ProviderSegmentQueryProcessor::process(workingmemory::ProviderSegment& result, const armem::query::data::ProviderSegmentQuery& query, const workingmemory::ProviderSegment& providerSegment) const { if (auto q = dynamic_cast<const armem::query::data::provider::All*>(&query)) { @@ -33,8 +33,8 @@ namespace armarx::armem::query_proc } - void ProviderSegmentQueryProcessor::process(ProviderSegment& result, - const armem::query::data::provider::All& query, const ProviderSegment& providerSegment) const + void ProviderSegmentQueryProcessor::process(workingmemory::ProviderSegment& result, + const armem::query::data::provider::All& query, const workingmemory::ProviderSegment& providerSegment) const { for (const auto& [name, entity] : providerSegment.entities) { @@ -42,12 +42,12 @@ namespace armarx::armem::query_proc } } - void ProviderSegmentQueryProcessor::process(ProviderSegment& result, - const armem::query::data::provider::Single& query, const ProviderSegment& providerSegment) const + void ProviderSegmentQueryProcessor::process(workingmemory::ProviderSegment& result, + const armem::query::data::provider::Single& query, const workingmemory::ProviderSegment& providerSegment) const { try { - const Entity& entity = providerSegment.getEntity(query.entityName); + const workingmemory::Entity& entity = providerSegment.getEntity(query.entityName); result.addEntity(entityProcessor.process(query.entityQueries, entity)); } catch (const error::MissingEntry&) @@ -56,8 +56,8 @@ namespace armarx::armem::query_proc } } - void ProviderSegmentQueryProcessor::process(ProviderSegment& result, - const armem::query::data::provider::Regex& query, const ProviderSegment& providerSegment) const + void ProviderSegmentQueryProcessor::process(workingmemory::ProviderSegment& result, + const armem::query::data::provider::Regex& query, const workingmemory::ProviderSegment& providerSegment) const { std::regex regex(query.entityNameRegex); for (const auto& [name, entity] : providerSegment.entities) @@ -71,7 +71,7 @@ namespace armarx::armem::query_proc data::ProviderSegment ProviderSegmentQueryProcessor::processToIce( - const armem::query::data::ProviderSegmentQuery& query, const ProviderSegment& providerSegment) const + const armem::query::data::ProviderSegmentQuery& query, const workingmemory::ProviderSegment& providerSegment) const { return toIce<data::ProviderSegment>(process(query, providerSegment)); } diff --git a/source/RobotAPI/libraries/armem/server/query_proc/ProviderSegmentQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/ProviderSegmentQueryProcessor.h index da5c200bf..8397431e4 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/ProviderSegmentQueryProcessor.h +++ b/source/RobotAPI/libraries/armem/server/query_proc/ProviderSegmentQueryProcessor.h @@ -2,7 +2,7 @@ #include <RobotAPI/interface/armem/query.h> -#include <RobotAPI/libraries/armem/core/Memory.h> +#include <RobotAPI/libraries/armem/core/workingMemory/Memory.h> #include "BaseQueryProcessor.h" #include "EntityQueryProcessor.h" @@ -15,7 +15,7 @@ namespace armarx::armem::query_proc /** * @brief Handles memory queries. */ - class ProviderSegmentQueryProcessor : public BaseQueryProcessor<ProviderSegment, armem::query::data::ProviderSegmentQuery> + class ProviderSegmentQueryProcessor : public BaseQueryProcessor<workingmemory::ProviderSegment, armem::query::data::ProviderSegmentQuery> { public: @@ -26,14 +26,14 @@ namespace armarx::armem::query_proc using BaseQueryProcessor::process; - void process(ProviderSegment& result, const armem::query::data::ProviderSegmentQuery& query, const ProviderSegment& providerSegment) const; + void process(workingmemory::ProviderSegment& result, const armem::query::data::ProviderSegmentQuery& query, const workingmemory::ProviderSegment& providerSegment) const; - void process(ProviderSegment& result, const armem::query::data::provider::All& query, const ProviderSegment& providerSegment) const; - void process(ProviderSegment& result, const armem::query::data::provider::Single& query, const ProviderSegment& providerSegment) const; - void process(ProviderSegment& result, const armem::query::data::provider::Regex& query, const ProviderSegment& providerSegment) const; + void process(workingmemory::ProviderSegment& result, const armem::query::data::provider::All& query, const workingmemory::ProviderSegment& providerSegment) const; + void process(workingmemory::ProviderSegment& result, const armem::query::data::provider::Single& query, const workingmemory::ProviderSegment& providerSegment) const; + void process(workingmemory::ProviderSegment& result, const armem::query::data::provider::Regex& query, const workingmemory::ProviderSegment& providerSegment) const; - data::ProviderSegment processToIce(const armem::query::data::ProviderSegmentQuery& query, const ProviderSegment& providerSegment) const; + data::ProviderSegment processToIce(const armem::query::data::ProviderSegmentQuery& query, const workingmemory::ProviderSegment& providerSegment) const; private: diff --git a/source/RobotAPI/libraries/armem/test/ArMemLTMTest.cpp b/source/RobotAPI/libraries/armem/test/ArMemLTMTest.cpp index c953a5acb..1cc71d15c 100644 --- a/source/RobotAPI/libraries/armem/test/ArMemLTMTest.cpp +++ b/source/RobotAPI/libraries/armem/test/ArMemLTMTest.cpp @@ -25,7 +25,7 @@ #define ARMARX_BOOST_TEST #include <RobotAPI/Test.h> -#include "../core/Memory.h" +#include "../core/workingMemory/Memory.h" #include "../core/error.h" #include <RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h> @@ -34,9 +34,9 @@ #include <RobotAPI/libraries/aron/core/Debug.h> -#include "../core/io/DiskMemory.h" +#include "../core/longtermMemory/Memory.h" -#include "../core/io/diskWriter/NlohmannJSON/NlohmannJSONDiskWriter.h" +//#include "../core/io/diskWriter/NlohmannJSON/NlohmannJSONDiskWriter.h" #include <filesystem> #include <iostream> @@ -82,7 +82,7 @@ namespace ArMemLTMTest } - static armem::Memory setupMemoryWithType( + static armem::workingmemory::Memory setupMemoryWithType( const std::string& memoryName, const aron::typenavigator::ObjectNavigatorPtr& t1, const aron::typenavigator::ObjectNavigatorPtr& t2, @@ -91,14 +91,14 @@ namespace ArMemLTMTest { aron::Randomizer r; - armem::Memory memory(memoryName); + armem::workingmemory::Memory memory(memoryName); BOOST_CHECK_EQUAL(memory.name(), memoryName); - armem::CoreSegment& coreSegment = memory.addCoreSegment("TestCoreSegment"); + armem::workingmemory::CoreSegment& coreSegment = memory.addCoreSegment("TestCoreSegment"); BOOST_CHECK_EQUAL(coreSegment.name(), "TestCoreSegment"); BOOST_CHECK(memory.hasCoreSegment(coreSegment.name())); - armem::ProviderSegment& providerSegment = coreSegment.addProviderSegment("TestProvider"); + armem::workingmemory::ProviderSegment& providerSegment = coreSegment.addProviderSegment("TestProvider"); BOOST_CHECK_EQUAL(providerSegment.name(), "TestProvider"); BOOST_CHECK(coreSegment.hasProviderSegment(providerSegment.name())); diff --git a/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp b/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp index b7ba95c63..3d9588118 100644 --- a/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp +++ b/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp @@ -26,7 +26,7 @@ #include <RobotAPI/Test.h> -#include "../core/Memory.h" +#include "../core/workingMemory/Memory.h" #include "../core/error.h" @@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE(test_segment_setup) { armem::EntityUpdate update; - armem::Memory memory("Memory"); + armem::workingmemory::Memory memory("Memory"); BOOST_CHECK_EQUAL(memory.name(), "Memory"); { update.entityID = armem::MemoryID::fromString("OtherMemory/SomeSegment"); @@ -89,7 +89,7 @@ BOOST_AUTO_TEST_CASE(test_segment_setup) BOOST_CHECK_THROW(memory.update(update), armem::error::MissingEntry); } - armem::CoreSegment& coreSegment = memory.addCoreSegment("ImageRGB"); + armem::workingmemory::CoreSegment& coreSegment = memory.addCoreSegment("ImageRGB"); BOOST_CHECK_EQUAL(coreSegment.name(), "ImageRGB"); BOOST_CHECK(memory.hasCoreSegment(coreSegment.name())); { @@ -99,7 +99,7 @@ BOOST_AUTO_TEST_CASE(test_segment_setup) BOOST_CHECK_THROW(coreSegment.update(update), armem::error::MissingEntry); } - armem::ProviderSegment& providerSegment = coreSegment.addProviderSegment("SomeRGBImageProvider"); + armem::workingmemory::ProviderSegment& providerSegment = coreSegment.addProviderSegment("SomeRGBImageProvider"); BOOST_CHECK_EQUAL(providerSegment.name(), "SomeRGBImageProvider"); BOOST_CHECK(coreSegment.hasProviderSegment(providerSegment.name())); { @@ -123,12 +123,12 @@ BOOST_AUTO_TEST_CASE(test_segment_setup) BOOST_CHECK(providerSegment.hasEntity("image")); BOOST_CHECK(!providerSegment.hasEntity("other_image")); - armem::Entity& entity = providerSegment.getEntity("image"); + armem::workingmemory::Entity& entity = providerSegment.getEntity("image"); BOOST_CHECK_EQUAL(entity.name(), "image"); BOOST_CHECK_EQUAL(entity.history.size(), 1); BOOST_CHECK_EQUAL(entity.history.count(update.timeCreated), 1); - armem::EntitySnapshot& entitySnapshot = entity.history.at(update.timeCreated); + armem::workingmemory::EntitySnapshot& entitySnapshot = entity.history.at(update.timeCreated); BOOST_CHECK_EQUAL(entitySnapshot.instances.size(), update.instancesData.size()); @@ -154,7 +154,7 @@ BOOST_AUTO_TEST_CASE(test_segment_setup) BOOST_AUTO_TEST_CASE(test_history_size_in_entity) { - armem::Entity entity("entity"); + armem::workingmemory::Entity entity("entity"); armem::EntityUpdate update; update.entityID.entityName = entity.name(); @@ -197,7 +197,7 @@ BOOST_AUTO_TEST_CASE(test_history_size_in_entity) BOOST_AUTO_TEST_CASE(test_history_size_in_provider_segment) { - armem::ProviderSegment providerSegment("SomeRGBImageProvider"); + armem::workingmemory::ProviderSegment providerSegment("SomeRGBImageProvider"); armem::EntityUpdate update; update.entityID.providerSegmentName = providerSegment.name(); diff --git a/source/RobotAPI/libraries/armem/test/ArMemQueryTest.cpp b/source/RobotAPI/libraries/armem/test/ArMemQueryTest.cpp index b35fb3945..5c51491af 100644 --- a/source/RobotAPI/libraries/armem/test/ArMemQueryTest.cpp +++ b/source/RobotAPI/libraries/armem/test/ArMemQueryTest.cpp @@ -50,19 +50,19 @@ namespace ArMemQueryTest struct Fixture { - armem::Entity entity; + armem::workingmemory::Entity entity; armem::query_proc::EntityQueryProcessor processor; query::EntityQueryPtr entityQuery; - std::vector<armem::Entity> results; + std::vector<armem::workingmemory::Entity> results; Fixture() { - entity = armem::Entity("entity"); + entity = armem::workingmemory::Entity("entity"); - armem::EntitySnapshot snapshot; + armem::workingmemory::EntitySnapshot snapshot; snapshot.time() = armem::Time::microSeconds(1000); entity.addSnapshot(snapshot); snapshot.time() = armem::Time::microSeconds(2000); @@ -119,7 +119,7 @@ BOOST_AUTO_TEST_CASE(test_entity_Single_latest) addResults(query::entity::Single()); BOOST_REQUIRE_GT(results.size(), 0); - for (const armem::Entity& result : results) + for (const armem::workingmemory::Entity& result : results) { BOOST_CHECK_EQUAL(result.name(), entity.name()); BOOST_CHECK_EQUAL(result.size(), 1); @@ -134,7 +134,7 @@ BOOST_AUTO_TEST_CASE(test_entity_Single_existing) addResults(query::entity::Single { 3000 }); BOOST_REQUIRE_GT(results.size(), 0); - for (const armem::Entity& result : results) + for (const armem::workingmemory::Entity& result : results) { BOOST_CHECK_EQUAL(result.name(), entity.name()); BOOST_CHECK_EQUAL(result.size(), 1); @@ -148,7 +148,7 @@ BOOST_AUTO_TEST_CASE(test_entity_Single_non_existing) addResults(query::entity::Single { 3500 }); BOOST_REQUIRE_GT(results.size(), 0); - for (const armem::Entity& result : results) + for (const armem::workingmemory::Entity& result : results) { BOOST_CHECK_EQUAL(result.name(), entity.name()); BOOST_CHECK_EQUAL(result.size(), 0); @@ -161,7 +161,7 @@ BOOST_AUTO_TEST_CASE(test_entity_All) addResults(query::entity::All()); BOOST_REQUIRE_GT(results.size(), 0); - for (const armem::Entity& result : results) + for (const armem::workingmemory::Entity& result : results) { BOOST_CHECK_EQUAL(result.name(), entity.name()); BOOST_CHECK_EQUAL(result.size(), entity.size()); @@ -182,7 +182,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeRange_slice) addResults(query::entity::TimeRange{ 1500, 3500 }); BOOST_REQUIRE_GT(results.size(), 0); - for (const armem::Entity& result : results) + for (const armem::workingmemory::Entity& result : results) { BOOST_CHECK_EQUAL(result.name(), entity.name()); @@ -203,7 +203,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeRange_exact) addResults(query::entity::TimeRange{ 2000, 4000 }); BOOST_REQUIRE_GT(results.size(), 0); - for (const armem::Entity& result : results) + for (const armem::workingmemory::Entity& result : results) { BOOST_CHECK_EQUAL(result.name(), entity.name()); @@ -224,7 +224,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeRange_all) addResults(query::entity::TimeRange{ -1, -1 }); BOOST_REQUIRE_GT(results.size(), 0); - for (const armem::Entity& result : results) + for (const armem::workingmemory::Entity& result : results) { BOOST_CHECK_EQUAL(result.name(), entity.name()); @@ -243,7 +243,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeRange_empty) addResults(query::entity::TimeRange{ 6000, 1000 }); BOOST_REQUIRE_GT(results.size(), 0); - for (const armem::Entity& result : results) + for (const armem::workingmemory::Entity& result : results) { BOOST_CHECK_EQUAL(result.name(), entity.name()); @@ -257,7 +257,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeRange_from_start) addResults(query::entity::TimeRange{ -1, 2500 }); BOOST_REQUIRE_GT(results.size(), 0); - for (const armem::Entity& result : results) + for (const armem::workingmemory::Entity& result : results) { BOOST_CHECK_EQUAL(result.name(), entity.name()); @@ -278,7 +278,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeRange_to_end) addResults(query::entity::TimeRange{ 2500, -1 }); BOOST_REQUIRE_GT(results.size(), 0); - for (const armem::Entity& result : results) + for (const armem::workingmemory::Entity& result : results) { BOOST_CHECK_EQUAL(result.name(), entity.name()); @@ -332,7 +332,7 @@ BOOST_AUTO_TEST_CASE(test_entity_IndexRange_all_default) addResults(query::entity::IndexRange(0, -1)); BOOST_REQUIRE_GT(results.size(), 0); - for (const armem::Entity& result : results) + for (const armem::workingmemory::Entity& result : results) { BOOST_CHECK_EQUAL(result.name(), entity.name()); @@ -355,7 +355,7 @@ BOOST_AUTO_TEST_CASE(test_entity_IndexRange_slice) addResults(query::entity::IndexRange{ -4, -2 }); BOOST_REQUIRE_GT(results.size(), 0); - for (const armem::Entity& result : results) + for (const armem::workingmemory::Entity& result : results) { BOOST_CHECK_EQUAL(result.name(), entity.name()); @@ -383,7 +383,7 @@ BOOST_AUTO_TEST_CASE(test_entity_IndexRange_empty_range) BOOST_REQUIRE_GT(results.size(), 0); - for (const armem::Entity& result : results) + for (const armem::workingmemory::Entity& result : results) { BOOST_CHECK_EQUAL(result.name(), entity.name()); @@ -405,7 +405,7 @@ BOOST_AUTO_TEST_CASE(test_entity_IndexRange_empty_entity) BOOST_REQUIRE_GT(results.size(), 0); - for (const armem::Entity& result : results) + for (const armem::workingmemory::Entity& result : results) { BOOST_CHECK_EQUAL(result.name(), entity.name()); BOOST_CHECK_EQUAL(result.size(), 0); diff --git a/source/RobotAPI/libraries/armem/util/util.h b/source/RobotAPI/libraries/armem/util/util.h index 4fa457ab6..e295131c2 100644 --- a/source/RobotAPI/libraries/armem/util/util.h +++ b/source/RobotAPI/libraries/armem/util/util.h @@ -26,8 +26,8 @@ #include <vector> #include <optional> -#include <RobotAPI/libraries/armem/core/Entity.h> -#include <RobotAPI/libraries/armem/core/EntityInstance.h> +#include <RobotAPI/libraries/armem/core/workingMemory/Entity.h> +#include <RobotAPI/libraries/armem/core/workingMemory/EntityInstance.h> #include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/AronCppClass.h> namespace armarx::armem @@ -41,7 +41,7 @@ namespace armarx::armem * @return std::optional<AronClass> */ template <typename AronClass> - std::optional<AronClass> tryCast(const EntityInstance& item) + std::optional<AronClass> tryCast(const workingmemory::EntityInstance& item) { static_assert(std::is_base_of<armarx::aron::cppcodegenerator::AronCppClass, AronClass>::value); @@ -67,7 +67,7 @@ namespace armarx::armem */ template <typename AronClass> std::vector<AronClass> - allOfType(const std::map<std::string, Entity>& entities) + allOfType(const std::map<std::string, workingmemory::Entity>& entities) { static_assert(std::is_base_of<armarx::aron::cppcodegenerator::AronCppClass, AronClass>::value); @@ -113,7 +113,7 @@ namespace armarx::armem * @return vector of "pred"-transformed elements that can be cast to AronClass */ template <typename AronClass> - auto transformAllOfType(const std::map<std::string, Entity>& entities, + auto transformAllOfType(const std::map<std::string, workingmemory::Entity>& entities, auto pred) -> std::vector<decltype(pred(AronClass()))> { static_assert(std::is_base_of<armarx::aron::cppcodegenerator::AronCppClass, @@ -153,4 +153,4 @@ namespace armarx::armem return outV; } -} // namespace armarx::armem \ No newline at end of file +} // namespace armarx::armem diff --git a/source/RobotAPI/libraries/armem_gui/MemoryViewer.cpp b/source/RobotAPI/libraries/armem_gui/MemoryViewer.cpp index c634cb344..53669802d 100644 --- a/source/RobotAPI/libraries/armem_gui/MemoryViewer.cpp +++ b/source/RobotAPI/libraries/armem_gui/MemoryViewer.cpp @@ -3,7 +3,7 @@ #include <RobotAPI/libraries/armem/core/ice_conversions.h> #include <RobotAPI/libraries/armem_gui/gui_utils.h> -#include <RobotAPI/libraries/armem/core/io/diskWriter/NlohmannJSON/NlohmannJSONDiskWriter.h> +//#include <RobotAPI/libraries/armem/core/io/diskWriter/NlohmannJSON/NlohmannJSONDiskWriter.h> #include <ArmarXGui/libraries/SimpleConfigDialog/SimpleConfigDialog.h> @@ -231,7 +231,7 @@ namespace armarx::armem::gui return; } - const std::optional<armem::Memory>& data = memoryData.at(selectedID.memoryName); + const std::optional<armem::workingmemory::Memory>& data = memoryData.at(selectedID.memoryName); if (data) { @@ -240,10 +240,10 @@ namespace armarx::armem::gui return; } armem::MemoryID id = selectedID; - const armem::EntitySnapshot* snapshot = nullptr; + const armem::workingmemory::EntitySnapshot* snapshot = nullptr; if (!id.hasTimestamp()) { - const armem::Entity& entity = data->getEntity(id); + const armem::workingmemory::Entity& entity = data->getEntity(id); if (entity.empty()) { return; @@ -281,13 +281,17 @@ namespace armarx::armem::gui void MemoryViewer::updateMemoryTree() { - std::map<std::string, const armem::Memory*> convMap; + std::map<std::string, const armem::workingmemory::Memory*> convMap; for (auto& [name, data] : memoryData) { if (data.has_value()) { convMap[name] = &data.value(); } + /*if (data.second.has_value()) + { + convMap[name].second = &data.second.value(); + }*/ } if (convMap.empty()) diff --git a/source/RobotAPI/libraries/armem_gui/MemoryViewer.h b/source/RobotAPI/libraries/armem_gui/MemoryViewer.h index 1d0595bbb..2a31ba203 100644 --- a/source/RobotAPI/libraries/armem_gui/MemoryViewer.h +++ b/source/RobotAPI/libraries/armem_gui/MemoryViewer.h @@ -103,7 +103,7 @@ namespace armarx::armem::gui armem::mns::MemoryNameSystemInterfacePrx mns; std::map<std::string, armem::client::Reader> memoryReaders; - std::map<std::string, std::optional<armem::Memory>> memoryData; + std::map<std::string, std::optional<armem::workingmemory::Memory>> memoryData; QLayout* ltmControlWidgetLayout; armem::gui::LTMControlWidget* ltmControlWidget; diff --git a/source/RobotAPI/libraries/armem_gui/instance/InstanceView.cpp b/source/RobotAPI/libraries/armem_gui/instance/InstanceView.cpp index 83d528d4b..ceaab2cd4 100644 --- a/source/RobotAPI/libraries/armem_gui/instance/InstanceView.cpp +++ b/source/RobotAPI/libraries/armem_gui/instance/InstanceView.cpp @@ -89,16 +89,16 @@ namespace armarx::armem::gui::instance } - void InstanceView::update(const MemoryID& id, const Memory& memory) + void InstanceView::update(const MemoryID& id, const workingmemory::Memory& memory) { aron::typenavigator::ObjectNavigatorPtr aronType = nullptr; - const armem::EntityInstance* instance = nullptr; + const armem::workingmemory::EntityInstance* instance = nullptr; try { instance = &memory.getEntityInstance(id); if (useTypeInfo) { - aronType = memory.getCoreSegment(id.coreSegmentName).getProviderSegment(id.providerSegmentName).aronType(); + aronType = memory.getCoreSegment(id.coreSegmentName).getProviderSegment(id.providerSegmentName).aronType; } } catch (const armem::error::ArMemError& e) @@ -113,7 +113,7 @@ namespace armarx::armem::gui::instance } - void InstanceView::update(const EntityInstance& instance, aron::typenavigator::ObjectNavigatorPtr aronType) + void InstanceView::update(const workingmemory::EntityInstance& instance, aron::typenavigator::ObjectNavigatorPtr aronType) { currentInstance = instance; currentAronType = aronType; @@ -124,7 +124,7 @@ namespace armarx::armem::gui::instance { if (currentInstance) { - updateInstanceID(currentInstance->id()); + updateInstanceID(currentInstance->id); updateMetaData(currentInstance->metadata()); updateData(currentInstance->data(), currentAronType); updateImageView(currentInstance->data()); @@ -168,7 +168,7 @@ namespace armarx::armem::gui::instance treeItemData->setExpanded(true); } - void InstanceView::updateMetaData(const EntityInstanceMetadata& metadata) + void InstanceView::updateMetaData(const workingmemory::EntityInstanceMetadata& metadata) { std::vector<std::string> items = { diff --git a/source/RobotAPI/libraries/armem_gui/instance/InstanceView.h b/source/RobotAPI/libraries/armem_gui/instance/InstanceView.h index 00027a3e0..ce81a17a1 100644 --- a/source/RobotAPI/libraries/armem_gui/instance/InstanceView.h +++ b/source/RobotAPI/libraries/armem_gui/instance/InstanceView.h @@ -6,7 +6,7 @@ #include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> -#include <RobotAPI/libraries/armem/core/Memory.h> +#include <RobotAPI/libraries/armem/core/workingMemory/Memory.h> class QGroupBox; @@ -34,8 +34,8 @@ namespace armarx::armem::gui::instance void setStatusLabel(QLabel* statusLabel); void setUseTypeInfo(bool enable); - void update(const MemoryID& id, const Memory& memory); - void update(const EntityInstance& instance, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); + void update(const MemoryID& id, const workingmemory::Memory& memory); + void update(const workingmemory::EntityInstance& instance, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); void update(); @@ -56,7 +56,7 @@ namespace armarx::armem::gui::instance void updateInstanceID(const MemoryID& id); void updateData(const aron::datanavigator::DictNavigatorPtr& data, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); - void updateMetaData(const EntityInstanceMetadata& metadata); + void updateMetaData(const workingmemory::EntityInstanceMetadata& metadata); void updateImageView(const aron::datanavigator::DictNavigatorPtr& data); void showErrorMessage(const std::string& message); @@ -71,7 +71,7 @@ namespace armarx::armem::gui::instance TYPE = 2, }; - std::optional<EntityInstance> currentInstance; + std::optional<workingmemory::EntityInstance> currentInstance; aron::typenavigator::ObjectNavigatorPtr currentAronType = nullptr; bool useTypeInfo = true; diff --git a/source/RobotAPI/libraries/armem_gui/memory/TreeWidget.cpp b/source/RobotAPI/libraries/armem_gui/memory/TreeWidget.cpp index e622a3a44..1da781d09 100644 --- a/source/RobotAPI/libraries/armem_gui/memory/TreeWidget.cpp +++ b/source/RobotAPI/libraries/armem_gui/memory/TreeWidget.cpp @@ -49,12 +49,12 @@ namespace armarx::armem::gui::memory void TreeWidget::initBuilders() { - memoryBuilder.setExpand(true); - memoryBuilder.setMakeItemFn([this](const std::string & name, const Memory * memory) + workingmemoryBuilder.setExpand(true); + workingmemoryBuilder.setMakeItemFn([this](const std::string & name, const workingmemory::Memory * memory) { return makeItem(name, *memory); }); - memoryBuilder.setUpdateItemFn([this](const std::string&, const Memory * memory, QTreeWidgetItem * memoryItem) + workingmemoryBuilder.setUpdateItemFn([this](const std::string&, const workingmemory::Memory * memory, QTreeWidgetItem * memoryItem) { updateContainerItem(*memory, memoryItem); if (memoryItem) @@ -65,24 +65,24 @@ namespace armarx::armem::gui::memory }); - coreSegmentBuilder.setExpand(true); - coreSegmentBuilder.setMakeItemFn([this](const std::string & name, const CoreSegment & coreSeg) + workingmemoryCoreSegmentBuilder.setExpand(true); + workingmemoryCoreSegmentBuilder.setMakeItemFn([this](const std::string & name, const workingmemory::CoreSegment & coreSeg) { return makeItem(name, coreSeg); }); - coreSegmentBuilder.setUpdateItemFn([this](const std::string&, const CoreSegment & coreSeg, QTreeWidgetItem * coreSegItem) + workingmemoryCoreSegmentBuilder.setUpdateItemFn([this](const std::string&, const workingmemory::CoreSegment & coreSeg, QTreeWidgetItem * coreSegItem) { updateTypedContainerItem(coreSeg, coreSegItem); updateChildren(coreSeg, coreSegItem); return true; }); - provSegmentBuilder.setExpand(true); - provSegmentBuilder.setMakeItemFn([this](const std::string & name, const ProviderSegment & provSeg) + workingmemoryProvSegmentBuilder.setExpand(true); + workingmemoryProvSegmentBuilder.setMakeItemFn([this](const std::string & name, const workingmemory::ProviderSegment & provSeg) { return makeItem(name, provSeg); }); - provSegmentBuilder.setUpdateItemFn([this](const std::string&, const ProviderSegment & provSeg, QTreeWidgetItem * provSegItem) + workingmemoryProvSegmentBuilder.setUpdateItemFn([this](const std::string&, const workingmemory::ProviderSegment & provSeg, QTreeWidgetItem * provSegItem) { updateTypedContainerItem(provSeg, provSegItem); updateChildren(provSeg, provSegItem); @@ -90,46 +90,46 @@ namespace armarx::armem::gui::memory }); // entityBuilder.setExpand(true); - entityBuilder.setMakeItemFn([this](const std::string & name, const Entity & entity) + workingmemoryEntityBuilder.setMakeItemFn([this](const std::string & name, const workingmemory::Entity & entity) { return makeItem(name, entity); }); - entityBuilder.setUpdateItemFn([this](const std::string&, const Entity & entity, QTreeWidgetItem * entityItem) + workingmemoryEntityBuilder.setUpdateItemFn([this](const std::string&, const workingmemory::Entity & entity, QTreeWidgetItem * entityItem) { updateContainerItem(entity, entityItem); updateChildren(entity, entityItem); return true; }); - snapshotBuilder.setMakeItemFn([this](const armem::Time & time, const EntitySnapshot & snapshot) + workingmemorySnapshotBuilder.setMakeItemFn([this](const armem::Time & time, const workingmemory::EntitySnapshot & snapshot) { QTreeWidgetItem* item = makeItem(toDateTimeMilliSeconds(time), snapshot); item->setData(int(Columns::KEY), Qt::ItemDataRole::UserRole, QVariant(static_cast<qlonglong>(snapshot.time().toMicroSeconds()))); return item; }); - snapshotBuilder.setCompareFn([](const auto & pair, QTreeWidgetItem * item) + workingmemorySnapshotBuilder.setCompareFn([](const auto & pair, QTreeWidgetItem * item) { - const EntitySnapshot& snapshot = pair.second; + const workingmemory::EntitySnapshot& snapshot = pair.second; return armarx::detail::compare(static_cast<qlonglong>(snapshot.time().toMicroSeconds()), item->data(int(Columns::KEY), Qt::ItemDataRole::UserRole).toLongLong()); }); - snapshotBuilder.setUpdateItemFn([this](const armem::Time&, const EntitySnapshot & snapshot, QTreeWidgetItem * snapshotItem) + workingmemorySnapshotBuilder.setUpdateItemFn([this](const armem::Time&, const workingmemory::EntitySnapshot & snapshot, QTreeWidgetItem * snapshotItem) { updateContainerItem(snapshot, snapshotItem); updateChildren(snapshot, snapshotItem); return true; }); - instanceBuilder.setMakeItemFn([this](const EntityInstance & instance) + workingmemoryInstanceBuilder.setMakeItemFn([this](const workingmemory::EntityInstance & instance) { QTreeWidgetItem* item = makeItem("", instance); return item; }); - instanceBuilder.setCompareFn([](const EntityInstance & lhs, QTreeWidgetItem * rhsItem) + workingmemoryInstanceBuilder.setCompareFn([](const workingmemory::EntityInstance & lhs, QTreeWidgetItem * rhsItem) { return armarx::detail::compare(lhs.index(), rhsItem->text(0).toInt()); }); - instanceBuilder.setUpdateItemFn([this](const EntityInstance & instance, QTreeWidgetItem * instanceItem) + workingmemoryInstanceBuilder.setUpdateItemFn([this](const workingmemory::EntityInstance & instance, QTreeWidgetItem * instanceItem) { updateItemItem(instance, instanceItem); updateChildren(instance, instanceItem); @@ -139,7 +139,7 @@ namespace armarx::armem::gui::memory } - void TreeWidget::update(const armem::Memory& memory) + void TreeWidget::update(const armem::workingmemory::Memory& memory) { // Removing elements during the update can create unwanted signals triggering selection handling. handleSelections = false; @@ -148,7 +148,7 @@ namespace armarx::armem::gui::memory emit updated(); } - void TreeWidget::update(const std::map<std::string, const armem::Memory*>& memories) + void TreeWidget::update(const std::map<std::string, const armem::workingmemory::Memory*>& memories) { handleSelections = false; updateChildren(memories, this); @@ -181,27 +181,27 @@ namespace armarx::armem::gui::memory _selectedID = id; const std::string levelName = item->data(int(Columns::LEVEL), Qt::UserRole).toString().toStdString(); - if (levelName == Memory().getLevelName()) + if (levelName == workingmemory::Memory().getLevelName()) { emit memorySelected(*_selectedID); } - else if (levelName == CoreSegment().getLevelName()) + else if (levelName == workingmemory::CoreSegment().getLevelName()) { emit coreSegmentSelected(*_selectedID); } - else if (levelName == ProviderSegment().getLevelName()) + else if (levelName == workingmemory::ProviderSegment().getLevelName()) { emit providerSegmentSelected(*_selectedID); } - else if (levelName == Entity().getLevelName()) + else if (levelName == workingmemory::Entity().getLevelName()) { emit entitySelected(*_selectedID); } - else if (levelName == EntitySnapshot().getLevelName()) + else if (levelName == workingmemory::EntitySnapshot().getLevelName()) { emit snapshotSelected(*_selectedID); } - else if (levelName == EntityInstance().getLevelName()) + else if (levelName == workingmemory::EntityInstance().getLevelName()) { emit instanceSelected(*_selectedID); } @@ -212,43 +212,43 @@ namespace armarx::armem::gui::memory } - void TreeWidget::updateChildren(const armem::Memory& memory, QTreeWidget* tree) + void TreeWidget::updateChildren(const armem::workingmemory::Memory& memory, QTreeWidget* tree) { - updateChildren(std::map<std::string, const armem::Memory*> {{memory.name(), &memory}}, tree); + updateChildren(std::map<std::string, const armem::workingmemory::Memory*> {{memory.name(), &memory}}, tree); } - void TreeWidget::updateChildren(const std::map<std::string, const armem::Memory*>& memories, QTreeWidget* tree) + void TreeWidget::updateChildren(const std::map<std::string, const armem::workingmemory::Memory*>& memories, QTreeWidget* tree) { - memoryBuilder.updateTree(tree, memories); + workingmemoryBuilder.updateTree(tree, memories); } - void TreeWidget::updateChildren(const armem::Memory& memory, QTreeWidgetItem* memoryItem) + void TreeWidget::updateChildren(const armem::workingmemory::Memory& memory, QTreeWidgetItem* memoryItem) { - coreSegmentBuilder.updateTree(memoryItem, memory.coreSegments); + workingmemoryCoreSegmentBuilder.updateTree(memoryItem, memory.coreSegments); } - void TreeWidget::updateChildren(const armem::CoreSegment& coreSeg, QTreeWidgetItem* coreSegItem) + void TreeWidget::updateChildren(const armem::workingmemory::CoreSegment& coreSeg, QTreeWidgetItem* coreSegItem) { - provSegmentBuilder.updateTree(coreSegItem, coreSeg.providerSegments); + workingmemoryProvSegmentBuilder.updateTree(coreSegItem, coreSeg.providerSegments); } - void TreeWidget::updateChildren(const armem::ProviderSegment& provSeg, QTreeWidgetItem* provSegItem) + void TreeWidget::updateChildren(const armem::workingmemory::ProviderSegment& provSeg, QTreeWidgetItem* provSegItem) { - entityBuilder.updateTree(provSegItem, provSeg.entities); + workingmemoryEntityBuilder.updateTree(provSegItem, provSeg.entities); } - void TreeWidget::updateChildren(const armem::Entity& entity, QTreeWidgetItem* entityItem) + void TreeWidget::updateChildren(const armem::workingmemory::Entity& entity, QTreeWidgetItem* entityItem) { - snapshotBuilder.updateTree(entityItem, entity.history); + workingmemorySnapshotBuilder.updateTree(entityItem, entity.history); } - void TreeWidget::updateChildren(const armem::EntitySnapshot& snapshot, QTreeWidgetItem* snapshotItem) + void TreeWidget::updateChildren(const armem::workingmemory::EntitySnapshot& snapshot, QTreeWidgetItem* snapshotItem) { - instanceBuilder.updateTree(snapshotItem, snapshot.instances); + workingmemoryInstanceBuilder.updateTree(snapshotItem, snapshot.instances); } - void TreeWidget::updateChildren(const armem::EntityInstance& data, QTreeWidgetItem* dataItem) + void TreeWidget::updateChildren(const armem::workingmemory::EntityInstance& data, QTreeWidgetItem* dataItem) { (void) data, (void) dataItem; } @@ -261,11 +261,11 @@ namespace armarx::armem::gui::memory columns.insert(int(Columns::SIZE), ""); columns.insert(int(Columns::TYPE), ""); columns.insert(int(Columns::LEVEL), QString::fromStdString(simox::alg::capitalize_words(memoryItem.getLevelName()))); - columns.insert(int(Columns::ID), QString::fromStdString(memoryItem.id().str())); + columns.insert(int(Columns::ID), QString::fromStdString(memoryItem.id.str())); QTreeWidgetItem* item = new QTreeWidgetItem(columns); item->setData(int(Columns::LEVEL), Qt::UserRole, QString::fromStdString(memoryItem.getLevelName())); - item->setData(int(Columns::ID), Qt::UserRole, QString::fromStdString(memoryItem.id().str())); + item->setData(int(Columns::ID), Qt::UserRole, QString::fromStdString(memoryItem.id.str())); item->setTextAlignment(int(Columns::SIZE), Qt::AlignRight); return item; } @@ -277,7 +277,7 @@ namespace armarx::armem::gui::memory template <class... T> void TreeWidget::updateContainerItem( - const armem::detail::MemoryContainer<T...>& container, QTreeWidgetItem* item) + const armem::workingmemory::detail::MemoryContainer<T...>& container, QTreeWidgetItem* item) { updateItemItem(container, item); item->setText(int(Columns::SIZE), QString::number(container.size())); @@ -285,13 +285,13 @@ namespace armarx::armem::gui::memory template <class... T> void TreeWidget::updateTypedContainerItem( - const armem::detail::TypedEntityContainer<T...>& container, QTreeWidgetItem* item) + const armem::workingmemory::detail::TypedEntityContainer<T...>& container, QTreeWidgetItem* item) { updateContainerItem(container, item); std::string typeName; - if (container.aronType()) + if (container.aronType) { - typeName = container.aronType()->getName(); + typeName = container.aronType->getName(); std::string del = "::"; size_t find = typeName.rfind(del); diff --git a/source/RobotAPI/libraries/armem_gui/memory/TreeWidget.h b/source/RobotAPI/libraries/armem_gui/memory/TreeWidget.h index be73a68b6..d93bed9ab 100644 --- a/source/RobotAPI/libraries/armem_gui/memory/TreeWidget.h +++ b/source/RobotAPI/libraries/armem_gui/memory/TreeWidget.h @@ -4,7 +4,9 @@ #include <QTreeWidget> -#include <RobotAPI/libraries/armem/core/Memory.h> +#include <RobotAPI/libraries/armem/core/workingMemory/Memory.h> +#include <RobotAPI/libraries/armem/core/longtermMemory/Memory.h> + #include <RobotAPI/libraries/armem_gui/TreeWidgetBuilder.h> @@ -20,8 +22,8 @@ namespace armarx::armem::gui::memory TreeWidget(); - void update(const armem::Memory& memory); - void update(const std::map<std::string, const armem::Memory*>& memories); + void update(const armem::workingmemory::Memory& memory); + void update(const std::map<std::string, const armem::workingmemory::Memory*>& memories); std::optional<MemoryID> selectedID() const; @@ -54,34 +56,34 @@ namespace armarx::armem::gui::memory void initWidget(); void initBuilders(); - void updateChildren(const armem::Memory& memory, QTreeWidget* tree); - void updateChildren(const std::map<std::string, const armem::Memory*>& memories, QTreeWidget* tree); + void updateChildren(const armem::workingmemory::Memory& memory, QTreeWidget* tree); + void updateChildren(const std::map<std::string, const armem::workingmemory::Memory*>& memories, QTreeWidget* tree); - void updateChildren(const armem::Memory& memory, QTreeWidgetItem* memoryItem); - void updateChildren(const armem::CoreSegment& coreSeg, QTreeWidgetItem* coreSegItem); - void updateChildren(const armem::ProviderSegment& provSeg, QTreeWidgetItem* provSegItem); - void updateChildren(const armem::Entity& entity, QTreeWidgetItem* entityItem); - void updateChildren(const armem::EntitySnapshot& snapshot, QTreeWidgetItem* snapshotItem); - void updateChildren(const armem::EntityInstance& data, QTreeWidgetItem* parent); + void updateChildren(const armem::workingmemory::Memory& memory, QTreeWidgetItem* memoryItem); + void updateChildren(const armem::workingmemory::CoreSegment& coreSeg, QTreeWidgetItem* coreSegItem); + void updateChildren(const armem::workingmemory::ProviderSegment& provSeg, QTreeWidgetItem* provSegItem); + void updateChildren(const armem::workingmemory::Entity& entity, QTreeWidgetItem* entityItem); + void updateChildren(const armem::workingmemory::EntitySnapshot& snapshot, QTreeWidgetItem* snapshotItem); + void updateChildren(const armem::workingmemory::EntityInstance& data, QTreeWidgetItem* parent); QTreeWidgetItem* makeItem(const std::string& key, const armem::detail::MemoryItem& container); void updateItemItem(const armem::detail::MemoryItem& level, QTreeWidgetItem* item); template <class... T> - void updateContainerItem(const armem::detail::MemoryContainer<T...>& container, QTreeWidgetItem* item); + void updateContainerItem(const armem::workingmemory::detail::MemoryContainer<T...>& container, QTreeWidgetItem* item); template <class... T> - void updateTypedContainerItem(const armem::detail::TypedEntityContainer<T...>& container, QTreeWidgetItem* item); + void updateTypedContainerItem(const armem::workingmemory::detail::TypedEntityContainer<T...>& container, QTreeWidgetItem* item); private: - MapTreeWidgetBuilder<std::string, const Memory*> memoryBuilder; - MapTreeWidgetBuilder<std::string, CoreSegment> coreSegmentBuilder; - MapTreeWidgetBuilder<std::string, ProviderSegment> provSegmentBuilder; - MapTreeWidgetBuilder<std::string, Entity> entityBuilder; - MapTreeWidgetBuilder<armem::Time, EntitySnapshot> snapshotBuilder; - TreeWidgetBuilder<std::vector<EntityInstance>> instanceBuilder; + MapTreeWidgetBuilder<std::string, const workingmemory::Memory*> workingmemoryBuilder; + MapTreeWidgetBuilder<std::string, workingmemory::CoreSegment> workingmemoryCoreSegmentBuilder; + MapTreeWidgetBuilder<std::string, workingmemory::ProviderSegment> workingmemoryProvSegmentBuilder; + MapTreeWidgetBuilder<std::string, workingmemory::Entity> workingmemoryEntityBuilder; + MapTreeWidgetBuilder<armem::Time, workingmemory::EntitySnapshot> workingmemorySnapshotBuilder; + TreeWidgetBuilder<std::vector<workingmemory::EntityInstance>> workingmemoryInstanceBuilder; std::optional<MemoryID> _selectedID; /// While this is false, do not handle selection updates. diff --git a/source/RobotAPI/libraries/armem_robot_localization/TransformReader.cpp b/source/RobotAPI/libraries/armem_robot_localization/TransformReader.cpp index b14f1a711..12d56558e 100644 --- a/source/RobotAPI/libraries/armem_robot_localization/TransformReader.cpp +++ b/source/RobotAPI/libraries/armem_robot_localization/TransformReader.cpp @@ -47,9 +47,9 @@ // this package #include <RobotAPI/libraries/armem/client/query/Builder.h> #include <RobotAPI/libraries/armem/client/query/query_fns.h> -#include <RobotAPI/libraries/armem/core/Memory.h> -#include <RobotAPI/libraries/armem/core/ProviderSegment.h> -#include <RobotAPI/libraries/armem/core/ice_conversions.h> +#include <RobotAPI/libraries/armem/core/workingMemory/Memory.h> +#include <RobotAPI/libraries/armem/core/workingMemory/ProviderSegment.h> +#include <RobotAPI/libraries/armem/core/workingMemory/ice_conversions.h> #include <RobotAPI/libraries/armem/server/MemoryRemoteGui.h> #include <RobotAPI/libraries/aron/core/navigator/type/NavigatorFactory.h> #include <RobotAPI/libraries/core/FramedPose.h> diff --git a/source/RobotAPI/libraries/armem_robot_localization/TransformReader.h b/source/RobotAPI/libraries/armem_robot_localization/TransformReader.h index 061499f7b..f7f6533fb 100644 --- a/source/RobotAPI/libraries/armem_robot_localization/TransformReader.h +++ b/source/RobotAPI/libraries/armem_robot_localization/TransformReader.h @@ -64,14 +64,14 @@ namespace armarx::armem } private: - std::vector<std::string> buildTransformChain(const armem::Memory& memory, + std::vector<std::string> buildTransformChain(const armem::workingmemory::Memory& memory, const TransformQuery& query) const; - std::vector<Eigen::Affine3f> obtainTransforms(const armem::Memory& memory, + std::vector<Eigen::Affine3f> obtainTransforms(const armem::workingmemory::Memory& memory, const std::vector<std::string>& tfChain, const std::string& agent, const std::int64_t& timestamp) const; - Eigen::Affine3f obtainTransform(const std::string& entityName, const armem::ProviderSegment& agentProviderSegment, int64_t timestamp) const; + Eigen::Affine3f obtainTransform(const std::string& entityName, const armem::workingmemory::ProviderSegment& agentProviderSegment, int64_t timestamp) const; armem::client::Reader memoryReader; diff --git a/source/RobotAPI/libraries/armem_robot_localization/TransformWriter.cpp b/source/RobotAPI/libraries/armem_robot_localization/TransformWriter.cpp index 2db61f978..d805dc9d8 100644 --- a/source/RobotAPI/libraries/armem_robot_localization/TransformWriter.cpp +++ b/source/RobotAPI/libraries/armem_robot_localization/TransformWriter.cpp @@ -37,10 +37,10 @@ #include <RobotAPI/libraries/armem/client/query/Builder.h> #include <RobotAPI/libraries/armem/client/query/query_fns.h> -#include <RobotAPI/libraries/armem/core/ice_conversions.h> +#include <RobotAPI/libraries/armem/core/workingMemory/ice_conversions.h> +#include <RobotAPI/libraries/armem/core/workingMemory/Memory.h> +#include <RobotAPI/libraries/armem/core/workingMemory/ProviderSegment.h> #include <RobotAPI/libraries/armem/server/MemoryRemoteGui.h> -#include <RobotAPI/libraries/armem/core/Memory.h> -#include <RobotAPI/libraries/armem/core/ProviderSegment.h> #include <RobotAPI/libraries/aron/core/navigator/type/NavigatorFactory.h> #include <RobotAPI/libraries/core/FramedPose.h> -- GitLab