Salome HOME
A patch from Paul RASCLE for: kernel documentation with doxygen, modification on...
[modules/kernel.git] / src / Batch / Batch_BatchManager_Local_RSH.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_RSH.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 #include <sys/wait.h>
39 #include <ctime>
40 #include <unistd.h>
41 #include <pthread.h>
42 #include <signal.h>
43 #include <errno.h>
44 #include <string.h>
45 #include "Batch_IOMutex.hxx"
46 #include "Batch_BatchManager_Local_RSH.hxx"
47
48 #ifndef RM
49 #error "RM undefined. You must set RM to a valid path to a rm-like command."
50 #endif
51
52 #ifndef RCP
53 #error "RCP undefined. You must set RCP to a valid path to a rcp-like command."
54 #endif
55
56 #ifndef RSH
57 #error "RSH undefined. You must set RSH to a valid path to a rsh-like command."
58 #endif
59
60 namespace Batch {
61
62
63   // Constructeur
64   BatchManager_Local_RSH::BatchManager_Local_RSH(const FactBatchManager * parent, const char * host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager_Local(parent, host)
65   {
66   }
67
68   // Destructeur
69   BatchManager_Local_RSH::~BatchManager_Local_RSH()
70   {
71   }
72
73
74   // Methode abstraite qui renvoie la commande de copie du fichier source en destination
75   string BatchManager_Local_RSH::copy_command(const string & host_source, const string & source, const string & host_destination, const string & destination) const
76   {
77     ostringstream fullsource;
78     if (host_source.size() == 0) {
79       fullsource << "localhost:";
80     } else {
81       fullsource << host_source << ":";
82     }
83     fullsource << source;
84
85     ostringstream fulldestination;
86     if (host_destination.size() == 0) {
87       fulldestination << "localhost:";
88     } else {
89       fulldestination << host_destination << ":";
90     }
91     fulldestination << destination;
92
93     ostringstream copy_cmd;
94     copy_cmd << RCP << " " << fullsource.str() << " " << fulldestination.str();
95     return copy_cmd.str();
96   }
97   
98   // Methode abstraite qui renvoie la commande a executer
99   string BatchManager_Local_RSH::exec_command(Parametre & param) const
100   {
101     ostringstream exec_sub_cmd;
102     exec_sub_cmd << param[EXECUTABLE];
103
104     if (param.find(ARGUMENTS) != param.end()) {
105       Versatile V = param[ARGUMENTS];
106       for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++) {
107         StringType argt = * static_cast<StringType *>(*it);
108         string     arg  = argt;
109         exec_sub_cmd << " " << arg;
110       }
111     }
112
113
114     Versatile new_arguments;
115     new_arguments.setMaxSize(0);
116     new_arguments = string(param[EXECUTIONHOST]);
117
118
119     if (param.find(USER) != param.end()) {
120       new_arguments += "-l";
121       new_arguments += string(param[USER]);
122     }
123
124     new_arguments += exec_sub_cmd.str();
125
126     param[ARGUMENTS] = new_arguments;
127
128     // Sous Linux on est oblige de modifier ces deux parametres pour faire fonctionner la commande rsh
129     param[EXECUTABLE] = RSH;
130     param.erase(NAME);
131
132     return RSH;
133   }
134
135   // Methode qui renvoie la commande d'effacement du fichier
136   string BatchManager_Local_RSH::remove_command(const string & host_destination, const string & destination) const
137   {
138     string host = (host_destination.size()) ? host_destination : "localhost:";
139
140     ostringstream remove_cmd;
141     remove_cmd << RSH << " " << host << " \"" << RM << " " << destination << "\"";
142     return remove_cmd.str();
143   }
144 }