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 <mutex>
26 #include <map>
27 #include <functional>
28 
32 
35 
36 
37 namespace armarx::plugins
38 {
39  /**
40  * @defgroup Library-ArmarXGuiComponentPlugins ArmarXGuiComponentPlugins
41  * @ingroup ArmarXGui
42  * A description of the library ArmarXGuiComponentPlugins.
43  */
44 
45  /**
46  * @class ArmarXGuiComponentPlugins
47  * @ingroup Library-ArmarXGuiComponentPlugins
48  * @brief Brief description of class ArmarXGuiComponentPlugins.
49  *
50  * Detailed description of class ArmarXGuiComponentPlugins.
51  */
53  {
54  public:
55 
56  template<class T>
58 
59  using TabTask = std::function<void(RemoteGui::TabProxy&)>;
60 
61  using ComponentPlugin::ComponentPlugin;
62 
63  void createOrUpdateTab(const RemoteGui::WidgetPtr& widget,
64  TabTask guiTaskFnc,
65  unsigned long guiTaskPeriod = 10);
66  void createOrUpdateTab(const std::string& name,
67  const RemoteGui::WidgetPtr& widget,
68  TabTask guiTaskFnc,
69  unsigned long guiTaskPeriod = 10);
70 
71  void createOrUpdateTab(const std::string& name,
72  const RemoteGui::WidgetPtr& widget,
73  unsigned long guiTaskPeriod = 10);
74 
75  template<class T>
78  const std::string& name,
79  T& data,
80  unsigned long guiTaskPeriod = 10)
81  {
82  ARMARX_INFO << "create remote tab '" << name
83  << "'. writing data to 0x" << &data << " (type: "
84  << simox::meta::get_type_name<T>() << ')';
86  name,
88  [nam = name, ptr = &data](RemoteGui::TabProxy & prx)
89  {
90  prx.receiveUpdates();
92  << "updating remote tab '" << nam
93  << "'. writing data to 0x" << ptr << " (type: "
94  << simox::meta::get_type_name<T>() << ')';
95  prx.getValue(*ptr, nam);
96  prx.sendUpdates();
97  },
98  guiTaskPeriod
99  );
100  }
101  template<class T>
102  enable_if_auto_gui_cfg<T>
104  unsigned long guiTaskPeriod = 10)
105  {
106  createOrUpdateTab("", data, guiTaskPeriod);
107  }
108 
109  template<class T>
110  enable_if_auto_gui_cfg<T>
112  const std::string& name,
114  unsigned long guiTaskPeriod = 10)
115  {
116  ARMARX_INFO << "create remote tab '" << name
117  << "'. writing data to 0x" << &data << " (type: "
118  << simox::meta::get_type_name<T>() << ')';
120  name,
121  RemoteGui::MakeGuiConfig(name, data.getWriteBuffer()),
122  [nam = name, ptr = &data](RemoteGui::TabProxy & prx)
123  {
124  ARMARX_TRACE;
125  ARMARX_DEBUG << deactivateSpam(1)
126  << "updating remote tab '" << nam
127  << "'. writing data to 0x" << ptr << " (type: "
128  << simox::meta::get_type_name<T>() << ')';
129  prx.receiveUpdates();
130  prx.getValue(ptr->getWriteBuffer(), nam);
131  ptr->commitWrite();
132  prx.sendUpdates();
133  },
134  guiTaskPeriod
135  );
136  }
137  template<class T>
138  enable_if_auto_gui_cfg<T>
141  unsigned long guiTaskPeriod = 10)
142  {
143  createOrUpdateTab("", data, guiTaskPeriod);
144  }
145 
146  template<class T, class LockableT>
147  enable_if_auto_gui_cfg<T>
149  const std::string& name,
151  LockableT& mutex,
152  unsigned long guiTaskPeriod = 10)
153  {
154  ARMARX_INFO << "create remote tab '" << name
155  << "'. writing data to 0x" << &data << " (type: "
156  << simox::meta::get_type_name<T>() << ')';
157  std::lock_guard lock{mutex};
159  name,
160  RemoteGui::MakeGuiConfig(name, data.getWriteBuffer()),
161  [nam = name, mtx = &mutex, ptr = &data](RemoteGui::TabProxy & prx)
162  {
163  ARMARX_TRACE;
164  ARMARX_DEBUG << deactivateSpam(1)
165  << "updating remote tab '" << nam
166  << "'. writing data to 0x" << ptr << " (type: "
167  << simox::meta::get_type_name<T>() << ')';
168  prx.receiveUpdates();
169  {
170  std::lock_guard<LockableT> lock{*mtx};
171  prx.getValue(ptr->getWriteBuffer(), nam);
172  ptr->commitWrite();
173  }
174  prx.sendUpdates();
175  },
176  guiTaskPeriod
177  );
178  }
179  template<class T, class LockableT>
180  enable_if_auto_gui_cfg<T>
183  LockableT& mutex,
184  unsigned long guiTaskPeriod = 10)
185  {
186  createOrUpdateTab("", data, mutex, guiTaskPeriod);
187  }
188 
189 
190 
191  RemoteGui::TabProxy& getTab(const std::string& name = "");
192 
193  bool hasTab(const std::string& name = "");
194 
195  void removeTab(const std::string& name = "");
196 
197  const RemoteGuiInterfacePrx& getRemoteGui() const;
198  protected:
199  void preOnInitComponent() override;
200  void preOnConnectComponent() override;
201  void postOnConnectComponent() override;
202  void postOnDisconnectComponent() override;
203 
204  void postCreatePropertyDefinitions(PropertyDefinitionsPtr& properties) override;
205 
206  //structs
207  private:
208  struct TabData
209  {
210  //settings
211  TabTask fnc;
212  RemoteGui::WidgetPtr widget;
213  unsigned long taskPeriod{10};
214 
215  //run data
218  };
219 
220  //fncs
221  private:
222  std::string tabName(const std::string& name);
223  void create(const std::string& name, TabData& td);
224  void remove(const std::string& name, TabData& td);
225 
226  //data
227  private:
228  static constexpr auto _propertyName = "RemoteGuiName";
229  RemoteGuiInterfacePrx _remoteGui;
230  mutable std::recursive_mutex _tabsMutex;
231  std::map<std::string, TabData> _tabs;
232  };
233 }
234 
235 
237 
238 namespace armarx
239 {
241  {
242  public:
245  private:
246  RemoteGuiComponentPlugin* _remoteGuiComponentPlugin{nullptr};
247  public:
249 
250  const RemoteGuiInterfacePrx& getRemoteGui() const;
253 
254  template<class...Ts>
255  void createOrUpdateRemoteGuiTab(Ts&& ...ts)
256  {
257  getRemoteGuiPlugin().createOrUpdateTab(std::forward<Ts>(ts)...);
258  }
259 
260  RemoteGui::TabProxy& getRemoteGuiTab(const std::string& name = "");
261 
262  bool hasRemoteGuiTab(const std::string& name = "");
263 
264  void removeRemoteGuiTab(const std::string& name = "");
265  };
266 }
armarx::plugins::RemoteGuiComponentPlugin::createOrUpdateTab
enable_if_auto_gui_cfg< T > createOrUpdateTab(T &data, unsigned long guiTaskPeriod=10)
Definition: RemoteGuiComponentPlugin.h:103
armarx::RemoteGui::MakeGuiConfig
RemoteGui::WidgetPtr MakeGuiConfig(const std::string &name, const T &val)
Definition: MakeGuiConfig.h:8
armarx::plugins::RemoteGuiComponentPlugin::createOrUpdateTab
enable_if_auto_gui_cfg< T > createOrUpdateTab(WriteBufferedTripleBuffer< T > &data, LockableT &mutex, unsigned long guiTaskPeriod=10)
Definition: RemoteGuiComponentPlugin.h:181
armarx::plugins::RemoteGuiComponentPlugin::createOrUpdateTab
enable_if_auto_gui_cfg< T > createOrUpdateTab(WriteBufferedTripleBuffer< T > &data, unsigned long guiTaskPeriod=10)
Definition: RemoteGuiComponentPlugin.h:139
armarx::plugins::RemoteGuiComponentPlugin::enable_if_auto_gui_cfg
std::enable_if_t< meta::cfg::gui_definition_create< T >::value > enable_if_auto_gui_cfg
Definition: RemoteGuiComponentPlugin.h:57
ConfigIntrospection.h
deactivateSpam
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition: Logging.cpp:72
armarx::RemoteGui::TabProxy
Definition: WidgetProxy.h:17
armarx::plugins::RemoteGuiComponentPlugin::createOrUpdateTab
void createOrUpdateTab(const RemoteGui::WidgetPtr &widget, TabTask guiTaskFnc, unsigned long guiTaskPeriod=10)
Definition: RemoteGuiComponentPlugin.cpp:30
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::RemoteGui::TabProxy::receiveUpdates
void receiveUpdates()
Definition: WidgetProxy.h:131
armarx::RemoteGuiComponentPluginUser::removeRemoteGuiTab
void removeRemoteGuiTab(const std::string &name="")
Definition: RemoteGuiComponentPlugin.cpp:227
ManagedIceObject.h
armarx::RemoteGuiComponentPluginUser::getRemoteGui
const RemoteGuiInterfacePrx & getRemoteGui() const
Definition: RemoteGuiComponentPlugin.cpp:232
armarx::plugins
This file is part of ArmarX.
Definition: DebugObserverComponentPlugin.cpp:28
armarx::ComponentPlugin
Definition: ComponentPlugin.h:38
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
armarx::RemoteGuiComponentPluginUser::getRemoteGuiTab
RemoteGui::TabProxy & getRemoteGuiTab(const std::string &name="")
Definition: RemoteGuiComponentPlugin.cpp:217
armarx::RemoteGuiComponentPluginUser::RemoteGuiComponentPluginUser
RemoteGuiComponentPluginUser()
Definition: RemoteGuiComponentPlugin.cpp:212
WidgetProxy.h
armarx::plugins::RemoteGuiComponentPlugin::TabTask
std::function< void(RemoteGui::TabProxy &)> TabTask
Definition: RemoteGuiComponentPlugin.h:59
armarx::plugins::RemoteGuiComponentPlugin::createOrUpdateTab
enable_if_auto_gui_cfg< T > createOrUpdateTab(const std::string &name, WriteBufferedTripleBuffer< T > &data, LockableT &mutex, unsigned long guiTaskPeriod=10)
Definition: RemoteGuiComponentPlugin.h:148
TaskUtil.h
armarx::RemoteGuiComponentPluginUser
Definition: RemoteGuiComponentPlugin.h:240
armarx::RemoteGuiComponentPluginUser::getRemoteGuiPlugin
const armarx::plugins::RemoteGuiComponentPlugin & getRemoteGuiPlugin() const
Definition: RemoteGuiComponentPlugin.cpp:236
armarx::WidgetDescription::WidgetPtr
::IceInternal::Handle<::armarx::WidgetDescription::Widget > WidgetPtr
Definition: NJointControllerBase.h:66
armarx::RemoteGui::TabProxy::getValue
ValueProxy< T > getValue(std::string const &name)
Definition: WidgetProxy.h:161
TripleBuffer.h
armarx::RemoteGuiComponentPluginUser::RemoteGuiTabTask
RemoteGuiComponentPlugin::TabTask RemoteGuiTabTask
Definition: RemoteGuiComponentPlugin.h:244
armarx::ManagedIceObject
The ManagedIceObject is the base class for all ArmarX objects.
Definition: ManagedIceObject.h:163
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::plugins::RemoteGuiComponentPlugin
Definition: RemoteGuiComponentPlugin.h:52
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::RemoteGui::TabProxy::sendUpdates
void sendUpdates()
Definition: WidgetProxy.h:146
armarx::WriteBufferedTripleBuffer
Same as the TripleBuffer, but partial writes of the data structure are ok. The write operation may be...
Definition: TripleBuffer.h:267
ComponentPlugin.h
armarx::RemoteGuiComponentPluginUser::createOrUpdateRemoteGuiTab
void createOrUpdateRemoteGuiTab(Ts &&...ts)
Definition: RemoteGuiComponentPlugin.h:255
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
armarx::plugins::RemoteGuiComponentPlugin::createOrUpdateTab
enable_if_auto_gui_cfg< T > createOrUpdateTab(const std::string &name, WriteBufferedTripleBuffer< T > &data, unsigned long guiTaskPeriod=10)
Definition: RemoteGuiComponentPlugin.h:111
armarx::RemoteGuiComponentPluginUser::hasRemoteGuiTab
bool hasRemoteGuiTab(const std::string &name="")
Definition: RemoteGuiComponentPlugin.cpp:222
armarx::plugins::RemoteGuiComponentPlugin::createOrUpdateTab
enable_if_auto_gui_cfg< T > createOrUpdateTab(const std::string &name, T &data, unsigned long guiTaskPeriod=10)
Definition: RemoteGuiComponentPlugin.h:77
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::SimplePeriodicTask
Usage:
Definition: ApplicationNetworkStats.h:32