You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
190 lines
5.9 KiB
C++
190 lines
5.9 KiB
C++
/*
|
|
* 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 CLIENT_H
|
|
#define CLIENT_H
|
|
|
|
#include <QObject>
|
|
#include <QThread>
|
|
|
|
class QTimer;
|
|
|
|
namespace lc {
|
|
|
|
class ClientPinger;
|
|
class Settings;
|
|
|
|
//! 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
|
|
{
|
|
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);
|
|
|
|
public:
|
|
const QString ip;
|
|
const QString mac;
|
|
const QString name;
|
|
const unsigned short int xPosition = 1;
|
|
const unsigned short int yPosition = 1;
|
|
|
|
/*!
|
|
* \brief Client's constructor
|
|
* \param argIP The IP address the represented client has
|
|
* \param argMAC The MAC address the represented client has
|
|
* \param argName The hostname of the represented client
|
|
* \param argXPosition The client's x coordinate in the lab's grid
|
|
* \param argYPosition The client's y coordinate in the lab's grid
|
|
*/
|
|
Client(const QString &argIP, const QString &argMAC, const QString &argName,
|
|
const Settings *const argSettings,
|
|
const unsigned short int argXPosition,
|
|
const unsigned short int argYPosition,
|
|
const QString &argPingCmd);
|
|
//! Client's destructor
|
|
~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);
|
|
/*!
|
|
* \brief Boots the client
|
|
*/
|
|
void Boot();
|
|
/*!
|
|
* \brief DeactiveScreensaver deactivates potentially running screensavers on the client
|
|
*/
|
|
void DeactiveScreensaver();
|
|
//! Returns the current state of the client
|
|
/*!
|
|
@return The current state of the client
|
|
*/
|
|
EState GetClientState() const
|
|
{
|
|
return state;
|
|
}
|
|
int GetSessionPort() const
|
|
{
|
|
return sessionPort;
|
|
}
|
|
/*!
|
|
* \brief Kills all processes 'zleaf.exe' on the client
|
|
*/
|
|
void KillZLeaf();
|
|
//! Opens a file manager for the client's file system
|
|
/*!
|
|
@param argUserToBeUsed The name of the user on the clients
|
|
*/
|
|
void OpenFilesystem(const QString *const argUserToBeUsed);
|
|
/*!
|
|
* \brief Opens a terminal for the client
|
|
* \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(const int argSP)
|
|
{
|
|
sessionPort = argSP;
|
|
}
|
|
void SetzLeafVersion(const QString &argzLeafV)
|
|
{
|
|
zLeafVersion = argzLeafV;
|
|
}
|
|
//! Shows the desktop of the given client
|
|
void ShowDesktopViewOnly();
|
|
void ShowDesktopFullControl();
|
|
/*!
|
|
* \brief Shuts down the client
|
|
*/
|
|
void Shutdown();
|
|
|
|
/*!
|
|
* \brief Starts a zLeaf instance on the client
|
|
* @param argFakeName The name the zLeaf instance shall have (if not the default, which is the hostname of the client)
|
|
*/
|
|
void StartZLeaf(const QString *argFakeName = nullptr, QString cmd = "");
|
|
|
|
/*!
|
|
* \brief Opens a browser window on the client
|
|
* @param argURL URL to open in clients browser
|
|
*/
|
|
void StartClientBrowser(const QString *argURL = nullptr, const bool *argFullscreen = nullptr);
|
|
|
|
/*!
|
|
* \brief Closes all browser instances
|
|
*/
|
|
void StopClientBrowser();
|
|
|
|
private:
|
|
const QString &GetzLeafVersion() const
|
|
{
|
|
return zLeafVersion;
|
|
}
|
|
|
|
unsigned short int protectedCycles;
|
|
ClientPinger *pinger = nullptr;
|
|
QThread pingerThread;
|
|
const Settings *const settings = nullptr;
|
|
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 EState argState);
|
|
void RequestAPing();
|
|
|
|
signals:
|
|
void PingWanted();
|
|
};
|
|
|
|
} // namespace lc
|
|
|
|
#endif // CLIENT_H
|