28 #include <ArmarXGui/gui-plugins/SystemStateMonitorPlugin/ui_ArmarXManagerRepositoryDialog.h>
32 #include <ArmarXCore/interface/core/ArmarXManagerInterface.h>
35 #include <QStyledItemDelegate>
36 #include <QApplication>
56 return new QLineEdit(parent);
60 QLineEdit* lineEdit = qobject_cast<QLineEdit*>(editor);
63 QString propValue =
index.data().toString();
64 propValue.remove(0, propValue.indexOf(
":") + 2);
65 QString propName =
index.data().toString();
67 propName.truncate(propName.indexOf(
":") - 1);
68 lineEdit->setText(propValue);
69 lineEdit->setProperty(
"propertyName", propName);
72 void setModelData(QWidget* editor, QAbstractItemModel* model,
const QModelIndex&
index)
const override
74 QLineEdit* lineEdit = qobject_cast<QLineEdit*>(editor);
77 model->setData(
index, lineEdit->property(
"propertyName").toString() +
" : " + lineEdit->text());
78 auto it = managerPrxMap->find(
index.parent().parent().parent().data().toString());
79 if (it != managerPrxMap->end())
81 armarx::ArmarXManagerInterfacePrx prx = it->second;
82 prx->getPropertiesAdmin()->ice_collocationOptimized(
false)->setProperties({{
83 lineEdit->property(
"propertyName").
toString().toStdString(),
84 lineEdit->text().toStdString()
102 qRegisterMetaType<StateUpdateMap>(
"StateUpdateMap");
103 qRegisterMetaType<ArmarXManagerItem::ManagerDataMap>(
"ArmarXManagerItem::ManagerDataMap");
104 qRegisterMetaType<ArmarXManagerItem::ManagerData>(
"ArmarXManagerItem::ManagerData");
105 qRegisterMetaType<ManagerPrxMap>(
"ManagerPrxMap");
108 filterExpansionTimer.setSingleShot(
true);
109 connect(&filterExpansionTimer, SIGNAL(timeout()),
this, SLOT(delayedFilterExpansion()));
110 connect(ui.btnProblematicOnly, SIGNAL(toggled(
bool)),
this, SLOT(on_btnProblematicOnly_toggled(
bool)), Qt::UniqueConnection);
112 fillLegendLayout(ui.colorLegendLayout, *monitoredManagerModel);
121 stateUpdateTask->stop();
124 delete managerRepositoryModel;
125 delete monitoredManagerModel;
141 managerRepositoryModel,
142 monitoredManagerModel,
144 managerRepositoryDialog->setModal(
true);
145 connect(managerRepositoryDialog, SIGNAL(accepted()),
this, SLOT(
acceptConfig()));
149 filterModel->addCustomFilter([
this](QAbstractItemModel * model,
int source_row,
const QModelIndex & source_parent)
151 QModelIndex index0 = model->index(source_row, 0, source_parent);
152 if (this->ui.btnProblematicOnly->isChecked())
154 auto variant = index0.data((int)ArmarXManagerModel::UserDataRoles::ComponentStarted);
155 auto variantDependency = index0.data((int)ArmarXManagerModel::UserDataRoles::ResolvedDependency);
160 if (variant.toBool())
166 if (variantDependency.isValid())
168 if (variantDependency.toBool())
173 if (!variant.isValid() && !variantDependency.isValid())
184 filterModel->setSourceModel(monitoredManagerModel);
185 filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
186 ui.monitoredManagersTree->setModel(filterModel);
188 connect(ui.lineEditFilter, SIGNAL(textChanged(QString)), filterModel, SLOT(setFilterFixedString(QString)));
189 connect(ui.lineEditFilter, SIGNAL(textChanged(QString)),
this, SLOT(expandFilterSelection(QString)), Qt::QueuedConnection);
191 connect(ui.configureButton, SIGNAL(clicked()),
this, SLOT(openManagerRepositoryDialog()));
193 connect(
this, SIGNAL(updateManagerStatesSignal(ArmarXManagerItem::ManagerDataMap)),
this, SLOT(updateManagerStates(ArmarXManagerItem::ManagerDataMap)));
199 void SystemStateMonitorWidget::loadSettings(QSettings* settings)
201 managerRepositoryModel->populate(
202 settings->value(
"ManagerRepository").toStringList());
204 monitoredManagerModel->populate(
205 settings->value(
"MonitoredManagers").toStringList());
206 ui.monitoredManagersTree->expandToDepth(1);
210 void SystemStateMonitorWidget::saveSettings(QSettings* settings)
212 settings->setValue(
"ManagerRepository",
213 managerRepositoryModel->toStringList());
215 settings->setValue(
"MonitoredManagers",
216 monitoredManagerModel->toStringList());
220 void SystemStateMonitorWidget::onInitComponent()
222 monitoredManagerModel->setIceManager(getIceManager());
223 managerRepositoryModel->setIceManager(getIceManager());
227 void SystemStateMonitorWidget::onConnectComponent()
230 stateUpdateTask->setDelayWarningTolerance(5000);
231 stateUpdateTask->start();
232 if (monitoredManagerModel->empty())
238 std::unique_lock lock(managerPrxMapMutex);
239 currentManagerPrxMap = monitoredManagerModel->getManagerProxyMap();
243 void SystemStateMonitorWidget::onDisconnectComponent()
247 stateUpdateTask->stop();
252 void SystemStateMonitorWidget::onExitComponent()
256 stateUpdateTask->stop();
265 std::unique_lock lock(monitoredManagerModel->getMutex());
267 monitoredManagerModel->updateManagerDetails(managerData);
268 filterModel->invalidate();
277 managerData.
proxy = prx;
278 prx = prx->ice_timeout(1000);
279 managerData.
name = QString::fromStdString(prx->ice_getIdentity().name);
280 managerData.
appProperties = prx->getApplicationPropertyInfos();
281 result &= retrieveManagerObjectsState(prx, managerData.
objects);
284 managerData.
connection = prx->ice_collocationOptimized(
false)->ice_getConnection();
285 managerData.
endpointStr = managerData.
connection ? QString::fromStdString(managerData.
connection->getEndpoint()->toString()) :
"Endpoint: no connection data";
288 catch (
const IceUtil::Exception& ex)
291 managerData.
endpointStr = QString::fromStdString(
"? (" + std::string(ex.ice_id()) +
")");
293 managerData.
online =
true;
297 managerData.
online =
false;
310 prx->ice_timeout(200)->ice_ping();
319 Ice::StringSeq objectNames = prx->getManagedObjectNames();
321 for (
auto& objectName : objectNames)
324 objEntry.
name = objectName.c_str();
325 objEntry.
state = prx->getObjectState(objectName);
326 objEntry.
connectivity = prx->getObjectConnectivity(objectName);
327 objEntry.
properties = prx->getObjectPropertyInfos(objectName);
330 objEntry.
metaInfoMap = prx->getMetaInfo(objectName);
336 objectStates[objEntry.
name] = (objEntry);
342 void SystemStateMonitorWidget::updateManagerObjectsState()
349 decltype(currentManagerPrxMap) proxies;
351 std::unique_lock lock(managerPrxMapMutex);
352 proxies = currentManagerPrxMap;
355 for (
auto it = proxies.begin(); it != proxies.end(); it++)
358 bool online = retrieveManagerObjectsState(it->second, stateMap);
359 managerDataMap[it->first].online = online;
360 managerDataMap[it->first].name = it->first;
361 managerDataMap[it->first].objects = stateMap;
364 managerDataMap[it->first].appProperties = it->second->getApplicationPropertyInfos();
366 retrieveManagerData(it->second, managerDataMap[it->first]);
368 ARMARX_DEBUG <<
"update duration: " << (IceUtil::Time::now() - start).toMilliSecondsDouble();
371 emit updateManagerStatesSignal(managerDataMap);
374 void SystemStateMonitorWidget::acceptConfig()
376 this->managerRepositoryModel->copyFrom(
377 managerRepositoryDialog->getManagerRepositoryModel());
379 this->monitoredManagerModel->copyFrom(
380 managerRepositoryDialog->getMonitoredManagersModel());
381 ui.monitoredManagersTree->expandToDepth(1);
382 std::unique_lock lock(managerPrxMapMutex);
383 currentManagerPrxMap = monitoredManagerModel->getManagerProxyMap();
386 QStringList SystemStateMonitorWidget::fetchOnlineManagers()
388 enableMainWidgetAsync(
false);
389 auto admin = getIceManager()->getIceGridSession()->getAdmin();
391 IceGrid::ObjectInfoSeq objects = admin->getAllObjectInfos(
"*Manager");
393 IceGrid::ObjectInfoSeq::iterator iter = objects.begin();
394 IceGrid::ObjectInfoSeq result;
396 while (iter != objects.end())
398 Ice::ObjectPrx current = iter->proxy;
400 ArmarXManagerInterfacePrx object;
405 object = ArmarXManagerInterfacePrx::checkedCast(current->ice_timeout(60));
411 admin->removeObject(current->ice_getIdentity());
413 qApp->processEvents();
417 result.push_back(*iter);
423 enableMainWidgetAsync(
true);
425 QStringList managers;
426 for (
const IceGrid::ObjectInfo& info : result)
428 managers.append(info.proxy->ice_getIdentity().name.c_str());
435 void SystemStateMonitorWidget::retrieveOnlineManagers()
437 managerRepositoryDialog->addOnlineManagers(fetchOnlineManagers());
441 void SystemStateMonitorWidget::openManagerRepositoryDialog()
443 managerRepositoryDialog->getManagerRepositoryModel()->copyFrom(
444 managerRepositoryModel);
446 managerRepositoryDialog->getMonitoredManagersModel()->copyFrom(
447 monitoredManagerModel);
449 retrieveOnlineManagers();
451 managerRepositoryDialog->show();
455 void SystemStateMonitorWidget::prefillView()
457 managerRepositoryModel->clear();
458 monitoredManagerModel->clear();
460 QStringList managers = fetchOnlineManagers();
464 addArmarXManagers(managers);
465 QMetaObject::invokeMethod(ui.monitoredManagersTree,
"expandToDepth", Q_ARG(
int, 0));
466 std::unique_lock lock(managerPrxMapMutex);
467 currentManagerPrxMap = monitoredManagerModel->getManagerProxyMap(managers);
472 void SystemStateMonitorWidget::addArmarXManagerEntries(
ManagerPrxMap managers)
477 for (
auto& pair : managers)
479 ArmarXManagerItem* item =
new ArmarXManagerItem(pair.first);
480 item->setManagerProxy(pair.second);
481 monitoredManagerModel->appendRow(item);
484 ui.monitoredManagersTree->expandToDepth(1);
488 void SystemStateMonitorWidget::addArmarXManagers(QStringList managerNames)
491 for (
auto& name : managerNames)
498 auto proxy = getIceManager()->getProxy<ArmarXManagerInterfacePrx>(name.toStdString());
499 retrieveManagerData(proxy,
data);
510 void SystemStateMonitorWidget::expandFilterSelection(QString filterStr)
513 if (filterStr.length() == 0)
515 ui.monitoredManagersTree->collapseAll();
520 filterExpansionTimer.start(500);
524 void SystemStateMonitorWidget::delayedFilterExpansion()
528 InfixFilterModel::ExpandFilterResults(ui.monitoredManagersTree);
531 void armarx::SystemStateMonitorWidget::on_btnProblematicOnly_toggled(
bool checked)
536 filterModel->invalidate();
540 void SystemStateMonitorWidget::fillLegendLayout(QHBoxLayout* layout, ArmarXManagerModel& model)
const
542 auto addLegendEntry = [layout, &model](ManagedIceObjectState state,
const QString& text)
544 QLabel* label =
new QLabel(text);
546 QBrush brush = model.getBrush(state);
547 QPalette p = label->palette();
548 p.setColor(label->backgroundRole(), brush.color());
549 label->setPalette(p);
550 label->setAutoFillBackground(
true);
553 QFont font = label->font();
554 font.setPointSize(10);
555 label->setFont(font);
557 layout->addWidget(label);
560 addLegendEntry(armarx::eManagedIceObjectCreated,
"Created");
561 addLegendEntry(armarx::eManagedIceObjectInitializing,
"Initializing");
562 addLegendEntry(armarx::eManagedIceObjectInitialized,
"Initialized");
563 addLegendEntry(armarx::eManagedIceObjectInitializationFailed,
"Initialization Failed");
564 addLegendEntry(armarx::eManagedIceObjectStarting,
"Connecting");
565 addLegendEntry(armarx::eManagedIceObjectStarted,
"Connected");
566 addLegendEntry(armarx::eManagedIceObjectStartingFailed,
"Connecting Failed");
567 addLegendEntry(armarx::eManagedIceObjectExiting,
"Exiting");
568 addLegendEntry(armarx::eManagedIceObjectExited,
"Exited");