MemoryNameSystem.cpp
Go to the documentation of this file.
1 #include "MemoryNameSystem.h"
2 
4 {
5 
6  // dto::WaitForServerResult MemoryNameSystem::waitForServer(const dto::WaitForServerInput& input)
7  void
9  const AMD_MemoryNameSystemInterface_waitForServerPtr& future,
10  const dto::WaitForServerInput& input)
11  {
12  ARMARX_INFO << "Waiting for server `" << input.name << "`.";
13 
14  {
15  std::lock_guard g{futuresMtx};
16  waitForServerFutures[input.name].push_back(future);
17  }
18 
20  }
21 
22  void
24  {
25  std::lock_guard g{futuresMtx};
26 
27  for (auto it = waitForServerFutures.begin(); it != waitForServerFutures.end();)
28  {
29  auto& [name, futures] = *it;
30  if (auto st = servers.find(name); st != servers.end())
31  {
32  ServerInfo& info = st->second;
33 
34  dto::WaitForServerResult result;
35  result.success = true;
36  result.server = info.server;
37 
38  // Send responses and remove entry.
39  for (auto& future : futures)
40  {
41  future->ice_response(result);
42  }
43 
44  // it: iterator following the last removed element (https://en.cppreference.com/w/cpp/container/map/erase)
45  it = waitForServerFutures.erase(it);
46  }
47  else
48  {
49  ++it; // Skip.
50  ARMARX_INFO << "Server `" << name << "` not available yet.";
51  }
52  }
53  }
54 
55  dto::RegisterServerResult
56  MemoryNameSystem::registerServer(const dto::RegisterServerInput& input)
57  {
58  const auto result = Registry::registerServer(input);
60 
61  return result;
62  }
63 
66  {
67  using namespace armarx::RemoteGui::Client;
68 
69  GridLayout grid;
70 
71  int row = 0;
72  grid.add(Label("Memory Name"), {row, 0})
73  .add(Label("Component Name"), {row, 1})
74  .add(Label("R/W/P/A"), {row, 2})
75  .add(Label("Registration Time"), {row, 3});
76  row++;
77 
78  for (const auto& [name, info] : servers)
79  {
80  ARMARX_CHECK_EQUAL(name, info.name);
81  std::string componentName = "";
82  std::string mode = "";
83  if (info.server.reading)
84  {
85  componentName = info.server.reading->ice_getIdentity().name;
86  mode += "R";
87  }
88  if (info.server.writing)
89  {
90  componentName = info.server.writing->ice_getIdentity().name;
91  mode += "W";
92  }
93  if (info.server.prediction)
94  {
95  componentName = info.server.prediction->ice_getIdentity().name;
96  mode += "P";
97  }
98  if (info.server.actions)
99  {
100  componentName = info.server.actions->ice_getIdentity().name;
101  mode += "A";
102  }
103 
104  int col = 0;
105  grid.add(Label(name), {row, col});
106  ++col;
107 
108  grid.add(Label(componentName), {row, col});
109  ++col;
110 
111  grid.add(Label(mode), {row, col});
112  ++col;
113 
114  grid.add(Label(armem::toDateTimeMilliSeconds(info.timeRegistered, 0)), {row, col});
115  ++col;
116 
117  ++row;
118  }
119 
120  return grid;
121  }
122 
123 } // namespace armarx::armem::mns
armarx::armem::mns::MemoryNameSystem::waitForServer_async
void waitForServer_async(const AMD_MemoryNameSystemInterface_waitForServerPtr &future, const dto::WaitForServerInput &input)
Store the call in a container for later response.
Definition: MemoryNameSystem.cpp:8
armarx::armem::mns::Registry::ServerInfo
Information about a memory entry.
Definition: Registry.h:54
armarx::RemoteGui::Client::GridLayout::add
GridLayout & add(Widget const &child, Pos pos, Span span=Span{1, 1})
Definition: Widgets.cpp:438
armarx::armem::mns::Registry::ServerInfo::server
mns::dto::MemoryServerInterfaces server
Definition: Registry.h:57
armarx::armem::mns::MemoryNameSystem::waitForServer_processOnce
void waitForServer_processOnce()
Definition: MemoryNameSystem.cpp:23
visionx::voxelgrid::Label
uint32_t Label
Type of an object label.
Definition: types.h:6
armarx::RemoteGui::Client::GridLayout
Definition: Widgets.h:186
armarx::armem::toDateTimeMilliSeconds
std::string toDateTimeMilliSeconds(const Time &time, int decimals=6)
Returns timeas e.g.
Definition: Time.cpp:35
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:12
MemoryNameSystem.h
armarx::armem::mns::MemoryNameSystem::RemoteGui_buildInfoGrid
armarx::RemoteGui::Client::GridLayout RemoteGui_buildInfoGrid()
Builds a RemoteGui grid containing information about registered memories.
Definition: MemoryNameSystem.cpp:65
armarx::armem::mns
Definition: MemoryNameSystem.cpp:3
armarx::armem::mns::MemoryNameSystem::registerServer
dto::RegisterServerResult registerServer(const dto::RegisterServerInput &input) override
Register a new memory server or update an existing entry.
Definition: MemoryNameSystem.cpp:56
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::armem::mns::Registry::registerServer
virtual dto::RegisterServerResult registerServer(const dto::RegisterServerInput &input)
Register a new memory server or update an existing entry.
Definition: Registry.cpp:22
ARMARX_CHECK_EQUAL
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
Definition: ExpressionException.h:130
armarx::RemoteGui::Client
Definition: EigenWidgets.cpp:8
armarx::armem::mns::Registry::servers
std::map< std::string, ServerInfo > servers
The registered memories.
Definition: Registry.h:62