IceProxyWidgetController.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::gui-plugins::IceProxyWidgetController
17 * \author Raphael Grimm ( raphael dot grimm at kit dot edu )
18 * \date 2016
19 * \copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
24
25#include <chrono>
26#include <string>
27
28#include <Ice/Communicator.h>
29#include <Ice/Endpoint.h>
30
31namespace armarx
32{
34 {
35 widget.setupUi(getWidget());
37 widget.finderLayout->addWidget(finder);
38
39 connect(
40 widget.pushButtonFinder, SIGNAL(clicked()), this, SLOT(on_pushButtonFinder_clicked()));
41 connect(
42 widget.pushButtonString, SIGNAL(clicked()), this, SLOT(on_pushButtonString_clicked()));
43 }
44
45 void
47 {
48 finder->setIceManager(getIceManager());
49 }
50
51 void
53 {
54 //catch errors for each call, since each call can fail and we want to know which call failed for what reason
55 {
56 std::string str{"-----"};
57 try
58 {
59 str = prx->ice_getAdapterId();
60 }
61 catch (Ice::Exception& e)
62 {
63 ARMARX_ERROR << "Error while reading data for the current proxy "
64 "(ice_getAdapterId):\n what:\n"
65 << e.what();
66 }
67 widget.labelAdapterId->setText(QString::fromStdString(str));
68 }
69 {
70 std::string str{"-----"};
71 try
72 {
73 str = prx->ice_toString();
74 }
75 catch (Ice::Exception& e)
76 {
78 << "Error while reading data for the current proxy (ice_toString):\n what:\n"
79 << e.what();
80 }
81 widget.labelAsString->setText(QString::fromStdString(str));
82 }
83 {
84 std::string str{"-----"};
85 try
86 {
87 str = prx->ice_getIdentity().category + " / " + prx->ice_getIdentity().name;
88 }
89 catch (Ice::Exception& e)
90 {
92 << "Error while reading data for the current proxy (ice_getIdentity):\n what:\n"
93 << e.what();
94 }
95 widget.labelIdentity->setText(QString::fromStdString(str));
96 }
97 {
98 std::string str{"-----"};
99 try
100 {
101 std::stringstream ssend;
102 auto ends = prx->ice_getEndpoints();
103 for (const auto& end : ends)
104 {
105 ssend << end->toString() << "\n";
106 }
107 if (!ends.empty())
108 {
109 str = ssend.str();
110 }
111 }
112 catch (Ice::Exception& e)
113 {
114 ARMARX_ERROR << "Error while reading data for the current proxy "
115 "(ice_getEndpoints):\n what:\n"
116 << e.what();
117 }
118 widget.labelEndpoints->setText(QString::fromStdString(str));
119 }
120 {
121 std::string str{"-----"};
122 try
123 {
124 std::stringstream ssctx;
125 auto ctxs = prx->ice_getContext();
126 for (const auto& ctx : ctxs)
127 {
128 ssctx << ctx.first << "\t" << ctx.second << "\n";
129 }
130 if (!ctxs.empty())
131 {
132 str = ssctx.str();
133 }
134 }
135 catch (Ice::Exception& e)
136 {
138 << "Error while reading data for the current proxy (ice_getContext):\n what:\n"
139 << e.what();
140 }
141 widget.labelContext->setText(QString::fromStdString(str));
142 }
143 {
144 std::string str{"-----"};
145 try
146 {
147 std::stringstream ssids;
148 auto ids = prx->ice_ids();
149 for (const auto& id : ids)
150 {
151 ssids << id << "\n";
152 }
153 if (!ids.empty())
154 {
155 str = ssids.str();
156 }
157 }
158 catch (Ice::Exception& e)
159 {
161 << "Error while reading data for the current proxy (ice_ids):\n what:\n"
162 << e.what();
163 }
164 widget.labelIds->setText(QString::fromStdString(str));
165 }
166 {
167 std::string str{"-----"};
168 try
169 {
170 auto start = std::chrono::high_resolution_clock::now();
171 prx->ice_ping();
172 auto end = std::chrono::high_resolution_clock::now();
173 str = to_string(std::chrono::duration_cast<std::chrono::milliseconds>(end - start)
174 .count()) +
175 " ms";
176 }
177 catch (Ice::Exception& e)
178 {
180 << "Error while reading data for the current proxy (ice_ping):\n what:\n"
181 << e.what();
182 }
183 widget.labelPing->setText(QString::fromStdString(str));
184 }
185 }
186
187 void
188 armarx::IceProxyWidgetController::on_pushButtonFinder_clicked()
189 {
190 try
191 {
192 loadProxy(getIceManager()->getProxy<Ice::ObjectPrx>(
193 finder->getSelectedProxyName().toStdString()));
194 }
195 catch (...)
196 {
197 ARMARX_ERROR << "No proxy with the name '"
198 << finder->getSelectedProxyName().toStdString() << "' for Ice::ObjectPrx";
199 }
200 }
201
202 void
203 armarx::IceProxyWidgetController::on_pushButtonString_clicked()
204 {
205
206 try
207 {
208 loadProxy(getIceManager()->getCommunicator()->stringToProxy(
209 widget.lineEdit->text().toStdString()));
210 }
211 catch (...)
212 {
213 ARMARX_ERROR << "Can't convert '" << finder->getSelectedProxyName().toStdString()
214 << "' to Ice::ObjectPrx";
215 }
216 }
217} // namespace armarx
std::string str(const T &t)
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
Widget to conveniently retrieve a proxy instance name of a specific interface type (the template para...
IceProxyWidgetController()
Controller Constructor.
IceManagerPtr getIceManager() const
Returns the IceManager.
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
This file offers overloads of toIce() and fromIce() functions for STL container types.
const std::string & to_string(const std::string &s)