Salome HOME
Revert "Synchronize adm files"
[modules/kernel.git] / src / Launcher / Launcher.hxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef __LAUNCHER_HXX__
24 #define __LAUNCHER_HXX__
25
26 #include "Launcher_Utils.hxx"
27 #include "Launcher_Job.hxx"
28
29 #include "ResourcesManager.hxx"
30 #include <SALOME_ResourcesCatalog_Parser.hxx>
31
32 #include "SALOME_Launcher_Parser.hxx"
33
34 #include <string>
35 #include <vector>
36 #include <list>
37
38 #include <pthread.h>
39
40 class MpiImpl;
41
42 namespace Batch{
43   class BatchManager;
44   class Job;
45 }
46
47 struct batchParams{
48   std::string batch_directory;
49   std::string expected_during_time;
50   std::string mem;
51   unsigned long nb_proc;
52
53   // Parameters for COORM
54   std::string launcher_file;
55   std::string launcher_args;
56 };
57
58 class LAUNCHER_EXPORT Launcher_cpp
59 {
60
61 public:
62   Launcher_cpp();
63   virtual ~Launcher_cpp();
64
65   // Main interface
66   void         createJob(Launcher::Job * new_job);
67   void         launchJob(int job_id);
68   const char * getJobState(int job_id);
69   const char * getAssignedHostnames(int job_id); // Get names or ids of hosts assigned to the job
70   void         getJobResults(int job_id, std::string directory);
71   bool         getJobDumpState(int job_id, std::string directory);
72   void         stopJob(int job_id);
73   void         removeJob(int job_id);
74
75   /*! Load the jobs from the file "jobs_file" and add them to the Launcher.
76    *  Return a list with the IDs of the jobs that were successfully loaded.
77    */
78   std::list<int> loadJobs(const char* jobs_file);
79
80   //! Save the jobs of the Launcher to the file "jobs_file".
81   void saveJobs(const char* jobs_file);
82
83   // Useful methods
84   long createJobWithFile(std::string xmlExecuteFile, std::string clusterName);
85   std::map<int, Launcher::Job *> getJobs();
86   void createBatchManagerForJob(Launcher::Job * job);
87   void addJobDirectlyToMap(Launcher::Job * new_job);
88
89   // Lib methods
90   void SetResourcesManager( ResourcesManager_cpp* rm ) {_ResManager = rm;}
91
92   // Used by SALOME_Launcher
93   ResourcesManager_cpp *_ResManager;
94 protected:
95
96   virtual void notifyObservers(const std::string & event_name, const std::string & event_data) {}
97
98   // Methods used by user interface methods
99 #ifdef WITH_LIBBATCH
100   Batch::BatchManager *FactoryBatchManager(ParserResourcesType& params);
101   std::map <int, Batch::BatchManager*> _batchmap;
102 #endif
103   ParserLauncherType ParseXmlFile(std::string xmlExecuteFile);
104
105   std::map <int, Launcher::Job *> _launcher_job_map;  
106   int _job_cpt; // job number counter
107   pthread_mutex_t * _job_cpt_mutex; // mutex for job counter
108 };
109
110 #endif