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 <string>
26 #include <chrono>
27 
28 #include <Ice/Communicator.h>
29 #include <Ice/Endpoint.h>
30 
31 namespace armarx
32 {
34  {
35  widget.setupUi(getWidget());
37  widget.finderLayout->addWidget(finder);
38 
39  connect(widget.pushButtonFinder, SIGNAL(clicked()), this, SLOT(on_pushButtonFinder_clicked()));
40  connect(widget.pushButtonString, SIGNAL(clicked()), this, SLOT(on_pushButtonString_clicked()));
41  }
42 
44  {
45  finder->setIceManager(getIceManager());
46  }
47 
48  void IceProxyWidgetController::loadProxy(Ice::ObjectPrx prx)
49  {
50  //catch errors for each call, since each call can fail and we want to know which call failed for what reason
51  {
52  std::string str{"-----"};
53  try
54  {
55  str = prx->ice_getAdapterId();
56  }
57  catch (Ice::Exception& e)
58  {
59  ARMARX_ERROR << "Error while reading data for the current proxy (ice_getAdapterId):\n what:\n" << e.what();
60  }
61  widget.labelAdapterId->setText(QString::fromStdString(str));
62  }
63  {
64  std::string str{"-----"};
65  try
66  {
67  str = prx->ice_toString();
68  }
69  catch (Ice::Exception& e)
70  {
71  ARMARX_ERROR << "Error while reading data for the current proxy (ice_toString):\n what:\n" << e.what();
72  }
73  widget.labelAsString->setText(QString::fromStdString(str));
74  }
75  {
76  std::string str{"-----"};
77  try
78  {
79  str = prx->ice_getIdentity().category + " / " + prx->ice_getIdentity().name;
80  }
81  catch (Ice::Exception& e)
82  {
83  ARMARX_ERROR << "Error while reading data for the current proxy (ice_getIdentity):\n what:\n" << e.what();
84  }
85  widget.labelIdentity->setText(QString::fromStdString(str));
86  }
87  {
88  std::string str{"-----"};
89  try
90  {
91  std::stringstream ssend;
92  auto ends = prx->ice_getEndpoints();
93  for (const auto& end : ends)
94  {
95  ssend << end->toString() << "\n";
96  }
97  if (!ends.empty())
98  {
99  str = ssend.str();
100  }
101  }
102  catch (Ice::Exception& e)
103  {
104  ARMARX_ERROR << "Error while reading data for the current proxy (ice_getEndpoints):\n what:\n" << e.what();
105  }
106  widget.labelEndpoints->setText(QString::fromStdString(str));
107  }
108  {
109  std::string str{"-----"};
110  try
111  {
112  std::stringstream ssctx;
113  auto ctxs = prx->ice_getContext();
114  for (const auto& ctx : ctxs)
115  {
116  ssctx << ctx.first << "\t" << ctx.second << "\n";
117  }
118  if (!ctxs.empty())
119  {
120  str = ssctx.str();
121  }
122  }
123  catch (Ice::Exception& e)
124  {
125  ARMARX_ERROR << "Error while reading data for the current proxy (ice_getContext):\n what:\n" << e.what();
126  }
127  widget.labelContext->setText(QString::fromStdString(str));
128  }
129  {
130  std::string str{"-----"};
131  try
132  {
133  std::stringstream ssids;
134  auto ids = prx->ice_ids();
135  for (const auto& id : ids)
136  {
137  ssids << id << "\n";
138  }
139  if (!ids.empty())
140  {
141  str = ssids.str();
142  }
143  }
144  catch (Ice::Exception& e)
145  {
146  ARMARX_ERROR << "Error while reading data for the current proxy (ice_ids):\n what:\n" << e.what();
147  }
148  widget.labelIds->setText(QString::fromStdString(str));
149  }
150  {
151  std::string str{"-----"};
152  try
153  {
154  auto start = std::chrono::high_resolution_clock::now();
155  prx->ice_ping();
156  auto end = std::chrono::high_resolution_clock::now();
157  str = to_string(std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()) + " ms";
158  }
159  catch (Ice::Exception& e)
160  {
161  ARMARX_ERROR << "Error while reading data for the current proxy (ice_ping):\n what:\n" << e.what();
162  }
163  widget.labelPing->setText(QString::fromStdString(str));
164  }
165  }
166 
167  void armarx::IceProxyWidgetController::on_pushButtonFinder_clicked()
168  {
169  try
170  {
171  loadProxy(getIceManager()->getProxy<Ice::ObjectPrx>(finder->getSelectedProxyName().toStdString()));
172  }
173  catch (...)
174  {
175  ARMARX_ERROR << "No proxy with the name '" << finder->getSelectedProxyName().toStdString() << "' for Ice::ObjectPrx";
176  }
177  }
178 
179  void armarx::IceProxyWidgetController::on_pushButtonString_clicked()
180  {
181 
182  try
183  {
184  loadProxy(getIceManager()->getCommunicator()->stringToProxy(widget.lineEdit->text().toStdString()));
185  }
186  catch (...)
187  {
188  ARMARX_ERROR << "Can't convert '" << finder->getSelectedProxyName().toStdString() << "' to Ice::ObjectPrx";
189  }
190  }
191 }
armarx::ManagedIceObject::getIceManager
IceManagerPtr getIceManager() const
Returns the IceManager.
Definition: ManagedIceObject.cpp:353
str
std::string str(const T &t)
Definition: UserAssistedSegmenterGuiWidgetController.cpp:42
armarx::IceProxyWidgetController::loadProxy
void loadProxy(Ice::ObjectPrx prx)
Definition: IceProxyWidgetController.cpp:48
IceProxyWidgetController.h
armarx::IceProxyWidgetController::IceProxyWidgetController
IceProxyWidgetController()
Controller Constructor.
Definition: IceProxyWidgetController.cpp:33
armarx::IceProxyWidgetController::onInitComponent
void onInitComponent() override
Definition: IceProxyWidgetController.cpp:43
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
armarx::IceProxyFinder< Ice::ObjectPrx >
armarx::ArmarXWidgetController::getWidget
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
Definition: ArmarXWidgetController.cpp:54
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28