IceGridViewer.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 ArmarX::
17* @author Manfred Kroehnert ( Manfred.Kroehnert at kit dot edu)
18* @date 2013
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
23#include "IceGridViewer.h"
24
25#include <algorithm>
26
27#include <Ice/ObjectAdapter.h>
28
30
31#include <ArmarXGui/gui-plugins/SystemStateMonitorPlugin/ui_IceGridNodeView.h>
32#include <ArmarXGui/gui-plugins/SystemStateMonitorPlugin/ui_IceGridViewer.h>
33
34#include "NodeObserver.h"
36#include "model/NodeInfoModel.h"
38
39namespace armarx
40{
42 ui(new Ui::IceGridViewer), ADAPTER_NAME("IceGridNodeObserverGui")
43 {
44 ui->setupUi(getWidget());
45
46 qRegisterMetaType<QVector<int>>("QVector<int>");
47 qRegisterMetaType<IceGrid::ServerDynamicInfo>("IceGrid::ServerDynamicInfo");
48 connect(ui->gridNodeSelector,
49 SIGNAL(currentIndexChanged(int)),
50 this,
51 SLOT(selectGridNode(int)));
52
53 Ui::IceGridNodeView* content = new Ui::IceGridNodeView();
54 content->setupUi(ui->contentWidget);
55 nodeInfoModel = new NodeInfoModel;
56 content->NodeInfo->setModel(nodeInfoModel);
57 serverInfoModel = new ServerInfoModel;
58 content->ServerInfo->setModel(serverInfoModel);
59 adapterInfoModel = new AdapterInfoModel;
60 content->AdapterInfo->setModel(adapterInfoModel);
61
62 connect(serverInfoModel,
63 SIGNAL(serverInfoChanged(IceGrid::ServerDynamicInfo)),
64 this,
65 SLOT(serverInfoChanged(IceGrid::ServerDynamicInfo)));
66
67 selectorModel = new QStringListModel;
68 ui->gridNodeSelector->setModel(selectorModel);
69 }
70
72 {
73 delete ui;
74 }
75
76 void
77 IceGridViewer::loadSettings(QSettings* settings)
78 {
79 }
80
81 void
82 IceGridViewer::saveSettings(QSettings* settings)
83 {
84 }
85
86 void
88 {
89 // create new IceGridAdmin which also creates a new AdminSession
90 // Observers set on this new session won't interfer with the default observers
91 // used for tracking ManagedIceObject dependencies
92 iceGridAdmin = IceGridAdmin::Create(getIceManager()->getCommunicator(), ADAPTER_NAME);
93 // remove default observers which are not required and used here
94 iceGridAdmin->removeObservers();
95 }
96
97 void
99 {
100 IceGrid::AdminSessionPrx adminSession = iceGridAdmin->adminSession();
101
102 QtNodeObserverPtr observer = new QtNodeObserver(this);
103 Ice::ObjectPrx objectProxy =
104 iceGridAdmin->registerObjectWithNewAdapter(observer, ADAPTER_NAME, observerAdapter);
105 IceGrid::NodeObserverPrx nodeObserver = IceGrid::NodeObserverPrx::checkedCast(objectProxy);
106
107 adminSession->setObservers(NULL, NULL, NULL, NULL, NULL);
108 adminSession->setObservers(NULL, nodeObserver, NULL, NULL, NULL);
109 }
110
111 void
113 {
114 // stop updating the AdminSession so it can be removed
115 iceGridAdmin->stop();
116 // remove observers so the IceGridAmin does not hold any more references to them
117 iceGridAdmin->adminSession()->setObservers(NULL, NULL, NULL, NULL, NULL);
118 // destroy the object adapter to remove the observer objects
119 observerAdapter->destroy();
120 }
121
122 void
123 IceGridViewer::gridNodeListUpdate(const IceGrid::NodeDynamicInfoSeq& nodeSeq)
124 {
125 QString lastSelectionText = ui->gridNodeSelector->currentText();
126 {
127 std::unique_lock guard(gridNodeListMutex);
128 gridNodeList = nodeSeq;
129 QStringList nodeNames;
130
131 for (size_t i = 0; i < gridNodeList.size(); ++i)
132 {
133 nodeNames.append(QString::fromStdString(gridNodeList[i].info.name));
134 }
135
136 selectorModel->setStringList(nodeNames);
137 }
138
139 int index = ui->gridNodeSelector->findText(lastSelectionText);
140 index = std::max(0, index);
141
142 ui->gridNodeSelector->setCurrentIndex(index);
144 }
145
146 void
147 IceGridViewer::gridNodeListAdd(const IceGrid::NodeDynamicInfo& node)
148 {
149 std::unique_lock guard(gridNodeListMutex);
150 QStringList currentEntries = selectorModel->stringList();
151 currentEntries.append(QString::fromStdString(node.info.name));
152 gridNodeList.push_back(node);
153 selectorModel->setStringList(currentEntries);
154 }
155
156 void
158 {
159 QString lastSelectionText = ui->gridNodeSelector->currentText();
160 {
161 std::unique_lock guard(gridNodeListMutex);
162
163 QStringList currentEntries = selectorModel->stringList();
164 currentEntries.removeOne(node);
165
166 for (IceGrid::NodeDynamicInfoSeq::iterator nodeInfo = gridNodeList.begin();
167 nodeInfo != gridNodeList.end();
168 nodeInfo++)
169 {
170 if (nodeInfo->info.name == node.toStdString())
171 {
172 nodeInfo = gridNodeList.erase(nodeInfo);
173 }
174 }
175
176 selectorModel->setStringList(currentEntries);
177 }
178 int index = std::max<int>(0, ui->gridNodeSelector->findText(lastSelectionText));
179 ui->gridNodeSelector->setCurrentIndex(index);
181 }
182
183 void
184 IceGridViewer::updateServerInfo(const std::string& nodeName,
185 const IceGrid::ServerDynamicInfo& serverUpdateInfo)
186 {
187 {
188 std::unique_lock guard(gridNodeListMutex);
189 IceGrid::NodeDynamicInfoSeq::iterator nodeEntry =
190 std::find_if(gridNodeList.begin(),
191 gridNodeList.end(),
192 [nodeName](IceGrid::NodeDynamicInfo nodeInfo)
193 { return nodeName == nodeInfo.info.name; });
194
195 if (nodeEntry == gridNodeList.end())
196 {
197 return;
198 }
199
200 IceGrid::ServerDynamicInfoSeq::iterator serverEntry =
201 std::find_if(nodeEntry->servers.begin(),
202 nodeEntry->servers.end(),
203 [serverUpdateInfo](IceGrid::ServerDynamicInfo serverInfo)
204 { return serverUpdateInfo.id == serverInfo.id; });
205
206 if (serverEntry == nodeEntry->servers.end())
207 {
208 nodeEntry->servers.push_back(serverUpdateInfo);
209 }
210 else
211 {
212 if (serverUpdateInfo.pid == 0)
213 {
214 nodeEntry->servers.erase(serverEntry);
215 }
216 else
217 {
218 (*serverEntry) = serverUpdateInfo;
219 }
220 }
221 }
222
223 selectGridNode(ui->gridNodeSelector->currentIndex());
224 }
225
226 void
227 IceGridViewer::updateAdapterInfo(const std::string& nodeName,
228 const IceGrid::AdapterDynamicInfo& adapterUpdateInfo)
229 {
230 {
231 std::unique_lock guard(gridNodeListMutex);
232 IceGrid::NodeDynamicInfoSeq::iterator nodeEntry =
233 std::find_if(gridNodeList.begin(),
234 gridNodeList.end(),
235 [nodeName](IceGrid::NodeDynamicInfo nodeInfo)
236 { return nodeName == nodeInfo.info.name; });
237
238 if (nodeEntry == gridNodeList.end())
239 {
240 return;
241 }
242
243 IceGrid::AdapterDynamicInfoSeq::iterator adapterEntry =
244 std::find_if(nodeEntry->adapters.begin(),
245 nodeEntry->adapters.end(),
246 [adapterUpdateInfo](IceGrid::AdapterDynamicInfo adapterInfo)
247 { return adapterUpdateInfo.id == adapterInfo.id; });
248
249 if (adapterEntry == nodeEntry->adapters.end())
250 {
251 nodeEntry->adapters.push_back(adapterUpdateInfo);
252 }
253 else
254 {
255 if (!adapterUpdateInfo.proxy)
256 {
257 nodeEntry->adapters.erase(adapterEntry);
258 }
259 else
260 {
261 (*adapterEntry) = adapterUpdateInfo;
262 }
263 }
264 }
265
266 selectGridNode(ui->gridNodeSelector->currentIndex());
267 }
268
269 void
270 IceGridViewer::serverInfoChanged(IceGrid::ServerDynamicInfo serverInfo)
271 {
272 iceGridAdmin->getAdmin()->enableServer(serverInfo.id, serverInfo.enabled);
273 }
274
275 void
277 {
278 if (index >= (int)gridNodeList.size() || index < 0)
279 {
280 return;
281 }
282
283 std::unique_lock guard(gridNodeListMutex);
284 nodeInfoModel->setData(gridNodeList[index].info);
285 serverInfoModel->setData(gridNodeList[index].servers);
286 adapterInfoModel->setData(gridNodeList[index].adapters);
287 }
288} // namespace armarx
uint8_t index
IceUtil::Handle< QtNodeObserver > QtNodeObserverPtr
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
void onInitComponent() override
void gridNodeListAdd(const IceGrid::NodeDynamicInfo &node)
void loadSettings(QSettings *settings) override
Load stored manager models.
void saveSettings(QSettings *settings) override
Saves the manager models.
void gridNodeListRemove(const QString &node)
void updateServerInfo(const std::string &nodeName, const IceGrid::ServerDynamicInfo &serverUpdateInfo)
void onConnectComponent() override
void onExitComponent() override
Hook for subclass.
void serverInfoChanged(IceGrid::ServerDynamicInfo serverInfo)
void selectGridNode(int index)
void gridNodeListUpdate(const IceGrid::NodeDynamicInfoSeq &nodeSeq)
void updateAdapterInfo(const std::string &nodeName, const IceGrid::AdapterDynamicInfo &adapterUpdateInfo)
IceManagerPtr getIceManager() const
Returns the IceManager.
Ice::CommunicatorPtr getCommunicator() const
ArmarX Headers.
This file offers overloads of toIce() and fromIce() functions for STL container types.