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