RemoteGuiProvider.cpp
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::RemoteGuiProvider
17  * @author Fabian Paus ( fabian dot paus at kit dot edu )
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #include "RemoteGuiProvider.h"
24 
25 #include <functional>
26 
30 
32 
33 namespace armarx
34 {
35  void
37  {
38  topicName = getProperty<std::string>("TopicName").getValue();
39 
40  offeringTopic(topicName);
41  }
42 
43  void
45  {
46  topic = getTopic<RemoteGuiListenerInterfacePrx>(topicName);
47  }
48 
49  void
51  {
52  }
53 
54  void
56  {
57  }
58 
61  {
64  }
65 
66  std::string
67  RemoteGuiProvider::getTopicName(const Ice::Current&)
68  {
69  return topicName;
70  }
71 
72  static void
73  fillRecursively(RemoteGui::WidgetStateMap& widgetStates,
75  RemoteGui::WidgetPtr const& widget,
76  RemoteGui::WidgetPtr const& rootWidget)
77  {
79  const auto dumpInfo = ARMARX_STREAM_PRINTER
80  {
81  out << "\nall state names: " << getMapKeys(widgetStates)
82  << "\nall value names: " << getMapKeys(values) << "\nwidget tree\n";
83 
84  std::function<void(RemoteGui::WidgetPtr const&, std::size_t)> dump =
85  [&](RemoteGui::WidgetPtr const& node, std::size_t lvl)
86  {
87  out << std::string(lvl * 4, '-') << " " << node->name << " ["
88  << GetTypeString(*node) << "]\n";
89  for (const auto& c : node->children)
90  {
91  dump(c, lvl + 1);
92  }
93  };
94  dump(rootWidget, 1);
95  };
96  RemoteGui::WidgetHandler const& handler = RemoteGui::getWidgetHandler(widget);
97  {
98  std::stringstream s;
99  if (!handler.isValid(*widget, s))
100  {
101  throw LocalException()
102  << "Widget is not valid: " << widget->name << ", WidgetT: " << widget->ice_id()
103  << ", HandlerT: " << handler.getHandlerT() << "\nMessage:\n"
104  << s.str() << dumpInfo;
105  }
106  }
107 
108  std::string const& name = widget->name;
109  if (!name.empty())
110  {
111  ARMARX_TRACE;
112  bool nameIsNew = widgetStates.emplace(widget->name, widget->defaultState).second;
113  if (!nameIsNew)
114  {
115  ARMARX_TRACE;
116  throw LocalException()
117  << "Widget with name '" << widget->name << "' already exists" << dumpInfo;
118  }
119  nameIsNew = values.emplace(widget->name, widget->defaultValue).second;
120  ARMARX_CHECK_EXPRESSION(nameIsNew);
121  }
122 
123  for (auto& child : widget->children)
124  {
125  ARMARX_TRACE;
126  fillRecursively(widgetStates, values, child, rootWidget);
127  }
128  }
129 
130  void
131  RemoteGuiProvider::createTab(const std::string& tabId,
132  const RemoteGui::WidgetPtr& rootWidget,
133  const Ice::Current&)
134  {
135  ARMARX_TRACE;
136  ARMARX_INFO << "Creating remote tab: " << tabId;
137  {
138  std::unique_lock<std::mutex> lock(tabMutex);
139  tabs[tabId] = rootWidget;
140 
141  // Clear old state
142  auto& widgetStates = tabWidgetStates[tabId];
143  widgetStates.clear();
144  auto& values = tabStates[tabId];
145  values.clear();
146 
147  // Fill default values
148  fillRecursively(tabWidgetStates[tabId], tabStates[tabId], rootWidget, rootWidget);
149  }
150 
151  topic->reportTabChanged(tabId);
152  }
153 
154  void
155  RemoteGuiProvider::removeTab(const std::string& tabId, const Ice::Current&)
156  {
157  ARMARX_TRACE;
158  ARMARX_INFO << "Removing remote tab: " << tabId;
159  {
160  std::unique_lock<std::mutex> lock(tabMutex);
161  tabs.erase(tabId);
162  tabWidgetStates.erase(tabId);
163  tabStates.erase(tabId);
164  }
165  topic->reportTabsRemoved();
166  }
167 
168  RemoteGui::WidgetMap
169  RemoteGuiProvider::getTabs(const Ice::Current&)
170  {
171  std::unique_lock<std::mutex> lock(tabMutex);
172  return tabs;
173  }
174 
175  RemoteGui::TabWidgetStateMap
176  RemoteGuiProvider::getTabStates(const Ice::Current&)
177  {
178  std::unique_lock<std::mutex> lock(tabMutex);
179  return tabWidgetStates;
180  }
181 
182  RemoteGui::TabValueMap
184  {
185  std::unique_lock<std::mutex> lock(tabMutex);
186  return tabStates;
187  }
188 
190  RemoteGuiProvider::getValues(const std::string& tabId, const Ice::Current&)
191  {
192  std::unique_lock<std::mutex> lock(tabMutex);
193  return tabStates.at(tabId);
194  }
195 
196  void
197  RemoteGuiProvider::setValue(const std::string& tabId,
198  const std::string& widgetName,
199  const RemoteGui::ValueVariant& value,
200  const Ice::Current&)
201  {
202  ARMARX_TRACE;
203  std::unique_lock<std::mutex> lock(tabMutex);
204  RemoteGui::ValueMap& tabState = tabStates.at(tabId);
205  tabState.at(widgetName) = value;
206  RemoteGui::ValueMap delta;
207  delta[widgetName] = value;
208  topic->reportStateChanged(tabId, delta);
209  }
210 
211  void
212  RemoteGuiProvider::setValues(const std::string& tabId,
214  const Ice::Current&)
215  {
216  ARMARX_TRACE;
217  std::unique_lock<std::mutex> lock(tabMutex);
218  RemoteGui::ValueMap& merged = tabStates.at(tabId);
219  for (const auto& pair : values)
220  {
221  merged[pair.first] = pair.second;
222  }
223  topic->reportStateChanged(tabId, values);
224  }
225 
226  RemoteGui::WidgetStateMap
227  RemoteGuiProvider::getWidgetStates(const std::string& tabId, const Ice::Current&)
228  {
229  std::unique_lock<std::mutex> lock(tabMutex);
230  return tabWidgetStates.at(tabId);
231  }
232 
233  void
234  RemoteGuiProvider::setWidgetStates(const std::string& tabId,
235  const RemoteGui::WidgetStateMap& state,
236  const Ice::Current&)
237  {
238  ARMARX_TRACE;
239  std::unique_lock<std::mutex> lock(tabMutex);
240  RemoteGui::WidgetStateMap& tabWidgetState = tabWidgetStates.at(tabId);
241  tabWidgetState = state;
242  topic->reportWidgetChanged(tabId, tabWidgetState);
243  }
244 } // namespace armarx
algorithm.h
armarx::RemoteGuiProvider::getValuesForAllTabs
RemoteGui::TabValueMap getValuesForAllTabs(const Ice::Current &) override
Definition: RemoteGuiProvider.cpp:183
armarx::RemoteGuiProvider::getValues
RemoteGui::ValueMap getValues(const std::string &tabId, const Ice::Current &) override
Definition: RemoteGuiProvider.cpp:190
GetTypeString.h
armarx::RemoteGuiProvider::onInitComponent
void onInitComponent() override
Definition: RemoteGuiProvider.cpp:36
ProsthesisInterface.values
values
Definition: ProsthesisInterface.py:190
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::RemoteGui::ValueMap
std::map< std::string, ValueVariant > ValueMap
Definition: RemoteGuiVisitors.h:41
armarx::RemoteGuiProviderPropertyDefinitions
Definition: RemoteGuiProvider.h:39
armarx::RemoteGuiProvider::setValues
void setValues(const std::string &tabId, const RemoteGui::ValueMap &values, const Ice::Current &) override
Definition: RemoteGuiProvider.cpp:212
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:77
armarx::RemoteGuiProvider::createTab
void createTab(const std::string &tabId, const RemoteGui::WidgetPtr &rootWidget, const Ice::Current &) override
Definition: RemoteGuiProvider.cpp:131
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
armarx::RemoteGuiProvider::getTabStates
RemoteGui::TabWidgetStateMap getTabStates(const Ice::Current &) override
Definition: RemoteGuiProvider.cpp:176
armarx::RemoteGuiProvider::onConnectComponent
void onConnectComponent() override
Definition: RemoteGuiProvider.cpp:44
armarx::RemoteGuiProvider::onExitComponent
void onExitComponent() override
Definition: RemoteGuiProvider.cpp:55
dump
void dump(vec_point_2d &vec)
Definition: gdiam.cpp:1666
WidgetHandler.h
armarx::GetTypeString
std::string GetTypeString(const std::type_info &tinf, bool withoutNamespaceSpecifier=false)
Definition: GetTypeString.h:38
armarx::WidgetDescription::WidgetPtr
::IceInternal::Handle<::armarx::WidgetDescription::Widget > WidgetPtr
Definition: NJointControllerBase.h:67
ExpressionException.h
armarx::RemoteGuiProvider::setValue
void setValue(const std::string &tabId, const std::string &widgetName, const RemoteGui::ValueVariant &value, const Ice::Current &) override
Definition: RemoteGuiProvider.cpp:197
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
RemoteGuiProvider.h
armarx::RemoteGui::getWidgetHandler
const WidgetHandler & getWidgetHandler(WidgetPtr const &desc)
Definition: WidgetRegister.cpp:66
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::RemoteGuiProvider::setWidgetStates
void setWidgetStates(const std::string &tabId, const RemoteGui::WidgetStateMap &state, const Ice::Current &) override
Definition: RemoteGuiProvider.cpp:234
armarx::RemoteGuiProvider::getTopicName
std::string getTopicName(const Ice::Current &) override
Definition: RemoteGuiProvider.cpp:67
armarx::ManagedIceObject::offeringTopic
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
Definition: ManagedIceObject.cpp:300
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::RemoteGuiProvider::getWidgetStates
RemoteGui::WidgetStateMap getWidgetStates(const std::string &tabId, const Ice::Current &) override
Definition: RemoteGuiProvider.cpp:227
armarx::RemoteGuiProvider::removeTab
void removeTab(const std::string &tabId, const Ice::Current &) override
Definition: RemoteGuiProvider.cpp:155
armarx::RemoteGuiProvider::onDisconnectComponent
void onDisconnectComponent() override
Definition: RemoteGuiProvider.cpp:50
armarx::RemoteGuiProvider::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: RemoteGuiProvider.cpp:60
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx::getMapKeys
void getMapKeys(const MapType &map, OutputIteratorType it)
Definition: algorithm.h:173
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::RemoteGuiProvider::getTabs
RemoteGui::WidgetMap getTabs(const Ice::Current &) override
Definition: RemoteGuiProvider.cpp:169
ARMARX_STREAM_PRINTER
#define ARMARX_STREAM_PRINTER
use this macro to write output code that is executed when printed and thus not executed if the debug ...
Definition: Logging.h:310