Reformat Client

remotes/origin/HEAD
markuspg 7 years ago
parent 385a42dedf
commit e533ede28b

@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 Markus Prasser
* Copyright 2014-2018 Markus Prasser, Tobias Weiss
*
* This file is part of Labcontrol.
*
@ -17,19 +17,17 @@
* along with Labcontrol. If not, see <http://www.gnu.org/licenses/>.
*/
#include <memory>
#include <QDebug>
#include "client.h"
#include "settings.h"
#include "clientpinger.h"
#include "lablib.h"
#include <memory>
extern std::unique_ptr<lc::Settings> settings;
extern std::unique_ptr<lc::Lablib> lablib;
lc::Client::Client(const QString &argIP, const QString &argMAC, const QString &argName,
unsigned short int argXPosition, unsigned short int argYPosition,
const unsigned short int argXPosition,
const unsigned short int argYPosition,
const QString &argPingCmd):
ip{argIP},
mac{argMAC},
@ -38,7 +36,7 @@ lc::Client::Client( const QString &argIP, const QString &argMAC, const QString &
yPosition{argYPosition},
protectedCycles{0}
{
qRegisterMetaType< state_t >( "STATE" );
qRegisterMetaType<state_t>("state_t");
if (!argPingCmd.isEmpty()) {
pinger = new ClientPinger{ip, argPingCmd};
@ -62,7 +60,8 @@ lc::Client::Client( const QString &argIP, const QString &argMAC, const QString &
+ QString::number(yPosition)};
}
lc::Client::~Client() {
lc::Client::~Client()
{
if (pingTimer) {
pingTimer->stop();
}
@ -71,31 +70,33 @@ lc::Client::~Client() {
pingerThread.wait();
}
void lc::Client::BeamFile( const QString &argFileToBeam, const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients ) {
void lc::Client::BeamFile(const QString &argFileToBeam,
const QString *const argPublickeyPathUser,
const QString *const argUserNameOnClients)
{
if (state < state_t::RESPONDING) {
return;
}
QStringList arguments;
arguments << "-2" << "-i" << *argPublickeyPathUser << "-l" << "32768" << "-r"
<< argFileToBeam << QString{ *argUserNameOnClients + "@" + ip + ":media4ztree" };
const QStringList arguments{"-2", "-i", *argPublickeyPathUser, "-l",
"32768", "-r", argFileToBeam,
QString{*argUserNameOnClients + "@" + ip + ":media4ztree"}};
// Start the process
QProcess beamFileProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
beamFileProcess.setProcessEnvironment( env );
beamFileProcess.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
beamFileProcess.startDetached(settings->scpCmd, arguments);
qDebug() << settings->scpCmd << arguments.join(" ");
}
void lc::Client::Boot() {
QStringList arguments{ QStringList{} << "-i" << settings->netwBrdAddr << mac };
void lc::Client::Boot()
{
const QStringList arguments{"-i", settings->netwBrdAddr, mac};
// Start the process
QProcess wakeonlanProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
wakeonlanProcess.setProcessEnvironment( env );
wakeonlanProcess.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
wakeonlanProcess.startDetached(settings->wakeonlanCmd, arguments);
// Output message via the debug messages tab
@ -107,27 +108,30 @@ void lc::Client::Boot() {
GotStatusChanged(state_t::BOOTING);
}
void lc::Client::GotStatusChanged( state_t argState ) {
if ( ( protectedCycles > 0 ) && ( state == state_t::BOOTING ) && ( argState != state_t::RESPONDING ) ) {
void lc::Client::GotStatusChanged(state_t argState)
{
if ((protectedCycles > 0) && (state == state_t::BOOTING)
&& (argState != state_t::RESPONDING)) {
return;
}
if ( ( protectedCycles > 0 ) && ( state == state_t::SHUTTING_DOWN ) && argState != state_t::NOT_RESPONDING ) {
if ((protectedCycles > 0) && (state == state_t::SHUTTING_DOWN)
&& argState != state_t::NOT_RESPONDING) {
return;
}
state = argState;
qDebug() << name << "status changed to:" << static_cast< unsigned short int >( argState );
qDebug() << name << "status changed to:"
<< static_cast<unsigned short int>(argState);
}
void lc::Client::KillZLeaf() {
QStringList arguments;
arguments << "-i" << settings->pkeyPathUser
<< QString{ settings->userNameOnClients + "@" + ip }
<< settings->killallCmd << "-I" << "-q" << "zleaf.exe";
void lc::Client::KillZLeaf()
{
const QStringList arguments{"-i", settings->pkeyPathUser,
QString{settings->userNameOnClients + "@" + ip},
settings->killallCmd, "-I", "-q", "zleaf.exe"};
// Start the process
QProcess killZLeafProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
killZLeafProcess.setProcessEnvironment( env );
killZLeafProcess.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
killZLeafProcess.startDetached(settings->sshCmd, arguments);
// Output message via the debug messages tab
@ -137,58 +141,59 @@ void lc::Client::KillZLeaf() {
pingTimer->start(3000);
}
void lc::Client::OpenFilesystem( const QString * const argUserToBeUsed ) {
void lc::Client::OpenFilesystem(const QString *const argUserToBeUsed)
{
if (state < state_t::RESPONDING) {
return;
}
QStringList arguments = QStringList{} << QString{ "sftp://" + *argUserToBeUsed + "@" + ip };
const QStringList arguments{QString{ "sftp://" + *argUserToBeUsed + "@" + ip }};
QProcess openFilesystemProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
openFilesystemProcess.setProcessEnvironment( env );
openFilesystemProcess.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
openFilesystemProcess.startDetached(settings->fileMngr, arguments);
qDebug() << settings->fileMngr << arguments.join(" ");
}
void lc::Client::OpenTerminal( const QString &argCommand, const bool &argOpenAsRoot ) {
void lc::Client::OpenTerminal(const QString &argCommand,
const bool argOpenAsRoot)
{
if (!settings->termEmulCmd.isEmpty()) {
if (state < state_t::RESPONDING) {
return;
}
QStringList *arguments = nullptr;
arguments = new QStringList;
QStringList arguments;
if (!argOpenAsRoot) {
*arguments << "-e"
arguments << "-e"
<< QString{settings->sshCmd + " -i " + settings->pkeyPathUser + " "
+ settings->userNameOnClients + "@" + ip};
} else {
*arguments << "-e" <<
arguments << "-e" <<
QString{settings->sshCmd + " -i " + settings->pkeyPathRoot
+ " " + "root@" + ip};
}
if (!argCommand.isEmpty()) {
arguments->last().append( " '" + argCommand + "'" );
arguments.last().append(" '" + argCommand + "'");
}
QProcess openTerminalProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
openTerminalProcess.setProcessEnvironment( env );
openTerminalProcess.startDetached( settings->termEmulCmd, *arguments );
qDebug() << settings->termEmulCmd << arguments->join( " " );
delete arguments;
openTerminalProcess.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
openTerminalProcess.startDetached(settings->termEmulCmd, arguments);
qDebug() << settings->termEmulCmd << arguments.join(" ");
}
}
void lc::Client::RequestAPing() {
void lc::Client::RequestAPing()
{
if (protectedCycles > 0) {
--protectedCycles;
}
emit PingWanted();
}
void lc::Client::SetStateToZLEAF_RUNNING( QString argClientIP ) {
void lc::Client::SetStateToZLEAF_RUNNING(const QString &argClientIP)
{
if ( argClientIP != ip ) {
return;
}
@ -201,45 +206,43 @@ void lc::Client::SetStateToZLEAF_RUNNING( QString argClientIP ) {
}
}
void lc::Client::ShowDesktopViewOnly() {
QStringList arguments;
arguments << ip;
void lc::Client::ShowDesktopViewOnly()
{
QStringList arguments{ip};
QProcess showDesktopProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
showDesktopProcess.setProcessEnvironment( env );
showDesktopProcess.startDetached( settings->vncViewer, arguments );
showDesktopProcess.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
showDesktopProcess.startDetached( settings->vncViewer, QStringList{ip});
// Output message via the debug messages tab
qDebug() << settings->vncViewer << arguments.join( " " );
}
void lc::Client::ShowDesktopFullControl() {
QStringList arguments;
arguments << ip + ":5901";
void lc::Client::ShowDesktopFullControl()
{
const QStringList arguments{QString{ip + ":5901"}};
QProcess showDesktopProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
showDesktopProcess.setProcessEnvironment( env );
showDesktopProcess.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
showDesktopProcess.startDetached(settings->vncViewer, arguments);
// Output message via the debug messages tab
qDebug() << settings->vncViewer << arguments.join(" ");
}
void lc::Client::Shutdown() {
void lc::Client::Shutdown()
{
if (state == state_t::NOT_RESPONDING || state == state_t::BOOTING
|| state == state_t::SHUTTING_DOWN) {
return;
}
QStringList arguments;
arguments << "-i" << settings->pkeyPathUser
<< QString{ settings->userNameOnClients + "@" + ip } << "sudo shutdown -P now";
const QStringList arguments{"-i", settings->pkeyPathUser,
QString{settings->userNameOnClients + "@" + ip},
"sudo shutdown -P now"};
// Start the process
QProcess shutdownProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
shutdownProcess.setProcessEnvironment( env );
shutdownProcess.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
shutdownProcess.startDetached(settings->sshCmd, arguments);
// Output message via the debug messages tab
@ -252,8 +255,11 @@ void lc::Client::Shutdown() {
GotStatusChanged(state_t::SHUTTING_DOWN);
}
void lc::Client::StartZLeaf( const QString * argFakeName, QString cmd ) {
if ( state < state_t::RESPONDING || zLeafVersion.isEmpty() || GetSessionPort() < 7000 ) {
void lc::Client::StartZLeaf(const QString *argFakeName, QString cmd)
{
if (state < state_t::RESPONDING
|| zLeafVersion.isEmpty()
|| GetSessionPort() < 7000) {
return;
}
@ -287,8 +293,7 @@ void lc::Client::StartZLeaf( const QString * argFakeName, QString cmd ) {
// Start the process
QProcess startZLeafProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
startZLeafProcess.setProcessEnvironment( env );
startZLeafProcess.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
startZLeafProcess.startDetached(settings->sshCmd, arguments);
// Output message via the debug messages tab
@ -296,7 +301,9 @@ void lc::Client::StartZLeaf( const QString * argFakeName, QString cmd ) {
}
}
void lc::Client::StartClientBrowser( const QString * const argURL, const bool * const argFullscreen ) {
void lc::Client::StartClientBrowser(const QString *const argURL,
const bool *const argFullscreen)
{
//Declarations
QStringList arguments;
@ -314,29 +321,24 @@ void lc::Client::StartClientBrowser( const QString * const argURL, const bool *
// Start the process
QProcess startClientBrowserProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
startClientBrowserProcess.setProcessEnvironment( env );
startClientBrowserProcess.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
startClientBrowserProcess.startDetached(settings->sshCmd, arguments);
// Output message via the debug messages tab
qDebug() << settings->sshCmd << arguments.join(" ");
}
void lc::Client::StopClientBrowser() {
void lc::Client::StopClientBrowser()
{
//Declarations
QStringList arguments;
//Build arguments list
arguments << "-i" << settings->pkeyPathUser
<< QString{ settings->userNameOnClients + "@" + ip }
<< "killall"
<< settings->clientBrowserCmd
<< "& sleep 1 && rm -R /home/ewfuser/.mozilla/firefox/*";
QStringList arguments{"-i", settings->pkeyPathUser,
QString{settings->userNameOnClients + "@" + ip},
"killall", settings->clientBrowserCmd,
"& sleep 1 && rm -R /home/ewfuser/.mozilla/firefox/*"};
// Start the process
QProcess startClientBrowserProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
startClientBrowserProcess.setProcessEnvironment( env );
startClientBrowserProcess.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
startClientBrowserProcess.startDetached(settings->sshCmd, arguments);
// Output message via the debug messages tab

@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 Markus Prasser
* Copyright 2014-2018 Markus Prasser, Tobias Weiss
*
* This file is part of Labcontrol.
*
@ -20,29 +20,27 @@
#ifndef CLIENT_H
#define CLIENT_H
#include <QMessageBox>
#include <QPlainTextEdit>
#include <QProcess>
#include <QString>
#include <QTextStream>
#include "global.h"
#include <QThread>
#include <QTimer>
#include "global.h"
#include "clientpinger.h"
class QTimer;
namespace lc {
class ClientPinger;
//! Class which represents the clients in the lab
/*!
This class contains elements and functions needed to represent all functions of a client.
*/
class Client : public QObject {
class Client : public QObject
{
Q_OBJECT
public slots:
//! Sets the STATE of the client to 'ZLEAF_RUNNING'
void SetStateToZLEAF_RUNNING( QString argClientIP );
void SetStateToZLEAF_RUNNING(const QString &argClientIP);
public:
const QString ip;
@ -60,17 +58,19 @@ public:
* \param argYPosition The client's y coordinate in the lab's grid
*/
Client(const QString &argIP, const QString &argMAC, const QString &argName,
unsigned short int argXPosition, unsigned short int argYPosition,
const unsigned short int argXPosition,
const unsigned short int argYPosition,
const QString &argPingCmd);
//! Client's destructor
~Client();
~Client() override;
//! Beams the chosen file to the client's 'media4ztree' directory
/*!
@param argFileToBeam The file which shall be beamed to the client's 'media4ztree' directory
@param argPublickeyPathUser The path to the publickey for user login on the clients
@param argUserNameOnClients The name of the user on the clients
*/
void BeamFile( const QString &argFileToBeam, const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients );
void BeamFile(const QString &argFileToBeam, const QString *const argPublickeyPathUser,
const QString *const argUserNameOnClients);
/*!
* \brief Boots the client
*/
@ -83,8 +83,14 @@ public:
/*!
@return The current state of the client
*/
state_t GetClientState() const { return state; }
int GetSessionPort() const { return sessionPort; }
state_t GetClientState() const
{
return state;
}
int GetSessionPort() const
{
return sessionPort;
}
/*!
* \brief Kills all processes 'zleaf.exe' on the client
*/
@ -99,9 +105,15 @@ public:
* \param argCommand A command which shall be executed in the terminal window (Pass an empty QString if not wanted)
* \param argOpenAsRoot Run the terminal session as root (true) or as normal user (false)
*/
void OpenTerminal( const QString &argCommand, const bool &argOpenAsRoot );
void SetSessionPort( int argSP ) { sessionPort = argSP; }
void SetzLeafVersion( const QString &argzLeafV ) { zLeafVersion = argzLeafV; }
void OpenTerminal(const QString &argCommand, const bool argOpenAsRoot);
void SetSessionPort(const int argSP)
{
sessionPort = argSP;
}
void SetzLeafVersion(const QString &argzLeafV)
{
zLeafVersion = argzLeafV;
}
//! Shows the desktop of the given client
void ShowDesktopViewOnly();
void ShowDesktopFullControl();
@ -128,24 +140,28 @@ public:
void StopClientBrowser();
private:
const QString &GetzLeafVersion() const { return zLeafVersion; }
const QString &GetzLeafVersion() const
{
return zLeafVersion;
}
unsigned short int protectedCycles;
ClientPinger *pinger = nullptr;
QThread pingerThread;
state_t state = state_t::UNINITIALIZED;
QTimer *pingTimer = nullptr; //! QTimer used to trigger pings by pinger's ClientPinger instance
//! QTimer used to trigger pings by pinger's ClientPinger instance
QTimer *pingTimer = nullptr;
int sessionPort = 0;
QString zLeafVersion;
private slots:
void GotStatusChanged( state_t argState );
void GotStatusChanged(const state_t argState);
void RequestAPing();
signals:
void PingWanted();
};
}
} // namespace lc
#endif // CLIENT_H

@ -17,11 +17,19 @@
* along with Labcontrol. If not, see <http://www.gnu.org/licenses/>.
*/
/* #include "manualprintingsetup.h"
#include "ui_manualprintingsetup.h"
#include "Lib/settings.h"
#include <QFileDialog>
*/
#include "manualprintingsetup.h"
#include "ui_manualprintingsetup.h"
#include "Lib/settings.h"
#include <QFileDialog>
#include <QMessageBox>
#include <memory>

@ -45,7 +45,7 @@ signals:
private:
QString dateString;
Ui::ManualPrintingSetup *ui = nullptr;
Ui::ManualPrintingSetup *const ui = nullptr;
QString workPath;
private slots:

Loading…
Cancel
Save