Salome HOME
8a60afb495fccc580990ed7c0a8756f6b62fe007
[modules/jobmanager.git] / src / engine / BL_JobsManager.hxx
1 // Copyright (C) 2009-2016  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef _BL_JOBSMANAGER_HXX_
21 #define _BL_JOBSMANAGER_HXX_
22
23 #include "BL_Engine.hxx"
24 #include "BL_Job.hxx"
25 #include "BL_SALOMEServices.hxx"
26 #include "BL_Traces.hxx"
27 #include "BL_Observer.hxx"
28
29 #include <map>
30 #include <string>
31
32 #include <omnithread.h>
33
34 namespace BL{
35
36   class SALOMEServices;
37
38   class BL_Engine_EXPORT JobsManager
39   {
40     public:
41       JobsManager(BL::SALOMEServices * salome_services);
42       virtual ~JobsManager();
43
44       // Add QT observer
45       void setObserver(BL::Observer * observer);
46
47       // useful methods
48       BL::Job * createJob(const std::string & name);
49       BL::Job * getJob(const std::string & name);
50       std::map<std::string, BL::Job *> & getJobs();
51       bool job_already_exist(const std::string & name);
52
53       // remote methods
54       void addJobToLauncher(const std::string & name);
55       void removeJob(const std::string & name);
56
57       virtual void start_job(const std::string & name);
58       static void starting_job_thread(void * object_ptr);
59
60       virtual void stop_job(const std::string & name);
61       static void stop_job_thread(void * object_ptr);
62
63       virtual void get_results_job(const std::string & name);
64       static void get_results_job_thread(void * object_ptr);
65
66       virtual void refresh_jobs();
67       static void refresh_jobs_thread(void * object_ptr);
68
69       virtual void load_jobs(const std::string & xml_file);
70       virtual void save_jobs(const std::string & xml_file);
71       static void load_jobs_thread(void * object_ptr);
72       static void save_jobs_thread(void * object_ptr);
73
74       // event from launcher
75       void launcher_event_save_jobs(const std::string & data);
76       void launcher_event_load_jobs(const std::string & data);
77       void launcher_event_new_job(const std::string & data);
78       static void launcher_event_new_job_thread(void * object_ptr);
79       void launcher_event_remove_job(const std::string & data);
80       static void launcher_event_remove_job_thread(void * object_ptr);
81       void launcher_event_update_job_state(const std::string & data);
82
83       struct thread_info
84       {
85         BL::JobsManager * object_ptr;
86         std::string job_name;
87       };
88
89       struct thread_info_file
90       {
91         BL::JobsManager * object_ptr;
92         std::string file_name;
93       };
94
95       struct thread_info_new_job
96       {
97         BL::JobsManager * object_ptr;
98         int job_number;
99       };
100
101     protected:
102       BL::SALOMEServices * _salome_services;
103       BL::Observer * _observer;
104
105     private:
106       typedef std::map<std::string, BL::Job *> _jobs_map;
107       _jobs_map _jobs;
108       _jobs_map::iterator _jobs_it;
109
110       // Mutex used for the jobs map
111       omni_mutex _thread_mutex_jobs_map;
112
113       // To avoid two jobs with the same name
114       int _name_counter;
115   };
116
117 }
118
119 #endif
120