Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/kernel.git] / src / ResourcesManager / ResourcesManager.hxx
1 // Copyright (C) 2007-2012  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.
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 __RESOURCESMANAGER_HXX__
24 #define __RESOURCESMANAGER_HXX__
25
26 #include "ResourcesManager_Defs.hxx"
27
28 #include <string>
29 #include <fstream>
30 #include <vector>
31 #include <list>
32 #include "SALOME_ResourcesCatalog_Parser.hxx"
33 #include "SALOME_ResourcesCatalog_Handler.hxx"
34 #include "SALOME_LoadRateManager.hxx"
35 #include <sys/types.h>
36 #include <sys/stat.h>
37 #ifdef WNT
38 #else
39 #include <unistd.h>
40 #endif
41
42 #ifdef WNT
43 #pragma warning(disable:4251) // Warning DLL Interface ...
44 #pragma warning(disable:4290) // Warning Exception ...
45 #endif
46
47 // --- WARNING ---
48 // The call of BuildTempFileToLaunchRemoteContainer and RmTmpFile must be done
49 // in a critical section to be sure to be clean.
50 // Only one thread should use the SALOME_ResourcesManager class in a SALOME
51 // session.
52 struct resourceParams
53 {
54   std::string name;
55   std::string hostname;
56   std::string OS;
57   long nb_proc;
58   long nb_node;
59   long nb_proc_per_node;
60   long cpu_clock;
61   long mem_mb;
62   std::vector<std::string> componentList;
63   std::vector<std::string> resourceList;
64 };
65
66 class RESOURCESMANAGER_EXPORT ResourcesException
67 {
68 public:
69   const std::string msg;
70
71   ResourcesException(const std::string m) : msg(m) {}
72 };
73
74 class RESOURCESMANAGER_EXPORT ResourcesManager_cpp
75   {
76
77   public:
78
79     ResourcesManager_cpp(const char *xmlFilePath);
80     ResourcesManager_cpp() throw(ResourcesException);
81
82     ~ResourcesManager_cpp();
83
84     std::vector<std::string> 
85     GetFittingResources(const resourceParams& params) throw(ResourcesException);
86
87     std::string Find(const std::string& policy, 
88                      const std::vector<std::string>& listOfResources);
89
90     void AddResourceInCatalog (const ParserResourcesType & new_resource) throw(ResourcesException);
91
92     void DeleteResourceInCatalog(const char * name);
93
94     void WriteInXmlFile(std::string xml_file);
95
96     const MapOfParserResourcesType& ParseXmlFiles();
97
98     const MapOfParserResourcesType& GetList() const;
99
100     ParserResourcesType GetResourcesDescr(const std::string & name);
101
102   protected:
103     
104     void SelectOnlyResourcesWithOS(std::vector<std::string>& resources, std::string OS);
105
106     void KeepOnlyResourcesWithComponent(std::vector<std::string>& resources, 
107                                         const std::vector<std::string>& componentList);
108
109     //! will contain the path to the ressources catalog
110     std::list<std::string> _path_resources;
111     std::list<std::string>::iterator _path_resources_it;
112
113     //! will contain the informations on the data type catalog(after parsing)
114     MapOfParserResourcesType _resourcesList;
115
116     //! a map that contains all the available load rate managers (the key is the name)
117     std::map<std::string , LoadRateManager*> _resourceManagerMap;
118
119     //! contain the time where resourcesList was created
120     time_t _lasttime;
121   };
122
123 #endif // __RESOURCESMANAGER_HXX__