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