diff --git a/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp b/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp index 12553981eb746925c5a3f505dda663488fc88784..3cc3879dff04014162043cd20ab1c9e7ae90c4f4 100644 --- a/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp +++ b/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp @@ -186,17 +186,43 @@ namespace armarx::armem::server result.snapshotID = updateResult.id; result.timeArrived = update.timeArrived; - // also store in ltm if transfermode is set to always - // TODO: Move outside of loop? - if (longtermMemory) + for (const auto& snapshot : updateResult.removedSnapshots) { - + ARMARX_DEBUG << "The id " << snapshot.id() << " was removed from wm"; } - // TODO: Consollidate to ltm if onFilledTransfer is enabled (fabian.peller) - for (const auto& snapshot : updateResult.removedSnapshots) + // Consollidate to ltm + if (longtermMemory) { - ARMARX_DEBUG << "The id " << snapshot.id() << " was removed from wm"; + //ARMARX_IMPORTANT << longtermMemory->id().str(); + //ARMARX_IMPORTANT << longtermMemory->getPath(); + + // Create Memory out of list TODO: make nicer + armem::wm::Memory m(longtermMemory->name()); + for (const auto& snapshot : updateResult.removedSnapshots) + { + if (!m.hasCoreSegment(snapshot.id().coreSegmentName)) + { + m.addCoreSegment(snapshot.id().coreSegmentName); + } + auto* c = m.findCoreSegment(snapshot.id().coreSegmentName); + + if (!c->hasProviderSegment(snapshot.id().providerSegmentName)) + { + c->addProviderSegment(snapshot.id().providerSegmentName); + } + auto* p = c->findProviderSegment(snapshot.id().providerSegmentName); + + if (!p->hasEntity(snapshot.id().entityName)) + { + p->addEntity(snapshot.id().entityName); + } + auto* e = p->findEntity(snapshot.id().entityName); + + e->addSnapshot(snapshot); + } + longtermMemory->store(m); + longtermMemory->storeBuffer(); } if (publishUpdates)