]> SALOME platform Git repositories - modules/jobmanager.git/commitdiff
Salome HOME
Adding new button: stop
authorribes <ribes>
Tue, 11 Oct 2011 16:02:26 +0000 (16:02 +0000)
committerribes <ribes>
Tue, 11 Oct 2011 16:02:26 +0000 (16:02 +0000)
Bug Tracker PAL: #1960

src/engine/BL_JobsManager.cxx
src/engine/BL_JobsManager.hxx
src/engine/BL_SALOMEServices.cxx
src/engine/BL_SALOMEServices.hxx
src/genericgui/BL_Buttons.cxx
src/genericgui/BL_Buttons.hxx
src/genericgui/BL_GenericGui.cxx
src/genericgui/BL_GenericGui.hxx
src/genericgui/BL_JobsManager_QT.cxx

index 9eee2ae4f7be975f1e540854b17e0c2188c92993..071154ac7c45be8a23b8bb5b9c6cad091f05e8e6 100644 (file)
@@ -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<BL::JobsManager::thread_info*>(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)
 {
index 37ce93682044acfbcafe4b3fd447c02c95e5e226..e782551dd3c44ff487380171407728210be27450 100644 (file)
@@ -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
       {
index 1b05577df0258989e76e2850f863ffcd41d2efd8..0fb24e01c4d135d09146c2e90301dda9f63b69f7 100644 (file)
@@ -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");
index 7c8eb553ed303587e1f14939793ee3b18a6cac60..83295b52e0c1a54c5e4b107765ea0fdc6d59fadb 100644 (file)
@@ -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);
index a4c716e1fd369be2af7ef5af267a48cd8273e36f..a677db3abf99da6145dd63f8efbcbf7db1e0150d 100644 (file)
 
 #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()
 {
index 8ec8ec087fa008ca16d78fe7b30d0dc18f8b2cd2..b4be4a417223aea151edb33890a600ecde116f96 100644 (file)
@@ -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;
   };
 }
 
index 3254484edf01f47549ed697a1beade8921a8754a..f626d381a3921fe2f9b88e2cd45f78ef591a6747 100644 (file)
@@ -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;
     }
   }
index c5f246088cc7db973e35b6030935869ae582d226..9cfeceb1b93dace459e566d74512556d02de78c7 100644 (file)
@@ -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;
 
index b157c46f0410dfe8bbbedb842f5542abe88c9636..b9f9bf649a01a628bbd3db8596b57243b262beb1 100644 (file)
@@ -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")