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