Rename state_t to EState and move it into Client

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

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

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

@ -20,8 +20,7 @@
#ifndef CLIENT_H #ifndef CLIENT_H
#define CLIENT_H #define CLIENT_H
#include "global.h" #include <QObject>
#include <QThread> #include <QThread>
class QTimer; class QTimer;
@ -39,6 +38,26 @@ class Client : public QObject
{ {
Q_OBJECT 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: public slots:
//! Sets the STATE of the client to 'ZLEAF_RUNNING' //! Sets the STATE of the client to 'ZLEAF_RUNNING'
void SetStateToZLEAF_RUNNING(const QString &argClientIP); void SetStateToZLEAF_RUNNING(const QString &argClientIP);
@ -85,7 +104,7 @@ public:
/*! /*!
@return The current state of the client @return The current state of the client
*/ */
state_t GetClientState() const EState GetClientState() const
{ {
return state; return state;
} }
@ -151,14 +170,14 @@ private:
ClientPinger *pinger = nullptr; ClientPinger *pinger = nullptr;
QThread pingerThread; QThread pingerThread;
const Settings *const settings = nullptr; 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 used to trigger pings by pinger's ClientPinger instance
QTimer *pingTimer = nullptr; QTimer *pingTimer = nullptr;
int sessionPort = 0; int sessionPort = 0;
QString zLeafVersion; QString zLeafVersion;
private slots: private slots:
void GotStatusChanged(const state_t argState); void GotStatusChanged(const EState argState);
void RequestAPing(); void RequestAPing();
signals: signals:

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

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

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

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

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

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

Loading…
Cancel
Save