Salome HOME
Fix compilation with gcc 4.7
[tools/libbatch.git] / src / Core / Batch_BatchManager_eClient.cxx
index a7546459df9dba7441ebe0c46df9f6289560389a..835b5956f8b27e910a4c4ef452fe1e6be60b6ca4 100644 (file)
@@ -1,4 +1,4 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+//  Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -29,6 +29,7 @@
 *
 */
 
+#include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -46,6 +47,7 @@
 
 #include <Batch_config.h>
 
+#include "Batch_Constants.hxx"
 #include "Batch_BatchManager_eClient.hxx"
 #include "Batch_RunTimeException.hxx"
 
@@ -61,8 +63,10 @@ using namespace std;
 namespace Batch {
 
   BatchManager_eClient::BatchManager_eClient(const Batch::FactBatchManager * parent, const char* host,
+                                             const char * username,
                                              CommunicationProtocolType protocolType, const char* mpiImpl)
-    : BatchManager(parent, host), _protocol(CommunicationProtocol::getInstance(protocolType)), _username("")
+    : BatchManager(parent, host), _protocol(CommunicationProtocol::getInstance(protocolType)),
+      _username(username)
   {
     // instanciation of mpi implementation needed to launch executable in batch script
     _mpiImpl = FactoryMpiImpl(mpiImpl);
@@ -79,8 +83,8 @@ namespace Batch {
   {
     int status;
     Parametre params = job.getParametre();
-    Versatile V = params[INFILE];
-    Versatile::iterator Vit;
+    const Versatile & V = params[INFILE];
+    Versatile::const_iterator Vit;
 
     status = _protocol.makeDirectory(string(params[TMPDIR]) + "/logs", _hostname, _username);
     if(status) {
@@ -144,9 +148,8 @@ namespace Batch {
   void BatchManager_eClient::importOutputFiles( const Job & job, const string directory )
   {
     Parametre params = job.getParametre();
-    Versatile V = params[OUTFILE];
-    Versatile::iterator Vit;
-    _username = string(params[USER]);
+    const Versatile & V = params[OUTFILE];
+    Versatile::const_iterator Vit;
 
     // Create local result directory
     int status = CommunicationProtocol::getInstance(SH).makeDirectory(directory, "", "");
@@ -187,6 +190,36 @@ namespace Batch {
 
   }
 
+  bool BatchManager_eClient::importDumpStateFile( const Job & job, const string directory )
+  {
+    Parametre params = job.getParametre();
+
+    // Create local result directory
+    int status = CommunicationProtocol::getInstance(SH).makeDirectory(directory, "", "");
+    if (status) {
+      string mess("Directory creation failed. Status is :");
+      ostringstream status_str;
+      status_str << status;
+      mess += status_str.str();
+      cerr << mess << endl;
+    }
+
+    bool ret = true;
+    status = _protocol.copyFile(string(params[TMPDIR]) + string("/dumpState*.xml"), _hostname, _username,
+                                directory, "", "");
+    if (status) {
+      // Try to get what we can (logs files)
+      // throw BatchException("Error of connection on remote host");
+      std::string mess("Copy command failed ! status is :");
+      ostringstream status_str;
+      status_str << status;
+      mess += status_str.str();
+      cerr << mess << endl;
+      ret = false;
+    }
+    return ret;
+  }
+
   MpiImpl *BatchManager_eClient::FactoryMpiImpl(string mpiImpl)
   {
     if(mpiImpl == "lam")
@@ -249,7 +282,8 @@ namespace Batch {
 #ifdef WIN32
 
     string fileName = generateTemporaryFileName(prefix);
-    outputStream.open(fileName.c_str());
+    // Open the file as binary to avoid problems with Windows newlines
+    outputStream.open(fileName.c_str(), ios_base::binary | ios_base::out);
 
 #else