Adds initial intermediate qt6 porting state
This commit is contained in:
11247 files changed
+1891537
No files matched your search
Executable
+359
@@ -0,0 +1,359 @@
|
||||
|
||||
|
||||
|
||||
|
||||
#include "scm_dialog.h"
|
||||
#include "ui_scm_dialog.h"
|
||||
|
||||
#include "scm_dialog_group.h"
|
||||
#include "scm_dialog_service.h"
|
||||
|
||||
#include <LtsUtilsCore/data_modification_enum.h>
|
||||
|
||||
#include <QVBoxLayout>
|
||||
|
||||
|
||||
namespace ServiceManagement
|
||||
{
|
||||
|
||||
|
||||
|
||||
ServiceManagementDialog::ServiceManagementDialog(QWidget *parent)
|
||||
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
|
||||
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
||||
, m_ui(new Ui::ServiceManagementDialog)
|
||||
, m_dtcExm(nullptr)
|
||||
, m_dtc(nullptr)
|
||||
, m_ftc(nullptr)
|
||||
, m_logger(getLogger("ServiceManagementDialog"))
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
|
||||
m_ui->lbGroupsIndicator->hide();
|
||||
m_ui->lbExercise->hide();
|
||||
m_ui->lbServer->hide();
|
||||
m_ui->cbServer->hide();
|
||||
m_ui->cbExercise->hide();
|
||||
|
||||
setOnlineHelpFilename(QStringLiteral("Administrator-Service_Management"));
|
||||
}
|
||||
|
||||
ServiceManagementDialog::~ServiceManagementDialog()
|
||||
{
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
|
||||
void ServiceManagementDialog::retranslate()
|
||||
{
|
||||
translate(m_ui, tr("Service Management"));
|
||||
}
|
||||
|
||||
|
||||
bool ServiceManagementDialog::init(const std::shared_ptr<ServiceManagement::Interface::Dtc> &dtc,
|
||||
const std::shared_ptr<ServiceManagement::Interface::Ftc> &ftc,
|
||||
const std::shared_ptr<ExerciseManagement::Interface::Dtc> &dtcExm)
|
||||
{
|
||||
m_dtc = dtc;
|
||||
m_ftc = ftc;
|
||||
m_dtcExm = dtcExm;
|
||||
|
||||
connect(m_dtc.get(), &Interface::Dtc::groupInformationChanged,
|
||||
this, &ServiceManagementDialog::slotGroupInformationChanged);
|
||||
|
||||
connect(m_dtc.get(), &Interface::Dtc::serviceInformationChanged,
|
||||
this, &ServiceManagementDialog::slotServiceInformationChanged);
|
||||
|
||||
const QMap<qint32, ServiceManagement::GroupInformation> groupInfo = m_dtc->groupInformations();
|
||||
|
||||
if (groupInfo.isEmpty())
|
||||
{
|
||||
INFO_LOG(m_logger) << "initModel - no groups!";
|
||||
return true;
|
||||
}
|
||||
|
||||
m_ui->lbNoServices->hide();
|
||||
|
||||
INFO_LOG(m_logger) << "initModel - #group information: " << groupInfo.size();
|
||||
|
||||
|
||||
|
||||
QVector<int> servicesList;
|
||||
for (const ServiceManagement::GroupInformation &gi : groupInfo)
|
||||
{
|
||||
|
||||
|
||||
const int server = gi.domainId();
|
||||
const int exercise = gi.exercisePartitionId();
|
||||
const int32_t replayPartitionId = gi.replayPartitionId();
|
||||
const QString groupName = groupEnumToGroupName(gi.type());
|
||||
long long timestamp = gi.timestamp();
|
||||
|
||||
servicesList.clear();
|
||||
servicesList.reserve(gi.services().size());
|
||||
for (auto service : gi.services())
|
||||
servicesList.append(service);
|
||||
|
||||
addGroup(gi.type(), server, exercise, replayPartitionId, groupName, timestamp, servicesList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
auto cbSvc = [this](const ServiceManagement::ServiceInformation & svc)
|
||||
{
|
||||
addService(svc);
|
||||
};
|
||||
m_dtc->serviceInformations(cbSvc);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
GroupWidget *ServiceManagementDialog::addGroup(const Core::ServiceGroupType &groupType, int server, int exercise, int32_t replayPartitionId,
|
||||
const QString &groupName, long long timestamp, const QVector<int> &servicesList)
|
||||
{
|
||||
|
||||
|
||||
QString exName = QString::fromStdString(m_dtcExm.get()->exercise(exercise).name());
|
||||
GroupWidget *group = new GroupWidget(groupType, server, exercise, replayPartitionId, exName, timestamp, servicesList);
|
||||
|
||||
QString groupObjectName = craftGroupName(server, exercise, groupName);
|
||||
group->setObjectName(groupObjectName);
|
||||
|
||||
|
||||
connect(group, &GroupWidget::signalRestartGroup, this, &ServiceManagementDialog::slotRestartGroup);
|
||||
connect(group, &GroupWidget::signalStartGroup, this, &ServiceManagementDialog::slotStartGroup);
|
||||
connect(group, &GroupWidget::signalStopGroup, this, &ServiceManagementDialog::slotStopGroup);
|
||||
|
||||
QVBoxLayout *l = qobject_cast<QVBoxLayout *>(m_ui->groupLayoutWidget->layout());
|
||||
if (!l)
|
||||
WARNING_LOG(m_logger) << "ServiceManagementDialog::addGroup: group layout failed, cannot add group";
|
||||
else
|
||||
l->addWidget(group, 0, Qt::AlignTop);
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
|
||||
void ServiceManagementDialog::slotRestartService(int serviceID)
|
||||
{
|
||||
const RestartServiceRequest req(serviceID);
|
||||
m_requestHelper->startSingleRequest([req, this]()
|
||||
{
|
||||
return m_ftc->restartServiceRequest(req, this);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
static int s_requestId = 0;
|
||||
void ServiceManagementDialog::slotRestartGroup(const Core::ServiceGroupType &groupType, int exercise, int server, int32_t replayPartitionId)
|
||||
{
|
||||
const GroupRequest req(groupType,
|
||||
exercise,
|
||||
server,
|
||||
replayPartitionId,
|
||||
++s_requestId,
|
||||
{});
|
||||
m_requestHelper->startSingleRequest([req, this]()
|
||||
{
|
||||
return m_ftc->restartGroupRequest(req, this);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void ServiceManagementDialog::slotStartGroup(const Core::ServiceGroupType &groupType, int exercise, int server, int32_t replayPartitionId)
|
||||
{
|
||||
const GroupRequest req(groupType,
|
||||
exercise,
|
||||
server,
|
||||
replayPartitionId,
|
||||
++s_requestId,
|
||||
{});
|
||||
m_requestHelper->startSingleRequest([req, this]()
|
||||
{
|
||||
return m_ftc->startGroupRequest(req, this);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void ServiceManagementDialog::slotStopGroup(const Core::ServiceGroupType &groupType, int exercise, int server, int32_t replayPartitionId)
|
||||
{
|
||||
const GroupRequest req(groupType,
|
||||
exercise,
|
||||
server,
|
||||
replayPartitionId,
|
||||
++s_requestId,
|
||||
{});
|
||||
m_requestHelper->startSingleRequest([req, this]()
|
||||
{
|
||||
return m_ftc->stopGroupRequest(req, this);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ServiceManagementDialog::slotGroupInformationChanged(ServiceManagement::GroupInformation info, DataModification mod)
|
||||
{
|
||||
|
||||
|
||||
|
||||
int server = info.domainId();
|
||||
int exercise = info.exercisePartitionId();
|
||||
int32_t replayPartitionId = info.replayPartitionId();
|
||||
QString groupName = groupEnumToGroupName(info.type());
|
||||
long long timestamp = info.timestamp();
|
||||
|
||||
QString findGroupName = craftGroupName(server, exercise, groupName);
|
||||
|
||||
GroupWidget *gw = m_ui->groupLayoutWidget->findChild<GroupWidget *>(findGroupName);
|
||||
|
||||
if (!gw)
|
||||
{
|
||||
|
||||
|
||||
QVector<int> servicesList;
|
||||
servicesList.reserve(info.services().size());
|
||||
for (auto service : info.services())
|
||||
servicesList << service;
|
||||
|
||||
m_ui->lbNoServices->hide();
|
||||
addGroup(info.type(), server, exercise, replayPartitionId, groupName, timestamp, servicesList);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (mod)
|
||||
{
|
||||
case DataModification::eAdded:
|
||||
case DataModification::eModified:
|
||||
{
|
||||
|
||||
|
||||
m_ui->lbNoServices->hide();
|
||||
|
||||
gw->setType(info.type());
|
||||
gw->setServer(server);
|
||||
gw->setExercise(exercise);
|
||||
gw->setTimestamp(timestamp);
|
||||
break;
|
||||
}
|
||||
|
||||
case DataModification::eRemoved:
|
||||
{
|
||||
|
||||
|
||||
if (m_ui->groupLayoutWidget->findChildren<GroupWidget *>().isEmpty())
|
||||
m_ui->lbNoServices->show();
|
||||
|
||||
delete gw;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ServiceManagementDialog::addService(const ServiceManagement::ServiceInformation &svc)
|
||||
{
|
||||
const int id = svc.id();
|
||||
const long long pid = svc.pid();
|
||||
const QString name(QString::fromStdString(svc.name()));
|
||||
const Core::RunningState &state = svc.state();
|
||||
const QString errorString(QString::fromStdString(svc.errorString()));
|
||||
|
||||
ServiceWidget *service = new ServiceWidget(id, pid, name, state, errorString);
|
||||
service->setObjectName(QLatin1String("service.") + QString::number(id));
|
||||
connect(service, &ServiceWidget::signalRestartService, this, &ServiceManagementDialog::slotRestartService);
|
||||
|
||||
|
||||
const auto groupList = findChildren<GroupWidget *>();
|
||||
for (GroupWidget *gw : groupList)
|
||||
gw->addService(service);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ServiceManagementDialog::slotServiceInformationChanged(ServiceManagement::ServiceInformation info, DataModification mod)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
int32_t serviceId = info.id();
|
||||
QString errorString = QString::fromStdString(info.errorString());
|
||||
QString serviceName = QString::fromStdString(info.name());
|
||||
long long pid = info.pid();
|
||||
const Core::RunningState &state = info.state();
|
||||
long long timestamp = info.timestamp();
|
||||
|
||||
QString findServiceName = QLatin1String("service.") + QString::number(serviceId);
|
||||
|
||||
const auto serviceList = findChildren<ServiceWidget *>(findServiceName);
|
||||
|
||||
if (serviceList.isEmpty() || mod == DataModification::eAdded)
|
||||
{
|
||||
|
||||
|
||||
addService(info);
|
||||
}
|
||||
|
||||
for (ServiceWidget *serviceWidget : serviceList)
|
||||
{
|
||||
switch (mod)
|
||||
{
|
||||
case DataModification::eModified:
|
||||
{
|
||||
|
||||
|
||||
serviceWidget->setErrorString(errorString);
|
||||
serviceWidget->setName(serviceName);
|
||||
serviceWidget->setPid(pid);
|
||||
serviceWidget->setState(state);
|
||||
serviceWidget->setTimestamp(timestamp);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case DataModification::eRemoved:
|
||||
{
|
||||
|
||||
|
||||
delete serviceWidget;
|
||||
serviceWidget = nullptr;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
const auto groupList = findChildren<GroupWidget *>();
|
||||
for (GroupWidget *groupWidget : groupList)
|
||||
groupWidget->checkStatus();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user