Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/kernel.git] / src / ResourcesManager / SALOME_ResourcesManager.hxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 #ifndef __SALOME_RESOURCESMANAGER_HXX__
21 #define __SALOME_RESOURCESMANAGER_HXX__
22
23 #include "Utils_SALOME_Exception.hxx"
24 #include "utilities.h"
25 #include <SALOMEconfig.h>
26 #include "SALOME_ResourcesCatalog_Handler.hxx"
27 #include "SALOME_LoadRateManager.hxx"
28 #include "SALOME_NamingService.hxx"
29 #include CORBA_CLIENT_HEADER(SALOME_ContainerManager)
30 #include <string>
31 #include <fstream>
32 #include <vector>
33
34
35
36 #if defined RESOURCESMANAGER_EXPORTS
37 #if defined WIN32
38 #define RESOURCESMANAGER_EXPORT __declspec( dllexport )
39 #else
40 #define RESOURCESMANAGER_EXPORT
41 #endif
42 #else
43 #if defined WNT
44 #define RESOURCESMANAGER_EXPORT __declspec( dllimport )
45 #else
46 #define RESOURCESMANAGER_EXPORT
47 #endif
48 #endif
49
50 // --- WARNING ---
51 // The call of BuildTempFileToLaunchRemoteContainer and RmTmpFile must be done
52 // in a critical section to be sure to be clean.
53 // Only one thread should use the SALOME_ResourcesManager class in a SALOME
54 // session.
55
56 class RESOURCESMANAGER_EXPORT SALOME_ResourcesManager
57   {
58
59   public:
60
61     SALOME_ResourcesManager(CORBA::ORB_ptr orb, const char *xmlFilePath);
62     SALOME_ResourcesManager(CORBA::ORB_ptr orb);
63
64     ~SALOME_ResourcesManager();
65
66     std::vector<std::string>
67     GetFittingResources(const Engines::MachineParameters& params,
68                         const char *moduleName)
69     throw(SALOME_Exception);
70
71     std::string FindBest(const Engines::MachineList& listOfMachines);
72
73     std::string BuildCommandToLaunchRemoteContainer
74     (const std::string& machine,
75      const Engines::MachineParameters& params, const long id);
76
77     std::string BuildCommandToLaunchLocalContainer
78     (const Engines::MachineParameters& params, const long id);
79
80     void RmTmpFile();
81
82     std::string BuildCommand(const std::string& machine,
83                              const char *containerName);
84
85     int AddResourceInCatalog
86     (const Engines::MachineParameters& paramsOfNewResources,
87      const std::map<std::string, std::string>& modulesOnNewResources,
88      const char *environPathOfPrerequired,
89      const char *alias,
90      const char *userName,
91      AccessModeType mode,
92      AccessProtocolType prot)
93     throw(SALOME_Exception);
94
95     void DeleteResourceInCatalog(const char *hostname);
96
97     void WriteInXmlFile();
98
99     const MapOfParserResourcesType& ParseXmlFile();
100
101     const MapOfParserResourcesType& GetList() const;
102
103   protected:
104     SALOME_NamingService *_NS;
105
106     std::string BuildTempFileToLaunchRemoteContainer
107     (const std::string& machine,
108      const Engines::MachineParameters& params);
109
110     void SelectOnlyResourcesWithOS(std::vector<std::string>& hosts,
111                                    const char *OS) const
112       throw(SALOME_Exception);
113
114     void KeepOnlyResourcesWithModule(std::vector<std::string>& hosts,
115                                      const char *moduleName) const
116       throw(SALOME_Exception);
117
118     void AddOmninamesParams(std::string& command) const;
119
120     void AddOmninamesParams(std::ofstream& fileStream) const;
121
122     std::string BuildTemporaryFileName() const;
123
124
125     //! will contain the path to the ressources catalog
126     QString _path_resources;
127
128     //! attribute that contains current tmp files generated
129     std::string _TmpFileName;
130
131     //! contains the rsh or ssh command to access directly to machine.
132     //  Only used by this->RmTmpFile in case of a remote launch.
133     std::string _CommandForRemAccess;
134
135     //! will contain the informations on the data type catalog(after parsing)
136     MapOfParserResourcesType _resourcesList;
137
138     SALOME_LoadRateManager _dynamicResourcesSelecter;
139
140     //! different behaviour if $APPLI exists (SALOME Application) 
141     bool _isAppliSalomeDefined;
142   };
143
144 #endif // RESSOURCESCATALOG_IMPL_H