util.cpp
Go to the documentation of this file.
1 #include "util.h"
2 
5 
6 namespace 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 
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 
34  std::optional<std::pair<armarx::aron::data::DictPtr, armarx::aron::type::ObjectPtr>>
37  {
38  const auto* instance = memory.findLatestInstance(memoryID);
39  if (instance == nullptr)
40  {
41  return {};
42  }
43 
44  armarx::aron::data::DictPtr aronData = instance->data();
46  const auto* providerSegment = memory.findProviderSegment(memoryID);
47  if (providerSegment == nullptr)
48  {
49  return {};
50  }
51 
52  if (!providerSegment->hasAronType())
53  {
54  const auto* coreSegment = memory.findCoreSegment(memoryID);
55  if (coreSegment == nullptr || !coreSegment->hasAronType())
56  {
57  return {};
58  }
59  aronType = coreSegment->aronType();
60  }
61  else
62  {
63  aronType = providerSegment->aronType();
64  }
65 
66  return {{aronData, aronType}};
67  }
68 } // namespace armarx::armem
armarx::armem::detail::SuccessHeader::success
bool success
Definition: SuccessHeader.h:20
armarx::armem::client::Reader
Reads data from a memory server.
Definition: Reader.h:24
armarx::armem::client::QueryResult::memory
wm::Memory memory
The slice of the memory that matched the query.
Definition: Query.h:58
client.h
armarx::armem
Definition: LegacyRobotStateMemoryAdapter.cpp:31
mns.h
armarx::armem::client::QueryResult
Result of a QueryInput.
Definition: Query.h:50
armarx::memory
Brief description of class memory.
Definition: memory.h:39
armarx::armem::resolveID
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
armarx::armem::client::Reader::queryMemoryIDs
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:290
armarx::armem::error::CouldNotResolveMemoryServer::makeMsg
static std::string makeMsg(const MemoryID &memoryID, const std::string &errorMessage="")
Definition: mns.cpp:34
armarx::armem::detail::SuccessHeader::errorMessage
std::string errorMessage
Definition: SuccessHeader.h:21
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::armem::wm::Memory
Client-side working memory.
Definition: memory_definitions.h:133
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
armarx::armem::index::memoryID
const MemoryID memoryID
Definition: memory_ids.cpp:29
armarx::armem::client::MemoryNameSystem
The memory name system (MNS) client.
Definition: MemoryNameSystem.h:69
armarx::armem::error::CouldNotResolveMemoryServer
Indicates that a query to the Memory Name System failed.
Definition: mns.h:26
util.h
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::armem::client::MemoryNameSystem::getReader
Reader getReader(const MemoryID &memoryID)
Get a reader to the given memory name.
Definition: MemoryNameSystem.cpp:177
armarx::armem::extractDataAndType
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:35