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

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

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

@ -84,7 +84,7 @@ public:
@return The current state of the client @return The current state of the client
*/ */
state_t GetClientState() const { return state; } 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 * \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) * \param argOpenAsRoot Run the terminal session as root (true) or as normal user (false)
*/ */
void OpenTerminal( const QString &argCommand, const bool &argOpenAsRoot ); 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; } void SetzLeafVersion( const QString &argzLeafV ) { zLeafVersion = argzLeafV; }
//! Shows the desktop of the given client //! Shows the desktop of the given client
void ShowDesktop(); void ShowDesktop();
@ -110,20 +110,19 @@ public:
void Shutdown(); void Shutdown();
//! 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 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) @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, void StartZLeaf( const QString * const argFakeName = nullptr );
const QString * const argFakeName = nullptr );
private: private:
const QString &GetzLeafVersion() const { return zLeafVersion; }
unsigned short int protectedCycles; unsigned short int protectedCycles;
ClientPinger *pinger = nullptr; ClientPinger *pinger = nullptr;
QThread pingerThread; QThread pingerThread;
state_t state = state_t::UNINITIALIZED; state_t state = state_t::UNINITIALIZED;
QTimer *pingTimer = nullptr; //! QTimer used to trigger pings by pinger's ClientPinger instance QTimer *pingTimer = nullptr; //! QTimer used to trigger pings by pinger's ClientPinger instance
QString sessionPort; int sessionPort = 0;
QString zLeafVersion; QString zLeafVersion;
private slots: private slots:

@ -439,15 +439,6 @@ void lc::MainWindow::on_PBPrintPaymentFileManually_clicked() {
} }
void lc::MainWindow::on_PBRunzLeaf_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 // Check if more than one client is selected and issue a warning message if so
unsigned short int numberOfSelectedClients = 0; unsigned short int numberOfSelectedClients = 0;
QModelIndexList activatedItems = ui->TVClients->selectionModel()->selectedIndexes(); QModelIndexList activatedItems = ui->TVClients->selectionModel()->selectedIndexes();
@ -462,16 +453,13 @@ void lc::MainWindow::on_PBRunzLeaf_clicked() {
messageBox.exec(); messageBox.exec();
} else { } else {
const QString * const fakeName = new QString{ ui->CBClientNames->currentText() }; 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 ) { 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->StartZLeaf( zLeafVersion, ui->SBzLeafPort->value(), client->StartZLeaf( fakeName );
fakeName );
} }
} }
delete fakeName; delete fakeName;
delete zLeafVersion;
} }
} }
@ -545,23 +533,13 @@ void lc::MainWindow::on_PBStartSession_clicked() {
} }
void lc::MainWindow::on_PBStartzLeaf_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(); 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 ) { 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->StartZLeaf( zLeafVersion, ui->SBzLeafPort->value(), client->StartZLeaf( nullptr );
nullptr );
} }
} }
delete zLeafVersion;
} }
void lc::MainWindow::on_PBViewDesktop_clicked() { void lc::MainWindow::on_PBViewDesktop_clicked() {
@ -581,8 +559,6 @@ void lc::MainWindow::on_RBUseLocalUser_toggled(bool checked) {
} }
void lc::MainWindow::SetupWidgets() { 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 // Fill the 'CBClientNames' with possible client names and the 'TVClients' with the clients
if ( !settings->GetClients().isEmpty() ) { if ( !settings->GetClients().isEmpty() ) {
valid_items = new QVector< QStandardItem * >; valid_items = new QVector< QStandardItem * >;
@ -637,17 +613,10 @@ void lc::MainWindow::SetupWidgets() {
if ( zTreeEntries.isEmpty() ) { if ( zTreeEntries.isEmpty() ) {
ui->CBClientNames->setEnabled( false ); ui->CBClientNames->setEnabled( false );
ui->GBzTree->setEnabled( false ); ui->GBzTree->setEnabled( false );
ui->GLzLeafSettings->setEnabled( false );
ui->LFakeName->setEnabled( false ); ui->LFakeName->setEnabled( false );
ui->PBRunzLeaf->setEnabled( false ); ui->PBRunzLeaf->setEnabled( false );
ui->PBStartLocalzLeaf->setEnabled( false ); ui->PBStartLocalzLeaf->setEnabled( false );
ui->PBStartzLeaf->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 // Disable the admin tab if the user has no administrative rights and set it up

@ -95,53 +95,6 @@
</property> </property>
</widget> </widget>
</item> </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> <item>
<widget class="QPushButton" name="PBStartzLeaf"> <widget class="QPushButton" name="PBStartzLeaf">
<property name="toolTip"> <property name="toolTip">

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

Loading…
Cancel
Save