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

feature: More informative signature for callback, allow subscribing to non-entities.

parent d5798a60
No related branches found
No related tags found
3 merge requests!102ArMem Memory Updates,!100Memory QueryBuilder,!99Memory subscriptions
......@@ -71,15 +71,23 @@ namespace armarx::armem
void
Reader::updated(const std::vector<MemoryID>& updatedIDs)
Reader::updated(const std::vector<MemoryID>& updatedSnapshotIDs)
{
MemoryID id;
for (const MemoryID& updatedID : updatedIDs)
for (const auto& [subscription, callback] : callbacks)
{
id = updatedID.getEntityID();
if (callbacks.find(id) != callbacks.end())
std::vector<MemoryID> matchingSnapshotIDs;
for (const MemoryID& updatedSnapshotID : updatedSnapshotIDs)
{
if (contains(subscription, updatedSnapshotID))
{
matchingSnapshotIDs.push_back(updatedSnapshotID);
}
}
if (not matchingSnapshotIDs.empty())
{
callbacks[id]();
callback(subscription, matchingSnapshotIDs);
}
}
}
......@@ -88,8 +96,7 @@ namespace armarx::armem
void
Reader::subscribe(const MemoryID& id, callback callback)
{
ARMARX_CHECK(id.hasEntityName()) << "MemoryID must be an entity ID.";
callbacks[id.getEntityID()] = callback;
callbacks[id] = callback;
}
}
......@@ -22,7 +22,7 @@ namespace armarx::armem
class Reader
{
using callback = std::function<void()>;
using callback = std::function<void(const MemoryID& subscriptionID, const std::vector<MemoryID>& updatedSnapshotIDs)>;
public:
......
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