Salome HOME
updated copyright message
[modules/kernel.git] / src / Launcher / SALOME_Launcher_Handler.cxx
1 // Copyright (C) 2007-2023  CEA, EDF, 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 //  SALOME ResourcesCatalog : implementation of catalog resources parsing (SALOME_ModuleCatalog.idl)
24 //  File   : SALOME_Laucher_Handler.cxx
25 //  Author : Bernard Secher
26 //  Module : SALOME
27 //  $Header$
28 //
29 #include "SALOME_Launcher_Handler.hxx"
30 #include <iostream>
31 #include <map>
32
33 //=============================================================================
34 /*!
35  *  Constructor
36  *  \param listOfResources: map of ParserResourcesType to fill when parsing
37  */ 
38 //=============================================================================
39
40 SALOME_Launcher_Handler::SALOME_Launcher_Handler(ParserLauncherType& launch):
41     _launch(launch)
42 {
43   //XML tags initialisation
44   test_machine_list = "machine-list";
45   test_main = "main";
46
47   test_machine = "machine";
48   test_env_file = "env-file";
49   test_work_directory = "work-directory";
50   test_ref_directory = "ref-directory";
51   test_nb_processes = "nb-processes";
52   test_input_file = "input-file";
53   test_output_file = "output-file";
54   test_command = "command";
55
56 }
57
58 //=============================================================================
59 /*!
60  *  Destructor
61  */ 
62 //=============================================================================
63
64 SALOME_Launcher_Handler::~SALOME_Launcher_Handler()
65 {
66   //  cout << "SALOME_Launcher_Handler destruction") << endl;
67 }
68
69 //=============================================================================
70 /*!
71  *  Retrieves DS after the file parse.
72  */ 
73 //=============================================================================
74
75 const ParserLauncherType&
76 SALOME_Launcher_Handler::GetLauncherAfterParsing() const
77 {
78   return _launch;
79 }
80
81 //=============================================================================
82 /*!
83  *  Processes XML document and fills the list of resources
84  */ 
85 //=============================================================================
86
87 void SALOME_Launcher_Handler::ProcessXmlDocument(xmlDocPtr theDoc)
88 {
89   // cout << "Begin parse document" << endl;
90
91   // Empty private elements
92   _launch.Clear();
93
94   // Get the document root node
95   xmlNodePtr aCurNode = xmlDocGetRootElement(theDoc);
96
97   aCurNode = aCurNode->xmlChildrenNode;
98   
99   // Processing the document nodes
100   while(aCurNode != NULL){
101     if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_machine_list) ){
102       xmlNodePtr aCurNode2 = aCurNode->xmlChildrenNode;
103       while(aCurNode2 != NULL){
104         if ( !xmlStrcmp(aCurNode2->name,(const xmlChar*)test_machine) ){
105           _machp.Clear();
106           xmlChar* name = xmlNodeGetContent(aCurNode2);
107           std::string clusterName = (const char*)name;
108           xmlFree(name);
109         
110           if (xmlHasProp(aCurNode2, (const xmlChar*)test_env_file)){
111             xmlChar* envfile = xmlGetProp(aCurNode2, (const xmlChar*)test_env_file);
112             _machp.EnvFile = (const char*)envfile;
113             xmlFree(envfile);
114           }
115
116           if (xmlHasProp(aCurNode2, (const xmlChar*)test_work_directory)){
117             xmlChar* workdirectory = xmlGetProp(aCurNode2, (const xmlChar*)test_work_directory);
118             _machp.WorkDirectory = (const char*)workdirectory;
119             xmlFree(workdirectory);
120           }
121           _launch.MachinesList[clusterName]=_machp ;
122         }
123         aCurNode2 = aCurNode2->next;
124       }
125     }
126
127     if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_ref_directory) ){
128       xmlChar* refdirectory = xmlNodeGetContent(aCurNode);
129       _launch.RefDirectory = (const char*)refdirectory;
130       xmlFree(refdirectory);
131     }
132           
133     if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_nb_processes) ){
134       xmlChar* nbofprocesses = xmlNodeGetContent(aCurNode);
135       _launch.NbOfProcesses = atoi((const char*)nbofprocesses);
136       xmlFree(nbofprocesses);
137     }
138           
139     if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_input_file) ){
140       xmlChar* inputfile = xmlNodeGetContent(aCurNode);
141       _launch.InputFile.push_back((const char*)inputfile);
142       xmlFree(inputfile);
143     }
144           
145     if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_output_file) ){
146       xmlChar* outputfile = xmlNodeGetContent(aCurNode);
147       _launch.OutputFile.push_back((const char*)outputfile);
148       xmlFree(outputfile);
149     }
150           
151     if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_command) ){
152       xmlChar* command = xmlNodeGetContent(aCurNode);
153       _launch.Command = (const char*)command;
154       xmlFree(command);
155     }
156           
157     aCurNode = aCurNode->next;
158   }
159
160 }