From 3a168feaec0c3a5086831da3718bfcb1c89c1dbc Mon Sep 17 00:00:00 2001 From: ribes Date: Tue, 11 Oct 2011 16:02:26 +0000 Subject: [PATCH] Adding new button: stop Bug Tracker PAL: #1960 --- src/engine/BL_JobsManager.cxx | 55 ++++++++++++++++++++ src/engine/BL_JobsManager.hxx | 4 ++ src/engine/BL_SALOMEServices.cxx | 26 ++++++++++ src/engine/BL_SALOMEServices.hxx | 1 + src/genericgui/BL_Buttons.cxx | 75 ++++++++++++++++++++-------- src/genericgui/BL_Buttons.hxx | 7 ++- src/genericgui/BL_GenericGui.cxx | 37 ++++++++++++-- src/genericgui/BL_GenericGui.hxx | 2 + src/genericgui/BL_JobsManager_QT.cxx | 16 ++++++ 9 files changed, 197 insertions(+), 26 deletions(-) diff --git a/src/engine/BL_JobsManager.cxx b/src/engine/BL_JobsManager.cxx index 9eee2ae..071154a 100644 --- a/src/engine/BL_JobsManager.cxx +++ b/src/engine/BL_JobsManager.cxx @@ -202,6 +202,55 @@ BL::JobsManager::starting_job_thread(void * object_ptr) object->_thread_mutex_jobs_map.unlock(); } +void +BL::JobsManager::stop_job(const std::string & name) +{ + DEBTRACE("stop_job BL::JobsManager called"); + + _thread_mutex_jobs_map.lock(); + // Check job exits + _jobs_it = _jobs.find(name); + if (_jobs_it == _jobs.end()) + { + DEBTRACE("BL::JobsManager::stop_job job unknown: " << name); + _thread_mutex_jobs_map.unlock(); + return; + } + else + { + // Prepare Info for thread + BL::JobsManager::thread_info * ti = new thread_info(); + ti->object_ptr = this; + ti->job_name = name; + omni_thread::create(BL::JobsManager::stop_job_thread, ti); + } +} + +void +BL::JobsManager::stop_job_thread(void * object_ptr) +{ + DEBTRACE("stop_job_thread BL::JobsManager called"); + BL::JobsManager::thread_info * ti = reinterpret_cast(object_ptr); + BL::JobsManager * object = ti->object_ptr; + std::string job_name = ti->job_name; + BL::Job * job = object->getJob(job_name); + + std::string result = object->_salome_services->stop_job(job); + + // End + if (result == "") + { + if (object->_observer) + object->_observer->sendEvent("stop_job", "Ok", job_name, ""); + } + else + { + if (object->_observer) + object->_observer->sendEvent("stop_job", "Error", job_name, result); + } + object->_thread_mutex_jobs_map.unlock(); +} + void BL::JobsManager::refresh_jobs() { @@ -401,6 +450,12 @@ BL::JobsManager::launcher_event_new_job(const std::string & data) } } +void +BL::JobsManager::launcher_event_update_job_state(const std::string & data) +{ + refresh_jobs(); +} + void BL::JobsManager::launcher_event_new_job_thread(void * object_ptr) { diff --git a/src/engine/BL_JobsManager.hxx b/src/engine/BL_JobsManager.hxx index 37ce936..e782551 100644 --- a/src/engine/BL_JobsManager.hxx +++ b/src/engine/BL_JobsManager.hxx @@ -56,6 +56,9 @@ namespace BL{ virtual void start_job(const std::string & name); static void starting_job_thread(void * object_ptr); + virtual void stop_job(const std::string & name); + static void stop_job_thread(void * object_ptr); + virtual void get_results_job(const std::string & name); static void get_results_job_thread(void * object_ptr); @@ -74,6 +77,7 @@ namespace BL{ static void launcher_event_new_job_thread(void * object_ptr); void launcher_event_remove_job(const std::string & data); static void launcher_event_remove_job_thread(void * object_ptr); + void launcher_event_update_job_state(const std::string & data); struct thread_info { diff --git a/src/engine/BL_SALOMEServices.cxx b/src/engine/BL_SALOMEServices.cxx index 1b05577..0fb24e0 100644 --- a/src/engine/BL_SALOMEServices.cxx +++ b/src/engine/BL_SALOMEServices.cxx @@ -409,6 +409,28 @@ BL::SALOMEServices::delete_job(BL::Job * job) return ret; } +std::string +BL::SALOMEServices::stop_job(BL::Job * job) +{ + std::string ret = ""; + try + { + _salome_launcher->stopJob(job->getSalomeLauncherId()); + } + catch (const SALOME::SALOME_Exception & ex) + { + DEBMSG("SALOME Exception in stopJob !"); + ret = ex.details.text.in(); + } + catch (const CORBA::SystemException& ex) + { + DEBMSG("Receive SALOME System Exception: " << ex); + DEBMSG("Check SALOME servers..."); + ret = "SALOME System Exception - see logs"; + } + return ret; +} + std::string BL::SALOMEServices::get_results_job(BL::Job * job) { @@ -506,6 +528,10 @@ BL::SALOMEServices::notify(const char* event_name, const char * event_data) { _manager->launcher_event_remove_job(data); } + else if (event == "UPDATE_JOB_STATE") + { + _manager->launcher_event_update_job_state(data); + } else { DEBMSG("Unkown launcher event received"); diff --git a/src/engine/BL_SALOMEServices.hxx b/src/engine/BL_SALOMEServices.hxx index 7c8eb55..83295b5 100644 --- a/src/engine/BL_SALOMEServices.hxx +++ b/src/engine/BL_SALOMEServices.hxx @@ -82,6 +82,7 @@ namespace BL{ std::string start_job(BL::Job * job); std::string refresh_job(BL::Job * job); std::string delete_job(BL::Job * job); + std::string stop_job(BL::Job * job); std::string get_results_job(BL::Job * job); BL::Job * get_new_job(int job_number); diff --git a/src/genericgui/BL_Buttons.cxx b/src/genericgui/BL_Buttons.cxx index a4c716e..a677db3 100644 --- a/src/genericgui/BL_Buttons.cxx +++ b/src/genericgui/BL_Buttons.cxx @@ -19,37 +19,50 @@ #include "BL_Buttons.hxx" -BL::Buttons::Buttons(QWidget * parent) : QGroupBox(parent) +BL::Buttons::Buttons(QWidget * parent) : QWidget(parent) { DEBTRACE("Creating BL::Buttons"); - setTitle("Actions"); + _create_button = new QPushButton("Create", this); + _start_button = new QPushButton("Start", this); + _get_results_button = new QPushButton("Get Results", this); - _create_button = new QPushButton("Create a Job", this); - _edit_clone_button = new QPushButton("Edit/Clone a Job", this); - _start_button = new QPushButton("Start a Job", this); - _restart_button = new QPushButton("Restart a Job", this); - _delete_button = new QPushButton("Delete a Job", this); - _get_results_button = new QPushButton("Get Job Results", this); - _refresh_button = new QPushButton("Refresh Jobs", this); + _stop_button = new QPushButton("Stop", this); + _delete_button = new QPushButton("Delete", this); + _restart_button = new QPushButton("Restart", this); + _edit_clone_button = new QPushButton("Edit/Clone", this); + + _refresh_button = new QPushButton("Refresh Jobs", this); + + QGroupBox * main_buttons = new QGroupBox(this); + main_buttons->setTitle("Main"); QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addWidget(_create_button); - mainLayout->addWidget(_edit_clone_button); mainLayout->addWidget(_start_button); - mainLayout->addWidget(_restart_button); - mainLayout->addWidget(_delete_button); mainLayout->addWidget(_get_results_button); - mainLayout->addWidget(_refresh_button); - mainLayout->setSpacing(0); // Space between buttons - - setLayout(mainLayout); - - //QSizePolicy poli; - //poli.setControlType(QSizePolicy::PushButton); - //poli.setVerticalPolicy(QSizePolicy::Fixed); - //poli.setHorizontalPolicy(QSizePolicy::Fixed); - //setSizePolicy(poli); + main_buttons->setLayout(mainLayout); + + QGroupBox * manage_buttons = new QGroupBox(this); + manage_buttons->setTitle("Management"); + QHBoxLayout *manageLayout = new QHBoxLayout; + manageLayout->addWidget(_stop_button); + manageLayout->addWidget(_delete_button); + manageLayout->addWidget(_restart_button); + manageLayout->addWidget(_edit_clone_button); + manage_buttons->setLayout(manageLayout); + + QGroupBox * refresh_buttons = new QGroupBox(this); + refresh_buttons->setTitle("Refresh"); + QHBoxLayout *refreshLayout = new QHBoxLayout; + refreshLayout->addWidget(_refresh_button); + refresh_buttons->setLayout(refreshLayout); + + QGridLayout * gridLayout = new QGridLayout; + gridLayout->addWidget(main_buttons, 0 ,0); + gridLayout->addWidget(manage_buttons, 0 ,1); + gridLayout->addWidget(refresh_buttons, 0 , 2); + setLayout(gridLayout); } BL::Buttons::~Buttons() @@ -81,6 +94,12 @@ BL::Buttons::setReStartButtonSlot(QObject * receiver, const char * name) connect(_restart_button, SIGNAL(clicked()), receiver, name); } +void +BL::Buttons::setStopButtonSlot(QObject * receiver, const char * name) +{ + connect(_stop_button, SIGNAL(clicked()), receiver, name); +} + void BL::Buttons::setDeleteButtonSlot(QObject * receiver, const char * name) { @@ -135,6 +154,18 @@ BL::Buttons::disable_restart_button() _restart_button->setEnabled(false); } +void +BL::Buttons::enable_stop_button() +{ + _stop_button->setEnabled(true); +} + +void +BL::Buttons::disable_stop_button() +{ + _stop_button->setEnabled(false); +} + void BL::Buttons::enable_delete_button() { diff --git a/src/genericgui/BL_Buttons.hxx b/src/genericgui/BL_Buttons.hxx index 8ec8ec0..b4be4a4 100644 --- a/src/genericgui/BL_Buttons.hxx +++ b/src/genericgui/BL_Buttons.hxx @@ -26,7 +26,7 @@ namespace BL { - class Buttons: public QGroupBox + class Buttons: public QWidget { Q_OBJECT @@ -38,6 +38,7 @@ namespace BL void setEditCloneButtonSlot(QObject * receiver, const char * name); void setStartButtonSlot(QObject * receiver, const char * name); void setReStartButtonSlot(QObject * receiver, const char * name); + void setStopButtonSlot(QObject * receiver, const char * name); void setDeleteButtonSlot(QObject * receiver, const char * name); void setRefreshButtonSlot(QObject * receiver, const char * name); void setGetResultsButtonSlot(QObject * receiver, const char * name); @@ -51,6 +52,9 @@ namespace BL void enable_restart_button(); void disable_restart_button(); + void enable_stop_button(); + void disable_stop_button(); + void enable_delete_button(); void disable_delete_button(); @@ -65,6 +69,7 @@ namespace BL QPushButton * _delete_button; QPushButton * _get_results_button; QPushButton * _refresh_button; + QPushButton * _stop_button; }; } diff --git a/src/genericgui/BL_GenericGui.cxx b/src/genericgui/BL_GenericGui.cxx index 3254484..f626d38 100644 --- a/src/genericgui/BL_GenericGui.cxx +++ b/src/genericgui/BL_GenericGui.cxx @@ -106,6 +106,7 @@ BL::GenericGui::createCentralWidget() _buttons->setStartButtonSlot(this, SLOT(start_job())); _buttons->setReStartButtonSlot(this, SLOT(restart_job())); _buttons->setDeleteButtonSlot(this, SLOT(delete_job())); + _buttons->setStopButtonSlot(this, SLOT(stop_job())); _buttons->setRefreshButtonSlot(this, SLOT(refresh_job())); _buttons->setGetResultsButtonSlot(this, SLOT(get_results_job())); @@ -186,6 +187,7 @@ BL::GenericGui::createActions() _delete_job_action = _wrapper->createAction("Delete a Job", QIcon(), "Delete a Job", "Delete a Job", 0, _dock_parent, false, this, SLOT(delete_job())); _refresh_job_action = _wrapper->createAction("Refresh Jobs", QIcon(), "Refresh Jobs", "Refresh Jobs", 0, _dock_parent, false, this, SLOT(refresh_job())); _get_results_job_action = _wrapper->createAction("Get Job Results", QIcon(), "Get Job Results", "Get Job Results", 0, _dock_parent, false, this, SLOT(refresh_job())); + _stop_job_action = _wrapper->createAction("Stop a Job", QIcon(), "Stop a Job", "Stop a Job", 0, _dock_parent, false, this, SLOT(stop_job())); } void @@ -197,6 +199,7 @@ BL::GenericGui::createMenus() _wrapper->addActionToMenu(_edit_clone_job_action, menu_id); _wrapper->addActionToMenu(_start_job_action, menu_id); _wrapper->addActionToMenu(_restart_job_action, menu_id); + _wrapper->addActionToMenu(_stop_job_action, menu_id); _wrapper->addActionToMenu(_delete_job_action, menu_id); _wrapper->addActionToMenu(_get_results_job_action, menu_id); _wrapper->addActionToMenu(_refresh_job_action, menu_id); @@ -246,13 +249,21 @@ BL::GenericGui::get_results_job() _jobs_manager->get_results_job(_job_name_selected.toStdString()); } +void +BL::GenericGui::stop_job() +{ + DEBTRACE("Stop Job Slot BL::GenericGui"); + _jobs_manager->stop_job(_job_name_selected.toStdString()); +} + + void BL::GenericGui::delete_job() { DEBTRACE("Delete Job Slot BL::GenericGui"); int ret = QMessageBox::warning(NULL, "Delete a job", "Do you really want to delete this job ?", - QMessageBox::Ok|QMessageBox::Cancel, - QMessageBox::Ok); + QMessageBox::Ok|QMessageBox::Cancel, + QMessageBox::Ok); if (ret == QMessageBox::Ok) { delete_job_internal(); @@ -319,6 +330,8 @@ BL::GenericGui::updateButtonsStates() _buttons->disable_edit_clone_button(); _restart_job_action->setEnabled(false); _buttons->disable_restart_button(); + _stop_job_action->setEnabled(false); + _buttons->disable_stop_button(); } else if (_job_name_selected != "" and _row_selected != -1) { @@ -338,6 +351,8 @@ BL::GenericGui::updateButtonsStates() _buttons->disable_get_results_button(); _restart_job_action->setEnabled(false); _buttons->disable_restart_button(); + _stop_job_action->setEnabled(false); + _buttons->disable_stop_button(); break; case BL::Job::IN_PROCESS: @@ -349,6 +364,8 @@ BL::GenericGui::updateButtonsStates() _buttons->disable_get_results_button(); _restart_job_action->setEnabled(false); _buttons->disable_restart_button(); + _stop_job_action->setEnabled(false); + _buttons->disable_stop_button(); break; case BL::Job::QUEUED: @@ -360,6 +377,8 @@ BL::GenericGui::updateButtonsStates() _buttons->disable_get_results_button(); _restart_job_action->setEnabled(false); _buttons->disable_restart_button(); + _stop_job_action->setEnabled(true); + _buttons->enable_stop_button(); break; case BL::Job::RUNNING: @@ -371,6 +390,8 @@ BL::GenericGui::updateButtonsStates() _buttons->disable_get_results_button(); _restart_job_action->setEnabled(false); _buttons->disable_restart_button(); + _stop_job_action->setEnabled(true); + _buttons->enable_stop_button(); break; case BL::Job::PAUSED: @@ -382,6 +403,8 @@ BL::GenericGui::updateButtonsStates() _buttons->disable_get_results_button(); _restart_job_action->setEnabled(false); _buttons->disable_restart_button(); + _stop_job_action->setEnabled(true); + _buttons->enable_stop_button(); break; case BL::Job::ERROR: @@ -393,6 +416,8 @@ BL::GenericGui::updateButtonsStates() _buttons->disable_get_results_button(); _restart_job_action->setEnabled(true); _buttons->enable_restart_button(); + _stop_job_action->setEnabled(false); + _buttons->disable_stop_button(); break; case BL::Job::FINISHED: @@ -404,6 +429,8 @@ BL::GenericGui::updateButtonsStates() _buttons->enable_get_results_button(); _restart_job_action->setEnabled(true); _buttons->enable_restart_button(); + _stop_job_action->setEnabled(false); + _buttons->disable_stop_button(); break; case BL::Job::FAILED: @@ -412,9 +439,11 @@ BL::GenericGui::updateButtonsStates() _delete_job_action->setEnabled(true); _buttons->enable_delete_button(); _get_results_job_action->setEnabled(true); - _buttons->disable_get_results_button(); + _buttons->enable_get_results_button(); _restart_job_action->setEnabled(true); _buttons->enable_restart_button(); + _stop_job_action->setEnabled(false); + _buttons->disable_stop_button(); break; case BL::Job::NOT_CREATED: @@ -426,6 +455,8 @@ BL::GenericGui::updateButtonsStates() _buttons->disable_get_results_button(); _restart_job_action->setEnabled(true); _buttons->enable_restart_button(); + _stop_job_action->setEnabled(false); + _buttons->disable_stop_button(); break; } } diff --git a/src/genericgui/BL_GenericGui.hxx b/src/genericgui/BL_GenericGui.hxx index c5f2460..9cfeceb 100644 --- a/src/genericgui/BL_GenericGui.hxx +++ b/src/genericgui/BL_GenericGui.hxx @@ -66,6 +66,7 @@ namespace BL void restart_job(); void delete_job(); void refresh_job(); + void stop_job(); void get_results_job(); void job_selected(const QModelIndex & index); void job_state_changed(const QString & name); @@ -95,6 +96,7 @@ namespace BL QAction * _start_job_action; QAction * _restart_job_action; QAction * _delete_job_action; + QAction * _stop_job_action; QAction * _get_results_job_action; QAction * _refresh_job_action; diff --git a/src/genericgui/BL_JobsManager_QT.cxx b/src/genericgui/BL_JobsManager_QT.cxx index b157c46..b9f9bf6 100644 --- a/src/genericgui/BL_JobsManager_QT.cxx +++ b/src/genericgui/BL_JobsManager_QT.cxx @@ -425,6 +425,22 @@ BL::JobsManager_QT::event(QEvent * e) write_error_text(" ***\n"); } } + else if (event->action == "stop_job") + { + if (event->event_name == "Ok") + { + QString str((event->job_name).c_str()); + write_normal_text("Job " + str + " is stopped\n"); + } + else + { + QString str((event->job_name).c_str()); + write_error_text("Error when trying to stop job: " + str + "\n"); + write_error_text("*** "); + write_error_text((event->data).c_str()); + write_error_text(" ***\n"); + } + } else if (event->action == "save_jobs") { if (event->event_name == "Error") -- 2.39.2