ExampleMemory.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package RobotAPI::ArmarXObjects::ExampleMemory
17 * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu )
18 * @date 2020
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#pragma once
24
25#include <map>
26#include <mutex>
27
29#include <ArmarXCore/interface/observers/ObserverInterface.h>
30
32
35
36namespace armarx
37{
38 /**
39 * @defgroup Component-ExampleMemory ExampleMemory
40 * @ingroup RobotAPI-Components
41 * A description of the component ExampleMemory.
42 *
43 * @class ExampleMemory
44 * @ingroup Component-ExampleMemory
45 * @brief Brief description of class ExampleMemory.
46 *
47 * Detailed description of class ExampleMemory.
48 */
50 virtual public armarx::Component,
53 {
54 public:
55 /// @see armarx::ManagedIceObject::getDefaultName()
56 std::string getDefaultName() const override;
57
58
59 // WritingInterface interface
60 public:
61 armem::data::AddSegmentsResult addSegments(const armem::data::AddSegmentsInput& input,
62 const Ice::Current&) override;
63 armem::data::CommitResult commit(const armem::data::Commit& commit,
64 const Ice::Current& = Ice::emptyCurrent) override;
65
66 // ReadingInterface interface
67 armem::query::data::Result query(const armem::query::data::Input& input,
68 const Ice::Current& = Ice::emptyCurrent) override;
69
70
71 // LightweightRemoteGuiComponentPluginUser interface
72 public:
73 void createRemoteGuiTab();
74 void RemoteGui_update() override;
75
76 // ActionsInterface interface
77 public:
78 armem::actions::GetActionsOutputSeq
79 getActions(const armem::actions::GetActionsInputSeq& input) override;
80 armem::actions::ExecuteActionOutputSeq
81 executeActions(const armem::actions::ExecuteActionInputSeq& input) override;
82
83
84 protected:
86
87 void onInitComponent() override;
88 void onConnectComponent() override;
89 void onDisconnectComponent() override;
90 void onExitComponent() override;
91
92
93 private:
94 armem::PredictionResult predictLatest(const armem::PredictionRequest& request);
95
96 // Client statistics tracking
97 struct ClientStatistics
98 {
99 std::string connectionString;
100 std::string remoteAddress;
101 int remotePort = -1;
102 int clientPid = -1; // From Ice context if available
103 size_t commitCount = 0;
104 size_t queryCount = 0;
105 armem::Time firstSeen;
106 armem::Time lastCommit;
107 armem::Time lastQuery;
108 };
109
110 std::string extractClientIdentifier(const Ice::Current& current) const;
111 std::string formatClientIdentifier(const std::string& connectionString) const;
112 void parseConnectionInfo(const std::string& connectionString, std::string& address, int& port) const;
113 int extractClientPid(const Ice::Current& current) const;
114 void recordCommit(const Ice::Current& current);
115 void recordQuery(const Ice::Current& current);
116 void logClientStatistics() const;
117 RemoteGui::Client::GroupBox createClientStatisticsGroupBox();
118 void updateClientStatisticsLabels();
119 void updateClientStatisticsLabelsInternal(); // Internal version without mutex lock
120
121 mutable std::mutex clientStatsMutex;
122 mutable std::map<std::string, ClientStatistics> clientStats;
123
125
126 struct Properties
127 {
129 {
130 std::vector<std::string> defaultCoreSegments = {"ExampleModality",
131 "ExampleConcept"};
133 bool addOnUsage = false;
134 };
135
136 CoreSegments core;
137
138 bool enableRemoteGui = false;
139 bool showMemoryContent = true; // Show memory content in RemoteGui
140 bool showClientStats = true; // Show client statistics in RemoteGui
141 bool publishToDebugObserver = false; // Publish client statistics to DebugObserver
142 };
143
144 Properties p;
145
146 // Client index tracking for DebugObserver channel naming
147 std::map<std::string, int> clientIndices;
148 int nextClientIndex = 1;
149 int getClientIndex(const std::string& clientId);
150
151 struct RemoteGuiTab : RemoteGui::Client::Tab
152 {
153 std::atomic_bool rebuild = false;
154
155 RemoteGui::Client::GroupBox memoryGroup;
156 RemoteGui::Client::GroupBox clientStatsGroup;
157
158 // Labels for updating client statistics without rebuilding
159 RemoteGui::Client::Label summaryLabel;
160 std::map<std::string, RemoteGui::Client::Label> clientLabels;
161 std::map<std::string, RemoteGui::Client::Label> connectionLabels;
162
163 armem::Time lastStatsUpdate;
164 int statsUpdateIntervalMs = 10000; // Update every 10 seconds
165 };
166
167 RemoteGuiTab tab;
168 };
169} // namespace armarx
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
Brief description of class ExampleMemory.
void onInitComponent() override
Pure virtual hook for the subclass.
armem::query::data::Result query(const armem::query::data::Input &input, const Ice::Current &=Ice::emptyCurrent) override
void onDisconnectComponent() override
Hook for subclass.
void RemoteGui_update() override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
armem::data::CommitResult commit(const armem::data::Commit &commit, const Ice::Current &=Ice::emptyCurrent) override
armem::actions::ExecuteActionOutputSeq executeActions(const armem::actions::ExecuteActionInputSeq &input) override
armem::actions::GetActionsOutputSeq getActions(const armem::actions::GetActionsInputSeq &input) override
void onConnectComponent() override
Pure virtual hook for the subclass.
void onExitComponent() override
Hook for subclass.
armem::data::AddSegmentsResult addSegments(const armem::data::AddSegmentsInput &input, const Ice::Current &) override
std::string getDefaultName() const override
Base class of memory server components.
armarx::core::time::DateTime Time
This file offers overloads of toIce() and fromIce() functions for STL container types.
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.