Skip to content
Snippets Groups Projects
Commit ca9a7271 authored by Christian Dreher's avatar Christian Dreher
Browse files

refactor: Use local reader and writer instead of creating new ones.

parent abeb61ca
No related branches found
No related tags found
No related merge requests found
......@@ -107,11 +107,8 @@ namespace armarx
sleep(2);
ARMARX_IMPORTANT << "Running now.";
armem::client::Reader reader(memory);
armem::client::Writer writer(memory);
armem::MemoryID snapshotID = commitSingleSnapshot(writer, entityID);
commitMultipleSnapshots(writer, entityID, 3);
armem::MemoryID snapshotID = commitSingleSnapshot(entityID);
commitMultipleSnapshots(entityID, 3);
if (true)
{
......@@ -119,18 +116,18 @@ namespace armarx
}
if (true)
{
querySnapshot(reader, snapshotID);
querySnapshot(snapshotID);
}
if (true)
{
commitPrimitives(writer);
queryPrimitives(reader);
commitPrimitives();
queryPrimitives();
}
CycleUtil c(500);
while (!task->isStopped())
{
commitSingleSnapshot(writer, entityID);
commitSingleSnapshot(entityID);
c.waitForCycleDuration();
}
}
......@@ -204,7 +201,7 @@ namespace armarx
}
}
void ArMemExampleClient::querySnapshot(armem::client::Reader& reader, const armem::MemoryID& snapshotID)
void ArMemExampleClient::querySnapshot(const armem::MemoryID& snapshotID)
{
ARMARX_IMPORTANT
<< "Querying exact snapshot of entity: (via query builder)"
......@@ -218,7 +215,7 @@ namespace armarx
.entities().withID(snapshotID)
.snapshots().withID(snapshotID);
armem::client::QueryResult qResult = reader.query(qb.buildQueryInput());
armem::client::QueryResult qResult = memoryReader.query(qb.buildQueryInput());
ARMARX_INFO << "Result: "
<< "\n- success: \t" << qResult.success
<< "\n- error message: \t" << qResult.errorMessage
......@@ -288,7 +285,7 @@ namespace armarx
return armem::MemoryID::fromString(result.segmentID);
}
armem::MemoryID ArMemExampleClient::commitSingleSnapshot(armem::client::Writer& writer, const armem::MemoryID& entityID)
armem::MemoryID ArMemExampleClient::commitSingleSnapshot(const armem::MemoryID& entityID)
{
armem::Commit commit;
armem::EntityUpdate& update = commit.updates.emplace_back();
......@@ -301,7 +298,7 @@ namespace armarx
<< "Committing:"
<< "\n- entityID: \t'" << update.entityID.str() << "'"
;
armem::CommitResult commitResult = writer.commit(commit);
armem::CommitResult commitResult = memoryWriter.commit(commit);
ARMARX_CHECK_EQUAL(commitResult.results.size(), 1);
armem::EntityUpdateResult& result = commitResult.results.at(0);
......@@ -310,7 +307,7 @@ namespace armarx
return result.snapshotID;
}
void ArMemExampleClient::commitMultipleSnapshots(armem::client::Writer& writer, const armem::MemoryID& entityID, int num)
void ArMemExampleClient::commitMultipleSnapshots(const armem::MemoryID& entityID, int num)
{
armem::Commit commit;
for (int i = 0; i < num; ++i)
......@@ -325,16 +322,16 @@ namespace armarx
}
ARMARX_INFO << "Commiting " << commit.updates.size() << " more updates.";
armem::CommitResult commitResult = writer.commit(commit);
armem::CommitResult commitResult = memoryWriter.commit(commit);
ARMARX_CHECK_EQUAL(commitResult.results.size(), commit.updates.size());
}
void ArMemExampleClient::commitPrimitives(armem::client::Writer& writer)
void ArMemExampleClient::commitPrimitives()
{
ARMARX_IMPORTANT << "Adding segment " << "Primitive" << "/" << getName();
auto addSegmentResult = writer.addSegment("Primitive", getName());
auto addSegmentResult = memoryWriter.addSegment("Primitive", getName());
if (!addSegmentResult.success)
{
ARMARX_ERROR << addSegmentResult.errorMessage;
......@@ -370,14 +367,14 @@ namespace armarx
update.instancesData = { primitive.toAron() };
}
armem::CommitResult commitResult = writer.commit(commit);
armem::CommitResult commitResult = memoryWriter.commit(commit);
if (!commitResult.allSuccess())
{
ARMARX_WARNING << commitResult.allErrorMessages();
}
}
void ArMemExampleClient::queryPrimitives(armem::client::Reader& reader)
void ArMemExampleClient::queryPrimitives()
{
// Query all entities from provider.
armem::client::QueryBuilder qb;
......@@ -387,7 +384,7 @@ namespace armarx
.entities().all()
.snapshots().all();
armem::client::QueryResult result = reader.query(qb.buildQueryInput());
armem::client::QueryResult result = memoryReader.query(qb.buildQueryInput());
if (result)
{
tab.queryResult = std::move(result.memory);
......
......@@ -112,14 +112,14 @@ namespace armarx
void waitForMemory();
armem::MemoryID addProviderSegment();
armem::MemoryID commitSingleSnapshot(armem::client::Writer& writer, const armem::MemoryID& entityID);
void commitMultipleSnapshots(armem::client::Writer& writer, const armem::MemoryID& entityID, int num = 3);
armem::MemoryID commitSingleSnapshot(const armem::MemoryID& entityID);
void commitMultipleSnapshots(const armem::MemoryID& entityID, int num = 3);
void queryLatestRawIce(const armem::MemoryID& entityID);
void querySnapshot(armem::client::Reader& reader, const armem::MemoryID& snapshotID);
void querySnapshot(const armem::MemoryID& snapshotID);
void commitPrimitives(armem::client::Writer& writer);
void queryPrimitives(armem::client::Reader& reader);
void commitPrimitives();
void queryPrimitives();
private:
......
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