Skip to content
Snippets Groups Projects
Commit 0000bccd authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Allow passing server memory to disk ltm

parent 72720bd9
No related branches found
No related tags found
1 merge request!198Refactor/new arch armem
// Header
#include "CoreSegment.h"
// ArmarX
#include <ArmarXCore/core/time/TimeUtil.h>
#include <ArmarXCore/core/logging/Logging.h>
#include <RobotAPI/libraries/armem/server/wm/memory_definitions.h>
namespace armarx::armem::server::ltm::disk
{
namespace
......@@ -88,13 +89,24 @@ namespace armarx::armem::server::ltm::disk
});
}
void CoreSegment::store(const armem::wm::CoreSegment& c)
template <class CoreSegmentT>
void CoreSegment::_store(const CoreSegmentT& c)
{
c.forEachProviderSegment([this](const armem::wm::ProviderSegment& e)
c.forEachProviderSegment([this](const auto& provSegment)
{
util::ensureFolderExists(std::filesystem::path(path) / e.id().providerSegmentName);
ProviderSegment c(std::filesystem::path(path) / e.id().providerSegmentName);
c.store(e);
util::ensureFolderExists(std::filesystem::path(path) / provSegment.id().providerSegmentName);
ProviderSegment c(std::filesystem::path(path) / provSegment.id().providerSegmentName);
c.store(provSegment);
});
}
void CoreSegment::store(const armem::wm::CoreSegment& c)
{
this->_store(c);
}
void CoreSegment::store(const armem::server::wm::CoreSegment& c)
{
this->_store(c);
}
}
......@@ -20,7 +20,8 @@ namespace armarx::armem::server::ltm::disk
armem::wm::CoreSegment loadAll() override;
void convert(armem::wm::CoreSegment&) override;
void store(const armem::wm::CoreSegment&) override;
void store(const armem::wm::CoreSegment& coreSegment) override;
void store(const armem::server::wm::CoreSegment& coreSegment);
bool forEachProviderSegment(std::function<void(ProviderSegment&)>&& func) const override;
......@@ -28,6 +29,10 @@ namespace armarx::armem::server::ltm::disk
protected:
std::string getExpectedFolderName() const override;
private:
template <class CoreSegmentT> void _store(const CoreSegmentT& coreSegment);
};
} // namespace armarx::armem::server::ltm::disk
......@@ -5,6 +5,9 @@
#include <ArmarXCore/core/time/TimeUtil.h>
#include <ArmarXCore/core/logging/Logging.h>
#include <RobotAPI/libraries/armem/server/wm/memory_definitions.h>
namespace armarx::armem::server::ltm::disk
{
......@@ -136,13 +139,24 @@ namespace armarx::armem::server::ltm::disk
});
}
void Entity::store(const armem::wm::Entity& c)
template <class EntityT>
void Entity::_store(const EntityT& entity)
{
c.forEachSnapshot([this](armem::wm::EntitySnapshot& e)
entity.forEachSnapshot([this](armem::wm::EntitySnapshot& e)
{
util::ensureFolderExists(std::filesystem::path(path) / std::to_string(e.id().timestamp.toMicroSeconds()));
EntitySnapshot c(std::filesystem::path(path) / std::to_string(e.id().timestamp.toMicroSeconds()));
c.store(e);
});
}
void Entity::store(const armem::wm::Entity& c)
{
this->_store(c);
}
void Entity::store(const armem::server::wm::Entity& c)
{
this->_store(c);
}
}
......@@ -22,6 +22,7 @@ namespace armarx::armem::server::ltm::disk
armem::wm::Entity loadAll() override;
void convert(armem::wm::Entity&) override;
void store(const armem::wm::Entity&) override;
void store(const armem::server::wm::Entity&);
bool forEachSnapshot(std::function<void(EntitySnapshot&)>&& func) const override;
bool forEachSnapshotInIndexRange(long first, long last, std::function<void(EntitySnapshot&)>&& func) const override;
......@@ -38,6 +39,10 @@ namespace armarx::armem::server::ltm::disk
protected:
std::string getExpectedFolderName() const override;
private:
template <class EntityT> void _store(const EntityT& entity);
};
} // namespace armarx::armem::server::ltm::disk
......@@ -23,6 +23,7 @@ namespace armarx::armem::server::ltm::disk
protected:
std::string getExpectedFolderName() const override;
};
} // namespace armarx::armem::server::ltm::disk
// Header
#include "Memory.h"
// ArmarX
#include <ArmarXCore/core/time/TimeUtil.h>
#include <ArmarXCore/core/logging/Logging.h>
#include <RobotAPI/libraries/armem/server/wm/memory_definitions.h>
namespace armarx::armem::server::ltm::disk
{
namespace
......@@ -116,7 +117,8 @@ namespace armarx::armem::server::ltm::disk
TIMING_END_STREAM(LTM_Memory_Convert, ARMARX_DEBUG);
}
void Memory::store(const armem::wm::Memory& m)
template <class MemoryT>
void Memory::_store(const MemoryT& memory)
{
TIMING_START(LTM_Memory_Store);
......@@ -127,11 +129,11 @@ namespace armarx::armem::server::ltm::disk
std::lock_guard l(ltm_mutex);
m.forEachCoreSegment([this](const armem::wm::CoreSegment& e)
memory.forEachCoreSegment([this](const auto& core)
{
util::ensureFolderExists(std::filesystem::path(path) / e.id().coreSegmentName);
CoreSegment c(std::filesystem::path(path) / e.id().coreSegmentName);
c.store(e);
util::ensureFolderExists(std::filesystem::path(path) / core.id().coreSegmentName);
CoreSegment c(std::filesystem::path(path) / core.id().coreSegmentName);
c.store(core);
});
// Finaly clear cache and put reference to lut
......@@ -139,4 +141,15 @@ namespace armarx::armem::server::ltm::disk
TIMING_END_STREAM(LTM_Memory_Store, ARMARX_DEBUG);
}
void Memory::store(const armem::wm::Memory& m)
{
this->_store(m);
}
void Memory::store(const armem::server::wm::Memory& m)
{
this->_store(m);
}
}
......@@ -3,7 +3,7 @@
#include <filesystem>
// Base Class
#include "../base/detail/BufferedMemoryBase.h"
#include <RobotAPI/libraries/armem/server/ltm/base/detail/BufferedMemoryBase.h>
#include "detail/DiskStorage.h"
#include "CoreSegment.h"
......@@ -22,7 +22,9 @@ namespace armarx::armem::server::ltm::disk
armem::wm::Memory loadAll() override;
void convert(armem::wm::Memory&) override;
void store(const armem::wm::Memory&) override;
void store(const armem::server::wm::Memory&);
bool forEachCoreSegment(std::function<void(CoreSegment&)>&& func) const override;
......@@ -30,5 +32,9 @@ namespace armarx::armem::server::ltm::disk
protected:
std::string getExpectedFolderName() const override;
private:
template <class MemoryT> void _store(const MemoryT& memory);
};
} // namespace armarx::armem::server::ltm::disk
......@@ -5,6 +5,9 @@
#include <ArmarXCore/core/time/TimeUtil.h>
#include <ArmarXCore/core/logging/Logging.h>
#include <RobotAPI/libraries/armem/server/wm/memory_definitions.h>
namespace armarx::armem::server::ltm::disk
{
namespace
......@@ -89,13 +92,25 @@ namespace armarx::armem::server::ltm::disk
});
}
void ProviderSegment::store(const armem::wm::ProviderSegment& p)
template <class ProviderSegmentT>
void ProviderSegment::_store(const ProviderSegmentT& providerSegment)
{
p.forEachEntity([this](const armem::wm::Entity& e)
providerSegment.forEachEntity([this](const auto& entity)
{
util::ensureFolderExists(std::filesystem::path(path) / e.id().entityName);
Entity c(std::filesystem::path(path) / e.id().entityName);
c.store(e);
util::ensureFolderExists(std::filesystem::path(path) / entity.id().entityName);
Entity c(std::filesystem::path(path) / entity.id().entityName);
c.store(entity);
});
}
void ProviderSegment::store(const armem::wm::ProviderSegment& p)
{
this->_store(p);
}
void ProviderSegment::store(const armem::server::wm::ProviderSegment& p)
{
this->_store(p);
}
}
......@@ -21,6 +21,7 @@ namespace armarx::armem::server::ltm::disk
armem::wm::ProviderSegment loadAll() override;
void convert(armem::wm::ProviderSegment&) override;
void store(const armem::wm::ProviderSegment&) override;
void store(const armem::server::wm::ProviderSegment&);
bool forEachEntity(std::function<void(Entity&)>&& func) const override;
......@@ -28,6 +29,11 @@ namespace armarx::armem::server::ltm::disk
protected:
std::string getExpectedFolderName() const override;
private:
template <class ProviderSegmentT> void _store(const ProviderSegmentT& providerSegment);
};
} // namespace armarx::armem::server::ltm::disk
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment