]> SALOME platform Git repositories - modules/kernel.git/blob - src/Batch/Batch_BatchManager_Local_SSH.cxx
Salome HOME
Porting functionality on Win32 Platform
[modules/kernel.git] / src / Batch / Batch_BatchManager_Local_SSH.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA, EDF R&D, LEG
2 //           PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 // 
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 // 
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 // 
19 /*
20  * BatchManager_Local_SSH.cxx : 
21  *
22  * Auteur : Ivan DUTKA-MALEN - EDF R&D
23  * Mail   : mailto:ivan.dutka-malen@der.edf.fr
24  * Date   : Thu Nov  6 10:17:22 2003
25  * Projet : Salome 2
26  *
27  */
28
29 #ifdef HAVE_CONFIG_H
30 #  include <SALOMEconfig.h>
31 #endif
32
33 #include <iostream>
34 #include <fstream>
35 #include <sstream>
36 #include <cstdlib>
37 #include <sys/types.h>
38 #ifndef WIN32
39 #include <sys/wait.h>
40 #include <unistd.h>
41 #endif
42 #include <ctime>
43
44 #include <pthread.h>
45 #include <signal.h>
46 #include <errno.h>
47 #include <string.h>
48 #include "Batch_IOMutex.hxx"
49 #include "Batch_BatchManager_Local_SSH.hxx"
50
51 #ifndef RM
52 #error "RM undefined. You must set RM to a valid path to a rm-like command."
53 #endif
54
55 #ifndef RCP
56 #error "RCP undefined. You must set RCP to a valid path to a scp-like command."
57 #endif
58
59 #ifndef SSH
60 #error "SSH undefined. You must set SSH to a valid path to a ssh-like command."
61 #endif
62
63 namespace Batch {
64
65
66   // Constructeur
67   BatchManager_Local_SSH::BatchManager_Local_SSH(const FactBatchManager * parent, const char * host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager_Local(parent, host)
68   {
69   }
70
71   // Destructeur
72   BatchManager_Local_SSH::~BatchManager_Local_SSH()
73   {
74   }
75
76
77   // Methode abstraite qui renvoie la commande de copie du fichier source en destination
78   string BatchManager_Local_SSH::copy_command(const string & host_source, const string & source, const string & host_destination, const string & destination) const
79   {
80     ostringstream fullsource;
81     if (host_source.size() == 0) {
82       fullsource << "localhost:";
83     } else {
84       fullsource << host_source << ":";
85     }
86     fullsource << source;
87
88     ostringstream fulldestination;
89     if (host_destination.size() == 0) {
90       fulldestination << "localhost:";
91     } else {
92       fulldestination << host_destination << ":";
93     }
94     fulldestination << destination;
95
96     ostringstream copy_cmd;
97     copy_cmd << RCP << " " << fullsource.str() << " " << fulldestination.str();
98     return copy_cmd.str();
99   }
100   
101   // Methode abstraite qui renvoie la commande a executer
102   string BatchManager_Local_SSH::exec_command(Parametre & param) const
103   {
104     ostringstream exec_sub_cmd;
105     exec_sub_cmd << param[EXECUTABLE];
106
107     if (param.find(ARGUMENTS) != param.end()) {
108       Versatile V = param[ARGUMENTS];
109       for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++) {
110         StringType argt = * static_cast<StringType *>(*it);
111         string     arg  = argt;
112         exec_sub_cmd << " " << arg;
113       }
114     }
115
116
117     Versatile new_arguments;
118     new_arguments.setMaxSize(0);
119     new_arguments = string(param[EXECUTIONHOST]);
120
121
122     if (param.find(USER) != param.end()) {
123       new_arguments += "-l";
124       new_arguments += string(param[USER]);
125     }
126
127     new_arguments += exec_sub_cmd.str();
128
129     param[ARGUMENTS] = new_arguments;
130
131     // Sous Linux on est oblige de modifier ces deux parametres pour faire fonctionner la commande rsh
132     param[EXECUTABLE] = SSH;
133     param.erase(NAME);
134
135     return SSH;
136   }
137
138   // Methode qui renvoie la commande d'effacement du fichier
139   string BatchManager_Local_SSH::remove_command(const string & host_destination, const string & destination) const
140   {
141     string host = (host_destination.size()) ? host_destination : "localhost:";
142
143     ostringstream remove_cmd;
144     remove_cmd << SSH << " " << host << " \"" << RM << " " << destination << "\"";
145     return remove_cmd.str();
146   }
147 }