MemoryRemoteGui.cpp
Go to the documentation of this file.
1#include "MemoryRemoteGui.h"
2
3#include <mutex>
4
5#include <SimoxUtility/meta/type_name.h>
6
8
11
13
15{
16
17 template <class... Args>
19 MemoryRemoteGui::_makeGroupBox(const armem::base::MemoryBase<Args...>& memory) const
20 {
21 GroupBox group;
22 group.setLabel(makeGroupLabel("Memory", memory.name(), memory.size()));
23
24 if (memory.empty())
25 {
26 group.addChild(Label(makeNoItemsMessage("core segments")));
27 }
28 memory.forEachCoreSegment([this, &group](const auto& coreSegment)
29 { group.addChild(this->makeGroupBox(coreSegment)); });
30 return group;
31 }
32
33 static std::string
34 getTypeString(const armem::base::detail::AronTyped& typed)
35 {
36 std::stringstream type;
37 if (typed.aronType())
38 {
39 type << " (" << typed.aronType()->getFullName() << ")";
40 }
41 else
42 {
43 type << " (no Aron type)";
44 }
45 return type.str();
46 }
47
48 template <class... Args>
50 MemoryRemoteGui::_makeGroupBox(const armem::base::CoreSegmentBase<Args...>& coreSegment) const
51 {
52 GroupBox group;
53 group.setLabel(makeGroupLabel("Core Segment", coreSegment.name(), coreSegment.size()) +
54 getTypeString(coreSegment));
55
56 if (coreSegment.empty())
57 {
58 group.addChild(Label(makeNoItemsMessage("provider segments")));
59 }
60 coreSegment.forEachProviderSegment(
61 [this, &group](const auto& providerSegment)
62 { group.addChild(this->makeGroupBox(providerSegment)); });
63 return group;
64 }
65
66 template <class... Args>
68 MemoryRemoteGui::_makeGroupBox(
69 const armem::base::ProviderSegmentBase<Args...>& providerSegment) const
70 {
71 GroupBox group;
72 group.setLabel(
73 makeGroupLabel("Provider Segment", providerSegment.name(), providerSegment.size()) +
74 getTypeString(providerSegment));
75
76 if (providerSegment.empty())
77 {
78 group.addChild(Label(makeNoItemsMessage("entities")));
79 }
80 providerSegment.forEachEntity([this, &group](const auto& entity)
81 { group.addChild(this->makeGroupBox(entity)); });
82 return group;
83 }
84
85 template <class... Args>
87 MemoryRemoteGui::_makeGroupBox(const armem::base::EntityBase<Args...>& entity) const
88 {
89 GroupBox group;
90 group.setLabel(makeGroupLabel("Entity", entity.name(), entity.size()));
91
92 if (entity.empty())
93 {
94 group.addChild(Label(makeNoItemsMessage("snapshots")));
95 }
96
97 auto addChild = [this, &group](const armem::wm::EntitySnapshot& snapshot)
98 { group.addChild(makeGroupBox(snapshot)); };
99
100 if (int(entity.size()) <= maxHistorySize)
101 {
102 entity.forEachSnapshot(addChild);
103 }
104 else
105 {
106 const int margin = 2;
107 entity.forEachSnapshotInIndexRange(0, margin, addChild);
108 entity.forEachSnapshotInIndexRange(-margin, -1, addChild);
109 }
110 group.setCollapsed(true);
111
112 return group;
113 }
114
117 {
118 return this->_makeGroupBox(memory);
119 }
120
123 {
124 return this->_makeGroupBox(memory);
125 }
126
129 {
130 return coreSegment.doLocked([this, &coreSegment]()
131 { return this->_makeGroupBox(coreSegment); });
132 }
133
136 {
137 return this->_makeGroupBox(coreSegment);
138 }
139
142 {
143 return this->_makeGroupBox(providerSegment);
144 }
145
148 {
149 return this->_makeGroupBox(providerSegment);
150 }
151
154 {
155 return this->_makeGroupBox(entity);
156 }
157
160 {
161 return this->_makeGroupBox(entity);
162 }
163
166 {
167 GroupBox group;
169 "t", armem::toDateTimeMilliSeconds(snapshot.time()), snapshot.size(), " = ", ""));
170
171 if (snapshot.empty())
172 {
173 group.addChild(Label(makeNoItemsMessage("instances")));
174 }
175 snapshot.forEachInstance(
176 [this, &group](const armem::wm::EntityInstance& instance)
177 {
178 group.addChild(makeGroupBox(instance));
179 return true;
180 });
181 group.setCollapsed(true);
182
183 return group;
184 }
185
188 {
189 GroupBox group;
190
191 if (instance.data())
192 {
194 aron::data::visitRecursive(v, instance.data());
195 group = v.result;
196 }
197 else
198 {
199 group.addChild(Label("(No data.)"));
200 }
201
202 std::stringstream ss;
203 ss << "Instance #" << instance.index();
204 group.setLabel(ss.str());
205 group.setCollapsed(true);
206
207 return group;
208 }
209
210 std::string
211 MemoryRemoteGui::makeGroupLabel(const std::string& term,
212 const std::string& name,
213 size_t size,
214 const std::string& namePrefix,
215 const std::string& nameSuffix) const
216 {
217 std::stringstream ss;
218 ss << term << namePrefix << name << nameSuffix << " (" << size << ")";
219 return ss.str();
220 }
221
222 std::string
223 MemoryRemoteGui::makeNoItemsMessage(const std::string& term) const
224 {
225 std::stringstream ss;
226 ss << "(no " << term << ")";
227 return ss.str();
228 }
229
230
231} // namespace armarx::armem::server
bool forEachProviderSegment(ProviderSegmentFunctionT &&func)
void forEachSnapshotInIndexRange(long first, long last, FunctionT &&func) const
Return all snapshots from first to last index.
Definition EntityBase.h:549
bool forEachSnapshot(SnapshotFunctionT &&func)
Definition EntityBase.h:391
bool forEachInstance(InstanceFunctionT &&func)
bool forEachCoreSegment(CoreSegmentFunctionT &&func)
Definition MemoryBase.h:188
aron::type::ObjectPtr & aronType()
Definition AronTyped.cpp:19
GroupBox makeGroupBox(const armem::wm::Memory &memory) const
armarx::RemoteGui::Client::GroupBox GroupBox
armarx::RemoteGui::Client::Label Label
std::string makeGroupLabel(const std::string &term, const std::string &name, size_t size, const std::string &namePrefix=": '", const std::string &nameSuffix="'") const
std::string makeNoItemsMessage(const std::string &term) const
auto doLocked(FunctionT &&function) const
Execute function under shared (read) lock.
Client-side working memory core segment.
Client-side working entity instance.
Client-side working memory entity snapshot.
Client-side working memory entity.
Client-side working memory.
Client-side working memory provider segment.
Brief description of class memory.
Definition memory.h:39
std::string toDateTimeMilliSeconds(const Time &time, int decimals=6)
Returns timeas e.g.
Definition Time.cpp:35
void visitRecursive(RecursiveVisitorImplementation &v, typename RecursiveVisitorImplementation::Input &o)
void addChild(Widget const &child)
Definition Widgets.cpp:95
void setLabel(std::string const &text)
Definition Widgets.cpp:420
void setCollapsed(bool collapsed)
Definition Widgets.cpp:427