RemoteGuiComponentPlugin.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 ArmarXGui::ArmarXObjects::ArmarXGuiComponentPlugins
17 * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
18 * @date 2019
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#pragma once
24
25#include <functional>
26#include <map>
27#include <mutex>
28
32
35
36namespace armarx::plugins
37{
38 /**
39 * @defgroup Library-ArmarXGuiComponentPlugins ArmarXGuiComponentPlugins
40 * @ingroup ArmarXGui
41 * A description of the library ArmarXGuiComponentPlugins.
42 */
43
44 /**
45 * @class ArmarXGuiComponentPlugins
46 * @ingroup Library-ArmarXGuiComponentPlugins
47 * @brief Brief description of class ArmarXGuiComponentPlugins.
48 *
49 * Detailed description of class ArmarXGuiComponentPlugins.
50 */
52 {
53 public:
54 template <class T>
55 using enable_if_auto_gui_cfg = std::enable_if_t<meta::cfg::gui_definition_create<T>::value>;
56
57 using TabTask = std::function<void(RemoteGui::TabProxy&)>;
58
59 using ComponentPlugin::ComponentPlugin;
60
61 void createOrUpdateTab(const RemoteGui::WidgetPtr& widget,
62 TabTask guiTaskFnc,
63 unsigned long guiTaskPeriod = 10);
64 void createOrUpdateTab(const std::string& name,
65 const RemoteGui::WidgetPtr& widget,
66 TabTask guiTaskFnc,
67 unsigned long guiTaskPeriod = 10);
68
69 void createOrUpdateTab(const std::string& name,
70 const RemoteGui::WidgetPtr& widget,
71 unsigned long guiTaskPeriod = 10);
72
73 template <class T>
75 createOrUpdateTab(const std::string& name, T& data, unsigned long guiTaskPeriod = 10)
76 {
77 ARMARX_INFO << "create remote tab '" << name << "'. writing data to 0x" << &data
78 << " (type: " << simox::meta::get_type_name<T>() << ')';
80 name,
82 [nam = name, ptr = &data](RemoteGui::TabProxy& prx)
83 {
84 prx.receiveUpdates();
85 ARMARX_DEBUG << deactivateSpam(1) << "updating remote tab '" << nam
86 << "'. writing data to 0x" << ptr
87 << " (type: " << simox::meta::get_type_name<T>() << ')';
88 prx.getValue(*ptr, nam);
89 prx.sendUpdates();
90 },
91 guiTaskPeriod);
92 }
93
94 template <class T>
96 createOrUpdateTab(T& data, unsigned long guiTaskPeriod = 10)
97 {
98 createOrUpdateTab("", data, guiTaskPeriod);
99 }
100
101 template <class T>
103 createOrUpdateTab(const std::string& name,
105 unsigned long guiTaskPeriod = 10)
106 {
107 ARMARX_INFO << "create remote tab '" << name << "'. writing data to 0x" << &data
108 << " (type: " << simox::meta::get_type_name<T>() << ')';
110 name,
111 RemoteGui::MakeGuiConfig(name, data.getWriteBuffer()),
112 [nam = name, ptr = &data](RemoteGui::TabProxy& prx)
113 {
114 ARMARX_TRACE;
115 ARMARX_DEBUG << deactivateSpam(1) << "updating remote tab '" << nam
116 << "'. writing data to 0x" << ptr
117 << " (type: " << simox::meta::get_type_name<T>() << ')';
118 prx.receiveUpdates();
119 prx.getValue(ptr->getWriteBuffer(), nam);
120 ptr->commitWrite();
121 prx.sendUpdates();
122 },
123 guiTaskPeriod);
124 }
125
126 template <class T>
128 createOrUpdateTab(WriteBufferedTripleBuffer<T>& data, unsigned long guiTaskPeriod = 10)
129 {
130 createOrUpdateTab("", data, guiTaskPeriod);
131 }
132
133 template <class T, class LockableT>
135 createOrUpdateTab(const std::string& name,
137 LockableT& mutex,
138 unsigned long guiTaskPeriod = 10)
139 {
140 ARMARX_INFO << "create remote tab '" << name << "'. writing data to 0x" << &data
141 << " (type: " << simox::meta::get_type_name<T>() << ')';
142 std::lock_guard lock{mutex};
144 name,
145 RemoteGui::MakeGuiConfig(name, data.getWriteBuffer()),
146 [nam = name, mtx = &mutex, ptr = &data](RemoteGui::TabProxy& prx)
147 {
148 ARMARX_TRACE;
149 ARMARX_DEBUG << deactivateSpam(1) << "updating remote tab '" << nam
150 << "'. writing data to 0x" << ptr
151 << " (type: " << simox::meta::get_type_name<T>() << ')';
152 prx.receiveUpdates();
153 {
154 std::lock_guard<LockableT> lock{*mtx};
155 prx.getValue(ptr->getWriteBuffer(), nam);
156 ptr->commitWrite();
157 }
158 prx.sendUpdates();
159 },
160 guiTaskPeriod);
161 }
162
163 template <class T, class LockableT>
164 enable_if_auto_gui_cfg<T>
166 LockableT& mutex,
167 unsigned long guiTaskPeriod = 10)
168 {
169 createOrUpdateTab("", data, mutex, guiTaskPeriod);
170 }
171
172 RemoteGui::TabProxy& getTab(const std::string& name = "");
173
174 bool hasTab(const std::string& name = "");
175
176 void removeTab(const std::string& name = "");
177
178 const RemoteGuiInterfacePrx& getRemoteGui() const;
179
180 protected:
181 void preOnInitComponent() override;
182 void preOnConnectComponent() override;
183 void postOnConnectComponent() override;
184 void postOnDisconnectComponent() override;
185
186 void postCreatePropertyDefinitions(PropertyDefinitionsPtr& properties) override;
187
188 //structs
189 private:
190 struct TabData
191 {
192 //settings
193 TabTask fnc;
194 RemoteGui::WidgetPtr widget;
195 unsigned long taskPeriod{10};
196
197 //run data
200 };
201
202 //fncs
203 private:
204 std::string tabName(const std::string& name);
205 void create(const std::string& name, TabData& td);
206 void remove(const std::string& name, TabData& td);
207
208 //data
209 private:
210 static constexpr auto _propertyName = "RemoteGuiName";
211 RemoteGuiInterfacePrx _remoteGui;
212 mutable std::recursive_mutex _tabsMutex;
213 std::map<std::string, TabData> _tabs;
214 };
215} // namespace armarx::plugins
216
218
219namespace armarx
220{
222 {
223 public:
226
227 private:
228 RemoteGuiComponentPlugin* _remoteGuiComponentPlugin{nullptr};
229
230 public:
232
233 const RemoteGuiInterfacePrx& getRemoteGui() const;
236
237 template <class... Ts>
238 void
240 {
241 getRemoteGuiPlugin().createOrUpdateTab(std::forward<Ts>(ts)...);
242 }
243
244 RemoteGui::TabProxy& getRemoteGuiTab(const std::string& name = "");
245
246 bool hasRemoteGuiTab(const std::string& name = "");
247
248 void removeRemoteGuiTab(const std::string& name = "");
249 };
250} // namespace armarx
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition Logging.cpp:75
ManagedIceObject(ManagedIceObject const &other)
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
bool hasRemoteGuiTab(const std::string &name="")
void removeRemoteGuiTab(const std::string &name="")
const armarx::plugins::RemoteGuiComponentPlugin & getRemoteGuiPlugin() const
RemoteGuiComponentPlugin::TabTask RemoteGuiTabTask
RemoteGui::TabProxy & getRemoteGuiTab(const std::string &name="")
const RemoteGuiInterfacePrx & getRemoteGui() const
armarx::plugins::RemoteGuiComponentPlugin RemoteGuiComponentPlugin
ValueProxy< T > getValue(std::string const &name)
Same as the TripleBuffer, but partial writes of the data structure are ok. The write operation may be...
enable_if_auto_gui_cfg< T > createOrUpdateTab(const std::string &name, WriteBufferedTripleBuffer< T > &data, LockableT &mutex, unsigned long guiTaskPeriod=10)
enable_if_auto_gui_cfg< T > createOrUpdateTab(WriteBufferedTripleBuffer< T > &data, unsigned long guiTaskPeriod=10)
std::enable_if_t< meta::cfg::gui_definition_create< T >::value > enable_if_auto_gui_cfg
std::function< void(RemoteGui::TabProxy &)> TabTask
void createOrUpdateTab(const RemoteGui::WidgetPtr &widget, TabTask guiTaskFnc, unsigned long guiTaskPeriod=10)
enable_if_auto_gui_cfg< T > createOrUpdateTab(const std::string &name, WriteBufferedTripleBuffer< T > &data, unsigned long guiTaskPeriod=10)
enable_if_auto_gui_cfg< T > createOrUpdateTab(WriteBufferedTripleBuffer< T > &data, LockableT &mutex, unsigned long guiTaskPeriod=10)
enable_if_auto_gui_cfg< T > createOrUpdateTab(T &data, unsigned long guiTaskPeriod=10)
enable_if_auto_gui_cfg< T > createOrUpdateTab(const std::string &name, T &data, unsigned long guiTaskPeriod=10)
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
RemoteGui::WidgetPtr MakeGuiConfig(const std::string &name, const T &val)
This file is part of ArmarX.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.