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 <functional>
24 
25 #include "RemoteGuiProvider.h"
26 
31 
32 
33 namespace armarx
34 {
36  {
37  topicName = getProperty<std::string>("TopicName").getValue();
38 
39  offeringTopic(topicName);
40  }
41 
42 
44  {
45  topic = getTopic<RemoteGuiListenerInterfacePrx>(topicName);
46  }
47 
48 
50  {
51 
52  }
53 
54 
56  {
57 
58  }
59 
61  {
64  }
65 
66  std::string RemoteGuiProvider::getTopicName(const Ice::Current&)
67  {
68  return topicName;
69  }
70 
71  static void fillRecursively(RemoteGui::WidgetStateMap& widgetStates,
73  RemoteGui::WidgetPtr const& widget,
74  RemoteGui::WidgetPtr const& rootWidget)
75  {
77  const auto dumpInfo = ARMARX_STREAM_PRINTER
78  {
79  out << "\nall state names: " << getMapKeys(widgetStates)
80  << "\nall value names: " << getMapKeys(values)
81  << "\nwidget tree\n";
82 
83  std::function<void(RemoteGui::WidgetPtr const&, std::size_t)> dump =
84  [&](RemoteGui::WidgetPtr const & node, std::size_t lvl)
85  {
86  out << std::string(lvl * 4, '-') << " " << node->name
87  << " [" << GetTypeString(*node) << "]\n";
88  for (const auto& c : node->children)
89  {
90  dump(c, lvl + 1);
91  }
92  };
93  dump(rootWidget, 1);
94  };
95  RemoteGui::WidgetHandler const& handler = RemoteGui::getWidgetHandler(widget);
96  {
97  std::stringstream s;
98  if (!handler.isValid(*widget, s))
99  {
100  throw LocalException() << "Widget is not valid: " << widget->name
101  << ", WidgetT: " << widget->ice_id()
102  << ", HandlerT: " << handler.getHandlerT()
103  << "\nMessage:\n" << s.str()
104  << 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() << "Widget with name '" << widget->name << "' already exists"
117  << 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 RemoteGuiProvider::createTab(const std::string& tabId, const RemoteGui::WidgetPtr& rootWidget, const Ice::Current&)
131  {
132  ARMARX_TRACE;
133  ARMARX_INFO << "Creating remote tab: " << tabId;
134  {
135  std::unique_lock<std::mutex> lock(tabMutex);
136  tabs[tabId] = rootWidget;
137 
138  // Clear old state
139  auto& widgetStates = tabWidgetStates[tabId];
140  widgetStates.clear();
141  auto& values = tabStates[tabId];
142  values.clear();
143 
144  // Fill default values
145  fillRecursively(tabWidgetStates[tabId], tabStates[tabId], rootWidget, rootWidget);
146  }
147 
148  topic->reportTabChanged(tabId);
149  }
150 
151  void RemoteGuiProvider::removeTab(const std::string& tabId, const Ice::Current&)
152  {
153  ARMARX_TRACE;
154  ARMARX_INFO << "Removing remote tab: " << tabId;
155  {
156  std::unique_lock<std::mutex> lock(tabMutex);
157  tabs.erase(tabId);
158  tabWidgetStates.erase(tabId);
159  tabStates.erase(tabId);
160  }
161  topic->reportTabsRemoved();
162  }
163 
164  RemoteGui::WidgetMap RemoteGuiProvider::getTabs(const Ice::Current&)
165  {
166  std::unique_lock<std::mutex> lock(tabMutex);
167  return tabs;
168  }
169 
170  RemoteGui::TabWidgetStateMap RemoteGuiProvider::getTabStates(const Ice::Current&)
171  {
172  std::unique_lock<std::mutex> lock(tabMutex);
173  return tabWidgetStates;
174  }
175 
176  RemoteGui::TabValueMap RemoteGuiProvider::getValuesForAllTabs(const Ice::Current&)
177  {
178  std::unique_lock<std::mutex> lock(tabMutex);
179  return tabStates;
180  }
181 
182  RemoteGui::ValueMap RemoteGuiProvider::getValues(const std::string& tabId, const Ice::Current&)
183  {
184  std::unique_lock<std::mutex> lock(tabMutex);
185  return tabStates.at(tabId);
186  }
187 
188  void RemoteGuiProvider::setValue(const std::string& tabId, const std::string& widgetName, const RemoteGui::ValueVariant& value, const Ice::Current&)
189  {
190  ARMARX_TRACE;
191  std::unique_lock<std::mutex> lock(tabMutex);
192  RemoteGui::ValueMap& tabState = tabStates.at(tabId);
193  tabState.at(widgetName) = value;
194  RemoteGui::ValueMap delta;
195  delta[widgetName] = value;
196  topic->reportStateChanged(tabId, delta);
197  }
198 
199  void RemoteGuiProvider::setValues(const std::string& tabId, const RemoteGui::ValueMap& values, const Ice::Current&)
200  {
201  ARMARX_TRACE;
202  std::unique_lock<std::mutex> lock(tabMutex);
203  RemoteGui::ValueMap& merged = tabStates.at(tabId);
204  for (const auto& pair : values)
205  {
206  merged[pair.first] = pair.second;
207  }
208  topic->reportStateChanged(tabId, values);
209  }
210 
211  RemoteGui::WidgetStateMap RemoteGuiProvider::getWidgetStates(const std::string& tabId, const Ice::Current&)
212  {
213  std::unique_lock<std::mutex> lock(tabMutex);
214  return tabWidgetStates.at(tabId);
215  }
216 
217  void RemoteGuiProvider::setWidgetStates(const std::string& tabId, const RemoteGui::WidgetStateMap& state, const Ice::Current&)
218  {
219  ARMARX_TRACE;
220  std::unique_lock<std::mutex> lock(tabMutex);
221  RemoteGui::WidgetStateMap& tabWidgetState = tabWidgetStates.at(tabId);
222  tabWidgetState = state;
223  topic->reportWidgetChanged(tabId, tabWidgetState);
224  }
225 }
algorithm.h
armarx::RemoteGuiProvider::getValuesForAllTabs
RemoteGui::TabValueMap getValuesForAllTabs(const Ice::Current &) override
Definition: RemoteGuiProvider.cpp:176
armarx::RemoteGuiProvider::getValues
RemoteGui::ValueMap getValues(const std::string &tabId, const Ice::Current &) override
Definition: RemoteGuiProvider.cpp:182
GetTypeString.h
armarx::RemoteGuiProvider::onInitComponent
void onInitComponent() override
Definition: RemoteGuiProvider.cpp:35
ProsthesisInterface.values
values
Definition: ProsthesisInterface.py:190
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
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:199
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
armarx::RemoteGuiProvider::createTab
void createTab(const std::string &tabId, const RemoteGui::WidgetPtr &rootWidget, const Ice::Current &) override
Definition: RemoteGuiProvider.cpp:130
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::RemoteGuiProvider::getTabStates
RemoteGui::TabWidgetStateMap getTabStates(const Ice::Current &) override
Definition: RemoteGuiProvider.cpp:170
armarx::RemoteGuiProvider::onConnectComponent
void onConnectComponent() override
Definition: RemoteGuiProvider.cpp:43
armarx::RemoteGuiProvider::onExitComponent
void onExitComponent() override
Definition: RemoteGuiProvider.cpp:55
dump
void dump(vec_point_2d &vec)
Definition: gdiam.cpp:1717
WidgetHandler.h
armarx::GetTypeString
std::string GetTypeString(const std::type_info &tinf, bool withoutNamespaceSpecifier=false)
Definition: GetTypeString.h:36
armarx::WidgetDescription::WidgetPtr
::IceInternal::Handle<::armarx::WidgetDescription::Widget > WidgetPtr
Definition: NJointControllerBase.h:66
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:188
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
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:60
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::RemoteGuiProvider::setWidgetStates
void setWidgetStates(const std::string &tabId, const RemoteGui::WidgetStateMap &state, const Ice::Current &) override
Definition: RemoteGuiProvider.cpp:217
armarx::RemoteGuiProvider::getTopicName
std::string getTopicName(const Ice::Current &) override
Definition: RemoteGuiProvider.cpp:66
armarx::ManagedIceObject::offeringTopic
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
Definition: ManagedIceObject.cpp:290
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::RemoteGuiProvider::getWidgetStates
RemoteGui::WidgetStateMap getWidgetStates(const std::string &tabId, const Ice::Current &) override
Definition: RemoteGuiProvider.cpp:211
armarx::RemoteGuiProvider::removeTab
void removeTab(const std::string &tabId, const Ice::Current &) override
Definition: RemoteGuiProvider.cpp:151
armarx::RemoteGuiProvider::onDisconnectComponent
void onDisconnectComponent() override
Definition: RemoteGuiProvider.cpp:49
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:34
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:157
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::RemoteGuiProvider::getTabs
RemoteGui::WidgetMap getTabs(const Ice::Current &) override
Definition: RemoteGuiProvider.cpp:164
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:304