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()
{
}
}
+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)
{
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);
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
{
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)
{
{
_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");
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);
#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()
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)
{
_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()
{
namespace BL
{
- class Buttons: public QGroupBox
+ class Buttons: public QWidget
{
Q_OBJECT
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);
void enable_restart_button();
void disable_restart_button();
+ void enable_stop_button();
+ void disable_stop_button();
+
void enable_delete_button();
void disable_delete_button();
QPushButton * _delete_button;
QPushButton * _get_results_button;
QPushButton * _refresh_button;
+ QPushButton * _stop_button;
};
}
_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()));
_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
_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);
_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();
_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)
{
_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:
_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:
_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:
_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:
_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:
_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:
_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:
_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:
_buttons->disable_get_results_button();
_restart_job_action->setEnabled(true);
_buttons->enable_restart_button();
+ _stop_job_action->setEnabled(false);
+ _buttons->disable_stop_button();
break;
}
}
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);
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;
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")