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
int Label(int n[], int size, int *curLabel, MiscLib::Vector< std::pair< int, size_t > > *labels)
Definition Bitmap.cpp:801
armarx::RemoteGui::Client::GridLayout RemoteGui_buildInfoGrid()
Builds a RemoteGui grid containing information about registered memories.
dto::RegisterServerResult registerServer(const dto::RegisterServerInput &input) override
Register a new memory server or update an existing entry.
void waitForServer_async(const AMD_MemoryNameSystemInterface_waitForServerPtr &future, const dto::WaitForServerInput &input)
Store the call in a container for later response.
std::map< std::string, ServerInfo > servers
The registered memories.
Definition Registry.h:62
virtual dto::RegisterServerResult registerServer(const dto::RegisterServerInput &input)
Register a new memory server or update an existing entry.
Definition Registry.cpp:22
#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...
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
std::string toDateTimeMilliSeconds(const Time &time, int decimals=6)
Returns timeas e.g.
Definition Time.cpp:35
GridLayout & add(Widget const &child, Pos pos, Span span=Span{1, 1})
Definition Widgets.cpp:438
Information about a memory entry.
Definition Registry.h:55
mns::dto::MemoryServerInterfaces server
Definition Registry.h:57