util.cpp
Go to the documentation of this file.
1#include "util.h"
2
5
6namespace armarx::armem
7{
8
9 std::optional<armarx::armem::wm::Memory>
11 {
13 try
14 {
15 reader = mns.getReader(memoryID);
16 }
18 {
20 return {};
21 }
22
23 const armarx::armem::ClientQueryResult result = reader.queryMemoryIDs({memoryID});
24 if (result.success)
25 {
26 return result.memory;
27 }
28 ARMARX_WARNING << "Could not query memory for ID " << memoryID << ", "
29 << result.errorMessage;
30 return {};
31 }
32
33 std::optional<std::pair<armarx::aron::data::DictPtr, armarx::aron::type::ObjectPtr>>
35 const armarx::armem::MemoryID& memoryID)
36 {
37 const auto* instance = memory.findLatestInstance(memoryID);
38 if (instance == nullptr)
39 {
40 return {};
41 }
42
43 armarx::aron::data::DictPtr aronData = instance->data();
45 const auto* providerSegment = memory.findProviderSegment(memoryID);
46 if (providerSegment == nullptr)
47 {
48 return {};
49 }
50
51 if (!providerSegment->hasAronType())
52 {
53 const auto* coreSegment = memory.findCoreSegment(memoryID);
54 if (coreSegment == nullptr || !coreSegment->hasAronType())
55 {
56 return {};
57 }
58 aronType = coreSegment->aronType();
59 }
60 else
61 {
62 aronType = providerSegment->aronType();
63 }
64
65 return {{aronData, aronType}};
66 }
67} // namespace armarx::armem
The memory name system (MNS) client.
Reads data from a memory server.
Definition Reader.h:25
QueryResult queryMemoryIDs(const std::vector< MemoryID > &ids, armem::query::DataMode dataMode=armem::query::DataMode::WithData) const
Query a specific set of memory IDs.
Definition Reader.cpp:374
Indicates that a query to the Memory Name System failed.
Definition mns.h:25
static std::string makeMsg(const MemoryID &memoryID, const std::string &errorMessage="")
Definition mns.cpp:36
Client-side working memory.
Brief description of class memory.
Definition memory.h:39
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
client::QueryResult ClientQueryResult
Definition client.h:18
std::optional< std::pair< armarx::aron::data::DictPtr, armarx::aron::type::ObjectPtr > > extractDataAndType(const armarx::armem::wm::Memory &memory, const armarx::armem::MemoryID &memoryID)
get the data and type of the given MemoryID in the given Memory.
Definition util.cpp:34
std::optional< armarx::armem::wm::Memory > resolveID(armarx::armem::client::MemoryNameSystem &mns, const armarx::armem::MemoryID &memoryID)
resolve a single MemoryID with the given MemoryNameSystem.
Definition util.cpp:10
std::shared_ptr< Dict > DictPtr
Definition Dict.h:42
std::shared_ptr< Object > ObjectPtr
Definition Object.h:36
wm::Memory memory
The slice of the memory that matched the query.
Definition Query.h:58