1 Star 0 Fork 0

zhouws-chn/EndpointCli

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
mainwindow.cpp 5.93 KB
一键复制 编辑 原始数据 按行查看 历史
zhouws-chn 提交于 2023-05-29 20:36 . 添加源代码
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include "endpointcli.h"
#include <QFileDialog>
#include <QDateTime>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->textEdit->setText("");
ui->textEdit->setTextColor(Qt::green);
ui->textEdit->setStyleSheet("QTextEdit{background-color: black;}");
m_ixchariotDialog = new IxchariotPairDialog();
m_endpointCli = new EndpointCli();
EndpointStatus epRes;
epRes = m_endpointCli->CheckIxchariotLibEnv();
if( EP_OK != epRes)
{
ui->textEdit->append(m_endpointCli->GetErrorInformation());
}
RefreshPairList();
ui->stopBtn->setEnabled(false);
m_endpointStatus = 0;
m_checkEndpointTimer = new QTimer(this);
connect(m_checkEndpointTimer, SIGNAL(timeout()), this, SLOT(checkEndpointTimerTimeout()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::RefreshPairList()
{
ui->pairList->clear();
for (int i=0; i<m_pairList.length(); i++) {
PairInfo pairItemInfo = m_pairList.at(i);
QString title = QString::number(i+1) + ". " + pairItemInfo.ip1 + " > " + pairItemInfo.ip2 + "\t Protocol: " + pairItemInfo.networkProtocol;
title = title + " Count: " + QString::number(pairItemInfo.pairCount) + " Script: "+ pairItemInfo.pairScriptPath;
ui->pairList->insertItem(i, title);
}
ui->pairList->insertItem(m_pairList.length(), "点此添加IxChariot条目");
ui->pairList->item(m_pairList.length())->setTextColor(Qt::red);
}
void MainWindow::on_pairList_itemDoubleClicked(QListWidgetItem *item)
{
//m_endpointCli->GetEndpointTestResult();
//return ;
if(m_endpointStatus != 0)
{
return ;
}
if(!item->text().compare("点此添加IxChariot条目", Qt::CaseInsensitive))
{
ui->textEdit->append("准备添加 IxChariot Pair 页面");
m_ixchariotDialog->SetIxchariotModeForCreat(1);
int res = m_ixchariotDialog->exec();
if(!res) {
ui->textEdit->append("取消添加");
return ;
}
PairInfo pairInfo = m_ixchariotDialog->GetIxchariotPairInfo();
m_pairList.push_back(pairInfo);
ui->textEdit->append(QString("IxChariot Pair %1条添加成功").arg(pairInfo.pairCount));
RefreshPairList();
}
else
{
ui->textEdit->append("准备编辑 IxChariot Pair 页面");
m_ixchariotDialog->SetIxchariotModeForCreat(0);
QString itemTitle = item->text();
int index = itemTitle.left(itemTitle.indexOf('.')).toInt();
m_ixchariotDialog->SetIxchariotPairInfo(m_pairList.at(index-1));
int res = m_ixchariotDialog->exec();
if(0==res) {
ui->textEdit->append("取消编辑");
return ;
}
// delete
if(2==res) {
m_pairList.erase(m_pairList.begin()+index-1);
}
// save
PairInfo pairInfo = m_ixchariotDialog->GetIxchariotPairInfo();
for (QVector<PairInfo>::iterator iter = m_pairList.begin(); iter != m_pairList.end(); iter++)
{
if((iter-m_pairList.begin())==(index-1))
{
*iter = pairInfo;
break;
}
}
ui->textEdit->append("保存成功");
RefreshPairList();
}
}
void MainWindow::on_chooseResultPathBtn_clicked()
{
if(m_endpointStatus != 0)
{
return ;
}
QString filename = QFileDialog::getSaveFileName(
this,
tr("选择跑流结果保存位置"),
"test_result_" + QDateTime::currentDateTime().toString("MMdd-hhmmss")+ ".tst",
"Script files (*.tst);;All files(*.*)");
if(filename.length()>0)
{
ui->resultEdit->setText(filename);
}
}
void MainWindow::on_startBtn_clicked()
{
if(m_pairList.length()==0)
{
QMessageBox::information(this, "tips", "pair条目为空,请先添加pair条目");
return ;
}
if(ui->resultEdit->text().length()==0)
{
QMessageBox::information(this, "tips", "请先选择结果保存位置");
return ;
}
if(ui->resultEdit->text().contains(QRegExp("[\\x4e00-\\x9fa5]+")))
{
QMessageBox::information(this, "tips", "路径中不能有中文字符");
return ;
}
if(m_endpointCli->CheckIxchariotLibEnv() != EP_OK)
{
QMessageBox::information(this,"tips","please check Ixchariot sdk enviroment");
}
// m_endpointCli->testFunc();
int res = m_endpointCli->StartTask(m_pairList,ui->resultEdit->text(),ui->testTimeBox->value(), ui->timeoutBox->value());
if(res==0)
{
ui->testTimeBox->setReadOnly(true);
ui->timeoutBox->setReadOnly(true);
m_endpointStatus = 1;
m_checkEndpointTimer->start(1000);
ui->textEdit->append("开始测试...");
ui->textEdit->append(QString("测试时间:%1秒").arg(ui->testTimeBox->value()));
ui->textEdit->append(QString("测试结果文件:%1").arg(ui->resultEdit->text()));
}
}
void MainWindow::checkEndpointTimerTimeout()
{
int runtime = 0;
int status;
status = m_endpointCli->GetEndpointStatus(runtime);
if(status==EP_TASK_RUNNING)
{
ui->progressBar->setValue(runtime*100/ui->testTimeBox->value());
ui->remainDurationEdit->setText(QString::number(ui->testTimeBox->value()-runtime));
ui->startBtn->setEnabled(false);
ui->stopBtn->setEnabled(true);
}
if(status==EP_TASK_FINISHED)
{
m_checkEndpointTimer->stop();
ui->progressBar->setValue(100);
ui->remainDurationEdit->setText("已完成");
ui->startBtn->setEnabled(true);
ui->stopBtn->setEnabled(false);
double throughputRes;
m_endpointCli->GetEndpointTestResult(throughputRes);
ui->textEdit->append("测试完成");
ui->textEdit->append(QString("本次测试结果: %1Mbps.").arg(throughputRes));
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/zhouws-chn/endpoint-cli.git
[email protected]:zhouws-chn/endpoint-cli.git
zhouws-chn
endpoint-cli
EndpointCli
master

搜索帮助