YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
batchqosconfdialog.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: GPL-3.0-or-later
4 */
5
6#include <fstream>
7#include <QFileDialog>
8#include <QMessageBox>
9
10#include <yarp/os/Bottle.h>
11#include <yarp/os/LogStream.h>
12
13#include "batchqosconfdialog.h"
14#include "ui_batchqosconfdialog.h"
15
16#include "qosconfigdialog.h"
17
18using namespace yarp::os;
19using namespace yarp::profiler;
20
22 QDialog(parent),
24{
25 ui->setupUi(this);
26 ui->treeWidgetCons->header()->resizeSection(0, 120);
27 ui->treeWidgetCons->header()->resizeSection(3, 120);
28 ui->treeWidgetCons->header()->resizeSection(4, 120);
29 ui->treeWidgetCons->header()->resizeSection(5, 150);
30
31 connect(ui->pushButtonBatchQosOpen, SIGNAL(clicked()), this, SLOT(openCons()));
32 connect(ui->pushButtonBatchQosUpdate, SIGNAL(clicked()), this, SLOT(updateQos()));
33 connect(ui->pushButtonBatchQosConfigure, SIGNAL(clicked()), this, SLOT(configureQos()));
34 ui->pushButtonBatchQosUpdate->setEnabled(false);
35 ui->pushButtonBatchQosConfigure->setEnabled(false);
36
37}
38
43
44
45void BatchQosConfDialog::openCons()
46{
47 QString filters("Text files (*.txt);;All files (*.*)");
48 QString defaultFilter("Connections list file (*.txt)");
49 QString filename = QFileDialog::getOpenFileName(nullptr, "Load connections list",
50 QDir::homePath(),
52 if (filename.size() == 0) {
53 return;
54 }
55
56 std::fstream file;
57 file.open(filename.toStdString().c_str());
58 if (!file.is_open()) {
59 QMessageBox::critical(nullptr, QObject::tr("Error"), QObject::tr("Cannot open the file for loading"));
60 return;
61 }
62
63 ui->treeWidgetCons->clear();
64 std::string line;
65 unsigned int count = 0;
66 while(getline(file, line)) {
67 count++;
68 Bottle sample(line);
69 if(sample.size() == 3) {
70 //data.addList() = sample;
71 //yInfo()<<sample.toString();
72 QTreeWidgetItem* item;
73 QStringList prop;
74 prop.clear();
75 prop.append("Unknown");
76 prop.append(sample.get(0).asString().c_str());
77 prop.append(sample.get(1).asString().c_str());
78 prop.append(sample.get(2).asString().c_str());
79 item = new QTreeWidgetItem( ui->treeWidgetCons, prop);
81 } else {
82 yWarning() << "Wrong connection data at line" << count;
83 }
84 }
85 file.close();
86
87 if(ui->treeWidgetCons->topLevelItemCount() > 0) {
88 ui->pushButtonBatchQosUpdate->setEnabled(true);
89 ui->pushButtonBatchQosConfigure->setEnabled(true);
90 updateQos();
91 }
92 else {
94 messageBox.critical(nullptr,"Error","Could not load any connections! \n Please check the file format.");
95 messageBox.setFixedSize(500,200);
96 }
97
98}
99
100void BatchQosConfDialog::updateQos()
101{
102 for( int i=0; i < ui->treeWidgetCons->topLevelItemCount(); ++i ){
103 QTreeWidgetItem *item = ui->treeWidgetCons->topLevelItem(i);
105 if(yarp::os::NetworkBase::getConnectionQos(item->text(1).toUtf8().constData(),
106 item->text(2).toUtf8().constData(), fromStyle, toStyle)) {
107 QString qosStr = NetworkProfiler::packetPrioToString(fromStyle.getPacketPriorityAsLevel()).c_str();
108 QBrush b;
109 switch(fromStyle.getPacketPriorityAsLevel()) {
111 b.setColor(Qt::black);
112 break;
113 }
115 b.setColor(QColor(255,215,0));
116 break;
117 }
119 b.setColor(QColor(255,140,0));
120 break;
121 }
123 b.setColor(Qt::red);
124 break;
125 }
127 b.setColor(Qt::black);
128 break;
129 }
130 default: {
131 b.setColor(Qt::black);
132 }
133 }
134 item->setForeground( 0 , b);
135 item->setText(0, qosStr);
136 qosStr += ", " + QString::number(fromStyle.getThreadPolicy()) + ", " + QString::number(fromStyle.getThreadPriority());
137 item->setText(4, qosStr);
138 qosStr.clear();
139 qosStr = NetworkProfiler::packetPrioToString(toStyle.getPacketPriorityAsLevel()).c_str();
140 qosStr += ", " + QString::number(toStyle.getThreadPolicy()) + ", " + QString::number(toStyle.getThreadPriority());
141 item->setText(5, qosStr);
142 } else {
143 yWarning() << "Cannot retrieve Qos property of" << item->text(0).toUtf8().constData() << "->" << item->text(0).toUtf8().constData();
144 }
145 }
146 ui->treeWidgetCons->update();
147}
148
149void BatchQosConfDialog::configureQos() {
151 QosConfigDialog dialog(nullptr);
152 dialog.setModal(true);
153 if (dialog.exec() != QDialog::Accepted) {
154 return;
155 }
156 dialog.getUserQosStyles(fromStyle, toStyle);
157 for( int i=0; i < ui->treeWidgetCons->topLevelItemCount(); ++i ){
158 QTreeWidgetItem *item = ui->treeWidgetCons->topLevelItem(i);
159 std::string from = item->text(1).toUtf8().constData();
160 std::string to = item->text(2).toUtf8().constData();
162 yWarning()<<"Cannot set Qos property of connection"<<from<<"->"<<to;
163 }
164 }
165 updateQos();
166}
#define yWarning(...)
Definition Log.h:340
int SIGNAL(int pid, int signum)
BatchQosConfDialog(QWidget *parent=0)
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
A mini-server for performing network communication in the background.
void close() override
Stop port activity.
static bool getConnectionQos(const std::string &src, const std::string &dest, QosStyle &srcStyle, QosStyle &destStyle, bool quiet=true)
Gets the Qos preferences of a connection.
Definition Network.cpp:1182
static bool setConnectionQos(const std::string &src, const std::string &dest, const QosStyle &srcStyle, const QosStyle &destStyle, bool quiet=true)
Adjust the Qos preferences of a connection.
Definition Network.cpp:1072
Preferences for the port's Quality of Service.
Definition QosStyle.h:23
static std::string packetPrioToString(yarp::os::QosStyle::PacketPriorityLevel level)
Definition aboutdlg.h:11
An interface to the operating system, including Port based communication.
#define YARP_UNUSED(var)
Definition api.h:162