Made function arguments for 'lc::Client' class consistent

remotes/origin/HEAD
markuspg 10 years ago
parent 598e68855a
commit e68d404056

@ -26,12 +26,11 @@
extern std::unique_ptr< lc::Settings > settings; extern std::unique_ptr< lc::Settings > settings;
lc::Client::Client( QString *argIP, QString *argMAC, lc::Client::Client( const QString &argIP, const QString &argMAC, const QString &argName,
QString *argName, unsigned short int argXPosition, unsigned short int argXPosition, unsigned short int argYPosition ):
unsigned short int argYPosition ): ip{ argIP },
ip{ *argIP }, mac{ argMAC },
mac{ *argMAC }, name{ argName },
name{ *argName },
xPosition{ argXPosition }, xPosition{ argXPosition },
yPosition{ argYPosition }, yPosition{ argYPosition },
protectedCycles{ 0 } protectedCycles{ 0 }
@ -88,8 +87,8 @@ void lc::Client::BeamFile( const QString &argFileToBeam, const QString * const a
qDebug() << settings->scpCmd << arguments.join( " " ); qDebug() << settings->scpCmd << arguments.join( " " );
} }
void lc::Client::Boot( const QString &argNetworkBroadcastAddress ) { void lc::Client::Boot() {
QStringList arguments{ QStringList{} << "-i" << argNetworkBroadcastAddress << mac }; QStringList arguments{ QStringList{} << "-i" << settings->netwBrdAddr << mac };
// Start the process // Start the process
QProcess wakeonlanProcess; QProcess wakeonlanProcess;
@ -106,10 +105,10 @@ void lc::Client::Boot( const QString &argNetworkBroadcastAddress ) {
GotStatusChanged( state_t::BOOTING ); GotStatusChanged( state_t::BOOTING );
} }
void lc::Client::DeactiveScreensaver( const QString &argPublickeyPathUser, void lc::Client::DeactiveScreensaver() {
const QString &argUserNameOnClients ) {
QStringList arguments; QStringList arguments;
arguments << "-i" << argPublickeyPathUser << QString{ argUserNameOnClients + "@" + ip } arguments << "-i" << settings->pkeyPathUser
<< QString{ settings->userNameOnClients + "@" + ip }
<< settings->xsetCmd << "-display" << ":0.0" << "dpms" << "force" << "on"; << settings->xsetCmd << "-display" << ":0.0" << "dpms" << "force" << "on";
// Start the process // Start the process
@ -170,9 +169,7 @@ void lc::Client::OpenFilesystem( const QString * const argUserToBeUsed ) {
qDebug() << settings->fileMngr << arguments.join( " " ); 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 ) {
const QString & argPublickeyPathUser,
const QString &argUserNameOnClients ) {
if ( !settings->termEmulCmd.isEmpty() ) { if ( !settings->termEmulCmd.isEmpty() ) {
if ( state < state_t::RESPONDING ) { if ( state < state_t::RESPONDING ) {
return; return;
@ -182,11 +179,11 @@ void lc::Client::OpenTerminal( const QString &argCommand, const bool &argOpenAsR
arguments = new QStringList; arguments = new QStringList;
if ( !argOpenAsRoot ) { if ( !argOpenAsRoot ) {
*arguments << "--title" << name << "-e" << *arguments << "--title" << name << "-e" <<
QString{ settings->sshCmd + " -i " + argPublickeyPathUser + " " QString{ settings->sshCmd + " -i " + settings->pkeyPathUser + " "
+ argUserNameOnClients + "@" + ip }; + settings->userNameOnClients + "@" + ip };
} else { } else {
*arguments << "--title" << name << "-e" << *arguments << "--title" << name << "-e" <<
QString{ settings->sshCmd + " -i " + argPublickeyPathUser + " " + "root@" + ip }; QString{ settings->sshCmd + " -i " + settings->pkeyPathRoot + " " + "root@" + ip };
} }
if ( settings->termEmulCmd.contains( "konsole" ) ) { if ( settings->termEmulCmd.contains( "konsole" ) ) {
@ -244,12 +241,13 @@ void lc::Client::ShowDesktop() {
qDebug() << settings->vncViewer << arguments.join( " " ); qDebug() << settings->vncViewer << arguments.join( " " );
} }
void lc::Client::Shutdown( const QString &argPublickeyPathUser, const QString &argUserNameOnClients ) { void lc::Client::Shutdown() {
if ( state == state_t::NOT_RESPONDING || state == state_t::BOOTING || state == state_t::SHUTTING_DOWN ) { if ( state == state_t::NOT_RESPONDING || state == state_t::BOOTING || state == state_t::SHUTTING_DOWN ) {
return; return;
} }
QStringList arguments; QStringList arguments;
arguments << "-i" << argPublickeyPathUser << QString{ argUserNameOnClients + "@" + ip } << "sudo shutdown -P now"; arguments << "-i" << settings->pkeyPathUser
<< QString{ settings->userNameOnClients + "@" + ip } << "sudo shutdown -P now";
// Start the process // Start the process
QProcess shutdownProcess; QProcess shutdownProcess;

@ -51,18 +51,16 @@ public:
const unsigned short int xPosition = 1; const unsigned short int xPosition = 1;
const unsigned short int yPosition = 1; const unsigned short int yPosition = 1;
//! Client's constructor
/*! /*!
@param argDebugMessagesTextEditPtr A pointer to the debug messages text edit for verbose output * \brief Client's constructor
@param argIP The IP address the represented client has * \param argIP The IP address the represented client has
@param argMAC The MAC address the represented client has * \param argMAC The MAC address the represented client has
@param argName The hostname of the represented client * \param argName The hostname of the represented client
@param argXPosition The client's x coordinate in the lab * \param argXPosition The client's x coordinate in the lab's grid
@param argYPosition The client's y coordinate in the lab * \param argYPosition The client's y coordinate in the lab's grid
@param argSettingsItems A QVector storing many needed data QStrings */
*/ Client( const QString &argIP, const QString &argMAC, const QString &argName,
Client( QString *argIP, QString *argMAC, unsigned short int argXPosition, unsigned short int argYPosition );
QString *argName, unsigned short int argXPosition, unsigned short int argYPosition );
//! Client's destructor //! Client's destructor
~Client(); ~Client();
//! Beams the chosen file to the client's 'media4ztree' directory //! Beams the chosen file to the client's 'media4ztree' directory
@ -72,18 +70,14 @@ public:
@param argUserNameOnClients The name of the user 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 );
//! Boots the client
/*! /*!
@param argNetworkBroadcastAddress The network broadcast address of the lab * \brief Boots the client
*/ */
void Boot( const QString &argNetworkBroadcastAddress ); void Boot();
//! Runs the 'deactivate_screensaver.sh' script on the client to deactivate the screensaver
/*! /*!
@param argPublickeyPathUser The path to the publickey for user login on the clients * \brief DeactiveScreensaver deactivates potentially running screensavers on the client
@param argUserNameOnClients The name of the user on the clients */
*/ void DeactiveScreensaver();
void DeactiveScreensaver( const QString &argPublickeyPathUser,
const QString &argUserNameOnClients );
//! Returns the current state of the client //! Returns the current state of the client
/*! /*!
@return The current state of the client @return The current state of the client
@ -98,24 +92,18 @@ public:
@param argUserToBeUsed The name of the user on the clients @param argUserToBeUsed The name of the user on the clients
*/ */
void OpenFilesystem( const QString * const argUserToBeUsed ); void OpenFilesystem( const QString * const argUserToBeUsed );
//! 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) * \brief Opens a terminal for the client
@param argOpenAsRoot Run the terminal session as root (true) or as normal user (false) * \param argCommand A command which shall be executed in the terminal window (Pass an empty QString if not wanted)
@param argPublickeyPathUser The path to the publickey for user login on the clients * \param argOpenAsRoot Run the terminal session as root (true) or as normal user (false)
@param argUserNameOnClients The name of the user on the clients */
*/ void OpenTerminal( const QString &argCommand, const bool &argOpenAsRoot );
void OpenTerminal( const QString &argCommand, const bool &argOpenAsRoot,
const QString &argPublickeyPathUser,
const QString &argUserNameOnClients );
//! Shows the desktop of the given client //! Shows the desktop of the given client
void ShowDesktop(); void ShowDesktop();
//! Shuts down the client
/*! /*!
@param argPublickeyPathUser The path to the publickey for user login on the clients * \brief Shuts down the client
@param argUserNameOnClients The name of the user on the clients */
*/ void Shutdown();
void Shutdown( const QString &argPublickeyPathUser, const QString &argUserNameOnClients );
//! Starts a zLeaf instance on the client //! Starts a zLeaf instance on the client
/*! /*!
@param argZTreeVersion The version of zLeaf which shall be started @param argZTreeVersion The version of zLeaf which shall be started

@ -236,8 +236,8 @@ void lc::Lablib::ReadSettings() {
clients = new QVector< Client* >; clients = new QVector< Client* >;
for ( int i = 0; i < clientQuantity; i++ ) { for ( int i = 0; i < clientQuantity; i++ ) {
clients->append( new Client{ &clientIPs[ i ], &clientMACs[ i ], clients->append( new Client{ clientIPs[ i ], clientMACs[ i ], clientNames[ i ],
&clientNames[ i ], clientXPositions[ i ].toUShort(), clientXPositions[ i ].toUShort(),
clientYPositions[ i ].toUShort() } ); clientYPositions[ i ].toUShort() } );
// Add an corresponding entry to the 'client_ips_to_clients_map' std::map<QString, Client*> // Add an corresponding entry to the 'client_ips_to_clients_map' std::map<QString, Client*>

@ -245,7 +245,7 @@ void lc::MainWindow::on_PBBoot_clicked() {
for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) { for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) { if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() ); Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->Boot( settings->netwBrdAddr ); client->Boot();
} }
} }
} }
@ -272,7 +272,7 @@ void lc::MainWindow::on_PBDeactivateScreensaver_clicked() {
QVector< Client* > *clients = lablib->GetClients(); QVector< Client* > *clients = lablib->GetClients();
for ( auto s : *clients ) { for ( auto s : *clients ) {
if ( s->GetClientState() >= state_t::RESPONDING ) if ( s->GetClientState() >= state_t::RESPONDING )
s->DeactiveScreensaver( settings->pkeyPathUser, settings->userNameOnClients ); s->DeactiveScreensaver();
} }
} }
@ -316,8 +316,7 @@ void lc::MainWindow::on_PBExecute_clicked() {
qDebug() << "Executing command" << command << "on every client."; qDebug() << "Executing command" << command << "on every client.";
for ( auto s: *clients ) { for ( auto s: *clients ) {
if ( !( s->name.contains( "backup", Qt::CaseInsensitive ) ) ) { if ( !( s->name.contains( "backup", Qt::CaseInsensitive ) ) ) {
s->OpenTerminal( command, ui->RBUseUserRoot->isChecked(), pkeyPathUser, s->OpenTerminal( command, ui->RBUseUserRoot->isChecked() );
settings->userNameOnClients );
} }
} }
} else { } else {
@ -326,8 +325,7 @@ void lc::MainWindow::on_PBExecute_clicked() {
for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) { for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) { if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() ); Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->OpenTerminal( command, ui->RBUseUserRoot->isChecked(), pkeyPathUser, client->OpenTerminal( command, ui->RBUseUserRoot->isChecked() );
settings->userNameOnClients );
} }
} }
} }
@ -392,8 +390,7 @@ void lc::MainWindow::on_PBOpenTerminal_clicked() {
for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) { for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) { if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() ); Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->OpenTerminal( QString{}, ui->RBUseUserRoot->isChecked(), client->OpenTerminal( QString{}, ui->RBUseUserRoot->isChecked() );
pkeyPathUser, settings->userNameOnClients );
} }
} }
} }
@ -476,7 +473,7 @@ void lc::MainWindow::on_PBShutdown_clicked() {
for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) { for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) { if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() ); Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->Shutdown( settings->pkeyPathUser, settings->userNameOnClients ); client->Shutdown();
} }
} }
} }

Loading…
Cancel
Save