Salome HOME
786c2dc17ad51dd02ccf6a75d2f1cc88b1cde7e6
[modules/kernel.git] / src / ResourcesManager / SALOME_ResourcesManager_Common.cxx
1 // Copyright (C) 2007-2020  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 #include "SALOME_ResourcesManager_Common.hxx"
24
25 using namespace std;
26
27 template <class T>
28 vector<string> strvec_CORBAtoCPP(const T & strvecCorba)
29 {
30   vector<string> strvecCpp;
31   for(unsigned int i=0; i<strvecCorba.length(); i++)
32     strvecCpp.push_back(string(strvecCorba[i]));
33   return strvecCpp;
34 }
35
36 template <class T>
37 typename T::_var_type strvec_CPPtoCORBA(const vector<string> & strvecCpp)
38 {
39   typename T::_var_type strvecCorba = new T;
40   strvecCorba->length(strvecCpp.size());
41   for(unsigned int i=0;i<strvecCpp.size();i++)
42     strvecCorba[i] = strvecCpp[i].c_str();
43   return strvecCorba;
44 }
45
46 resourceParams resourceParameters_CORBAtoCPP(const Engines::ResourceParameters & params)
47 {
48   resourceParams p;
49   p.name = params.name;
50   p.hostname = params.hostname;
51   p.can_launch_batch_jobs = params.can_launch_batch_jobs;
52   p.can_run_containers = params.can_run_containers;
53   p.OS = params.OS;
54   p.nb_proc = params.nb_proc;
55   p.nb_node = params.nb_node;
56   p.nb_proc_per_node = params.nb_proc_per_node;
57   p.cpu_clock = params.cpu_clock;
58   p.mem_mb = params.mem_mb;
59   p.componentList = strvec_CORBAtoCPP<Engines::CompoList>(params.componentList);
60   p.resourceList = resourceList_CORBAtoCPP(params.resList);
61   return p;
62 }
63
64 Engines::ResourceParameters_var resourceParameters_CPPtoCORBA(const resourceParams & params)
65 {
66   Engines::ResourceParameters_var p = new Engines::ResourceParameters;
67   p->name = params.name.c_str();
68   p->hostname = params.hostname.c_str();
69   p->can_launch_batch_jobs = params.can_launch_batch_jobs;
70   p->can_run_containers = params.can_run_containers;
71   p->OS = params.OS.c_str();
72   p->nb_proc = params.nb_proc;
73   p->nb_node = params.nb_node;
74   p->nb_proc_per_node = params.nb_proc_per_node;
75   p->cpu_clock = params.cpu_clock;
76   p->mem_mb = params.mem_mb;
77   p->componentList = strvec_CPPtoCORBA<Engines::CompoList>(params.componentList);
78   p->resList = resourceList_CPPtoCORBA(params.resourceList);
79   return p;
80 }
81
82 vector<string> resourceList_CORBAtoCPP(const Engines::ResourceList & resList)
83 {
84   return strvec_CORBAtoCPP<Engines::ResourceList>(resList);
85 }
86
87 Engines::ResourceList_var resourceList_CPPtoCORBA(const vector<string> & resList)
88 {
89   return strvec_CPPtoCORBA<Engines::ResourceList>(resList);
90 }
91
92 ParserResourcesType resourceDefinition_CORBAtoCPP(const Engines::ResourceDefinition & resDef)
93 {
94   ParserResourcesType resource;
95   resource.Name = resDef.name;
96   resource.HostName = resDef.hostname;
97   resource.setResourceTypeStr(resDef.type.in());
98   resource.OS = resDef.OS;
99   resource.AppliPath = resDef.applipath;
100   resource.DataForSort._memInMB = resDef.mem_mb;
101   resource.DataForSort._CPUFreqMHz = resDef.cpu_clock;
102   resource.DataForSort._nbOfNodes = resDef.nb_node;
103   resource.DataForSort._nbOfProcPerNode = resDef.nb_proc_per_node;
104   resource.UserName = resDef.username;
105   resource.can_launch_batch_jobs = resDef.can_launch_batch_jobs;
106   resource.can_run_containers = resDef.can_run_containers;
107   resource.working_directory = resDef.working_directory;
108   resource.setBatchTypeStr(resDef.batch.in());
109   resource.setMpiImplTypeStr(resDef.mpiImpl.in());
110   resource.setAccessProtocolTypeStr(resDef.protocol.in());
111   resource.setClusterInternalProtocolStr(resDef.iprotocol.in());
112   resource.ComponentsList = strvec_CORBAtoCPP<Engines::CompoList>(resDef.componentList);
113   return resource;
114 }
115
116 Engines::ResourceDefinition_var resourceDefinition_CPPtoCORBA(const ParserResourcesType & resource)
117 {
118   Engines::ResourceDefinition_var resCorba = new Engines::ResourceDefinition;
119   resCorba->name = resource.Name.c_str();
120   resCorba->hostname = resource.HostName.c_str();
121   resCorba->type = resource.getResourceTypeStr().c_str();
122   resCorba->protocol = resource.getAccessProtocolTypeStr().c_str();
123   resCorba->iprotocol = resource.getClusterInternalProtocolStr().c_str();
124   resCorba->username = resource.UserName.c_str();
125   resCorba->applipath = resource.AppliPath.c_str();
126   resCorba->componentList = strvec_CPPtoCORBA<Engines::CompoList>(resource.ComponentsList);
127   resCorba->OS = resource.OS.c_str();
128   resCorba->mem_mb = resource.DataForSort._memInMB;
129   resCorba->cpu_clock = resource.DataForSort._CPUFreqMHz;
130   resCorba->nb_proc_per_node = resource.DataForSort._nbOfProcPerNode;
131   resCorba->nb_node = resource.DataForSort._nbOfNodes;
132   resCorba->can_launch_batch_jobs = resource.can_launch_batch_jobs;
133   resCorba->can_run_containers = resource.can_run_containers;
134   resCorba->working_directory = resource.working_directory.c_str();
135   resCorba->mpiImpl = resource.getMpiImplTypeStr().c_str();
136   resCorba->batch = resource.getBatchTypeStr().c_str();
137   return resCorba;
138 }