]> SALOME platform Git repositories - modules/kernel.git/blob - src/Batch/Batch_BatchManager_Local_SSH.cxx
Salome HOME
Remove warnings
[modules/kernel.git] / src / Batch / Batch_BatchManager_Local_SSH.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 /*
23  * BatchManager_Local_SSH.cxx : 
24  *
25  * Auteur : Ivan DUTKA-MALEN - EDF R&D
26  * Mail   : mailto:ivan.dutka-malen@der.edf.fr
27  * Date   : Thu Nov  6 10:17:22 2003
28  * Projet : Salome 2
29  *
30  */
31
32 #ifdef HAVE_CONFIG_H
33 #  include <SALOMEconfig.h>
34 #endif
35
36 #include <iostream>
37 #include <fstream>
38 #include <sstream>
39 #include <cstdlib>
40 #include <sys/types.h>
41 #ifndef WIN32
42 #include <sys/wait.h>
43 #include <unistd.h>
44 #endif
45 #include <ctime>
46
47 #include <pthread.h>
48 #include <signal.h>
49 #include <errno.h>
50 #include <string.h>
51 #include "Batch_IOMutex.hxx"
52 #include "Batch_BatchManager_Local_SSH.hxx"
53
54 #ifndef RM
55 #error "RM undefined. You must set RM to a valid path to a rm-like command."
56 #endif
57
58 #ifndef RCP
59 #error "RCP undefined. You must set RCP to a valid path to a scp-like command."
60 #endif
61
62 #ifndef SSH
63 #error "SSH undefined. You must set SSH to a valid path to a ssh-like command."
64 #endif
65
66 using namespace std;
67
68 namespace Batch {
69
70
71   // Constructeur
72   BatchManager_Local_SSH::BatchManager_Local_SSH(const FactBatchManager * parent, const char * host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager_Local(parent, host)
73   {
74   }
75
76   // Destructeur
77   BatchManager_Local_SSH::~BatchManager_Local_SSH()
78   {
79   }
80
81
82   // Methode abstraite qui renvoie la commande de copie du fichier source en destination
83   string BatchManager_Local_SSH::copy_command(const string & host_source, const string & source, const string & host_destination, const string & destination) const
84   {
85     ostringstream fullsource;
86     if (host_source.size() == 0) {
87       fullsource << "localhost:";
88     } else {
89       fullsource << host_source << ":";
90     }
91     fullsource << source;
92
93     ostringstream fulldestination;
94     if (host_destination.size() == 0) {
95       fulldestination << "localhost:";
96     } else {
97       fulldestination << host_destination << ":";
98     }
99     fulldestination << destination;
100
101     ostringstream copy_cmd;
102     copy_cmd << RCP << " " << fullsource.str() << " " << fulldestination.str();
103     return copy_cmd.str();
104   }
105   
106   // Methode abstraite qui renvoie la commande a executer
107   string BatchManager_Local_SSH::exec_command(Parametre & param) const
108   {
109     ostringstream exec_sub_cmd;
110     exec_sub_cmd << param[EXECUTABLE];
111
112     if (param.find(ARGUMENTS) != param.end()) {
113       Versatile V = param[ARGUMENTS];
114       for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++) {
115         StringType argt = * static_cast<StringType *>(*it);
116         string     arg  = argt;
117         exec_sub_cmd << " " << arg;
118       }
119     }
120
121
122     Versatile new_arguments;
123     new_arguments.setMaxSize(0);
124     new_arguments = string(param[EXECUTIONHOST]);
125
126
127     if (param.find(USER) != param.end()) {
128       new_arguments += "-l";
129       new_arguments += string(param[USER]);
130     }
131
132     new_arguments += exec_sub_cmd.str();
133
134     param[ARGUMENTS] = new_arguments;
135
136     // Sous Linux on est oblige de modifier ces deux parametres pour faire fonctionner la commande rsh
137     param[EXECUTABLE] = SSH;
138     param.erase(NAME);
139
140     return SSH;
141   }
142
143   // Methode qui renvoie la commande d'effacement du fichier
144   string BatchManager_Local_SSH::remove_command(const string & host_destination, const string & destination) const
145   {
146     string host = (host_destination.size()) ? host_destination : "localhost:";
147
148     ostringstream remove_cmd;
149     remove_cmd << SSH << " " << host << " \"" << RM << " " << destination << "\"";
150     return remove_cmd.str();
151   }
152 }