Salome HOME
Update copyrights 2014.
[modules/jobmanager.git] / src / genericgui / BL_JobsManager_QT.cxx
index 9b53f94031aabd2f226882d4e5998782b10ab6b1..6561025bc4e38c192ad71ff9ba38526ca898e286 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2009-2013  CEA/DEN, EDF R&D
+// Copyright (C) 2009-2014  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 #include "BL_JobsManager_QT.hxx"
 #include "BL_GenericGui.hxx"
+#include <vector>
+
+using namespace std;
+
+// To tokenize a string
+static void Tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters = " ");
 
 BL::JobManagerEvent::JobManagerEvent(const std::string & action_i, 
                                     const std::string & event_name_i, 
@@ -88,6 +94,7 @@ BL::JobsManager_QT::JobsManager_QT(QWidget * parent, BL::GenericGui * main_gui,
   scroll_widget->setWidgetResizable(true);
   setWidget(scroll_widget);
   setWindowTitle("Job Manager");
+  setObjectName("JobManagerDockWidget");
 }
 
 BL::JobsManager_QT::~JobsManager_QT()
@@ -288,10 +295,27 @@ BL::JobsManager_QT::create_job_with_wizard(BL::CreateJobWizard & wizard)
   // For all jobs
   new_job->setEnvFile(wizard.env_file);
   BL::Job::BatchParam param;
-  param.batch_directory = wizard.batch_directory;
+
+  // For COORM
+  if (wizard.coorm_batch_directory != "")
+  {
+       param.batch_directory = wizard.coorm_batch_directory;
+  }
+  else if (wizard.batch_directory != "")
+  {
+       param.batch_directory = wizard.batch_directory;
+  }
+
   param.maximum_duration = wizard.maximum_duration;
-  param.expected_memory = wizard.expected_memory;
+  param.mem_limit = wizard.mem_limit;
+  param.mem_req_type = wizard.mem_req_type;
   param.nb_proc = wizard.nb_proc;
+  param.exclusive = wizard.exclusive;
+
+  // Parameters for COORM
+  param.launcher_file = wizard.launcher_file;
+  param.launcher_args = wizard.launcher_args;
+
   new_job->setBatchParameters(param);
   BL::Job::FilesParam files_params;
   files_params.result_directory = wizard.result_directory;
@@ -447,6 +471,33 @@ BL::JobsManager_QT::event(QEvent * e)
       write_error_text(" ***\n");
     }
   }
+  else if (event->action == "get_assigned_hostnames")
+  {
+    if (event->event_name == "Ok")
+    {
+      QString str((event->job_name).c_str());
+
+         vector<string> hostnames;
+
+         Tokenize(event->data, hostnames, "+");
+
+         vector<string>::iterator it;
+
+      write_normal_text("Job " + str + " assigned hostnames are :\n");
+
+         for (it = hostnames.begin(); it < hostnames.end(); it++)
+         {
+                 vector<string> hostname;
+                 Tokenize(*it, hostname, ".");
+                 QString assigned_hostname(hostname[0].c_str());
+                 write_normal_text("+ " + assigned_hostname + "\n");
+         }
+    }
+    else
+    {
+               // Do nothing in case the batch manager does not support this
+    }
+  }
   else if (event->action == "save_jobs")
   {
     if (event->event_name == "Error")
@@ -522,3 +573,22 @@ BL::JobsManager_QT::write_error_text(const QString & text)
   _log->setTextCursor(cursor);
   _log->setReadOnly(true);
 }
+
+// To tokenize a string
+void Tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters)
+{
+       // Skip delimiters at beginning.
+       string::size_type lastPos = str.find_first_not_of(delimiters, 0);
+       // Find first "non-delimiter".
+       string::size_type pos     = str.find_first_of(delimiters, lastPos);
+
+       while (string::npos != pos || string::npos != lastPos)
+       {
+               // Found a token, add it to the vector.
+               tokens.push_back(str.substr(lastPos, pos - lastPos));
+               // Skip delimiters.  Note the "not_of"
+               lastPos = str.find_first_not_of(delimiters, pos);
+               // Find next "non-delimiter"
+               pos = str.find_first_of(delimiters, lastPos);
+       }
+}