Rename state_t to EState and move it into Client

remotes/origin/HEAD
markuspg 5 years ago
parent 9d304905e3
commit 256f10712e

@ -26,7 +26,6 @@ HEADERS += src/localzleafstarter.h \
src/Lib/client.h \
src/Lib/clienthelpnotificationserver.h \
src/Lib/clientpinger.h \
src/Lib/global.h \
src/Lib/lablib.h \
src/Lib/netstatagent.h \
src/Lib/receipts_handler.h \

@ -73,7 +73,7 @@ void lc::Client::BeamFile(const QString &argFileToBeam,
const QString *const argPublickeyPathUser,
const QString *const argUserNameOnClients)
{
if (state < state_t::RESPONDING) {
if (state < EState::RESPONDING) {
return;
}
@ -104,17 +104,17 @@ void lc::Client::Boot()
pingTimer->start(3000);
protectedCycles = 7;
GotStatusChanged(state_t::BOOTING);
GotStatusChanged(EState::BOOTING);
}
void lc::Client::GotStatusChanged(state_t argState)
void lc::Client::GotStatusChanged(EState argState)
{
if ((protectedCycles > 0) && (state == state_t::BOOTING)
&& (argState != state_t::RESPONDING)) {
if ((protectedCycles > 0) && (state == EState::BOOTING)
&& (argState != EState::RESPONDING)) {
return;
}
if ((protectedCycles > 0) && (state == state_t::SHUTTING_DOWN)
&& argState != state_t::NOT_RESPONDING) {
if ((protectedCycles > 0) && (state == EState::SHUTTING_DOWN)
&& argState != EState::NOT_RESPONDING) {
return;
}
state = argState;
@ -142,7 +142,7 @@ void lc::Client::KillZLeaf()
void lc::Client::OpenFilesystem(const QString *const argUserToBeUsed)
{
if (state < state_t::RESPONDING) {
if (state < EState::RESPONDING) {
return;
}
const QStringList arguments{QString{ "sftp://" + *argUserToBeUsed + "@" + ip }};
@ -157,7 +157,7 @@ void lc::Client::OpenTerminal(const QString &argCommand,
const bool argOpenAsRoot)
{
if (!settings->termEmulCmd.isEmpty()) {
if (state < state_t::RESPONDING) {
if (state < EState::RESPONDING) {
return;
}
@ -196,11 +196,11 @@ void lc::Client::SetStateToZLEAF_RUNNING(const QString &argClientIP)
if ( argClientIP != ip ) {
return;
}
if (state != state_t::ZLEAF_RUNNING) {
if (state != EState::ZLEAF_RUNNING) {
pingTimer->stop();
// Inform the ClientPinger instance, that zLeaf is now running
pinger->setStateToZLEAF_RUNNING();
this->GotStatusChanged(state_t::ZLEAF_RUNNING);
this->GotStatusChanged(EState::ZLEAF_RUNNING);
qDebug() << "Client" << name << "got 'ZLEAF_RUNNING' signal.";
}
}
@ -231,8 +231,8 @@ void lc::Client::ShowDesktopFullControl()
void lc::Client::Shutdown()
{
if (state == state_t::NOT_RESPONDING || state == state_t::BOOTING
|| state == state_t::SHUTTING_DOWN) {
if (state == EState::NOT_RESPONDING || state == EState::BOOTING
|| state == EState::SHUTTING_DOWN) {
return;
}
const QStringList arguments{"-i", settings->pkeyPathUser,
@ -251,12 +251,12 @@ void lc::Client::Shutdown()
pingTimer->start(3000);
protectedCycles = 3;
GotStatusChanged(state_t::SHUTTING_DOWN);
GotStatusChanged(EState::SHUTTING_DOWN);
}
void lc::Client::StartZLeaf(const QString *argFakeName, QString cmd)
{
if (state < state_t::RESPONDING
if (state < EState::RESPONDING
|| zLeafVersion.isEmpty()
|| GetSessionPort() < 7000) {
return;
@ -264,7 +264,7 @@ void lc::Client::StartZLeaf(const QString *argFakeName, QString cmd)
// Create a QMessageBox for user interaction if there is already a zLeaf running
std::unique_ptr<QMessageBox> messageBoxRunningZLeafFound;
if (state == state_t::ZLEAF_RUNNING) {
if (state == EState::ZLEAF_RUNNING) {
messageBoxRunningZLeafFound.reset(new QMessageBox{QMessageBox::Warning, "Running zLeaf found",
QString{"There is already a zLeaf running on " + name + "."},
QMessageBox::No | QMessageBox::Yes});
@ -277,7 +277,7 @@ void lc::Client::StartZLeaf(const QString *argFakeName, QString cmd)
if ((messageBoxRunningZLeafFound.get() != nullptr
&& messageBoxRunningZLeafFound->clickedButton()
== messageBoxRunningZLeafFound->button(QMessageBox::Yes))
|| state != state_t::ZLEAF_RUNNING) {
|| state != EState::ZLEAF_RUNNING) {
QStringList arguments;
if (argFakeName == nullptr) {
arguments << "-i" << settings->pkeyPathUser

@ -20,8 +20,7 @@
#ifndef CLIENT_H
#define CLIENT_H
#include "global.h"
#include <QObject>
#include <QThread>
class QTimer;
@ -39,6 +38,26 @@ class Client : public QObject
{
Q_OBJECT
public:
enum class EState : unsigned short {
//! The client's state is not yet defined (should only occur directly after client creation)
UNINITIALIZED = 1 << 0,
//! The client is booting but not yet responding
BOOTING = 1 << 1,
//! An error occurred determining the client's state
ERROR = 1 << 2,
//! The client is not responding to pings
NOT_RESPONDING = 1 << 3,
//! The client is shutting down but not yet stopped responding
SHUTTING_DOWN = 1 << 4,
//! The client is responding to pings
RESPONDING = 1 << 5,
//! The client is running a zLeaf
ZLEAF_RUNNING = 1 << 6,
};
Q_ENUM(EState)
public slots:
//! Sets the STATE of the client to 'ZLEAF_RUNNING'
void SetStateToZLEAF_RUNNING(const QString &argClientIP);
@ -85,7 +104,7 @@ public:
/*!
@return The current state of the client
*/
state_t GetClientState() const
EState GetClientState() const
{
return state;
}
@ -151,14 +170,14 @@ private:
ClientPinger *pinger = nullptr;
QThread pingerThread;
const Settings *const settings = nullptr;
state_t state = state_t::UNINITIALIZED;
EState state = EState::UNINITIALIZED;
//! QTimer used to trigger pings by pinger's ClientPinger instance
QTimer *pingTimer = nullptr;
int sessionPort = 0;
QString zLeafVersion;
private slots:
void GotStatusChanged(const state_t argState);
void GotStatusChanged(const EState argState);
void RequestAPing();
signals:

@ -35,18 +35,18 @@ lc::ClientPinger::ClientPinger(const QString &argIP,
void lc::ClientPinger::doPing()
{
// Initialize the new state to be queried
state_t newState = state_t::UNINITIALIZED;
Client::EState newState = Client::EState::UNINITIALIZED;
// Query the current state of the client
pingProcess->start(pingCommand, pingArguments);
if (!pingProcess->waitForFinished(2500)
|| pingProcess->exitStatus() != QProcess::NormalExit)
newState = state_t::ERROR;
newState = Client::EState::ERROR;
else {
if (pingProcess->exitCode() == 0) {
newState = state_t::RESPONDING;
newState = Client::EState::RESPONDING;
} else {
newState = state_t::NOT_RESPONDING;
newState = Client::EState::NOT_RESPONDING;
}
}
@ -58,5 +58,5 @@ void lc::ClientPinger::doPing()
void lc::ClientPinger::setStateToZLEAF_RUNNING()
{
state = state_t::ZLEAF_RUNNING;
state = Client::EState::ZLEAF_RUNNING;
}

@ -20,7 +20,7 @@
#ifndef CLIENTPINGER_H
#define CLIENTPINGER_H
#include "global.h"
#include "client.h"
#include <QObject>
#include <QProcess>
@ -63,12 +63,12 @@ private:
//! The 'ping' process which will be executed on every call of 'do_ping()'
std::unique_ptr<QProcess> pingProcess;
//! Stores the current state of the client
state_t state = state_t::UNINITIALIZED;
Client::EState state = Client::EState::UNINITIALIZED;
signals:
//! This signal was just implemented for testing purposes
//! This signal is emitted if the ping finished and the state of the client changed
void PingFinished(state_t state);
void PingFinished(Client::EState state);
};
} // namespace lc

@ -1,44 +0,0 @@
/*
* Copyright 2014-2018 Markus Prasser, Tobias Weiss
*
* This file is part of Labcontrol.
*
* Labcontrol is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Labcontrol is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Labcontrol. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GLOBAL_H
#define GLOBAL_H
#include <QMetaType>
//! Opens a terminal for the client
enum class state_t : unsigned short int {
//! The client is booting but not yet responding
BOOTING = 1 << 0,
//! An error occurred determining the client's state
ERROR = 1 << 1,
//! The client is not responding to pings
NOT_RESPONDING = 1 << 2,
//! The client is shutting down but not yet stopped responding
SHUTTING_DOWN = 1 << 3,
//! The client's state is not yet defined (should only occur directly after client creation)
UNINITIALIZED = 1 << 4,
//! The client is responding to pings
RESPONDING = 1 << 5,
//! The client is running a zLeaf
ZLEAF_RUNNING = 1 << 6,
};
Q_DECLARE_METATYPE(state_t)
#endif // GLOBAL_H

@ -38,7 +38,6 @@
#include "client.h"
#include "clienthelpnotificationserver.h"
#include "global.h"
#include "netstatagent.h"
#include "session.h"
#include "sessionsmodel.h"

@ -24,8 +24,6 @@
#include <QProcess>
#include <QThread>
#include "global.h"
namespace lc {
class Settings;

@ -20,8 +20,6 @@
#ifndef ZTREE_H
#define ZTREE_H
#include "global.h"
#include <QProcess>
namespace lc {

@ -25,7 +25,7 @@
int main(int argc, char *argv[])
{
qRegisterMetaType<state_t>();
qRegisterMetaType<lc::Client::EState>();
QApplication a{argc, argv};
lc::Settings settings{QSettings{"Labcontrol", "Labcontrol"}};

@ -17,6 +17,7 @@
* along with Labcontrol. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QButtonGroup>
#include <QtGlobal>
#include <QDebug>
#include <QInputDialog>
@ -471,31 +472,31 @@ void lc::MainWindow::StartReceiptsHandler(QString argzTreeDataTargetPath,
void lc::MainWindow::UpdateClientsTableView()
{
for ( auto s : *valid_items ) {
state_t state = static_cast< Client * >( s->data(
lc::Client::EState state = static_cast< Client * >( s->data(
Qt::UserRole ).value<void *>() )->GetClientState();
switch ( state ) {
case state_t::RESPONDING:
case Client::EState::RESPONDING:
s->setBackground( QBrush( QColor( 128, 255, 128, 255 ) ) );
s->setIcon( icons[ ( int )icons_t::ON ] );
break;
case state_t::NOT_RESPONDING:
case lc::Client::EState::NOT_RESPONDING:
s->setBackground( QBrush( QColor( 255, 255, 128, 255 ) ) );
s->setIcon( icons[ ( int )icons_t::OFF ] );
break;
case state_t::BOOTING:
case Client::EState::BOOTING:
s->setBackground( QBrush( QColor( 128, 128, 255, 255 ) ) );
s->setIcon( icons[ ( int )icons_t::BOOT ] );
break;
case state_t::SHUTTING_DOWN:
case Client::EState::SHUTTING_DOWN:
s->setBackground( QBrush( QColor( 128, 128, 255, 255 ) ) );
s->setIcon( icons[ ( int )icons_t::DOWN ] );
break;
case state_t::ZLEAF_RUNNING:
case Client::EState::ZLEAF_RUNNING:
s->setBackground( QBrush( QColor( 0, 255, 0, 255 ) ) );
s->setIcon( icons[ ( int )icons_t::ZLEAF ] );
break;
case state_t::UNINITIALIZED:
case state_t::ERROR:
case Client::EState::UNINITIALIZED:
case Client::EState::ERROR:
s->setBackground( QBrush( QColor( 255, 128, 128, 255 ) ) );
break;
}

Loading…
Cancel
Save