Salome HOME
Initial commit
[modules/jobmanager.git] / src / engine / BL_JobsManager.hxx
1 //  Copyright (C) 2009 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.
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_Job.hxx"
24 #include "BL_SALOMEServices.hxx"
25 #include "BL_Traces.hxx"
26 #include "BL_Observer.hxx"
27
28 #include <map>
29 #include <string>
30
31 #include <omnithread.h>
32
33 namespace BL{
34
35   class JobsManager
36   {
37     public:
38       JobsManager(BL::SALOMEServices * salome_services);
39       virtual ~JobsManager();
40
41       void setObserver(BL::Observer * observer);
42
43       BL::Job * addNewJob(const std::string & name);
44       void removeJob(const std::string & name);
45
46       BL::Job * getJob(const std::string & name);
47       std::map<std::string, BL::Job *> & getJobs();
48
49       bool job_already_exist(const std::string & name);
50
51       virtual void start_job(const std::string & name);
52       virtual void refresh_jobs();
53       virtual void get_results_job(const std::string & name);
54
55       static void starting_job_thread(void * object_ptr);
56       static void get_results_job_thread(void * object_ptr);
57       static void refresh_job(void * object_ptr);
58
59       struct thread_info
60       {
61         BL::JobsManager * object_ptr;
62         std::string job_name;
63       };
64
65     protected:
66       BL::SALOMEServices * _salome_services;
67       BL::Observer * _observer;
68
69     private:
70       typedef std::map<std::string, BL::Job *> _jobs_map;
71       _jobs_map _jobs;
72       _jobs_map::iterator _jobs_it;
73
74       omni_mutex _thread_mutex;
75       omni_mutex _thread_mutex_results;
76   };
77
78 }
79
80 #endif
81