Skip to content
Snippets Groups Projects
Commit 4bdfbea1 authored by armar-user's avatar armar-user
Browse files

changes to ltm

parent a76065f4
No related branches found
No related tags found
1 merge request!185Clean up interfaces and unneeded code in memory core classes
......@@ -69,6 +69,7 @@ namespace armarx::armem::server::robot_state
const std::string prefix = "mem.";
workingMemory.name() = "RobotState";
longtermMemory.name() = "RobotState";
defs->optional(workingMemory.name(), prefix + "MemoryName", "Name of this memory server.");
const std::string robotUnitPrefix{sensorValuePrefix};
......
......@@ -96,7 +96,7 @@ namespace armarx::armem::base::detail
{
DerivedT d;
this->_copySelfEmpty(d);
return d;
return std::move(d);
}
......
......@@ -10,6 +10,54 @@
namespace armarx::armem::ltm
{
Memory::Memory(const Memory& other) :
Base(other),
dbsettings(other.dbsettings),
alwaysTransferSettings(other.alwaysTransferSettings),
periodicTransferSettings(other.periodicTransferSettings),
onFullTransferSettings(other.onFullTransferSettings),
mongoDBMutex()
{
// Do not copy _mutex.
}
Memory::Memory(Memory&& other) :
Base(other),
dbsettings(other.dbsettings),
alwaysTransferSettings(other.alwaysTransferSettings),
periodicTransferSettings(other.periodicTransferSettings),
onFullTransferSettings(other.onFullTransferSettings)
{
// Do not move _mutex.
}
Memory& Memory::operator=(const Memory& other)
{
Base::operator=(other);
dbsettings = other.dbsettings;
alwaysTransferSettings = other.alwaysTransferSettings;
periodicTransferSettings = other.periodicTransferSettings;
onFullTransferSettings = other.onFullTransferSettings;
// Don't copy _mutex.
return *this;
}
Memory& Memory::operator=(Memory&& other)
{
Base::operator=(other);
dbsettings = std::move(other.dbsettings);
alwaysTransferSettings = std::move(other.alwaysTransferSettings);
periodicTransferSettings = std::move(other.periodicTransferSettings);
onFullTransferSettings = std::move(other.onFullTransferSettings);
// Don't move _mutex.
return *this;
}
bool Memory::checkConnection() const
{
// Check connection:
......@@ -67,22 +115,32 @@ namespace armarx::armem::ltm
return;
}
std::scoped_lock l(mongoDBMutex);
ARMARX_INFO << "(Re)Establishing connection to: " << dbsettings.toString();
_container.clear();
ARMARX_TRACE;
mongocxx::client& client = MongoDBConnectionManager::EstablishConnection(dbsettings);
ARMARX_TRACE;
if (not(bool) client)
if (!client)
{
ARMARX_ERROR << "A client has died. Could not reload.";
return;
}
auto databases = client.list_databases();
for (const auto& doc : databases)
{
nlohmann::json json = nlohmann::json::parse(bsoncxx::to_json(doc));
ARMARX_INFO << "Found the database: " << json.at("name");
}
mongocxx::database db = client[dbsettings.database];
ARMARX_INFO << "Getting collection for id: " << id().str();
mongocxx::collection coll = db[id().str()];
mongocxx::cursor cursor = coll.find({});
for (auto doc : cursor)
for (const auto& doc : cursor)
{
nlohmann::json json = nlohmann::json::parse(bsoncxx::to_json(doc));
ARMARX_INFO << "Memory: Found foreign key: " << json.at("foreign_key");
......@@ -115,6 +173,7 @@ namespace armarx::armem::ltm
return;
}
std::scoped_lock l(mongoDBMutex);
ARMARX_INFO << "Merge memory with name '" << m.name() << "' into the LTM with name '" << name() << "'";
TIMING_START(LTM_Append);
......
......@@ -55,6 +55,12 @@ namespace armarx::armem::ltm
Mode mode;
};
Memory(const Memory& other);
Memory(Memory&& other);
Memory& operator=(const Memory& other);
Memory& operator=(Memory&& other);
// PropertyDefinitions related to LTM
void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string& prefix = "");
......@@ -88,6 +94,9 @@ namespace armarx::armem::ltm
PeriodicTransferSettings periodicTransferSettings;
OnFullTransferSettings onFullTransferSettings;
private:
mutable std::mutex mongoDBMutex;
};
}
......@@ -177,7 +177,7 @@ namespace armarx::armem::server
{
if (longtermMemory->alwaysTransferSettings.enabled)
{
wm::Memory tmp("tmp");
wm::Memory tmp(longtermMemory->name());
tmp.update(update);
longtermMemory->append(tmp);
}
......
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