7#include "ui_applicationviewwidget.h"
17#include <QTreeWidgetItem>
29 modRunAction(nullptr),
30 modStopAction(nullptr),
31 modkillAction(nullptr),
32 modSeparator(nullptr),
33 modRefreshAction(nullptr),
34 modSelectAllAction(nullptr),
35 modAttachAction(nullptr),
36 modAssignAction(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)
54 itemsSelectedForResource.clear();
58 this->editingMode = editingMode;
65 prepareManagerFrom(lazy);
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);
76 ui->resourcesList->resizeColumnToContents(0);
77 ui->resourcesList->resizeColumnToContents(1);
78 ui->resourcesList->resizeColumnToContents(2);
79 ui->resourcesList->resizeColumnToContents(3);
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);
89 connect(ui->moduleList,
SIGNAL(itemSelectionChanged()),
this,SLOT(onModuleItemSelectionChanged()));
90 connect(ui->moduleList,
SIGNAL(itemDoubleClicked(QTreeWidgetItem*,
int)),
this,SLOT(onItemDoubleClicked(QTreeWidgetItem*,
int)));
92 connect(ui->resourcesList,
SIGNAL(itemSelectionChanged()),
this,SLOT(onResourceItemSelectionChanged()));
93 connect(ui->resourcesList,
SIGNAL(itemDoubleClicked(QTreeWidgetItem*,
int)),
this,SLOT(onItemDoubleClicked(QTreeWidgetItem*,
int)));
95 connect(ui->connectionList,
SIGNAL(itemSelectionChanged()),
this,SLOT(onConnectionItemSelectionChanged()));
96 connect(ui->connectionList,
SIGNAL(itemDoubleClicked(QTreeWidgetItem*,
int)),
this,SLOT(onItemDoubleClicked(QTreeWidgetItem*,
int)));
99 connect(
this,
SIGNAL(
selfConnect(
int)),
this,SLOT(onSelfConnect(
int)),Qt::QueuedConnection);
100 connect(
this,
SIGNAL(
selfDisconnect(
int)),
this,SLOT(onSelfDisconnect(
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);
106 createModulesViewContextMenu();
107 createConnectionsViewContextMenu();
108 createResourcesViewContextMenu();
110 l =
new QGridLayout(ui->builderContainer);
111 ui->builderContainer->setLayout(l);
115 layout()->removeWidget(ui->mainSplietter);
116 delete ui->mainSplietter;
117 l = (QGridLayout*)layout();
125 builderWindowContainer =
new QMainWindow(
nullptr,Qt::Widget);
126 builderWindowContainer->setDockNestingEnabled(
true);
127 l->addWidget(builderWindowContainer);
129 builderWidget =
new QDockWidget(
"YARP Builder",builderWindowContainer);
130 builderWindowContainer->addDockWidget(Qt::TopDockWidgetArea,builderWidget);
132 builderWidget->setWidget(builder);
134 builderWidget->setFeatures(QDockWidget::NoDockWidgetFeatures);
135 connect(builderWidget,
SIGNAL(topLevelChanged(
bool)),
this,SLOT(onBuilderFloatChanged(
bool)));
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>)));
192 ret = builder->
save();
238 builderWidget->setVisible(show);
243 return !ui->moduleList->selectedItems().isEmpty();
247 return !ui->connectionList->selectedItems().isEmpty();
252 return ui->moduleList;
257 return ui->connectionList;
262 return builderToolBar;
266void ApplicationViewWidget::createModulesViewContextMenu()
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);
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"));
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);
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()));
303 onModuleItemSelectionChanged();
307void ApplicationViewWidget::createConnectionsViewContextMenu()
309 connContex =
new QMenu(ui->connectionList);
310 connSubMenu =
new QMenu(
"Inspect",connContex);
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);
321 connYARPViewAction =
new QAction(
"yarpview",connSubMenu);
322 connYARPReadAction =
new QAction(
"yarpread",connSubMenu);
323 connYARPHearAction =
new QAction(
"yarphear",connSubMenu);
324 connYARPScopeAction =
new QAction(
"yarpscope",connSubMenu);
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"));
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()));
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()));
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);
349 connSubMenu->addAction(connYARPViewAction);
350 connSubMenu->addAction(connYARPReadAction);
351 connSubMenu->addAction(connYARPHearAction);
352 connSubMenu->addAction(connYARPScopeAction);
355 ui->connectionList->setContextMenu(connContex);
357 onConnectionItemSelectionChanged();
362void ApplicationViewWidget::createResourcesViewContextMenu()
364 resRefreshAction =
new QAction(
"Refresh Status",
this);
365 resSelectAllAction =
new QAction(
"Select All Resources",
this);
367 resRefreshAction->setIcon(QIcon(
":/refresh22.svg"));
368 resSelectAllAction->setIcon(QIcon(
":/select-all22.svg"));
370 ui->resourcesList->addAction(resRefreshAction);
371 ui->resourcesList->addAction(resSelectAllAction);
373 connect(resRefreshAction,
SIGNAL(triggered()),
this,SLOT(onRefresh()));
374 connect(resSelectAllAction,
SIGNAL(triggered()),
this,SLOT(selectAllResources()));
378void ApplicationViewWidget::onConnectionItemSelectionChanged()
380 if (ui->connectionList->selectedItems().isEmpty()) {
381 connConnectAction->setEnabled(
false);
382 connDisconnectAction->setEnabled(
false);
383 connSeparatorAction->setEnabled(
false);
384 connRefreshAction->setEnabled(
false);
386 connConnectAction->setEnabled(
true);
387 connDisconnectAction->setEnabled(
true);
388 connSeparatorAction->setEnabled(
true);
389 connRefreshAction->setEnabled(
true);
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());
405void ApplicationViewWidget::onModuleItemSelectionChanged()
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);
416 modRunAction->setEnabled(
true);
417 modStopAction->setEnabled(
true);
418 modkillAction->setEnabled(
true);
421 foreach (QTreeWidgetItem *it, ui->moduleList->selectedItems()) {
422 if (it->text(3) !=
"localhost") {
423 modAttachAction->setEnabled(
false);
429 modAttachAction->setEnabled(
true);
432 modAssignAction->setEnabled(
true);
433 modRefreshAction->setEnabled(
true);
437 if (ui->moduleList->hasFocus()) {
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);
451 selectModule(it,
true);
455 selectedItems = ui->moduleList->selectedItems();
456 foreach(QTreeWidgetItem *it,selectedItems) {
457 if (it->data(0,Qt::UserRole).toInt() ==
APPLICATION) {
460 QString
id = it->text(1);
461 selectedIds.append(
id.toInt());
472void ApplicationViewWidget::onResourceItemSelectionChanged()
474 if (ui->resourcesList->currentItem() ==
nullptr) {
475 resRefreshAction->setEnabled(
false);
477 resRefreshAction->setEnabled(
true);
488 updateApplicationWindow();
494void ApplicationViewWidget::onRefreshApplication()
501 updateApplicationWindow();
509void ApplicationViewWidget::onConnectionSelected(QList<int>
id)
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);
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);
523 onConnectionItemSelectionChanged();
524 connect(ui->connectionList,
SIGNAL(itemSelectionChanged()),
this,SLOT(onConnectionItemSelectionChanged()));
527void ApplicationViewWidget::onModuleSelected(QList<int>
id)
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);
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);
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);
561 onModuleItemSelectionChanged();
562 connect(ui->moduleList,
SIGNAL(itemSelectionChanged()),
this,SLOT(onModuleItemSelectionChanged()));
566void ApplicationViewWidget::updateApplicationWindow()
568 ui->moduleList->clear();
569 ui->connectionList->clear();
570 ui->resourcesList->clear();
571 listOfResourceNames.clear();
573 disconnect(ui->moduleList,
SIGNAL(itemChanged(QTreeWidgetItem*,
int)),
this,SLOT(onModuleItemChanged(QTreeWidgetItem*,
int)));
581 for(moditr=modules.begin(); moditr<modules.end(); moditr++)
584 Module *mod = (*moditr)->getModule();
588 if (modLabel != appLabel) {
590 for(
int i=0; i < ui->moduleList->topLevelItemCount();i++) {
591 if (ui->moduleList->topLevelItem(i)->data(0,Qt::UserRole + 1).toString() == modLabel) {
601 appNode->setData(0,Qt::UserRole + 1,modLabel);
603 appNode->setExpanded(
true);
604 appNode->setIcon(0,QIcon(
":/run22.svg"));
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());
622 l << command <<
id <<
"stopped" << host << param << stdio << workDir << env;
633 it->setIcon(0,QIcon(
":/close.svg"));
634 it->setForeground(2,QColor(
"#BF0303"));
635 ui->moduleList->addTopLevelItem(it);
639 for(cnnitr=connections.begin(); cnnitr<connections.end(); cnnitr++)
642 if ((*cnnitr).isPersistent()) {
645 if ((*cnnitr).isExternalFrom() || (*cnnitr).isExternalTo()) {
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";
658 if(carrier.isEmpty())
660 carrier =
"fast_tcp";
662 size_t pos = carrier.toStdString().find(
'+');
663 if(pos != std::string::npos)
665 modifier = carrier.mid(pos);
666 QStringList myStringList = carrier.split(
'+');
667 carrier = myStringList.first();
672 l <<
type << sId << status << from << to << carrier << modifier;
674 ui->moduleList->addTopLevelItem(it);
677 scanAvailableCarriers(carrier,
false);
679 auto* comboBox =
new QComboBox(
this);
680 comboBox->addItems(stringLst);
681 comboBox->setEditable(
true);
682 ui->connectionList->setItemWidget((QTreeWidgetItem *) it,5, comboBox);
684 it->setIcon(0,QIcon(
":/disconnect22.svg"));
685 it->setForeground(2,QColor(
"#BF0303"));
694 QString sId = QString(
"%1").arg(
id);
704 QString res = QString(
"%1").arg((*itrS)->getName());
705 if (std::find(listOfResourceNames.begin(),
706 listOfResourceNames.end(),
707 res.toStdString()) == listOfResourceNames.end())
709 listOfResourceNames.push_back(res.toStdString());
716 QString status =
"unknown";
720 l << res << sId <<
type << status ;
722 ui->moduleList->addTopLevelItem(it);
724 if (
type ==
"computer") {
725 it->setIcon(0,QIcon(
":/computer-unavailable22.svg"));
726 it->setForeground(3,QColor(
"#BF0303"));
728 it->setIcon(0,QIcon(
":/port-unavailable22.svg"));
729 it->setForeground(3,QColor(
"#BF0303"));
733 connect(ui->moduleList,
SIGNAL(itemChanged(QTreeWidgetItem*,
int)),
this,SLOT(onModuleItemChanged(QTreeWidgetItem*,
int)));
736void ApplicationViewWidget::onModuleItemChanged(QTreeWidgetItem *it,
int col)
738 Qt::ItemFlags tmp = it->flags();
739 if (!(tmp & Qt::ItemIsEditable)) {
745void ApplicationViewWidget::onItemDoubleClicked(QTreeWidgetItem *it,
int col)
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)));
760void ApplicationViewWidget::onItemChanged(QTreeWidgetItem *it,
int col)
765 ui->connectionList->blockSignals(
true);
767 updateConnectionItem(it);
769 it->setForeground(3,QColor(res ?
"#008C00" :
"#BF0303"));
776 updateConnectionItem(it);
777 bool res = safeManager.
existPortTo(it->text(1).toInt());
778 it->setForeground(3,QColor(res ?
"#008C00" :
"#BF0303"));
784 ui->connectionList->blockSignals(
false);
785 disconnect(ui->connectionList,
SIGNAL(itemChanged(QTreeWidgetItem*,
int)),
this,SLOT(onItemChanged(QTreeWidgetItem*,
int)));
799bool ApplicationViewWidget::isEditable(QTreeWidgetItem *it,
int col)
805 if (col == 4 || col == 5 || col == 6 || col == 7) {
806 if (it->text(2) ==
"stopped") {
811 if (it->text(2) ==
"stopped") {
818 if (col == 3 || col == 4 || col == 5 || col == 6) {
819 if (it->text(2) ==
"disconnected") {
836void ApplicationViewWidget::onCloseStdOut(
int id)
838 for(
int i=0;i<ui->moduleList->topLevelItemCount();i++) {
839 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
841 closeNestedApplicationStdOut(it,
id);
843 if (it->text(1).toInt() ==
id) {
844 auto* stdouWin = qvariant_cast<StdoutWindow *>(it->data(0,Qt::UserRole));
845 if (stdouWin && stdouWin->getId() ==
id) {
847 it->setData(0,Qt::UserRole,QVariant::fromValue(NULL));
855void ApplicationViewWidget::closeNestedApplicationStdOut(QTreeWidgetItem *it,
int id)
857 for(
int j=0; j<it->childCount();j++) {
858 QTreeWidgetItem *ch = it->child(j);
860 closeNestedApplicationStdOut(it,
id);
862 if (ch->text(1).toInt() ==
id) {
863 auto* stdouWin = qvariant_cast<StdoutWindow *>(ch->data(0,Qt::UserRole));
864 if (stdouWin && stdouWin->getId() ==
id) {
866 ch->setData(0,Qt::UserRole,QVariant::fromValue(NULL));
874bool ApplicationViewWidget::areAllShutdown()
877 for(
int i=0;i<ui->moduleList->topLevelItemCount();i++) {
878 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
880 ret = areAllNestedApplicationShutdown(it);
885 if (it->text(2) !=
"stopped") {
891 for(
int i=0;i<ui->connectionList->topLevelItemCount();i++) {
892 QTreeWidgetItem *it = ui->connectionList->topLevelItem(i);
893 if (it->text(2) !=
"disconnected") {
901bool ApplicationViewWidget::areAllNestedApplicationShutdown(QTreeWidgetItem *it)
904 for(
int j=0; j<it->childCount();j++) {
905 QTreeWidgetItem *ch = it->child(j);
907 ret = areAllNestedApplicationShutdown(ch);
912 if (ch->text(2) !=
"stopped") {
920void ApplicationViewWidget::onSelfSafeLoadBalance()
922 updateApplicationWindow();
926void ApplicationViewWidget::onAssignHost()
928 if (areAllShutdown() && !safeManager.
busy()) {
929 for(
int i=0;i<ui->moduleList->topLevelItemCount();i++) {
930 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
932 assignHostNestedApplication(it);
934 if (it->isSelected()) {
936 it->setText(2,
"waiting");
949 logger->
addError(
"Running modules should be stopped before assigning hosts.");
954void ApplicationViewWidget::assignHostNestedApplication(QTreeWidgetItem *it)
956 for(
int j=0; j<it->childCount();j++) {
957 QTreeWidgetItem *ch = it->child(j);
959 assignHostNestedApplication(ch);
961 if (ch->isSelected()) {
963 ch->setText(2,
"waiting");
970void ApplicationViewWidget::onAttachStdout()
972 if (safeManager.
busy()) {
976 std::vector<int> MIDs;
977 for(
int i=0;i<ui->moduleList->topLevelItemCount();i++) {
978 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
980 attachStdOutNestedApplication(it,&MIDs);
982 if (it->isSelected()) {
983 int id = it->text(1).toInt();
985 auto* stdouWin = qvariant_cast<StdoutWindow *>(it->data(0,Qt::UserRole));
986 if (stdouWin && stdouWin->getId() ==
id) {
991 MIDs.push_back(it->text(1).toInt());
993 QString name = QString(
"%1").arg(app->
getName());
994 QString strTitle = name +
":" + it->text(0) +
":" + it->text(1);
997 connect(stdOutWindow,
SIGNAL(closeStdOut(
int)),
this,SLOT(onCloseStdOut(
int)));
999 it->setData(0,Qt::UserRole,QVariant::fromValue(stdOutWindow));
1000 stdOutWindow->show();
1011void ApplicationViewWidget::attachStdOutNestedApplication(QTreeWidgetItem *it,std::vector<int> *MIDs)
1013 for(
int j=0; j<it->childCount();j++) {
1014 QTreeWidgetItem *ch = it->child(j);
1016 attachStdOutNestedApplication(ch,MIDs);
1018 if (ch->isSelected()) {
1019 int id = ch->text(1).toInt();
1021 auto* stdouWin = qvariant_cast<StdoutWindow *>(ch->data(0,Qt::UserRole));
1022 if (stdouWin && stdouWin->getId() ==
id) {
1027 MIDs->push_back(ch->text(1).toInt());
1029 QString name = QString(
"%1").arg(app->
getName());
1030 QString strTitle = name +
":" + ch->text(0) +
":" + ch->text(1);
1033 connect(stdOutWindow,
SIGNAL(closeStdOut(
int)),
this,SLOT(onCloseStdOut(
int)));
1035 ch->setData(0,Qt::UserRole,QVariant::fromValue(stdOutWindow));
1036 stdOutWindow->show();
1044bool ApplicationViewWidget::onRun()
1046 selectAllConnections(
true);
1047 selectAllResources(
true);
1048 if (safeManager.
busy() ) {
1052 std::vector<int> MIDs;
1053 for(
int i=0;i<ui->moduleList->topLevelItemCount();i++) {
1054 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
1057 runNestedApplication(it,&MIDs);
1060 if (it->isSelected()) {
1061 MIDs.push_back(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());
1069 it->setText(2,
"waiting");
1070 it->setIcon(0,QIcon(
":/refresh.svg"));
1071 it->setForeground(2,QColor(
"#000000"));
1080 std::vector<int> CIDs;
1086 std::vector<int> RIDs;
1098 safeManager.
safeRun(MIDs,CIDs,RIDs);
1100 selectAllModule(
false);
1101 selectAllConnections(
false);
1102 selectAllResources(
false);
1106void ApplicationViewWidget::runNestedApplication(QTreeWidgetItem *it,std::vector<int> *MIDs)
1108 for(
int j=0; j<it->childCount();j++) {
1109 QTreeWidgetItem *ch = it->child(j);
1112 runNestedApplication(ch,MIDs);
1114 if (ch->isSelected()) {
1115 MIDs->push_back(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());
1123 ch->setText(2,
"waiting");
1124 ch->setIcon(0,QIcon(
":/refresh.svg"));
1125 ch->setForeground(2,QColor(
"#000000"));
1135bool ApplicationViewWidget::onStop()
1137 selectAllConnections(
true);
1138 selectAllResources(
true);
1139 if (safeManager.
busy()) {
1143 std::vector<int> MIDs;
1144 for(
int i=0;i<ui->moduleList->topLevelItemCount();i++) {
1145 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
1147 stopNestedApplication(it,&MIDs);
1150 if (it->isSelected()) {
1152 MIDs.push_back(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());
1160 it->setText(2,
"waiting");
1161 it->setIcon(0,QIcon(
":/refresh.svg"));
1162 it->setForeground(2,QColor(
"#000000"));
1169 std::vector<int> CIDs;
1175 std::vector<int> RIDs;
1187 safeManager.
safeStop(MIDs,CIDs,RIDs);
1189 selectAllModule(
false);
1190 selectAllConnections(
false);
1191 selectAllResources(
false);
1195void ApplicationViewWidget::stopNestedApplication(QTreeWidgetItem *it,std::vector<int> *MIDs)
1197 for(
int j=0; j<it->childCount();j++) {
1198 QTreeWidgetItem *ch = it->child(j);
1200 stopNestedApplication(ch,MIDs);
1202 if (ch->isSelected()) {
1203 MIDs->push_back(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());
1211 ch->setText(2,
"waiting");
1212 ch->setIcon(0,QIcon(
":/refresh.svg"));
1213 ch->setForeground(2,QColor(
"#000000"));
1223bool ApplicationViewWidget::onKill()
1225 selectAllConnections(
true);
1226 selectAllResources(
true);
1227 if (safeManager.
busy()) {
1231 if (QMessageBox::question(
this,
"Killing modules!",
"Are you sure?") != QMessageBox::Yes) {
1235 std::vector<int> MIDs;
1236 for(
int i=0;i<ui->moduleList->topLevelItemCount();i++) {
1237 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
1239 killNestedApplication(it,&MIDs);
1241 if (it->isSelected()) {
1243 MIDs.push_back(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());
1251 it->setText(2,
"waiting");
1252 it->setIcon(0,QIcon(
":/refresh22.svg"));
1253 it->setForeground(2,QColor(
"#000000"));
1260 std::vector<int> CIDs;
1267 std::vector<int> RIDs;
1279 safeManager.
safeKill(MIDs, CIDs, RIDs);
1281 selectAllModule(
false);
1282 selectAllConnections(
false);
1283 selectAllResources(
false);
1287void ApplicationViewWidget::killNestedApplication(QTreeWidgetItem *it,std::vector<int> *MIDs)
1289 for(
int j=0; j<it->childCount();j++) {
1290 QTreeWidgetItem *ch = it->child(j);
1292 killNestedApplication(ch,MIDs);
1294 if (ch->isSelected()) {
1295 MIDs->push_back(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());
1303 ch->setText(2,
"waiting");
1304 ch->setIcon(0,QIcon(
":/refresh.svg"));
1305 ch->setForeground(2,QColor(
"#000000"));
1315bool ApplicationViewWidget::onConnect()
1317 if (safeManager.
busy()) {
1322 std::vector<int> CIDs;
1323 for(
int i=0;i<ui->connectionList->topLevelItemCount();i++)
1325 updateConnection(i,CIDs);
1331 selectAllConnections(
false);
1336bool ApplicationViewWidget::onDisconnect()
1338 if (safeManager.
busy()) {
1343 std::vector<int> CIDs;
1344 for(
int i=0;i<ui->connectionList->topLevelItemCount();i++)
1346 updateConnection(i, CIDs);
1352 selectAllConnections(
false);
1358bool ApplicationViewWidget::onRefresh()
1360 if (safeManager.
busy()) {
1365 costlyRefresh(costly);
1367 std::vector<int> modulesIDs;
1368 std::vector<int> connectionsIDs;
1369 std::vector<int> resourcesIDs;
1371 for(
int i=0;i<ui->moduleList->topLevelItemCount();i++) {
1372 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
1374 refreshNestedApplication(it,&modulesIDs);
1376 if (it->isSelected()) {
1377 modulesIDs.push_back(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"));
1392 for(
int i=0;i<ui->connectionList->topLevelItemCount();i++) {
1393 updateConnection(i,connectionsIDs);
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"));
1406 if(m_firstRefresh || !costly) {
1407 yDebug() <<
"Performing safe refresh with module IDs:" << modulesIDs.size() <<
"connection IDs:" << connectionsIDs.size() <<
"resource IDs:" << resourcesIDs.size();
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;
1419 unsigned int id = 0;
1421 for(moditr=modules.begin(); moditr<modules.end(); moditr++)
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) {
1467 if (m_firstRefresh) {
1468 std::vector<std::string> yarprunHosts;
1469 for (
auto* exe : safeManager.getExecutables()) {
1471 const std::string host = exe->
getHost();
1472 if (std::find(yarprunHosts.begin(), yarprunHosts.end(), host) == yarprunHosts.end()) {
1473 yarprunHosts.push_back(host);
1477 m_resourcesNumber =
static_cast<int>(yarprunHosts.size());
1478 m_firstRefresh =
false;
1482 selectAllConnections(
false);
1483 selectAllModule(
false);
1484 selectAllResources(
false);
1488void ApplicationViewWidget::refreshNestedApplication(QTreeWidgetItem *it,std::vector<int> *MIDs)
1490 for(
int j=0; j<it->childCount();j++) {
1491 QTreeWidgetItem *ch = it->child(j);
1494 refreshNestedApplication(ch,MIDs);
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"));
1508void ApplicationViewWidget::selectAllModule()
1510 selectAllModule(
true);
1514void ApplicationViewWidget::selectAllConnections()
1516 selectAllConnections(
true);
1520void ApplicationViewWidget::selectAllResources()
1522 selectAllResources(
true);
1528void ApplicationViewWidget::selectAllModule(
bool check)
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);
1535 selectAllNestedApplicationModule(it,check);
1537 selectModule(it,check);
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);
1548 modRunAction->setEnabled(
true);
1549 modStopAction->setEnabled(
true);
1550 modkillAction->setEnabled(
true);
1553 foreach (QTreeWidgetItem *it, ui->moduleList->selectedItems()) {
1554 if (it->text(3) !=
"localhost") {
1555 modAttachAction->setEnabled(
false);
1561 modAttachAction->setEnabled(
true);
1571 modAssignAction->setEnabled(
true);
1572 modRefreshAction->setEnabled(
true);
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);
1589 selectedItems = ui->moduleList->selectedItems();
1590 foreach(QTreeWidgetItem *it,selectedItems) {
1591 if (it->data(0,Qt::UserRole).toInt() ==
APPLICATION) {
1594 QString
id = it->text(1);
1595 selectedIds.append(
id.toInt());
1602 connect(ui->moduleList,
SIGNAL(itemSelectionChanged()),
this,SLOT(onModuleItemSelectionChanged()));
1605void ApplicationViewWidget::selectAllNestedApplicationModule(QTreeWidgetItem *it,
bool check)
1607 for(
int j=0;j<it->childCount();j++) {
1608 QTreeWidgetItem *ch = it->child(j);
1610 selectAllNestedApplicationModule(ch, check);
1612 selectModule(ch,check);
1617bool ApplicationViewWidget::scanAvailableCarriers(QString carrier,
bool isConnection){
1622 stringLst.push_back(carrier);
1623 for (
size_t i=0; i<lst.
size(); i++)
1625 if (lst.
get(i).
asString() == carrier.toStdString()) {
1628 stringLst.push_back(lst.
get(i).
asString().c_str());
1631 if (!res && isConnection)
1633 std::string msg =
"Unable to find '"+ carrier.toStdString() +
1634 "' among the available carriers in this machine, the connection could fail.";
1640void ApplicationViewWidget::updateConnection(
int index, std::vector<int>& CIDs)
1642 QTreeWidgetItem *it = ui->connectionList->topLevelItem(index);
1643 if (it->isSelected()) {
1644 updateConnectionItem(it);
1646 CIDs.push_back(it->text(1).toInt());
1648 it->setText(2,
"waiting");
1649 it->setIcon(0,QIcon(
":/refresh22.svg"));
1650 it->setForeground(2,QColor(
"#000000"));
1655void ApplicationViewWidget::updateConnectionItem(QTreeWidgetItem *it)
1657 auto* box = qobject_cast<QComboBox*>(ui->connectionList->itemWidget((QTreeWidgetItem *)it, 5));
1658 QString carrier, modifier;
1661 carrier = box->currentText();
1666 carrier=it->text(5);
1671 size_t pos = carrier.toStdString().find(
'+');
1672 if(pos != std::string::npos)
1674 modifier = carrier.mid(pos);
1675 QStringList myStringList = carrier.split(
'+');
1676 carrier = myStringList.first();
1677 box->setCurrentText(carrier);
1678 it->setText(6,modifier);
1682 scanAvailableCarriers(carrier);
1683 carrier = carrier + it->text(6);
1685 it->text(3).toLatin1().data(),
1686 it->text(4).toLatin1().data(),
1687 carrier.toLatin1().data());
1690bool ApplicationViewWidget::costlyRefresh(
bool& costly)
1692 if (safeManager.
busy()) {
1698 int totalSelectedModules = 0;
1700 foreach(
const auto& it, itemsSelectedForResource){
1701 yDebug() <<
"Resource " << it.first.c_str() <<
" has " << it.second <<
" modules selected.";
1702 totalSelectedModules += it.second;
1704 if(totalSelectedModules > m_resourcesNumber) {
1713void ApplicationViewWidget::selectModule(QTreeWidgetItem *item,
bool check)
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();
1722 else if(check && !itemsSelectedForResource.count(item->text(3).toStdString()) && (item->text(3).toStdString() !=
"")) {
1723 itemsSelectedForResource[item->text(3).toStdString()] = 1;
1730void ApplicationViewWidget::selectAllConnections(
bool check)
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);
1738 if (ui->connectionList->selectedItems().isEmpty()) {
1739 connConnectAction->setEnabled(
false);
1740 connDisconnectAction->setEnabled(
false);
1741 connSeparatorAction->setEnabled(
false);
1742 connRefreshAction->setEnabled(
false);
1744 connConnectAction->setEnabled(
true);
1745 connDisconnectAction->setEnabled(
true);
1746 connSeparatorAction->setEnabled(
true);
1747 connRefreshAction->setEnabled(
true);
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());
1758 connect(ui->connectionList,
SIGNAL(itemSelectionChanged()),
this,SLOT(onConnectionItemSelectionChanged()));
1765void ApplicationViewWidget::selectAllResources(
bool check)
1767 for(
int i=0;i<ui->resourcesList->topLevelItemCount();i++) {
1768 QTreeWidgetItem *it = ui->resourcesList->topLevelItem(i);
1769 it->setSelected(check);
1777 selectAllConnections(
true);
1778 selectAllModule(
true);
1779 selectAllResources(
true);
1785 if (!onlySelected) {
1786 selectAllModule(
true);
1794 if (!onlySelected) {
1795 selectAllModule(
true);
1803 if (!onlySelected) {
1804 selectAllModule(
true);
1812 if (!onlySelected) {
1813 selectAllConnections(
true);
1821 if (!onlySelected) {
1822 selectAllConnections(
true);
1830 selectAllConnections(
true);
1831 selectAllModule(
true);
1832 selectAllResources(
true);
1838void ApplicationViewWidget::reportErrors()
1846 QString msg = QString(
"(%1) %2").arg(app->
getName()).arg(err);
1852 QString msg = QString(
"(%1) %2").arg(app->
getName()).arg(err);
1862 QString fileName = QFileDialog::getSaveFileName(
this,
"Export Graph",QApplication::applicationDirPath(),
"GraphViz format (*.dot)");
1864 if (!fileName.isEmpty()) {
1868 logger->
addError(
"Cannot export graph");
1877void ApplicationViewWidget::onYARPView()
1879 if (safeManager.
busy()) {
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";
1893 if (launcher.
init(
"yarpview",
nullptr,
nullptr,
nullptr,
nullptr, env.toLatin1().data()))
1895 if (!launcher.
start() && !launcher.
error().empty())
1898 msg = QString(
"Error while launching yarpview. %1").arg(launcher.
error().c_str());
1899 logger->
addError(msg.toLatin1().data());
1906 while(!timeout(base, 3.0)) {
1907 if (launcher.
exists(to.toLatin1().data())) {
1911 if (!launcher.
connect(from.toLatin1().data(), to.toLatin1().data(),
"udp")) {
1913 msg = QString(
"Cannot inspect '%1' : %2").arg(from).arg(launcher.
error().c_str());
1914 logger->
addError(msg.toLatin1().data());
1928void ApplicationViewWidget::onYARPHear()
1930 if (safeManager.
busy()) {
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);
1942 QString cmd =
"cmd.exe";
1944 param = QString(
"/C yarphear --name %1").arg(to);
1947 QString cmd =
"xterm";
1949 param = QString(
"-hold -title %1 -e yarphear --nodevice --name %2").arg(from).arg(to);
1954 if (launcher.
init(cmd.toLatin1().data(), param.toLatin1().data(),
nullptr,
nullptr,
nullptr,
nullptr))
1956 if (!launcher.
start() && !launcher.
error().empty())
1959 msg = QString(
"Error while launching yarpread. %1").arg(launcher.
error().c_str());
1960 logger->
addError(msg.toLatin1().data());
1967 while(!timeout(base, 3.0)) {
1968 if (launcher.
exists(to.toLatin1().data())) {
1972 if (!launcher.
exists(to.toLatin1().data())) {
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());
1978 }
else if (!launcher.
connect(from.toLatin1().data(), to.toLatin1().data(),
"udp")) {
1980 msg = QString(
"Cannot inspect '%1' : %2").arg(from).arg(launcher.
error().c_str());
1981 logger->
addError(msg.toLatin1().data());
1997void ApplicationViewWidget::onYARPRead()
1999 if (safeManager.
busy()) {
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);
2011 QString cmd =
"cmd.exe";
2013 param = QString(
"/C yarp read %1").arg(to);
2016 QString cmd =
"xterm";
2018 param = QString(
"-hold -title %1 -e yarp read %2").arg(from).arg(to);
2023 if (launcher.
init(cmd.toLatin1().data(), param.toLatin1().data(),
nullptr,
nullptr,
nullptr,
nullptr))
2025 if (!launcher.
start() && !launcher.
error().empty())
2028 msg = QString(
"Error while launching yarpread. %1").arg(launcher.
error().c_str());
2029 logger->
addError(msg.toLatin1().data());
2036 while(!timeout(base, 3.0)) {
2037 if (launcher.
exists(to.toLatin1().data())) {
2041 if (!launcher.
connect(from.toLatin1().data(), to.toLatin1().data(),
"udp")) {
2043 msg = QString(
"Cannot inspect '%1' : %2").arg(from).arg(launcher.
error().c_str());
2044 logger->
addError(msg.toLatin1().data());
2059void ApplicationViewWidget::onYARPScope()
2061 if (safeManager.
busy()) {
2068 if (dlg.exec() != QDialog::Accepted) {
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);
2085 param = QString(
"--title %1:%2 --bgcolor white --color blue --graph_size 2 --index %2").arg(from).arg(strIndex);
2089 if (launcher.
init(
"yarpscope", param.toLatin1().data(),
nullptr,
nullptr,
nullptr, env.toLatin1().data())) {
2090 if (!launcher.
start() && !launcher.
error().empty()) {
2092 msg = QString(
"Error while launching yarpscope. %1").arg(launcher.
error().c_str());
2093 logger->
addError(msg.toLatin1().data());
2099 while (!timeout(base, 3.0)) {
2100 if (launcher.
exists(to.toLatin1().data())) {
2104 if (!launcher.
connect(from.toLatin1().data(), to.toLatin1().data(),
"udp")) {
2106 msg = QString(
"Cannot inspect '%1' : %2").arg(from).arg(launcher.
error().c_str());
2107 logger->
addError(msg.toLatin1().data());
2121bool ApplicationViewWidget::timeout(
double base,
double timeout)
2139 for(
int i=0; i< ui->moduleList->topLevelItemCount();i++) {
2140 if (ui->moduleList->topLevelItem(i)->text(2) ==
"running") {
2152void ApplicationViewWidget::onSelfConnect(
int which)
2155 if (!getConRowByID(which, &row))
2157 yError()<<
"ApplicationViewWidget: unable to find row with id:"<<which;
2161 QTreeWidgetItem *it = ui->connectionList->topLevelItem(row);
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);
2181void ApplicationViewWidget::onSelfDisconnect(
int which)
2184 if (!getConRowByID(which, &row))
2186 yError()<<
"ApplicationViewWidget: unable to find row with id:"<<which;
2190 QTreeWidgetItem *it = ui->connectionList->topLevelItem(row);
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);
2204void ApplicationViewWidget::onSelfResAvailable(
int which)
2207 if (!getResRowByID(which, &row))
2209 yError()<<
"ApplicationViewWidget: unable to find row with id:"<<which;
2213 QTreeWidgetItem *it = ui->resourcesList->topLevelItem(row);
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"));
2220 it->setIcon(0,QIcon(
":/port-available22.svg"));
2221 it->setForeground(3,QColor(
"#008C00"));
2233void ApplicationViewWidget::onSelfResUnavailable(
int which)
2236 if (!getResRowByID(which, &row))
2238 yError()<<
"ApplicationViewWidget: unable to find row with id:"<<which;
2242 QTreeWidgetItem *it = ui->resourcesList->topLevelItem(row);
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"));
2249 it->setIcon(0,QIcon(
":/port-unavailable22.svg"));
2250 it->setForeground(3,QColor(
"#BF0303"));
2256void ApplicationViewWidget::onSelfStart(
int which)
2258 QTreeWidgetItem *it = getModRowByID(which);
2260 it->setText(2,
"running");
2261 it->setIcon(0,QIcon(
":/apply.svg"));
2262 it->setForeground(2,QColor(
"#008C00"));
2272void ApplicationViewWidget::onSelfStop(
int which)
2274 QTreeWidgetItem *it = getModRowByID(which);
2276 it->setText(2,
"stopped");
2277 it->setIcon(0,QIcon(
":/close.svg"));
2278 it->setForeground(2,QColor(
"#BF0303"));
2305 QString s = QString(
"%1").arg(msg);
2306 for(
int j=0;j<ui->moduleList->topLevelItemCount();j++) {
2307 QTreeWidgetItem *it = ui->moduleList->topLevelItem(j);
2309 modStdOutNestedApplication(it,which,s);
2311 auto* stdouWin = qvariant_cast<StdoutWindow *>(it->data(0,Qt::UserRole));
2312 if (stdouWin && stdouWin->getId() == which) {
2313 stdouWin->addMessage(s);
2321void ApplicationViewWidget::modStdOutNestedApplication(QTreeWidgetItem *it,
int id,QString s)
2323 for(
int j=0; j<it->childCount();j++) {
2324 QTreeWidgetItem *ch = it->child(j);
2326 modStdOutNestedApplication(ch,
id,s);
2328 auto* stdouWin = qvariant_cast<StdoutWindow *>(ch->data(0,Qt::UserRole));
2329 if (stdouWin && stdouWin->getId() ==
id) {
2330 stdouWin->addMessage(s);
2376 if (getConRowByID(from, &row)) {
2377 ui->connectionList->topLevelItem(row)->setForeground(3,QColor(
"#008C00"));
2384 if (getConRowByID(to, &row)) {
2385 ui->connectionList->topLevelItem(row)->setForeground(4,QColor(
"#008C00"));
2399 if (getConRowByID(from, &row)) {
2400 ui->connectionList->topLevelItem(row)->setForeground(3,QColor(
"#BF0303"));
2407 if (getConRowByID(to, &row)) {
2408 ui->connectionList->topLevelItem(row)->setForeground(4,QColor(
"#BF0303"));
2432void ApplicationViewWidget::onDetachStdout()
2441bool ApplicationViewWidget::getConRowByID(
int id,
int *row)
2443 for(
int i=0;i< ui->connectionList->topLevelItemCount();i++) {
2444 QTreeWidgetItem *it = ui->connectionList->topLevelItem(i);
2446 if (it->text(1).toInt() ==
id) {
2458bool ApplicationViewWidget::getResRowByID(
int id,
int *row)
2460 for(
int i=0;i< ui->resourcesList->topLevelItemCount();i++) {
2461 QTreeWidgetItem *it = ui->resourcesList->topLevelItem(i);
2463 if (it->text(1).toInt() ==
id) {
2474QTreeWidgetItem* ApplicationViewWidget::getModRowByID(
int id, QTreeWidgetItem *parent)
2476 QTreeWidgetItem *ret =
nullptr;
2478 for(
int i=0;i< ui->moduleList->topLevelItemCount();i++) {
2479 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
2481 ret = getModRowByID(
id,it);
2487 if (it->text(1).toInt() ==
id) {
2492 for(
int i=0;i< parent->childCount();i++) {
2493 QTreeWidgetItem *it = parent->child(i);
2495 ret = getModRowByID(
id,it);
2501 if (it->text(1).toInt() ==
id) {
2512 safeManager.
close();
int SIGNAL(int pid, int signum)
void setSelectedConnections(QList< int >selectedIds)
void load(bool refresh=false)
void addModulesAction(QAction *)
void setFileName(QString filename)
void setInputPortAvailable(QString, bool)
void setConnectionConnected(bool, QString from, QString to)
void addAction(QAction *)
void setAppName(QString appName)
void setModuleRunning(bool, int id)
void setOutputPortAvailable(QString, bool)
void addConnectionsAction(QAction *)
void setSelectedModules(QList< int >selectedIds)
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 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)
Singleton class ErrorLogger.
const char * getLastError()
void addError(const char *szError)
void addWarning(const char *szWarning)
static ErrorLogger * Instance()
Singleton class ErrorLogger.
const char * getLastWarning()
BrokerType getBrokerType()
const char * getCommand()
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
ExecutablePContainer & getExecutables()
bool updateConnection(unsigned int id, const char *from, const char *to, const char *carrier)
CnnContainer & getConnections()
ResourcePContainer & getResources()
bool existPortFrom(unsigned int id)
bool existPortTo(unsigned int id)
bool updateExecutable(unsigned int id, const char *szparam, const char *szhost, const char *szstdio, const char *szworkdir, const char *szenv)
void collectYarprunProcessesByHost(std::map< std::string, ProcessContainer > &hostProcesses, std::map< std::string, bool > &hostQueryOk)
bool loadApplication(const char *szAppName)
bool exportDependencyGraph(const char *szFileName)
A simple collection of objects that can be described and transmitted in a portable way.
size_type size() const
Gets the number of elements in the bottle.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
static Bottle listCarriers()
A class for storing options and configuration information.
static double nowSystem()
static void delaySystem(double seconds)
virtual std::string asString() const
Get string value.
std::vector< Executable * >::iterator ExecutablePIterator
std::vector< GenericResource * >::iterator ResourcePIterator
enum yarp::manager::__NodeType NodeType
std::vector< Connection >::iterator CnnIterator
std::vector< Executable * > ExecutablePContainer
std::vector< Connection > CnnContainer