Start z-Leaves on clients with in 'lc::SessionStarter' made settings

remotes/origin/HEAD
markuspg 8 years ago
parent 54ec27518f
commit e10f625c6e

@ -262,9 +262,8 @@ void lc::Client::Shutdown() {
GotStatusChanged( state_t::SHUTTING_DOWN );
}
void lc::Client::StartZLeaf( const QString * const argZTreeVersion, unsigned short int argPort,
const QString * const argFakeName ) {
if ( state < state_t::RESPONDING ) {
void lc::Client::StartZLeaf( const QString * const argFakeName ) {
if ( state < state_t::RESPONDING || zLeafVersion.isEmpty() || GetSessionPort() < 7000 ) {
return;
}
@ -285,27 +284,27 @@ void lc::Client::StartZLeaf( const QString * const argZTreeVersion, unsigned sho
== messageBoxRunningZLeafFound->button( QMessageBox::Yes ) )
|| state != state_t::ZLEAF_RUNNING ) {
QStringList arguments;
if ( argFakeName == nullptr && argPort == 7000 ) {
if ( argFakeName == nullptr && GetSessionPort() == 7000 ) {
arguments << "-i" << settings->pkeyPathUser
<< QString{ settings->userNameOnClients + "@" + ip }
<< "DISPLAY=:0.0" << settings->tasksetCmd << "0x00000001" << settings->wineCmd
<< QString{ settings->zTreeInstDir + "/zTree_" + *argZTreeVersion + "/zleaf.exe" }
<< QString{ settings->zTreeInstDir + "/zTree_" + GetzLeafVersion() + "/zleaf.exe" }
<< "/server" << settings->serverIP;
} else {
if ( argFakeName == nullptr ) {
arguments << "-i" << settings->pkeyPathUser
<< QString{ settings->userNameOnClients + "@" + ip }
<< "DISPLAY=:0.0" << settings->tasksetCmd << "0x00000001" << settings->wineCmd
<< QString{ settings->zTreeInstDir + "/zTree_" + *argZTreeVersion + "/zleaf.exe" }
<< QString{ settings->zTreeInstDir + "/zTree_" + GetzLeafVersion() + "/zleaf.exe" }
<< "/server" << settings->serverIP << "/channel"
<< QString::number( static_cast< int >( argPort ) - 7000 );
<< QString::number( GetSessionPort() - 7000 );
} else {
arguments << "-i" << settings->pkeyPathUser
<< QString{ settings->userNameOnClients + "@" + ip }
<< "DISPLAY=:0.0" << settings->tasksetCmd << "0x00000001" << settings->wineCmd
<< QString{ settings->zTreeInstDir + "/zTree_" + *argZTreeVersion + "/zleaf.exe" }
<< QString{ settings->zTreeInstDir + "/zTree_" + GetzLeafVersion() + "/zleaf.exe" }
<< "/server" << settings->serverIP << "/channel"
<< QString::number( static_cast< int >( argPort ) - 7000 )
<< QString::number( GetSessionPort() - 7000 )
<< "/name" << *argFakeName;
}
}

@ -84,7 +84,7 @@ public:
@return The current state of the client
*/
state_t GetClientState() const { return state; }
QString GetSessionPort() const { return sessionPort; }
int GetSessionPort() const { return sessionPort; }
/*!
* \brief Kills all processes 'zleaf.exe' on the client
*/
@ -100,7 +100,7 @@ public:
* \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 QString &argSP ) { sessionPort = argSP; }
void SetSessionPort( int argSP ) { sessionPort = argSP; }
void SetzLeafVersion( const QString &argzLeafV ) { zLeafVersion = argzLeafV; }
//! Shows the desktop of the given client
void ShowDesktop();
@ -110,20 +110,19 @@ public:
void Shutdown();
//! Starts a zLeaf instance on the client
/*!
@param argZTreeVersion The version of zLeaf which shall be started
@param argPort The port zTree ist listening on on the server
@param argFakeName The name the zLeaf instance shall have (if not the default, which is the hostname of the client)
*/
void StartZLeaf( const QString * const argZTreeVersion, unsigned short int argPort,
const QString * const argFakeName = nullptr );
void StartZLeaf( const QString * const argFakeName = nullptr );
private:
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
QString sessionPort;
int sessionPort = 0;
QString zLeafVersion;
private slots:

@ -439,15 +439,6 @@ void lc::MainWindow::on_PBPrintPaymentFileManually_clicked() {
}
void lc::MainWindow::on_PBRunzLeaf_clicked() {
// Show an error message, if no zTree version was chosen yet
if ( ui->CBzLeafVersion->currentIndex() == 0 ) {
QMessageBox messageBox{ QMessageBox::Warning, tr( "Unset z-Leaf version" ),
tr( "There is no z-Leaf version chosen yet. Please choose one." ),
QMessageBox::Ok, this };
messageBox.exec();
return;
}
// Check if more than one client is selected and issue a warning message if so
unsigned short int numberOfSelectedClients = 0;
QModelIndexList activatedItems = ui->TVClients->selectionModel()->selectedIndexes();
@ -462,16 +453,13 @@ void lc::MainWindow::on_PBRunzLeaf_clicked() {
messageBox.exec();
} else {
const QString * const fakeName = new QString{ ui->CBClientNames->currentText() };
const QString * const zLeafVersion = new QString{ ui->CBzLeafVersion->currentText() };
for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->StartZLeaf( zLeafVersion, ui->SBzLeafPort->value(),
fakeName );
client->StartZLeaf( fakeName );
}
}
delete fakeName;
delete zLeafVersion;
}
}
@ -545,23 +533,13 @@ void lc::MainWindow::on_PBStartSession_clicked() {
}
void lc::MainWindow::on_PBStartzLeaf_clicked() {
// Show an error message, if no z-Leaf version was chosen yet
if ( ui->CBzLeafVersion->currentIndex() == 0 ) {
QMessageBox messageBox{ QMessageBox::Warning, tr( "Unset z-Leaf version" ), tr( "There is no z-Leaf version chosen yet. Please choose one." ), QMessageBox::Ok, this };
messageBox.exec();
return;
}
QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes();
const QString * const zLeafVersion = new QString{ ui->CBzLeafVersion->currentText() };
for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->StartZLeaf( zLeafVersion, ui->SBzLeafPort->value(),
nullptr );
client->StartZLeaf( nullptr );
}
}
delete zLeafVersion;
}
void lc::MainWindow::on_PBViewDesktop_clicked() {
@ -581,8 +559,6 @@ void lc::MainWindow::on_RBUseLocalUser_toggled(bool checked) {
}
void lc::MainWindow::SetupWidgets() {
// Set the correct initial port for the
ui->SBzLeafPort->setValue( settings->GetChosenZTreePort() );
// Fill the 'CBClientNames' with possible client names and the 'TVClients' with the clients
if ( !settings->GetClients().isEmpty() ) {
valid_items = new QVector< QStandardItem * >;
@ -637,17 +613,10 @@ void lc::MainWindow::SetupWidgets() {
if ( zTreeEntries.isEmpty() ) {
ui->CBClientNames->setEnabled( false );
ui->GBzTree->setEnabled( false );
ui->GLzLeafSettings->setEnabled( false );
ui->LFakeName->setEnabled( false );
ui->PBRunzLeaf->setEnabled( false );
ui->PBStartLocalzLeaf->setEnabled( false );
ui->PBStartzLeaf->setEnabled( false );
} else {
ui->CBzLeafVersion->addItem( "NONE" );
for ( const auto &zTreeVersionString : zTreeEntries ) {
ui->CBzLeafVersion->addItem( zTreeVersionString );
}
ui->CBzLeafVersion->setCurrentIndex( 0 );
}
// Disable the admin tab if the user has no administrative rights and set it up

@ -95,53 +95,6 @@
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="GLzLeafSettings">
<item row="0" column="0">
<widget class="QLabel" name="LzLeafVersion">
<property name="toolTip">
<string>The z-Leaf version which shall be used for the experiment.</string>
</property>
<property name="text">
<string>z-Leaf version:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QComboBox" name="CBzLeafVersion">
<property name="toolTip">
<string>The z-Leaf version which shall be used for the experiment.</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="LzLeafPort">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The port which will be used by started z-Leaf instances. Only matters if multiple experiments shall be run in parallel.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Port</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="SBzLeafPort">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The port which will be used by started z-Leaf instances. Only matters if multiple experiments shall be run in parallel.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="minimum">
<number>7000</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>7000</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="PBStartzLeaf">
<property name="toolTip">

@ -80,8 +80,8 @@ lc::SessionStarter::SessionStarter( const QVector< quint16 > &argOccupiedPorts,
QStandardItem *item = new QStandardItem( s->name );
item->setEditable( false );
const QString sessionPort{ s->GetSessionPort() };
if ( sessionPort.isEmpty() ) {
const QString sessionPort{ QString::number( s->GetSessionPort() ) };
if ( sessionPort == "0" ) {
item->setText( s->name );
} else {
item->setBackground( QBrush{ QColor{ 196, 196, 255 } } );
@ -173,7 +173,7 @@ void lc::SessionStarter::on_PBStartSession_clicked() {
for ( auto cit = activatedItems.cbegin(); cit != activatedItems.cend(); ++cit ) {
if ( ( *cit ).data( Qt::DisplayRole ).type() != 0 ) {
Client *client = static_cast< Client* >( ( *cit ).data( Qt::UserRole ).value< void* >() );
client->SetSessionPort( QString::number( ui->SBPort->value() ) );
client->SetSessionPort( ui->SBPort->value() );
client->SetzLeafVersion( ui->CBzTreeVersion->currentText() );
associatedClients.append( client );
}

Loading…
Cancel
Save