YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
applicationviewwidget.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
7#include "ui_applicationviewwidget.h"
8#include <QMessageBox>
9#include <QMenu>
10#include <QFileDialog>
11#include <yarp/os/Log.h>
12#include <yarp/os/LogStream.h>
13#include <yarp/os/Bottle.h>
14#include <yarp/os/Carriers.h>
16#include "yscopewindow.h"
17#include <QTreeWidgetItem>
18#include <QMainWindow>
19#include <QMdiArea>
20
21
23 yarp::manager::Manager *lazyManager,
24 yarp::os::Property* config,
25 bool editingMode,
26 QWidget *parent) :
29 modRunAction(nullptr),
30 modStopAction(nullptr),
31 modkillAction(nullptr),
32 modSeparator(nullptr),
33 modRefreshAction(nullptr),
34 modSelectAllAction(nullptr),
35 modAttachAction(nullptr),
36 modAssignAction(nullptr),
37 connContex(nullptr),
38 connSubMenu(nullptr),
39 connConnectAction(nullptr),
40 connDisconnectAction(nullptr),
41 connSeparatorAction(nullptr),
42 connRefreshAction(nullptr),
43 connSelectAllAction(nullptr),
44 conn1SeparatorAction(nullptr),
45 connInspectAction(nullptr),
46 connYARPViewAction(nullptr),
47 connYARPReadAction(nullptr),
48 connYARPHearAction(nullptr),
49 connYARPScopeAction(nullptr),
50 resRefreshAction(nullptr),
51 resSelectAllAction(nullptr)
52{
53 ui->setupUi(this);
54 itemsSelectedForResource.clear();
55 lazy = lazyManager;
56 this->app = app;
57 m_pConfig = config;
58 this->editingMode = editingMode;
59 this->m_modified = false;
61
62 QGridLayout *l;
63
64 if (!editingMode) {
65 prepareManagerFrom(lazy);
66
67 ui->moduleList->resizeColumnToContents(0);
68 ui->moduleList->resizeColumnToContents(1);
69 ui->moduleList->resizeColumnToContents(2);
70 ui->moduleList->resizeColumnToContents(3);
71 ui->moduleList->resizeColumnToContents(4);
72 ui->moduleList->resizeColumnToContents(5);
73 ui->moduleList->resizeColumnToContents(6);
74 ui->moduleList->resizeColumnToContents(7);
75
76 ui->resourcesList->resizeColumnToContents(0);
77 ui->resourcesList->resizeColumnToContents(1);
78 ui->resourcesList->resizeColumnToContents(2);
79 ui->resourcesList->resizeColumnToContents(3);
80
81
82 ui->connectionList->resizeColumnToContents(0);
83 ui->connectionList->resizeColumnToContents(1);
84 ui->connectionList->resizeColumnToContents(2);
85 ui->connectionList->resizeColumnToContents(3);
86 ui->connectionList->resizeColumnToContents(4);
87 ui->connectionList->resizeColumnToContents(5);
88
89 connect(ui->moduleList,SIGNAL(itemSelectionChanged()),this,SLOT(onModuleItemSelectionChanged()));
90 connect(ui->moduleList,SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),this,SLOT(onItemDoubleClicked(QTreeWidgetItem*,int)));
91
92 connect(ui->resourcesList,SIGNAL(itemSelectionChanged()),this,SLOT(onResourceItemSelectionChanged()));
93 connect(ui->resourcesList,SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),this,SLOT(onItemDoubleClicked(QTreeWidgetItem*,int)));
94
95 connect(ui->connectionList,SIGNAL(itemSelectionChanged()),this,SLOT(onConnectionItemSelectionChanged()));
96 connect(ui->connectionList,SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),this,SLOT(onItemDoubleClicked(QTreeWidgetItem*,int)));
97
98 connect(this,SIGNAL(selfSafeLoadBolance()),this,SLOT(onSelfSafeLoadBalance()),Qt::QueuedConnection);
99 connect(this,SIGNAL(selfConnect(int)),this,SLOT(onSelfConnect(int)),Qt::QueuedConnection);
100 connect(this,SIGNAL(selfDisconnect(int)),this,SLOT(onSelfDisconnect(int)),Qt::QueuedConnection);
101 connect(this,SIGNAL(selfResAvailable(int)),this,SLOT(onSelfResAvailable(int)),Qt::QueuedConnection);
102 connect(this,SIGNAL(selfResUnavailable(int)),this,SLOT(onSelfResUnavailable(int)),Qt::QueuedConnection);
103 connect(this,SIGNAL(selfStart(int)),this,SLOT(onSelfStart(int)),Qt::QueuedConnection);
104 connect(this,SIGNAL(selfStop(int)),this,SLOT(onSelfStop(int)),Qt::QueuedConnection);
105
106 createModulesViewContextMenu();
107 createConnectionsViewContextMenu();
108 createResourcesViewContextMenu();
109
110 l = new QGridLayout(ui->builderContainer);
111 ui->builderContainer->setLayout(l);
112
113
114 } else {
115 layout()->removeWidget(ui->mainSplietter);
116 delete ui->mainSplietter;
117 l = (QGridLayout*)layout();
118
119 }
120
121
122 l->setMargin(0);
123
124
125 builderWindowContainer = new QMainWindow(nullptr,Qt::Widget);
126 builderWindowContainer->setDockNestingEnabled(true);
127 l->addWidget(builderWindowContainer);
128
129 builderWidget = new QDockWidget("YARP Builder",builderWindowContainer);
130 builderWindowContainer->addDockWidget(Qt::TopDockWidgetArea,builderWidget);
131 builder = YarpBuilderLib::getBuilder(this->app,lazyManager,&safeManager,editingMode);
132 builderWidget->setWidget(builder);
133 //builderWidget->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
134 builderWidget->setFeatures(QDockWidget::NoDockWidgetFeatures);
135 connect(builderWidget,SIGNAL(topLevelChanged(bool)),this,SLOT(onBuilderFloatChanged(bool)));
136
137 //builderWidget->pos()
138
139 if (!editingMode) {
140 //builder->addAction(modRunAction);
141 //builder->addAction(modStopAction);
142 //builder->addAction(modkillAction);
143 //builder->addAction(modSeparator);
144 //builder->addAction(modRefreshAction);
145 builder->addAction(modSelectAllAction);
146 //builder->addAction(modAttachAction);
147 //builder->addAction(modAssignAction);
148 builder->addAction(modSeparator);
149 //builder->addAction(connConnectAction);
150 //builder->addAction(connDisconnectAction);
151 //builder->addAction(connSeparatorAction);
152 //builder->addAction(connRefreshAction);
153 builder->addAction(connSelectAllAction);
154 //builder->addAction(conn1SeparatorAction);
155
156
157 builder->addModulesAction(modRunAction);
158 builder->addModulesAction(modStopAction);
159 builder->addModulesAction(modkillAction);
160 builder->addModulesAction(modSeparator);
161 builder->addModulesAction(modRefreshAction);
162 builder->addModulesAction(modSelectAllAction);
163 builder->addModulesAction(modAttachAction);
164 builder->addModulesAction(modAssignAction);
165
166 builder->addConnectionsAction(connConnectAction);
167 builder->addConnectionsAction(connDisconnectAction);
168 builder->addConnectionsAction(connSeparatorAction);
169 builder->addConnectionsAction(connRefreshAction);
170 builder->addConnectionsAction(connSelectAllAction);
171 builder->addConnectionsAction(conn1SeparatorAction);
172
173
174 connect(builder,SIGNAL(refreshApplication()),
175 this,SLOT(onRefreshApplication()),Qt::DirectConnection);
176 connect(builder,SIGNAL(setModuleSelected(QList<int>)),this,SLOT(onModuleSelected(QList<int>)));
177 connect(builder,SIGNAL(setConnectionSelected(QList<int>)),this,SLOT(onConnectionSelected(QList<int>)));
178
179 } else {
180 connect(builder,SIGNAL(modified(bool)),this,SLOT(onModified(bool)));
181 }
182
183
184 builder->load();
185 builderToolBar = builder->getToolBar();
186}
187
189{
190 bool ret = true;
191 if (builder) {
192 ret = builder->save();
193 }
194 return ret;
195}
196
198{
199 if (builder) {
200 return builder->getFileName();
201 } else {
202 return {};
203 };
204}
205
207{
208 if (builder) {
209 builder->setFileName(filename);
210 }
211 return;
212}
213
215{
216 if (builder) {
217 return builder->getAppName();
218 } else {
219 return {};
220 };
221}
222
224{
225 if (builder) {
226 builder->setAppName(appName);
227 }
228 return;
229}
230
235
237{
238 builderWidget->setVisible(show);
239}
240
242{
243 return !ui->moduleList->selectedItems().isEmpty();
244}
246{
247 return !ui->connectionList->selectedItems().isEmpty();
248}
249
251{
252 return ui->moduleList;
253}
254
256{
257 return ui->connectionList;
258}
259
261{
262 return builderToolBar;
263}
264
266void ApplicationViewWidget::createModulesViewContextMenu()
267{
268 modRunAction = new QAction("Run",this);
269 modStopAction = new QAction("Stop",this);
270 modkillAction = new QAction("Kill",this);
271 modSeparator = new QAction(this);
272 modSeparator->setSeparator(true);
273 modRefreshAction = new QAction("Refresh Status",this);
274 modSelectAllAction = new QAction("Select All Modules",this);
275 modAttachAction = new QAction("Attach to stdout",this);
276 modAssignAction = new QAction("Assign Hosts",this);
277
278 modRunAction->setIcon(QIcon(":/play22.svg"));
279 modStopAction->setIcon(QIcon(":/stop22.svg"));
280 modkillAction->setIcon(QIcon(":/kill22.svg"));
281 modRefreshAction->setIcon(QIcon(":/refresh22.svg"));
282 modSelectAllAction->setIcon(QIcon(":/select-all22.svg"));
283 modAssignAction->setIcon(QIcon(":/computer-available22.svg"));
284
285
286 ui->moduleList->addAction(modRunAction);
287 ui->moduleList->addAction(modStopAction);
288 ui->moduleList->addAction(modkillAction);
289 ui->moduleList->addAction(modSeparator);
290 ui->moduleList->addAction(modRefreshAction);
291 ui->moduleList->addAction(modSelectAllAction);
292 ui->moduleList->addAction(modAttachAction);
293 ui->moduleList->addAction(modAssignAction);
294
295 connect(modRunAction,SIGNAL(triggered()),this,SLOT(onRun()));
296 connect(modStopAction,SIGNAL(triggered()),this,SLOT(onStop()));
297 connect(modkillAction,SIGNAL(triggered()),this,SLOT(onKill()));
298 connect(modRefreshAction,SIGNAL(triggered()),this,SLOT(onRefresh()));
299 connect(modSelectAllAction,SIGNAL(triggered()),this,SLOT(selectAllModule()));
300 connect(modAttachAction,SIGNAL(triggered()),this,SLOT(onAttachStdout()));
301 connect(modAssignAction,SIGNAL(triggered()),this,SLOT(onAssignHost()));
302
303 onModuleItemSelectionChanged();
304}
305
307void ApplicationViewWidget::createConnectionsViewContextMenu()
308{
309 connContex = new QMenu(ui->connectionList);
310 connSubMenu = new QMenu("Inspect",connContex);
311
312 connConnectAction = new QAction("Connect",connContex);
313 connDisconnectAction = new QAction("Disconnect",connContex);
314 connSeparatorAction = new QAction(connContex);
315 connSeparatorAction->setSeparator(true);
316 connRefreshAction = new QAction("Refresh Status",connContex);
317 connSelectAllAction = new QAction("Select All Connections",connContex);
318 conn1SeparatorAction = new QAction(connContex);
319 conn1SeparatorAction->setSeparator(connContex);
320
321 connYARPViewAction = new QAction("yarpview",connSubMenu);
322 connYARPReadAction = new QAction("yarpread",connSubMenu);
323 connYARPHearAction = new QAction("yarphear",connSubMenu);
324 connYARPScopeAction = new QAction("yarpscope",connSubMenu);
325
326 connSelectAllAction->setIcon(QIcon(":/select-all22.svg"));
327 connRefreshAction->setIcon(QIcon(":/refresh22.svg"));
328 connConnectAction->setIcon(QIcon(":/connect22.svg"));
329 connDisconnectAction->setIcon(QIcon(":/disconnect22.svg"));
330
331 connect(connConnectAction,SIGNAL(triggered()),this,SLOT(onConnect()));
332 connect(connDisconnectAction,SIGNAL(triggered()),this,SLOT(onDisconnect()));
333 connect(connRefreshAction,SIGNAL(triggered()),this,SLOT(onRefresh()));
334 connect(connSelectAllAction,SIGNAL(triggered()),this,SLOT(selectAllConnections()));
335
336 connect(connYARPViewAction,SIGNAL(triggered()),this,SLOT(onYARPView()));
337 connect(connYARPReadAction,SIGNAL(triggered()),this,SLOT(onYARPRead()));
338 connect(connYARPHearAction,SIGNAL(triggered()),this,SLOT(onYARPHear()));
339 connect(connYARPScopeAction,SIGNAL(triggered()),this,SLOT(onYARPScope()));
340
341 connContex->addAction(connConnectAction);
342 connContex->addAction(connDisconnectAction);
343 connContex->addAction(connSeparatorAction);
344 connContex->addAction(connRefreshAction);
345 connContex->addAction(connSelectAllAction);
346 connContex->addAction(conn1SeparatorAction);
347 connContex->addMenu(connSubMenu);
348
349 connSubMenu->addAction(connYARPViewAction);
350 connSubMenu->addAction(connYARPReadAction);
351 connSubMenu->addAction(connYARPHearAction);
352 connSubMenu->addAction(connYARPScopeAction);
353
354
355 ui->connectionList->setContextMenu(connContex);
356
357 onConnectionItemSelectionChanged();
358
359}
360
362void ApplicationViewWidget::createResourcesViewContextMenu()
363{
364 resRefreshAction = new QAction("Refresh Status", this);
365 resSelectAllAction = new QAction("Select All Resources", this);
366
367 resRefreshAction->setIcon(QIcon(":/refresh22.svg"));
368 resSelectAllAction->setIcon(QIcon(":/select-all22.svg"));
369
370 ui->resourcesList->addAction(resRefreshAction);
371 ui->resourcesList->addAction(resSelectAllAction);
372
373 connect(resRefreshAction,SIGNAL(triggered()),this,SLOT(onRefresh()));
374 connect(resSelectAllAction,SIGNAL(triggered()),this,SLOT(selectAllResources()));
375}
376
378void ApplicationViewWidget::onConnectionItemSelectionChanged()
379{
380 if (ui->connectionList->selectedItems().isEmpty()) {
381 connConnectAction->setEnabled(false);
382 connDisconnectAction->setEnabled(false);
383 connSeparatorAction->setEnabled(false);
384 connRefreshAction->setEnabled(false);
385 } else {
386 connConnectAction->setEnabled(true);
387 connDisconnectAction->setEnabled(true);
388 connSeparatorAction->setEnabled(true);
389 connRefreshAction->setEnabled(true);
390 }
391
392 if (ui->connectionList->hasFocus()) {
393 QList<int>selectedIds;
394 QList<QTreeWidgetItem*> selectedItems = ui->connectionList->selectedItems();
395 foreach(QTreeWidgetItem *it,selectedItems) {
396 QString id = it->text(1);
397 selectedIds.append(id.toInt());
398 }
399
400 builder->setSelectedConnections(selectedIds);
401 }
402}
403
405void ApplicationViewWidget::onModuleItemSelectionChanged()
406{
407
408 if (ui->moduleList->selectedItems().isEmpty()) {
409 modRunAction->setEnabled(false);
410 modStopAction->setEnabled(false);
411 modkillAction->setEnabled(false);
412 modAttachAction->setEnabled(false);
413 modAssignAction->setEnabled(false);
414 modRefreshAction->setEnabled(false);
415 } else {
416 modRunAction->setEnabled(true);
417 modStopAction->setEnabled(true);
418 modkillAction->setEnabled(true);
419
420 bool all = true;
421 foreach (QTreeWidgetItem *it, ui->moduleList->selectedItems()) {
422 if (it->text(3) != "localhost") {
423 modAttachAction->setEnabled(false);
424 all = false;
425 break;
426 }
427 }
428 if (all) {
429 modAttachAction->setEnabled(true);
430 }
431
432 modAssignAction->setEnabled(true);
433 modRefreshAction->setEnabled(true);
434
435
436
437 if (ui->moduleList->hasFocus()) {
438
439 QList<int>selectedIds;
440 QList<QTreeWidgetItem*> selectedItems = ui->moduleList->selectedItems();
441 itemsSelectedForResource.clear();
442 foreach(QTreeWidgetItem *it,selectedItems) {
443 if (it->data(0,Qt::UserRole).toInt() == APPLICATION) {
444 for(int j=0;j<it->childCount();j++) {
445 QTreeWidgetItem *child = it->child(j);
446 selectModule(child,true);
447 }
448
449 }
450 else{
451 selectModule(it,true);
452 }
453
454 }
455 selectedItems = ui->moduleList->selectedItems();
456 foreach(QTreeWidgetItem *it,selectedItems) {
457 if (it->data(0,Qt::UserRole).toInt() == APPLICATION) {
458 continue;
459 }
460 QString id = it->text(1);
461 selectedIds.append(id.toInt());
462 }
463
464 builder->setSelectedModules(selectedIds);
465 }
466 }
467
468
469}
470
472void ApplicationViewWidget::onResourceItemSelectionChanged()
473{
474 if (ui->resourcesList->currentItem() == nullptr) {
475 resRefreshAction->setEnabled(false);
476 } else {
477 resRefreshAction->setEnabled(true);
478 }
479}
480
481void ApplicationViewWidget::prepareManagerFrom(yarp::manager::Manager* lazy)
482{
483
484 safeManager.prepare(lazy, m_pConfig,dynamic_cast<ApplicationEvent*>(this));
485
486 // loading application
487 if (safeManager.loadApplication(app->getName())) {
488 updateApplicationWindow();
489 }
490
491 reportErrors();
492}
493
494void ApplicationViewWidget::onRefreshApplication()
495{
496 //manager.close();
497
498 // loading application
499
500 if (safeManager.loadApplication(app->getName())) {
501 updateApplicationWindow();
502 }
503
504 reportErrors();
505}
506
507
508
509void ApplicationViewWidget::onConnectionSelected(QList<int> id)
510{
511 disconnect(ui->connectionList,SIGNAL(itemSelectionChanged()),this,SLOT(onConnectionItemSelectionChanged()));
512 for(int i=0;i<ui->connectionList->topLevelItemCount();i++) {
513 ui->connectionList->topLevelItem(i)->setSelected(false);
514 }
515 for(int i=0;i<ui->connectionList->topLevelItemCount();i++) {
516 for(int j=0;j<id.count();j++) {
517 if (ui->connectionList->topLevelItem(i)->text(1).toInt() == id.at(j)) {
518 ui->connectionList->topLevelItem(i)->setSelected(true);
519 }
520 }
521
522 }
523 onConnectionItemSelectionChanged();
524 connect(ui->connectionList,SIGNAL(itemSelectionChanged()),this,SLOT(onConnectionItemSelectionChanged()));
525}
526
527void ApplicationViewWidget::onModuleSelected(QList<int> id)
528{
529 disconnect(ui->moduleList,SIGNAL(itemSelectionChanged()),this,SLOT(onModuleItemSelectionChanged()));
530 for(int i=0;i<ui->moduleList->topLevelItemCount();i++) {
531 ui->moduleList->topLevelItem(i)->setSelected(false);
532 if (ui->moduleList->topLevelItem(i)->data(0,Qt::UserRole) == APPLICATION ) {
533 for(int k=0;k<ui->moduleList->topLevelItem(i)->childCount();k++) {
534 ui->moduleList->topLevelItem(i)->child(k)->setSelected(false);
535 }
536 }
537 }
538
539 for(int i=0;i<ui->moduleList->topLevelItemCount();i++) {
540 if (ui->moduleList->topLevelItem(i)->data(0,Qt::UserRole) == APPLICATION ) {
541 for(int k=0;k<ui->moduleList->topLevelItem(i)->childCount();k++) {
542 for(int j=0;j<id.count();j++) {
543 if (ui->moduleList->topLevelItem(i)->child(k)->text(1).toInt() == id.at(j)) {
544 ui->moduleList->topLevelItem(i)->child(k)->setSelected(true);
545 }
546 }
547
548
549 }
550
551 } else {
552 for(int j=0;j<id.count();j++) {
553 if (ui->moduleList->topLevelItem(i)->text(1).toInt() == id.at(j)) {
554 ui->moduleList->topLevelItem(i)->setSelected(true);
555 }
556 }
557 }
558
559
560 }
561 onModuleItemSelectionChanged();
562 connect(ui->moduleList,SIGNAL(itemSelectionChanged()),this,SLOT(onModuleItemSelectionChanged()));
563}
564
566void ApplicationViewWidget::updateApplicationWindow()
567{
568 ui->moduleList->clear();
569 ui->connectionList->clear();
570 ui->resourcesList->clear();
571 listOfResourceNames.clear();
572
573 disconnect(ui->moduleList,SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(onModuleItemChanged(QTreeWidgetItem*,int)));
574
576 yarp::manager::CnnContainer connections = safeManager.getConnections();
579
580 int id = 0;
581 for(moditr=modules.begin(); moditr<modules.end(); moditr++)
582 {
583
584 Module *mod = (*moditr)->getModule();
585 CustomTreeWidgetItem *appNode = nullptr;
586 QString modLabel = mod->owner()->getLabel();
587 QString appLabel = app->getLabel();
588 if (modLabel != appLabel) {
589
590 for(int i=0; i < ui->moduleList->topLevelItemCount();i++) {
591 if (ui->moduleList->topLevelItem(i)->data(0,Qt::UserRole + 1).toString() == modLabel) {
592 appNode = (CustomTreeWidgetItem*) ui->moduleList->topLevelItem(i);
593 break;
594 }
595 }
596 if (!appNode) {
597 QStringList l;
598 l << ((Application*)mod->owner())->getName();
599
600 appNode = new CustomTreeWidgetItem(ui->moduleList,l);
601 appNode->setData(0,Qt::UserRole + 1,modLabel);
602 appNode->setData(0,Qt::UserRole,APPLICATION);
603 appNode->setExpanded(true);
604 appNode->setIcon(0,QIcon(":/run22.svg"));
605 }
606 }
607 QString id = QString("%1").arg((*moditr)->getID());
608 QString command = QString("%1").arg((*moditr)->getCommand());
609 QString host = QString("%1").arg((*moditr)->getHost());
610 QString param = QString("%1").arg((*moditr)->getParam());
611 QString stdio = QString("%1").arg((*moditr)->getStdio());
612 QString workDir = QString("%1").arg((*moditr)->getWorkDir());
613 QString env = QString("%1").arg((*moditr)->getEnv());
614
615 // The default host is "localhost" if the <node> is not specified.
616 if(host.isEmpty())
617 {
618 host = "localhost";
619 }
620
621 QStringList l;
622 l << command << id << "stopped" << host << param << stdio << workDir << env;
623
625 if (!appNode) {
626 it = new CustomTreeWidgetItem(ui->moduleList,l);
627 } else {
628 it = new CustomTreeWidgetItem(appNode, l);
629 }
630
631 //it->setFlags(it->flags() | Qt::ItemIsEditable);
632 it->setData(0,Qt::UserRole,yarp::manager::MODULE);
633 it->setIcon(0,QIcon(":/close.svg"));
634 it->setForeground(2,QColor("#BF0303"));
635 ui->moduleList->addTopLevelItem(it);
636 }
637
638 id = 0;
639 for(cnnitr=connections.begin(); cnnitr<connections.end(); cnnitr++)
640 {
641 QString type;
642 if ((*cnnitr).isPersistent()) {
643 type = "Persistent";
644 } else {
645 if ((*cnnitr).isExternalFrom() || (*cnnitr).isExternalTo()) {
646 type = "External";
647 } else {
648 type = "Internal";
649 }
650 }
651 QString sId = QString("%1").arg(id);
652 QString from = QString("%1").arg((*cnnitr).from());
653 QString to = QString("%1").arg((*cnnitr).to());
654 QString carrier = QString("%1").arg((*cnnitr).carrier());
655 QString status = "disconnected";
656 QString modifier="";
657 // The default carrier is "fast_tcp" if <protocol> is not specified.
658 if(carrier.isEmpty())
659 {
660 carrier = "fast_tcp";
661 }
662 size_t pos = carrier.toStdString().find('+');
663 if(pos != std::string::npos)
664 {
665 modifier = carrier.mid(pos);
666 QStringList myStringList = carrier.split('+');
667 carrier = myStringList.first();
668 }
669
670
671 QStringList l;
672 l << type << sId << status << from << to << carrier << modifier;
673 auto* it = new CustomTreeWidgetItem(ui->connectionList,l);
674 ui->moduleList->addTopLevelItem(it);
675
676 //scanning available carriers:
677 scanAvailableCarriers(carrier,false);
678
679 auto* comboBox = new QComboBox(this);
680 comboBox->addItems(stringLst);
681 comboBox->setEditable(true);
682 ui->connectionList->setItemWidget((QTreeWidgetItem *) it,5, comboBox);
683 it->setData(0,Qt::UserRole,yarp::manager::INOUTD);
684 it->setIcon(0,QIcon(":/disconnect22.svg"));
685 it->setForeground(2,QColor("#BF0303"));
686 id++;
687 }
688
689 id = 0;
691 for(itrS=safeManager.getResources().begin(); itrS!=safeManager.getResources().end(); itrS++)
692 {
693 //m_resRow = *(m_refTreeResModel->append());
694 QString sId = QString("%1").arg(id);
695 QString type;
696 if (dynamic_cast<yarp::manager::Computer*>(*itrS))
697 {
698 type = "computer";
699 }
700 else if (dynamic_cast<yarp::manager::ResYarpPort*>(*itrS))
701 {
702 type = "port";
703 }
704 QString res = QString("%1").arg((*itrS)->getName());
705 if (std::find(listOfResourceNames.begin(),
706 listOfResourceNames.end(),
707 res.toStdString()) == listOfResourceNames.end())
708 {
709 listOfResourceNames.push_back(res.toStdString());
710 }
711 else
712 {
713 // The resource has been already added
714 continue;
715 }
716 QString status = "unknown";
717 //m_resRow[m_resColumns.m_col_color] = Gdk::Color("#00000");
718
719 QStringList l;
720 l << res << sId << type << status ;
721 auto* it = new CustomTreeWidgetItem(ui->resourcesList,l);
722 ui->moduleList->addTopLevelItem(it);
723 it->setData(0,Qt::UserRole,yarp::manager::RESOURCE);
724 if (type == "computer") {
725 it->setIcon(0,QIcon(":/computer-unavailable22.svg"));
726 it->setForeground(3,QColor("#BF0303"));
727 } else {
728 it->setIcon(0,QIcon(":/port-unavailable22.svg"));
729 it->setForeground(3,QColor("#BF0303"));
730 }
731 id++;
732 }
733 connect(ui->moduleList,SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(onModuleItemChanged(QTreeWidgetItem*,int)));
734}
735
736void ApplicationViewWidget::onModuleItemChanged(QTreeWidgetItem *it,int col)
737{
738 Qt::ItemFlags tmp = it->flags();
739 if (!(tmp & Qt::ItemIsEditable)) {
740 return;
741 }
742}
743
745void ApplicationViewWidget::onItemDoubleClicked(QTreeWidgetItem *it,int col)
746{
747 Qt::ItemFlags tmp = it->flags();
748 if (isEditable(it, col)) {
749 it->setFlags(tmp | Qt::ItemIsEditable);
750 disconnect(ui->connectionList,SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(onItemChanged(QTreeWidgetItem*,int)));
751 connect(ui->connectionList,SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(onItemChanged(QTreeWidgetItem*,int)));
752 } else if (tmp & Qt::ItemIsEditable) {
753 it->setFlags(tmp ^ Qt::ItemIsEditable);
754 disconnect(ui->connectionList,SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(onItemChanged(QTreeWidgetItem*,int)));
755 connect(ui->connectionList,SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(onItemChanged(QTreeWidgetItem*,int)));
756 }
757}
758
760void ApplicationViewWidget::onItemChanged(QTreeWidgetItem *it,int col)
761{
762 yarp::manager::NodeType type = (yarp::manager::NodeType)it->data(0,Qt::UserRole).toInt();
763 switch (type) {
765 ui->connectionList->blockSignals(true);
766 if (col == 3) {
767 updateConnectionItem(it);
768 bool res = safeManager.existPortFrom(it->text(1).toInt());
769 it->setForeground(3,QColor(res ? "#008C00" : "#BF0303"));
770 if (!res)
771 {
772 reportErrors();
773 }
774 }
775 if (col == 4) {
776 updateConnectionItem(it);
777 bool res = safeManager.existPortTo(it->text(1).toInt());
778 it->setForeground(3,QColor(res ? "#008C00" : "#BF0303"));
779 if (!res)
780 {
781 reportErrors();
782 }
783 }
784 ui->connectionList->blockSignals(false);
785 disconnect(ui->connectionList,SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(onItemChanged(QTreeWidgetItem*,int)));
786 break;
787 }
790 default:
791 break;
792 }
793}
794
799bool ApplicationViewWidget::isEditable(QTreeWidgetItem *it,int col)
800{
801 yarp::manager::NodeType type = (yarp::manager::NodeType)it->data(0,Qt::UserRole).toInt();
802
803 switch (type) {
805 if (col == 4 || col == 5 || col == 6 || col == 7) {
806 if (it->text(2) == "stopped") {
807 return true;
808 }
809 }
810 if (col == 3) {
811 if (it->text(2) == "stopped") {
812 return true;
813 }
814 }
815 break;
816 }
818 if (col == 3 || col == 4 || col == 5 || col == 6) {
819 if (it->text(2) == "disconnected") {
820 return true;
821 }
822 }
823 break;
824 }
826 return false;
827 break;
828 }
829 default:
830 break;
831 }
832
833 return false;
834}
835
836void ApplicationViewWidget::onCloseStdOut(int id)
837{
838 for(int i=0;i<ui->moduleList->topLevelItemCount();i++) {
839 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
840 if (it->data(0,Qt::UserRole) == APPLICATION) {
841 closeNestedApplicationStdOut(it,id);
842 } else {
843 if (it->text(1).toInt() == id) {
844 auto* stdouWin = qvariant_cast<StdoutWindow *>(it->data(0,Qt::UserRole));
845 if (stdouWin && stdouWin->getId() == id) {
846 delete stdouWin;
847 it->setData(0,Qt::UserRole,QVariant::fromValue(NULL));
848 return;
849 }
850 }
851 }
852 }
853}
854
855void ApplicationViewWidget::closeNestedApplicationStdOut(QTreeWidgetItem *it, int id)
856{
857 for(int j=0; j<it->childCount();j++) {
858 QTreeWidgetItem *ch = it->child(j);
859 if (ch->data(0,Qt::UserRole) == APPLICATION) {
860 closeNestedApplicationStdOut(it,id);
861 } else {
862 if (ch->text(1).toInt() == id) {
863 auto* stdouWin = qvariant_cast<StdoutWindow *>(ch->data(0,Qt::UserRole));
864 if (stdouWin && stdouWin->getId() == id) {
865 delete stdouWin;
866 ch->setData(0,Qt::UserRole,QVariant::fromValue(NULL));
867 return;
868 }
869 }
870 }
871 }
872}
873
874bool ApplicationViewWidget::areAllShutdown()
875{
876 bool ret = true;
877 for(int i=0;i<ui->moduleList->topLevelItemCount();i++) {
878 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
879 if (it->data(0,Qt::UserRole) == APPLICATION) {
880 ret = areAllNestedApplicationShutdown(it);
881 if (!ret) {
882 return false;
883 }
884 } else {
885 if (it->text(2) != "stopped") {
886 return false;
887 }
888 }
889 }
890
891 for(int i=0;i<ui->connectionList->topLevelItemCount();i++) {
892 QTreeWidgetItem *it = ui->connectionList->topLevelItem(i);
893 if (it->text(2) != "disconnected") {
894 return false;
895 }
896 }
897
898 return ret;
899}
900
901bool ApplicationViewWidget::areAllNestedApplicationShutdown(QTreeWidgetItem *it)
902{
903 bool ret = true;
904 for(int j=0; j<it->childCount();j++) {
905 QTreeWidgetItem *ch = it->child(j);
906 if (ch->data(0,Qt::UserRole) == APPLICATION) {
907 ret = areAllNestedApplicationShutdown(ch);
908 if (!ret) {
909 return false;
910 }
911 } else {
912 if (ch->text(2) != "stopped") {
913 return false;
914 }
915 }
916 }
917 return ret;
918}
919
920void ApplicationViewWidget::onSelfSafeLoadBalance()
921{
922 updateApplicationWindow();
923 reportErrors();
924}
925
926void ApplicationViewWidget::onAssignHost()
927{
928 if (areAllShutdown() && !safeManager.busy()) {
929 for(int i=0;i<ui->moduleList->topLevelItemCount();i++) {
930 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
931 if (it->data(0,Qt::UserRole) == APPLICATION) {
932 assignHostNestedApplication(it);
933 } else {
934 if (it->isSelected()) {
935 //QString waitHost = QString("%1").arg("?");
936 it->setText(2,"waiting");
937 it->setText(3,"?");
938 }
939 }
940
941
942 }
943 safeManager.safeLoadBalance();
945
946
947 } else {
949 logger->addError("Running modules should be stopped before assigning hosts.");
950 reportErrors();
951 }
952}
953
954void ApplicationViewWidget::assignHostNestedApplication(QTreeWidgetItem *it)
955{
956 for(int j=0; j<it->childCount();j++) {
957 QTreeWidgetItem *ch = it->child(j);
958 if (ch->data(0,Qt::UserRole) == APPLICATION) {
959 assignHostNestedApplication(ch);
960 } else {
961 if (ch->isSelected()) {
962 //QString waitHost = QString("%1").arg("?");
963 ch->setText(2,"waiting");
964 ch->setText(3,"?");
965 }
966 }
967 }
968}
969
970void ApplicationViewWidget::onAttachStdout()
971{
972 if (safeManager.busy()) {
973 return;
974 }
975
976 std::vector<int> MIDs;
977 for(int i=0;i<ui->moduleList->topLevelItemCount();i++) {
978 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
979 if (it->data(0,Qt::UserRole) == APPLICATION) {
980 attachStdOutNestedApplication(it,&MIDs);
981 } else {
982 if (it->isSelected()) {
983 int id = it->text(1).toInt();
984
985 auto* stdouWin = qvariant_cast<StdoutWindow *>(it->data(0,Qt::UserRole));
986 if (stdouWin && stdouWin->getId() == id) {
987 // found
988 continue;
989 }
990
991 MIDs.push_back(it->text(1).toInt());
992
993 QString name = QString("%1").arg(app->getName());
994 QString strTitle = name + ":" + it->text(0) + ":" + it->text(1);
995
996 StdoutWindow *stdOutWindow = new StdoutWindow(id,strTitle);
997 connect(stdOutWindow,SIGNAL(closeStdOut(int)),this,SLOT(onCloseStdOut(int)));
998 //stdoutWinList.append(stdOutWindow);
999 it->setData(0,Qt::UserRole,QVariant::fromValue(stdOutWindow));
1000 stdOutWindow->show();
1001 }
1002 }
1003
1004
1005 }
1006 safeManager.safeAttachStdout(MIDs);
1007
1008 //return true;
1009}
1010
1011void ApplicationViewWidget::attachStdOutNestedApplication(QTreeWidgetItem *it,std::vector<int> *MIDs)
1012{
1013 for(int j=0; j<it->childCount();j++) {
1014 QTreeWidgetItem *ch = it->child(j);
1015 if (ch->data(0,Qt::UserRole) == APPLICATION) {
1016 attachStdOutNestedApplication(ch,MIDs);
1017 } else {
1018 if (ch->isSelected()) {
1019 int id = ch->text(1).toInt();
1020
1021 auto* stdouWin = qvariant_cast<StdoutWindow *>(ch->data(0,Qt::UserRole));
1022 if (stdouWin && stdouWin->getId() == id) {
1023 // found
1024 continue;
1025 }
1026
1027 MIDs->push_back(ch->text(1).toInt());
1028
1029 QString name = QString("%1").arg(app->getName());
1030 QString strTitle = name + ":" + ch->text(0) + ":" + ch->text(1);
1031
1032 StdoutWindow *stdOutWindow = new StdoutWindow(id,strTitle);
1033 connect(stdOutWindow,SIGNAL(closeStdOut(int)),this,SLOT(onCloseStdOut(int)));
1034 //stdoutWinList.append(stdOutWindow);
1035 ch->setData(0,Qt::UserRole,QVariant::fromValue(stdOutWindow));
1036 stdOutWindow->show();
1037 }
1038
1039 }
1040 }
1041}
1042
1044bool ApplicationViewWidget::onRun()
1045{
1046 selectAllConnections(true);
1047 selectAllResources(true);
1048 if (safeManager.busy() ) {
1049 return false;
1050 }
1051
1052 std::vector<int> MIDs;
1053 for(int i=0;i<ui->moduleList->topLevelItemCount();i++) {
1054 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
1055
1056 if (it->data(0,Qt::UserRole) == APPLICATION) {
1057 runNestedApplication(it,&MIDs);
1058
1059 } else {
1060 if (it->isSelected()) {
1061 MIDs.push_back(it->text(1).toInt());
1062 safeManager.updateExecutable(it->text(1).toInt(),
1063 it->text(4).toLatin1().data(),
1064 it->text(3).toLatin1().data(),
1065 it->text(5).toLatin1().data(),
1066 it->text(6).toLatin1().data(),
1067 it->text(7).toLatin1().data());
1068
1069 it->setText(2,"waiting");
1070 it->setIcon(0,QIcon(":/refresh.svg"));
1071 it->setForeground(2,QColor("#000000"));
1072
1073 }
1074
1075 //yDebug("Trying to run module ID %i param %s host %s stdio %s wdir %s env %s",it->text(1).toInt(),it->text(4).toLatin1().data(),
1076 // it->text(3).toLatin1().data(),it->text(5).toLatin1().data(),it->text(6).toLatin1().data(),it->text(7).toLatin1().data());
1077 }
1078 }
1079
1080 std::vector<int> CIDs;
1081 /*for(int i=0;i<ui->connectionList->topLevelItemCount();i++)
1082 {
1083 updateConnection(i, CIDs);
1084 }*/
1085
1086 std::vector<int> RIDs;
1087 /*for(int i=0;i<ui->resourcesList->topLevelItemCount();i++) {
1088 QTreeWidgetItem *it = ui->resourcesList->topLevelItem(i);
1089 if (it->isSelected()) {
1090 RIDs.push_back(it->text(1).toInt());
1091 it->setText(3,"waiting");
1092 it->setIcon(0,QIcon(":/refresh22.svg"));
1093 it->setForeground(3,QColor("#000000"));
1094 }
1095 }*/
1096
1097
1098 safeManager.safeRun(MIDs,CIDs,RIDs);
1100 selectAllModule(false);
1101 selectAllConnections(false);
1102 selectAllResources(false);
1103 return true;
1104}
1105
1106void ApplicationViewWidget::runNestedApplication(QTreeWidgetItem *it,std::vector<int> *MIDs)
1107{
1108 for(int j=0; j<it->childCount();j++) {
1109 QTreeWidgetItem *ch = it->child(j);
1110
1111 if (ch->data(0,Qt::UserRole) == APPLICATION) {
1112 runNestedApplication(ch,MIDs);
1113 } else {
1114 if (ch->isSelected()) {
1115 MIDs->push_back(ch->text(1).toInt());
1116 safeManager.updateExecutable(ch->text(1).toInt(),
1117 ch->text(4).toLatin1().data(),
1118 ch->text(3).toLatin1().data(),
1119 ch->text(5).toLatin1().data(),
1120 ch->text(6).toLatin1().data(),
1121 ch->text(7).toLatin1().data());
1122
1123 ch->setText(2,"waiting");
1124 ch->setIcon(0,QIcon(":/refresh.svg"));
1125 ch->setForeground(2,QColor("#000000"));
1126 }
1127 }
1128
1129
1130
1131 }
1132}
1133
1135bool ApplicationViewWidget::onStop()
1136{
1137 selectAllConnections(true);
1138 selectAllResources(true);
1139 if (safeManager.busy()) {
1140 return false;
1141 }
1142
1143 std::vector<int> MIDs;
1144 for(int i=0;i<ui->moduleList->topLevelItemCount();i++) {
1145 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
1146 if (it->data(0,Qt::UserRole) == APPLICATION) {
1147 stopNestedApplication(it,&MIDs);
1148
1149 } else {
1150 if (it->isSelected()) {
1151 //moduluesIDs.append(it->text(1).toInt());
1152 MIDs.push_back(it->text(1).toInt());
1153 safeManager.updateExecutable(it->text(1).toInt(),
1154 it->text(4).toLatin1().data(),
1155 it->text(3).toLatin1().data(),
1156 it->text(5).toLatin1().data(),
1157 it->text(6).toLatin1().data(),
1158 it->text(7).toLatin1().data());
1159
1160 it->setText(2,"waiting");
1161 it->setIcon(0,QIcon(":/refresh.svg"));
1162 it->setForeground(2,QColor("#000000"));
1163
1164 }
1165 }
1166
1167 }
1168
1169 std::vector<int> CIDs;
1170 /*for(int i=0;i<ui->connectionList->topLevelItemCount();i++)
1171 {
1172 updateConnection(i, CIDs);
1173 }*/
1174
1175 std::vector<int> RIDs;
1176 /*for(int i=0;i<ui->resourcesList->topLevelItemCount();i++) {
1177 QTreeWidgetItem *it = ui->resourcesList->topLevelItem(i);
1178 if (it->isSelected()) {
1179 RIDs.push_back(it->text(1).toInt());
1180 it->setText(3,"waiting");
1181 it->setIcon(0,QIcon(":/refresh22.svg"));
1182 it->setForeground(3,QColor("#000000"));
1183 }
1184 }*/
1185
1186
1187 safeManager.safeStop(MIDs,CIDs,RIDs);
1189 selectAllModule(false);
1190 selectAllConnections(false);
1191 selectAllResources(false);
1192 return true;
1193}
1194
1195void ApplicationViewWidget::stopNestedApplication(QTreeWidgetItem *it,std::vector<int> *MIDs)
1196{
1197 for(int j=0; j<it->childCount();j++) {
1198 QTreeWidgetItem *ch = it->child(j);
1199 if (ch->data(0,Qt::UserRole) == APPLICATION) {
1200 stopNestedApplication(ch,MIDs);
1201 } else {
1202 if (ch->isSelected()) {
1203 MIDs->push_back(ch->text(1).toInt());
1204 safeManager.updateExecutable(ch->text(1).toInt(),
1205 ch->text(4).toLatin1().data(),
1206 ch->text(3).toLatin1().data(),
1207 ch->text(5).toLatin1().data(),
1208 ch->text(6).toLatin1().data(),
1209 ch->text(7).toLatin1().data());
1210
1211 ch->setText(2,"waiting");
1212 ch->setIcon(0,QIcon(":/refresh.svg"));
1213 ch->setForeground(2,QColor("#000000"));
1214 }
1215 }
1216
1217
1218
1219 }
1220}
1221
1223bool ApplicationViewWidget::onKill()
1224{
1225 selectAllConnections(true);
1226 selectAllResources(true);
1227 if (safeManager.busy()) {
1228 return false;
1229 }
1230
1231 if (QMessageBox::question(this,"Killing modules!","Are you sure?") != QMessageBox::Yes) {
1232 return true;
1233 }
1234
1235 std::vector<int> MIDs;
1236 for(int i=0;i<ui->moduleList->topLevelItemCount();i++) {
1237 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
1238 if (it->data(0,Qt::UserRole) == APPLICATION) {
1239 killNestedApplication(it,&MIDs);
1240 } else {
1241 if (it->isSelected()) {
1242 //moduluesIDs.append(it->text(1).toInt());
1243 MIDs.push_back(it->text(1).toInt());
1244 safeManager.updateExecutable(it->text(1).toInt(),
1245 it->text(4).toLatin1().data(),
1246 it->text(3).toLatin1().data(),
1247 it->text(5).toLatin1().data(),
1248 it->text(6).toLatin1().data(),
1249 it->text(7).toLatin1().data());
1250
1251 it->setText(2,"waiting");
1252 it->setIcon(0,QIcon(":/refresh22.svg"));
1253 it->setForeground(2,QColor("#000000"));
1254
1255 }
1256 }
1257
1258 }
1259
1260 std::vector<int> CIDs;
1261 /*for(int i=0;i<ui->connectionList->topLevelItemCount();i++)
1262 {
1263 updateConnection(i, CIDs);
1264
1265 }*/
1266
1267 std::vector<int> RIDs;
1268 /*for(int i=0;i<ui->resourcesList->topLevelItemCount();i++) {
1269 QTreeWidgetItem *it = ui->resourcesList->topLevelItem(i);
1270 if (it->isSelected()) {
1271 RIDs.push_back(it->text(1).toInt());
1272 it->setText(3,"waiting");
1273 it->setIcon(0,QIcon(":/refresh22.svg"));
1274 it->setForeground(3,QColor("#000000"));
1275 }
1276 }*/
1277
1278
1279 safeManager.safeKill(MIDs, CIDs, RIDs);
1281 selectAllModule(false);
1282 selectAllConnections(false);
1283 selectAllResources(false);
1284 return true;
1285}
1286
1287void ApplicationViewWidget::killNestedApplication(QTreeWidgetItem *it,std::vector<int> *MIDs)
1288{
1289 for(int j=0; j<it->childCount();j++) {
1290 QTreeWidgetItem *ch = it->child(j);
1291 if (ch->data(0,Qt::UserRole) == APPLICATION) {
1292 killNestedApplication(ch,MIDs);
1293 } else {
1294 if (ch->isSelected()) {
1295 MIDs->push_back(ch->text(1).toInt());
1296 safeManager.updateExecutable(ch->text(1).toInt(),
1297 ch->text(4).toLatin1().data(),
1298 ch->text(3).toLatin1().data(),
1299 ch->text(5).toLatin1().data(),
1300 ch->text(6).toLatin1().data(),
1301 ch->text(7).toLatin1().data());
1302
1303 ch->setText(2,"waiting");
1304 ch->setIcon(0,QIcon(":/refresh.svg"));
1305 ch->setForeground(2,QColor("#000000"));
1306 }
1307 }
1308
1309
1310
1311 }
1312}
1313
1315bool ApplicationViewWidget::onConnect()
1316{
1317 if (safeManager.busy()) {
1318 return false;
1319 }
1320
1321
1322 std::vector<int> CIDs;
1323 for(int i=0;i<ui->connectionList->topLevelItemCount();i++)
1324 {
1325 updateConnection(i,CIDs);
1326 }
1327
1328
1329 safeManager.safeConnect(CIDs);
1331 selectAllConnections(false);
1332 return true;
1333}
1334
1336bool ApplicationViewWidget::onDisconnect()
1337{
1338 if (safeManager.busy()) {
1339 return false;
1340 }
1341
1342
1343 std::vector<int> CIDs;
1344 for(int i=0;i<ui->connectionList->topLevelItemCount();i++)
1345 {
1346 updateConnection(i, CIDs);
1347 }
1348
1349
1350 safeManager.safeDisconnect(CIDs);
1352 selectAllConnections(false);
1353 return true;
1354}
1355
1356
1358bool ApplicationViewWidget::onRefresh()
1359{
1360 if (safeManager.busy()) {
1361 return false;
1362 }
1363
1364 bool costly{false};
1365 costlyRefresh(costly);
1366
1367 std::vector<int> modulesIDs;
1368 std::vector<int> connectionsIDs;
1369 std::vector<int> resourcesIDs;
1370
1371 for(int i=0;i<ui->moduleList->topLevelItemCount();i++) {
1372 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
1373 if (it->data(0,Qt::UserRole) == APPLICATION) {
1374 refreshNestedApplication(it,&modulesIDs);
1375 } else {
1376 if (it->isSelected()) {
1377 modulesIDs.push_back(it->text(1).toInt());
1378 safeManager.updateExecutable(it->text(1).toInt(),
1379 it->text(4).toLatin1().data(),
1380 it->text(3).toLatin1().data(),
1381 it->text(5).toLatin1().data(),
1382 it->text(6).toLatin1().data(),
1383 it->text(7).toLatin1().data());
1384 it->setText(2,"waiting");
1385 it->setIcon(0,QIcon(":/refresh22.svg"));
1386 it->setForeground(2,QColor("#000000"));
1387 }
1388 }
1389
1390 }
1391
1392 for(int i=0;i<ui->connectionList->topLevelItemCount();i++) {
1393 updateConnection(i,connectionsIDs);
1394 }
1395
1396 for(int i=0;i<ui->resourcesList->topLevelItemCount();i++) {
1397 QTreeWidgetItem *it = ui->resourcesList->topLevelItem(i);
1398 if (it->isSelected()) {
1399 resourcesIDs.push_back(it->text(1).toInt());
1400 it->setText(3,"waiting");
1401 it->setIcon(0,QIcon(":/refresh22.svg"));
1402 it->setForeground(3,QColor("#000000"));
1403 }
1404 }
1405
1406 if(m_firstRefresh || !costly) {
1407 yDebug() << "Performing safe refresh with module IDs:" << modulesIDs.size() << "connection IDs:" << connectionsIDs.size() << "resource IDs:" << resourcesIDs.size();
1408 safeManager.safeRefresh(modulesIDs,
1409 connectionsIDs,
1410 resourcesIDs);
1411 }
1412 else if(!m_firstRefresh && costly) {
1413 yDebug() << "Using batch ps call instead of classic refresh call to check running status of modules.";
1414 std::map<std::string, ProcessContainer> hostProcesses;
1415 std::map<std::string, bool> hostQueryOk;
1416 safeManager.collectYarprunProcessesByHost(hostProcesses, hostQueryOk);
1419 unsigned int id = 0;
1420
1421 for(moditr=modules.begin(); moditr<modules.end(); moditr++)
1422 {
1423 bool isRunning = false;
1424 yarp::manager::Executable* exe = *moditr;
1425 if (exe && exe->getBrokerType() == BrokerType::yarp) {
1426 const std::string host = exe->getHost();
1427 const auto hostOkIt = hostQueryOk.find(host);
1428 if (hostOkIt != hostQueryOk.end() && hostOkIt->second) {
1429 const auto procIt = hostProcesses.find(host);
1430 if (procIt != hostProcesses.end()) {
1431 const std::string exeCmd = exe->getCommand();
1432 const std::string exeParam = exe->getParam();
1433 for (const auto& proc : procIt->second) {
1434 const bool statusRunning = proc.status.empty() || proc.status == "running";
1435 const bool cmdMatches = proc.command.find(exeCmd) != std::string::npos;
1436 const bool paramMatches = exeParam.empty() || (proc.command.find(exeParam) != std::string::npos);
1437 if (statusRunning && cmdMatches && paramMatches) {
1438 isRunning = true;
1439 break;
1440 }
1441 }
1442 }
1443 } else {
1444 // Fallback to the old per-module check if the remote ps query failed.
1445 isRunning = safeManager.running(id);
1446 }
1447 } else {
1448 // Local and other brokers: keep previous behavior.
1449 isRunning = safeManager.running(id);
1450 }
1451
1452 if (isRunning) {
1453 onModStart(id);
1454 }
1455 else {
1456 onModStop(id);
1457 }
1458
1459 id++;
1460 }
1461 modulesIDs.clear();
1462 safeManager.safeRefresh(modulesIDs,
1463 connectionsIDs,
1464 resourcesIDs);
1465 }
1466
1467 if (m_firstRefresh) {
1468 std::vector<std::string> yarprunHosts;
1469 for (auto* exe : safeManager.getExecutables()) {
1470 if (exe && exe->getBrokerType() == BrokerType::yarp) {
1471 const std::string host = exe->getHost();
1472 if (std::find(yarprunHosts.begin(), yarprunHosts.end(), host) == yarprunHosts.end()) {
1473 yarprunHosts.push_back(host);
1474 }
1475 }
1476 }
1477 m_resourcesNumber = static_cast<int>(yarprunHosts.size());
1478 m_firstRefresh = false;
1479 }
1480
1482 selectAllConnections(false);
1483 selectAllModule(false);
1484 selectAllResources(false);
1485
1486 return true;
1487}
1488void ApplicationViewWidget::refreshNestedApplication(QTreeWidgetItem *it,std::vector<int> *MIDs)
1489{
1490 for(int j=0; j<it->childCount();j++) {
1491 QTreeWidgetItem *ch = it->child(j);
1492
1493 if (ch->data(0,Qt::UserRole) == APPLICATION) {
1494 refreshNestedApplication(ch,MIDs);
1495 } else {
1496 if (ch->isSelected()) {
1497 MIDs->push_back(ch->text(1).toInt());
1498 ch->setText(2,"waiting");
1499 ch->setIcon(0,QIcon(":/refresh22.svg"));
1500 ch->setForeground(2,QColor("#000000"));
1501 }
1502 }
1503
1504 }
1505}
1506
1508void ApplicationViewWidget::selectAllModule()
1509{
1510 selectAllModule(true);
1511}
1512
1514void ApplicationViewWidget::selectAllConnections()
1515{
1516 selectAllConnections(true);
1517}
1518
1520void ApplicationViewWidget::selectAllResources()
1521{
1522 selectAllResources(true);
1523}
1524
1528void ApplicationViewWidget::selectAllModule(bool check)
1529{
1530 disconnect(ui->moduleList,SIGNAL(itemSelectionChanged()),this,SLOT(onModuleItemSelectionChanged()));
1531 itemsSelectedForResource.clear();
1532 for(int i=0;i<ui->moduleList->topLevelItemCount();i++) {
1533 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
1534 if (it->data(0,Qt::UserRole) == APPLICATION) {
1535 selectAllNestedApplicationModule(it,check);
1536 } else {
1537 selectModule(it,check);
1538 }
1539 }
1540 if (ui->moduleList->selectedItems().isEmpty()) {
1541 modRunAction->setEnabled(false);
1542 modStopAction->setEnabled(false);
1543 modkillAction->setEnabled(false);
1544 modAttachAction->setEnabled(false);
1545 modAssignAction->setEnabled(false);
1546 modRefreshAction->setEnabled(false);
1547 } else {
1548 modRunAction->setEnabled(true);
1549 modStopAction->setEnabled(true);
1550 modkillAction->setEnabled(true);
1551
1552 bool all = true;
1553 foreach (QTreeWidgetItem *it, ui->moduleList->selectedItems()) {
1554 if (it->text(3) != "localhost") {
1555 modAttachAction->setEnabled(false);
1556 all = false;
1557 break;
1558 }
1559 }
1560 if (all) {
1561 modAttachAction->setEnabled(true);
1562 }
1563// if (ui->moduleList->currentItem()->text(3) == "localhost")
1564// {
1565// modAttachAction->setEnabled(true);
1566// }
1567// else
1568// {
1569// modAttachAction->setEnabled(false);
1570// }
1571 modAssignAction->setEnabled(true);
1572 modRefreshAction->setEnabled(true);
1573
1574
1575
1576
1577 QList<int>selectedIds;
1578 QList<QTreeWidgetItem*> selectedItems = ui->moduleList->selectedItems();
1579 foreach(QTreeWidgetItem *it,selectedItems) {
1580 if (it->data(0,Qt::UserRole).toInt() == APPLICATION) {
1581 for(int j=0;j<it->childCount();j++) {
1582 QTreeWidgetItem *child = it->child(j);
1583 child->setSelected(true);
1584 }
1585
1586 }
1587
1588 }
1589 selectedItems = ui->moduleList->selectedItems();
1590 foreach(QTreeWidgetItem *it,selectedItems) {
1591 if (it->data(0,Qt::UserRole).toInt() == APPLICATION) {
1592 continue;
1593 }
1594 QString id = it->text(1);
1595 selectedIds.append(id.toInt());
1596 }
1597
1598 builder->setSelectedModules(selectedIds);
1599 }
1600
1601
1602 connect(ui->moduleList,SIGNAL(itemSelectionChanged()),this,SLOT(onModuleItemSelectionChanged()));
1603}
1604
1605void ApplicationViewWidget::selectAllNestedApplicationModule(QTreeWidgetItem *it,bool check)
1606{
1607 for(int j=0;j<it->childCount();j++) {
1608 QTreeWidgetItem *ch = it->child(j);
1609 if (ch->data(0,Qt::UserRole) == APPLICATION) {
1610 selectAllNestedApplicationModule(ch, check);
1611 } else {
1612 selectModule(ch,check);
1613 }
1614 }
1615}
1616
1617bool ApplicationViewWidget::scanAvailableCarriers(QString carrier, bool isConnection){
1620 bool res=false;
1621 stringLst.clear();
1622 stringLst.push_back(carrier);
1623 for (size_t i=0; i<lst.size(); i++)
1624 {
1625 if (lst.get(i).asString() == carrier.toStdString()) {
1626 res = true;
1627 } else {
1628 stringLst.push_back(lst.get(i).asString().c_str());
1629 }
1630 }
1631 if (!res && isConnection)
1632 {
1633 std::string msg = "Unable to find '"+ carrier.toStdString() +
1634 "' among the available carriers in this machine, the connection could fail.";
1635 logger->addWarning(msg.c_str());
1636 }
1637 return res;
1638}
1639
1640void ApplicationViewWidget::updateConnection(int index, std::vector<int>& CIDs)
1641{
1642 QTreeWidgetItem *it = ui->connectionList->topLevelItem(index);
1643 if (it->isSelected()) {
1644 updateConnectionItem(it);
1645
1646 CIDs.push_back(it->text(1).toInt());
1647
1648 it->setText(2,"waiting");
1649 it->setIcon(0,QIcon(":/refresh22.svg"));
1650 it->setForeground(2,QColor("#000000"));
1651 }
1652
1653}
1654
1655void ApplicationViewWidget::updateConnectionItem(QTreeWidgetItem *it)
1656{
1657 auto* box = qobject_cast<QComboBox*>(ui->connectionList->itemWidget((QTreeWidgetItem *)it, 5));
1658 QString carrier, modifier;
1659 if (box)
1660 {
1661 carrier = box->currentText();
1662
1663 }
1664 else
1665 {
1666 carrier=it->text(5);
1667 }
1668
1669 //checking if in the carrier has been added a modifier
1670
1671 size_t pos = carrier.toStdString().find('+');
1672 if(pos != std::string::npos)
1673 {
1674 modifier = carrier.mid(pos);
1675 QStringList myStringList = carrier.split('+');
1676 carrier = myStringList.first();
1677 box->setCurrentText(carrier);
1678 it->setText(6,modifier);
1679 }
1680
1681 // scan the available carriers in the system where yarpmanager is launched.
1682 scanAvailableCarriers(carrier);
1683 carrier = carrier + it->text(6); //adding modifier.
1684 safeManager.updateConnection(it->text(1).toInt(),
1685 it->text(3).toLatin1().data(),
1686 it->text(4).toLatin1().data(),
1687 carrier.toLatin1().data());
1688}
1689
1690bool ApplicationViewWidget::costlyRefresh(bool& costly)
1691{
1692 if (safeManager.busy()) {
1693 return false;
1694 }
1695
1696 costly=false;
1697
1698 int totalSelectedModules = 0;
1699
1700 foreach(const auto& it, itemsSelectedForResource){
1701 yDebug() << "Resource " << it.first.c_str() << " has " << it.second << " modules selected.";
1702 totalSelectedModules += it.second;
1703
1704 if(totalSelectedModules > m_resourcesNumber) {
1705 costly = true;
1706 break;
1707 }
1708 }
1709
1710 return true;
1711}
1712
1713void ApplicationViewWidget::selectModule(QTreeWidgetItem *item, bool check)
1714{
1715 item->setSelected(check);
1716 if(itemsSelectedForResource.count(item->text(3).toStdString())) {
1717 itemsSelectedForResource[item->text(3).toStdString()] += check ? 1 : -1*(itemsSelectedForResource[item->text(3).toStdString()] > 0);
1718 if(itemsSelectedForResource[item->text(3).toStdString()] < 0){
1719 yError() << "Error in counting selected items for resource " << item->text(3).toStdString();
1720 }
1721 }
1722 else if(check && !itemsSelectedForResource.count(item->text(3).toStdString()) && (item->text(3).toStdString() != "")) {
1723 itemsSelectedForResource[item->text(3).toStdString()] = 1;
1724 }
1725}
1726
1730void ApplicationViewWidget::selectAllConnections(bool check)
1731{
1732 disconnect(ui->connectionList,SIGNAL(itemSelectionChanged()),this,SLOT(onConnectionItemSelectionChanged()));
1733 for(int i=0;i<ui->connectionList->topLevelItemCount();i++) {
1734 QTreeWidgetItem *it = ui->connectionList->topLevelItem(i);
1735 it->setSelected(check);
1736 }
1737
1738 if (ui->connectionList->selectedItems().isEmpty()) {
1739 connConnectAction->setEnabled(false);
1740 connDisconnectAction->setEnabled(false);
1741 connSeparatorAction->setEnabled(false);
1742 connRefreshAction->setEnabled(false);
1743 } else {
1744 connConnectAction->setEnabled(true);
1745 connDisconnectAction->setEnabled(true);
1746 connSeparatorAction->setEnabled(true);
1747 connRefreshAction->setEnabled(true);
1748 }
1749
1750 QList<int>selectedIds;
1751 QList<QTreeWidgetItem*> selectedItems = ui->connectionList->selectedItems();
1752 foreach(QTreeWidgetItem *it,selectedItems) {
1753 QString id = it->text(1);
1754 selectedIds.append(id.toInt());
1755 }
1756
1757 builder->setSelectedConnections(selectedIds);
1758 connect(ui->connectionList,SIGNAL(itemSelectionChanged()),this,SLOT(onConnectionItemSelectionChanged()));
1759
1760}
1761
1765void ApplicationViewWidget::selectAllResources(bool check)
1766{
1767 for(int i=0;i<ui->resourcesList->topLevelItemCount();i++) {
1768 QTreeWidgetItem *it = ui->resourcesList->topLevelItem(i);
1769 it->setSelected(check);
1770 }
1771}
1772
1776{
1777 selectAllConnections(true);
1778 selectAllModule(true);
1779 selectAllResources(true);
1780}
1781
1784{
1785 if (!onlySelected) {
1786 selectAllModule(true);
1787 }
1788 onRun();
1789}
1790
1793{
1794 if (!onlySelected) {
1795 selectAllModule(true);
1796 }
1797 onStop();
1798}
1799
1802{
1803 if (!onlySelected) {
1804 selectAllModule(true);
1805 }
1806 onKill();
1807}
1808
1811{
1812 if (!onlySelected) {
1813 selectAllConnections(true);
1814 }
1815 onConnect();
1816}
1817
1820{
1821 if (!onlySelected) {
1822 selectAllConnections(true);
1823 }
1824 onDisconnect();
1825}
1826
1829{
1830 selectAllConnections(true);
1831 selectAllModule(true);
1832 selectAllResources(true);
1833
1834 onRefresh();
1835}
1836
1838void ApplicationViewWidget::reportErrors()
1839{
1841 if (logger->errorCount() || logger->warningCount())
1842 {
1843 const char* err;
1844 while((err=logger->getLastError()))
1845 {
1846 QString msg = QString("(%1) %2").arg(app->getName()).arg(err);
1847 emit logError(msg);
1848 }
1849
1850 while((err=logger->getLastWarning()))
1851 {
1852 QString msg = QString("(%1) %2").arg(app->getName()).arg(err);
1853 emit logWarning(msg);
1854 }
1855 }
1856}
1857
1858
1861{
1862 QString fileName = QFileDialog::getSaveFileName(this,"Export Graph",QApplication::applicationDirPath(),"GraphViz format (*.dot)");
1863
1864 if (!fileName.isEmpty()) {
1865 if (!safeManager.exportDependencyGraph(fileName.toLatin1().data()))
1866 {
1868 logger->addError("Cannot export graph");
1869 reportErrors();
1870 return;
1871 }
1872 }
1873}
1874
1875
1877void ApplicationViewWidget::onYARPView()
1878{
1879 if (safeManager.busy()) {
1880 return;
1881 }
1883
1884 for(int i=0;i<ui->connectionList->topLevelItemCount();i++) {
1885 QTreeWidgetItem *it = ui->connectionList->topLevelItem(i);
1886 if (it->isSelected()) {
1887 QString from = it->text(3);
1888 QString to = QString("/inspect").arg(from);
1889 QString env = QString("YARP_PORT_PREFIX=%1").arg(to);
1890 to += "/yarpview/img:i";
1891
1893 if (launcher.init("yarpview", nullptr, nullptr, nullptr, nullptr, env.toLatin1().data()))
1894 {
1895 if (!launcher.start() && !launcher.error().empty())
1896 {
1897 QString msg;
1898 msg = QString("Error while launching yarpview. %1").arg(launcher.error().c_str());
1899 logger->addError(msg.toLatin1().data());
1900 reportErrors();
1901 }
1902 else
1903 {
1904 // waiting for the port to get open
1905 double base = yarp::os::SystemClock::nowSystem();
1906 while(!timeout(base, 3.0)) {
1907 if (launcher.exists(to.toLatin1().data())) {
1908 break;
1909 }
1910 }
1911 if (!launcher.connect(from.toLatin1().data(), to.toLatin1().data(), "udp")) {
1912 QString msg;
1913 msg = QString("Cannot inspect '%1' : %2").arg(from).arg(launcher.error().c_str());
1914 logger->addError(msg.toLatin1().data());
1915 launcher.stop();
1916 reportErrors();
1917 }
1918 }
1919 }
1920 }
1921 }
1922
1923
1925}
1926
1928void ApplicationViewWidget::onYARPHear()
1929{
1930 if (safeManager.busy()) {
1931 return;
1932 }
1934
1935 for(int i=0;i<ui->connectionList->topLevelItemCount();i++) {
1936 QTreeWidgetItem *it = ui->connectionList->topLevelItem(i);
1937 if (it->isSelected()) {
1938 QString from = it->text(3);
1939 QString to = QString("/inspect/hear%1").arg(from);
1940
1941#if defined(_WIN32)
1942 QString cmd = "cmd.exe";
1943 QString param;
1944 param = QString("/C yarphear --name %1").arg(to);
1945
1946#else
1947 QString cmd = "xterm";
1948 QString param;
1949 param = QString("-hold -title %1 -e yarphear --nodevice --name %2").arg(from).arg(to);
1950#endif
1951
1954 if (launcher.init(cmd.toLatin1().data(), param.toLatin1().data(), nullptr, nullptr, nullptr, nullptr))
1955 {
1956 if (!launcher.start() && !launcher.error().empty())
1957 {
1958 QString msg;
1959 msg = QString("Error while launching yarpread. %1").arg(launcher.error().c_str());
1960 logger->addError(msg.toLatin1().data());
1961 reportErrors();
1962 }
1963 else
1964 {
1965 // waiting for the port to get open
1966 double base = yarp::os::SystemClock::nowSystem();
1967 while(!timeout(base, 3.0)) {
1968 if (launcher.exists(to.toLatin1().data())) {
1969 break;
1970 }
1971 }
1972 if (!launcher.exists(to.toLatin1().data())) {
1973 QString msg;
1974 msg = QString("Cannot inspect '%1' : %2. Did you build yarp with 'portaudio' module?").arg(from).arg(launcher.error().c_str());
1975 logger->addError(msg.toLatin1().data());
1976 launcher.stop();
1977 reportErrors();
1978 }else if (!launcher.connect(from.toLatin1().data(), to.toLatin1().data(), "udp")) {
1979 QString msg;
1980 msg = QString("Cannot inspect '%1' : %2").arg(from).arg(launcher.error().c_str());
1981 logger->addError(msg.toLatin1().data());
1982 launcher.stop();
1983 reportErrors();
1984 }
1985 }
1986 }
1987
1988 }
1989 }
1991
1992
1993
1994}
1995
1997void ApplicationViewWidget::onYARPRead()
1998{
1999 if (safeManager.busy()) {
2000 return;
2001 }
2003
2004 for(int i=0;i<ui->connectionList->topLevelItemCount();i++) {
2005 QTreeWidgetItem *it = ui->connectionList->topLevelItem(i);
2006 if (it->isSelected()) {
2007 QString from = it->text(3);
2008 QString to = QString("/inspect/read%1").arg(from);
2009
2010#if defined(_WIN32)
2011 QString cmd = "cmd.exe";
2012 QString param;
2013 param = QString("/C yarp read %1").arg(to);
2014
2015#else
2016 QString cmd = "xterm";
2017 QString param;
2018 param = QString("-hold -title %1 -e yarp read %2").arg(from).arg(to);
2019#endif
2020
2023 if (launcher.init(cmd.toLatin1().data(), param.toLatin1().data(), nullptr, nullptr, nullptr, nullptr))
2024 {
2025 if (!launcher.start() && !launcher.error().empty())
2026 {
2027 QString msg;
2028 msg = QString("Error while launching yarpread. %1").arg(launcher.error().c_str());
2029 logger->addError(msg.toLatin1().data());
2030 reportErrors();
2031 }
2032 else
2033 {
2034 // waiting for the port to get open
2035 double base = yarp::os::SystemClock::nowSystem();
2036 while(!timeout(base, 3.0)) {
2037 if (launcher.exists(to.toLatin1().data())) {
2038 break;
2039 }
2040 }
2041 if (!launcher.connect(from.toLatin1().data(), to.toLatin1().data(), "udp")) {
2042 QString msg;
2043 msg = QString("Cannot inspect '%1' : %2").arg(from).arg(launcher.error().c_str());
2044 logger->addError(msg.toLatin1().data());
2045 launcher.stop();
2046 reportErrors();
2047 }
2048 }
2049 }
2050 }
2051 }
2052
2053
2055
2056}
2057
2059void ApplicationViewWidget::onYARPScope()
2060{
2061 if (safeManager.busy()) {
2062 return;
2063 }
2065
2066 YscopeWindow dlg;
2067 dlg.setModal(true);
2068 if (dlg.exec() != QDialog::Accepted) {
2069 return;
2070 }
2071 int strIndex = dlg.getIndex();
2072
2073
2074
2075
2076 for(int i=0;i<ui->connectionList->topLevelItemCount();i++) {
2077 QTreeWidgetItem *it = ui->connectionList->topLevelItem(i);
2078 if (it->isSelected()) {
2079 QString from = it->text(3);
2080 QString to = QString("/inspect").arg(from);
2081 QString env = QString("YARP_PORT_PREFIX=%1").arg(to);
2082 to += "/yarpscope";
2083
2084 QString param;
2085 param = QString("--title %1:%2 --bgcolor white --color blue --graph_size 2 --index %2").arg(from).arg(strIndex);
2086
2087
2089 if (launcher.init("yarpscope", param.toLatin1().data(), nullptr, nullptr, nullptr, env.toLatin1().data())) {
2090 if (!launcher.start() && !launcher.error().empty()) {
2091 QString msg;
2092 msg = QString("Error while launching yarpscope. %1").arg(launcher.error().c_str());
2093 logger->addError(msg.toLatin1().data());
2094 reportErrors();
2095 }
2096 else{
2097 // waiting for the port to get open
2098 double base = yarp::os::SystemClock::nowSystem();
2099 while (!timeout(base, 3.0)) {
2100 if (launcher.exists(to.toLatin1().data())) {
2101 break;
2102 }
2103 }
2104 if (!launcher.connect(from.toLatin1().data(), to.toLatin1().data(), "udp")) {
2105 QString msg;
2106 msg = QString("Cannot inspect '%1' : %2").arg(from).arg(launcher.error().c_str());
2107 logger->addError(msg.toLatin1().data());
2108 launcher.stop();
2109 reportErrors();
2110 }
2111 }
2112 }
2113
2114 }
2115 }
2117}
2118
2119
2120
2121bool ApplicationViewWidget::timeout(double base, double timeout)
2122{
2124 if ((yarp::os::SystemClock::nowSystem() - base) > timeout) {
2125 return true;
2126 }
2127 return false;
2128}
2129
2130
2131
2132
2135{
2136 if (editingMode) {
2137 return false;
2138 }
2139 for(int i=0; i< ui->moduleList->topLevelItemCount();i++) {
2140 if (ui->moduleList->topLevelItem(i)->text(2) == "running") {
2141 return true;
2142 }
2143 }
2144 return false;
2145}
2146
2148{
2149 return editingMode;
2150}
2151
2152void ApplicationViewWidget::onSelfConnect(int which)
2153{
2154 int row;
2155 if (!getConRowByID(which, &row))
2156 {
2157 yError()<<"ApplicationViewWidget: unable to find row with id:"<<which;
2158 return;
2159 }
2160
2161 QTreeWidgetItem *it = ui->connectionList->topLevelItem(row);
2162 if (it) {
2163 it->setText(2,"connected");
2164 it->setIcon(0,QIcon(":/connect22.svg"));
2165 it->setForeground(2,QColor("#008C00"));
2166 QString from = it->text(3);
2167 QString to = it->text(4);
2168 auto* box = qobject_cast<QComboBox*>(ui->connectionList->itemWidget((QTreeWidgetItem *)it, 5));
2169 box->setEnabled(false);
2170 builder->setConnectionConnected(true,from,to);
2171 }
2172
2173 /* row[m_conColumns.m_col_status] = "connected";
2174 row[m_conColumns.m_col_editable] = false;
2175 row[m_conColumns.m_col_color] = Gdk::Color("#008C00");
2176 row.set_value(0, m_refPixConnected);*/
2177
2178 reportErrors();
2179}
2180
2181void ApplicationViewWidget::onSelfDisconnect(int which)
2182{
2183 int row;
2184 if (!getConRowByID(which, &row))
2185 {
2186 yError()<<"ApplicationViewWidget: unable to find row with id:"<<which;
2187 return;
2188 }
2189
2190 QTreeWidgetItem *it = ui->connectionList->topLevelItem(row);
2191 if (it) {
2192 it->setText(2,"disconnected");
2193 it->setIcon(0,QIcon(":/disconnect22.svg"));
2194 it->setForeground(2,QColor("#BF0303"));
2195 QString from = it->text(3);
2196 QString to = it->text(4);
2197 auto* box = qobject_cast<QComboBox*>(ui->connectionList->itemWidget((QTreeWidgetItem *)it, 5));
2198 box->setEnabled(true);
2199 builder->setConnectionConnected(false,from,to);
2200 }
2201 reportErrors();
2202}
2203
2204void ApplicationViewWidget::onSelfResAvailable(int which)
2205{
2206 int row;
2207 if (!getResRowByID(which, &row))
2208 {
2209 yError()<<"ApplicationViewWidget: unable to find row with id:"<<which;
2210 return;
2211 }
2212
2213 QTreeWidgetItem *it = ui->resourcesList->topLevelItem(row);
2214 if (it) {
2215 it->setText(3,"available");
2216 if (it->text(2) == "computer") {
2217 it->setIcon(0,QIcon(":/computer-available22.svg"));
2218 it->setForeground(3,QColor("#008C00"));
2219 } else {
2220 it->setIcon(0,QIcon(":/port-available22.svg"));
2221 it->setForeground(3,QColor("#008C00"));
2222 }
2223 /*if (row[m_resColumns.m_col_type] == Glib::ustring("computer"))
2224 row.set_value(0, m_refPixAvailable);
2225 else
2226 row.set_value(0, m_refPixPortAvaibable);*/
2227 }
2228
2229
2230 reportErrors();
2231}
2232
2233void ApplicationViewWidget::onSelfResUnavailable(int which)
2234{
2235 int row;
2236 if (!getResRowByID(which, &row))
2237 {
2238 yError()<<"ApplicationViewWidget: unable to find row with id:"<<which;
2239 return;
2240 }
2241
2242 QTreeWidgetItem *it = ui->resourcesList->topLevelItem(row);
2243 if (it) {
2244 it->setText(3,"unavailable");
2245 if (it->text(2) == "computer") {
2246 it->setIcon(0,QIcon(":/computer-unavailable22.svg"));
2247 it->setForeground(3,QColor("#BF0303"));
2248 } else {
2249 it->setIcon(0,QIcon(":/port-unavailable22.svg"));
2250 it->setForeground(3,QColor("#BF0303"));
2251 }
2252 }
2253 reportErrors();
2254}
2255
2256void ApplicationViewWidget::onSelfStart(int which)
2257{
2258 QTreeWidgetItem *it = getModRowByID(which);
2259 if (it) {
2260 it->setText(2,"running");
2261 it->setIcon(0,QIcon(":/apply.svg"));
2262 it->setForeground(2,QColor("#008C00"));
2263 builder->setModuleRunning(true,which);
2264 //row[m_modColumns.m_col_editable] = false;
2265 //row[m_modColumns.m_col_color] = Gdk::Color("#008C00");
2266 //row.set_value(0, m_refPixRunning);
2267 }
2268
2269 reportErrors();
2270}
2271
2272void ApplicationViewWidget::onSelfStop(int which)
2273{
2274 QTreeWidgetItem *it = getModRowByID(which);
2275 if (it) {
2276 it->setText(2,"stopped");
2277 it->setIcon(0,QIcon(":/close.svg"));
2278 it->setForeground(2,QColor("#BF0303"));
2279 builder->setModuleRunning(false,which);
2280 }
2281 reportErrors();
2282}
2283
2288{
2289 emit selfStart(which);
2290}
2291
2296{
2297 emit selfStop(which);
2298}
2303void ApplicationViewWidget::onModStdout(int which, const char* msg)
2304{
2305 QString s = QString("%1").arg(msg);
2306 for(int j=0;j<ui->moduleList->topLevelItemCount();j++) {
2307 QTreeWidgetItem *it = ui->moduleList->topLevelItem(j);
2308 if (it->data(0,Qt::UserRole) == APPLICATION) {
2309 modStdOutNestedApplication(it,which,s);
2310 } else {
2311 auto* stdouWin = qvariant_cast<StdoutWindow *>(it->data(0,Qt::UserRole));
2312 if (stdouWin && stdouWin->getId() == which) {
2313 stdouWin->addMessage(s);
2314 break;
2315 }
2316 }
2317
2318 }
2319}
2320
2321void ApplicationViewWidget::modStdOutNestedApplication(QTreeWidgetItem *it, int id,QString s)
2322{
2323 for(int j=0; j<it->childCount();j++) {
2324 QTreeWidgetItem *ch = it->child(j);
2325 if (ch->data(0,Qt::UserRole) == APPLICATION) {
2326 modStdOutNestedApplication(ch,id,s);
2327 } else {
2328 auto* stdouWin = qvariant_cast<StdoutWindow *>(ch->data(0,Qt::UserRole));
2329 if (stdouWin && stdouWin->getId() == id) {
2330 stdouWin->addMessage(s);
2331 break;
2332 }
2333 }
2334 }
2335}
2336
2341{
2342 emit selfConnect(which);
2343}
2344
2349{
2350 emit selfDisconnect(which);
2351}
2352
2357{
2358 emit selfResAvailable(which);
2359}
2360
2365{
2366 emit selfResUnavailable(which);
2367}
2368
2373{
2374 if (from >= 0) {
2375 int row;
2376 if (getConRowByID(from, &row)) {
2377 ui->connectionList->topLevelItem(row)->setForeground(3,QColor("#008C00"));
2378 builder->setOutputPortAvailable(ui->connectionList->topLevelItem(row)->text(3),true);
2379 }
2380 }
2381
2382 if (to >= 0) {
2383 int row;
2384 if (getConRowByID(to, &row)) {
2385 ui->connectionList->topLevelItem(row)->setForeground(4,QColor("#008C00"));
2386 builder->setInputPortAvailable(ui->connectionList->topLevelItem(row)->text(4),true);
2387 }
2388 }
2389 reportErrors();
2390}
2391
2396{
2397 if (from >= 0) {
2398 int row;
2399 if (getConRowByID(from, &row)) {
2400 ui->connectionList->topLevelItem(row)->setForeground(3,QColor("#BF0303"));
2401 builder->setOutputPortAvailable(ui->connectionList->topLevelItem(row)->text(3),false);
2402 }
2403 }
2404
2405 if (to >= 0) {
2406 int row;
2407 if (getConRowByID(to, &row)) {
2408 ui->connectionList->topLevelItem(row)->setForeground(4,QColor("#BF0303"));
2409 builder->setInputPortAvailable(ui->connectionList->topLevelItem(row)->text(4),false);
2410 }
2411 }
2412 reportErrors();
2413}
2414
2419{
2420 reportErrors();
2421}
2422
2429
2430
2431
2432void ApplicationViewWidget::onDetachStdout()
2433{
2434
2435}
2436
2441bool ApplicationViewWidget::getConRowByID(int id, int *row)
2442{
2443 for(int i=0;i< ui->connectionList->topLevelItemCount();i++) {
2444 QTreeWidgetItem *it = ui->connectionList->topLevelItem(i);
2445
2446 if (it->text(1).toInt() == id) {
2447 *row = i;
2448 return true;
2449 }
2450 }
2451 return false;
2452}
2453
2458bool ApplicationViewWidget::getResRowByID(int id, int *row)
2459{
2460 for(int i=0;i< ui->resourcesList->topLevelItemCount();i++) {
2461 QTreeWidgetItem *it = ui->resourcesList->topLevelItem(i);
2462
2463 if (it->text(1).toInt() == id) {
2464 *row = i;
2465 return true;
2466 }
2467 }
2468 return false;
2469}
2474QTreeWidgetItem* ApplicationViewWidget::getModRowByID(int id, QTreeWidgetItem *parent)
2475{
2476 QTreeWidgetItem *ret = nullptr;
2477 if (!parent) {
2478 for(int i=0;i< ui->moduleList->topLevelItemCount();i++) {
2479 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
2480 if (it->data(0,Qt::UserRole) == APPLICATION) {
2481 ret = getModRowByID(id,it);
2482 if (ret) {
2483 break;
2484 }
2485 }
2486
2487 if (it->text(1).toInt() == id) {
2488 return it;
2489 }
2490 }
2491 } else {
2492 for(int i=0;i< parent->childCount();i++) {
2493 QTreeWidgetItem *it = parent->child(i);
2494 if (it->data(0,Qt::UserRole) == APPLICATION) {
2495 ret = getModRowByID(id,it);
2496 if (ret) {
2497 break;
2498 }
2499 }
2500
2501 if (it->text(1).toInt() == id) {
2502 return it;
2503 }
2504 }
2505 }
2506
2507 return ret;
2508}
2509
2510
2512 safeManager.close();
2513}
#define yError(...)
Definition Log.h:361
#define yDebug(...)
Definition Log.h:275
int SIGNAL(int pid, int signum)
The Application View Widget.
void onError() override
Called when an error occurred.
void selfResAvailable(int)
void connectConnectionSet(bool onlySelected)
Connect all modules in the application to their ports using connections list.
void selfResUnavailable(int)
void selectAll()
Select all element in the widget (modules, connections, resources)
void setFileName(QString filename)
void runApplicationSet(bool onlySelected)
Run all modules in the application.
ApplicationViewWidget(yarp::manager::Application *, yarp::manager::Manager *lazyManager, yarp::os::Property *config, bool editingMode=false, QWidget *parent=nullptr)
void onConConnect(int which) override
Called when a connection has been performed.
void exportGraph()
Export the current Graph.
void logWarning(QString)
void onConAvailable(int from, int to) override
Called when a connection become available.
bool isRunning()
Tells if a modules is in running state.
void onModStart(int which) override
Called when a modlue has been started.
void onLoadBalance() override
Refresh all and reports errors.
void onModStop(int which) override
Called when a modlue has been stopped.
void killApplicationSet(bool onlySelected)
Kill all running modules in the application.
void onConUnAvailable(int from, int to) override
Called when a connection become unavailable.
CustomTreeWidget * getConnectionList()
void setAppName(QString appName)
void onResUnAvailable(int which) override
Called when a resource become unavailable.
void logError(QString)
void disconnectConnectionSet(bool onlySelected)
Disconnect all modules in the application to their ports using connections list.
void onConDisconnect(int which) override
Called when a disconnection has been performed.
CustomTreeWidget * getModuleList()
void onModStdout(int which, const char *msg) override
Called when a modlue has writes on stdout.
void onResAvailable(int which) override
Called when a resource became available.
void stopApplicationSet(bool onlySelected)
Stop all modules in the application.
void setSelectedConnections(QList< int >selectedIds)
void load(bool refresh=false)
void addModulesAction(QAction *)
QString getAppName()
void setFileName(QString filename)
void setInputPortAvailable(QString, bool)
QString getFileName()
void setConnectionConnected(bool, QString from, QString to)
void addAction(QAction *)
void setAppName(QString appName)
void setModuleRunning(bool, int id)
void setOutputPortAvailable(QString, bool)
QToolBar * getToolBar()
void addConnectionsAction(QAction *)
void setSelectedModules(QList< int >selectedIds)
A custom QTreeWidgetItem.
A custom QTreeWidget.
Generic View Widget.
void modified(bool)
void onModified(bool mod)
yarp::manager::NodeType type
void safeConnect(std::vector< int > &CIDs)
void safeStop(std::vector< int > &MIDs, std::vector< int > &CIDs, std::vector< int > &RIDs)
void safeRun(std::vector< int > &MIDs, std::vector< int > &CIDs, std::vector< int > &RIDs)
void safeKill(std::vector< int > &MIDs, std::vector< int > &CIDs, std::vector< int > &RIDs)
void safeRefresh(std::vector< int > &MIDs, std::vector< int > &CIDs, std::vector< int > &RIDs)
void safeLoadBalance()
void safeAttachStdout(std::vector< int > &MIDs)
bool prepare(yarp::manager::Manager *lazy, yarp::os::Property *config, ApplicationEvent *event=nullptr)
void safeDisconnect(std::vector< int > &CDs)
static BuilderWindow * getBuilder(Application *app, Manager *lazyManager, SafeManager *manager, bool editingMode)
Class Application.
Singleton class ErrorLogger.
Definition utility.h:58
const char * getLastError()
Definition utility.cpp:148
void addError(const char *szError)
Definition utility.cpp:126
void addWarning(const char *szWarning)
Definition utility.cpp:104
static ErrorLogger * Instance()
Singleton class ErrorLogger.
Definition utility.cpp:98
const char * getLastWarning()
Definition utility.cpp:167
Class Executable.
Definition executable.h:71
const char * getParam()
Definition executable.h:102
const char * getCommand()
Definition executable.h:101
Class LocalBroker.
Definition localbroker.h:33
void setWindowMode(WindowMode m)
Define if the application will be visible or not.
bool exists(const std::string &port) override
std::string error() override
bool connect(const std::string &from, const std::string &to, const std::string &carrier, bool persist=false) override
connection broker
Class Manager.
Definition manager.h:21
ExecutablePContainer & getExecutables()
Definition manager.h:85
bool updateConnection(unsigned int id, const char *from, const char *to, const char *carrier)
Definition manager.cpp:457
CnnContainer & getConnections()
Definition manager.h:88
ResourcePContainer & getResources()
Definition manager.h:89
bool existPortFrom(unsigned int id)
Definition manager.cpp:732
bool existPortTo(unsigned int id)
Definition manager.cpp:753
bool updateExecutable(unsigned int id, const char *szparam, const char *szhost, const char *szstdio, const char *szworkdir, const char *szenv)
Definition manager.cpp:431
void collectYarprunProcessesByHost(std::map< std::string, ProcessContainer > &hostProcesses, std::map< std::string, bool > &hostQueryOk)
Definition manager.cpp:1283
bool loadApplication(const char *szAppName)
Definition manager.cpp:241
bool exportDependencyGraph(const char *szFileName)
Definition manager.h:102
Class Module.
Definition module.h:99
const char * getLabel()
Definition node.h:93
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:65
size_type size() const
Gets the number of elements in the bottle.
Definition Bottle.cpp:257
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:252
static Bottle listCarriers()
Definition Carriers.cpp:317
A class for storing options and configuration information.
Definition Property.h:33
static double nowSystem()
static void delaySystem(double seconds)
virtual std::string asString() const
Get string value.
Definition Value.cpp:246
Definition aboutdlg.h:11
std::vector< Executable * >::iterator ExecutablePIterator
Definition executable.h:167
std::vector< GenericResource * >::iterator ResourcePIterator
Definition resource.h:59
enum yarp::manager::__NodeType NodeType
std::vector< Connection >::iterator CnnIterator
std::vector< Executable * > ExecutablePContainer
Definition executable.h:166
std::vector< Connection > CnnContainer