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