Salome HOME
Merge from V5_1_main 14/05/2010
[modules/kernel.git] / src / LifeCycleCORBA / SALOME_FileTransferCORBA.cxx
index dee3b3109ce5d3857d65c2478a86ec9305fcd5ed..8514fe3f1f46953929482d9c1b7caebafeaa916c 100644 (file)
@@ -1,4 +1,4 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//  Copyright (C) 2007-2010  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
@@ -19,6 +19,7 @@
 //
 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 //  File   : SALOME_FileTransferCORBA.cxx
 //  Author : Paul RASCLE, EDF
 //  Module : SALOME
@@ -28,8 +29,7 @@
 #include "SALOME_LifeCycleCORBA.hxx"
 #include "utilities.h"
 #include "Basics_Utils.hxx"
-
-using namespace std;
+#include <cstdio>
 
 /*! \class SALOME_FileTransferCORBA
     \brief A class to manage file transfer in SALOME (CORBA context)
@@ -55,7 +55,7 @@ SALOME_FileTransferCORBA::SALOME_FileTransferCORBA()
 //=============================================================================
 
 SALOME_FileTransferCORBA::SALOME_FileTransferCORBA(Engines::fileRef_ptr
-                                                  aFileRef)
+                                                   aFileRef)
 {
   MESSAGE("SALOME_FileTransferCORBA::SALOME_FileTransferCORBA(aFileRef)");
   _theFileRef = aFileRef;
@@ -71,12 +71,12 @@ SALOME_FileTransferCORBA::SALOME_FileTransferCORBA(Engines::fileRef_ptr
  */
 //=============================================================================
 
-SALOME_FileTransferCORBA::SALOME_FileTransferCORBA(string refMachine,
-                                                  string origFileName,
-                                                  string containerName)
+SALOME_FileTransferCORBA::SALOME_FileTransferCORBA(std::string refMachine,
+                                                   std::string origFileName,
+                                                   std::string containerName)
 {
   MESSAGE("SALOME_FileTransferCORBA::SALOME_FileTransferCORBA"
-         << refMachine << " " << origFileName  << " " << containerName);
+          << refMachine << " " << origFileName  << " " << containerName);
   _refMachine = refMachine;
   _origFileName = origFileName;
   _containerName = containerName;
@@ -107,7 +107,7 @@ SALOME_FileTransferCORBA::~SALOME_FileTransferCORBA()
  */
 //=============================================================================
 
-string SALOME_FileTransferCORBA::getLocalFile(string localFile)
+std::string SALOME_FileTransferCORBA::getLocalFile(std::string localFile)
 {
   MESSAGE("SALOME_FileTransferCORBA::getLocalFile " << localFile);
 
@@ -116,10 +116,10 @@ string SALOME_FileTransferCORBA::getLocalFile(string localFile)
   if (CORBA::is_nil(_theFileRef))
     {
       if (_refMachine.empty() || _origFileName.empty())
-       {
-         INFOS("not enough parameters: machine and file name must be given");
-         return "";
-       }
+        {
+          INFOS("not enough parameters: machine and file name must be given");
+          return "";
+        }
 
       SALOME_LifeCycleCORBA LCC;
       Engines::ContainerManager_var contManager = LCC.getContainerManager();
@@ -130,84 +130,83 @@ string SALOME_FileTransferCORBA::getLocalFile(string localFile)
       params.container_name = _containerName.c_str();
       params.hostname = _refMachine.c_str();
 
-      Engines::CompoList clist;
-      Engines::MachineList_var listOfMachines =
-       resManager->GetFittingResources(params, clist);
-
-      container = contManager->FindOrStartContainer(params, listOfMachines);
+      Engines::ContainerParameters new_params;
+      LCC.convert(params, new_params);
+      new_params.mode = CORBA::string_dup("findorstart");
+      container = contManager->GiveContainer(new_params);
       if (CORBA::is_nil(container))
-       {
-         INFOS("machine " << _refMachine << " unreachable");
-         return "";
-       }
+        {
+          INFOS("machine " << _refMachine << " unreachable");
+          return "";
+        }
 
       _theFileRef = container->createFileRef(_origFileName.c_str());
       if (CORBA::is_nil(_theFileRef))
-       {
-         INFOS("impossible to create fileRef on " << _refMachine);
-         return "";
-       }
+        {
+          INFOS("impossible to create fileRef on " << _refMachine);
+          return "";
+        }
     }
 
   container = _theFileRef->getContainer();
   ASSERT(! CORBA::is_nil(container));
 
-  string myMachine = Kernel_Utils::GetHostname();
-  string localCopy = _theFileRef->getRef(myMachine.c_str());
+  std::string myMachine = Kernel_Utils::GetHostname();
+  std::string localCopy = _theFileRef->getRef(myMachine.c_str());
 
   if (localCopy.empty()) // no existing copy available
     {
       if (localFile.empty()) // no name provided for local copy
-       {
-         char bufName[256];
-         localCopy = tmpnam(bufName);
-         localFile = bufName;
-         SCRUTE(localFile);
-       }
+        {
+          char bufName[256];
+          localCopy = tmpnam(bufName);
+          localFile = bufName;
+          SCRUTE(localFile);
+        }
 
       FILE* fp;
       if ((fp = fopen(localFile.c_str(),"wb")) == NULL)
-       {
-         INFOS("file " << localFile << " cannot be open for writing");
-         return "";
-       }
+        {
+          INFOS("file " << localFile << " cannot be open for writing");
+          return "";
+        }
 
       Engines::fileTransfer_var fileTransfer = container->getFileTransfer();
       ASSERT(! CORBA::is_nil(fileTransfer));
 
       CORBA::Long fileId = fileTransfer->open(_origFileName.c_str());
       if (fileId > 0)
-       {
-         Engines::fileBlock* aBlock;
-         int toFollow = 1;
-         int ctr=0;
-         while (toFollow)
-           {
-             ctr++;
-             SCRUTE(ctr);
-             aBlock = fileTransfer->getBlock(fileId);
-             toFollow = aBlock->length();
-             SCRUTE(toFollow);
-             CORBA::Octet *buf = aBlock->get_buffer();
+        {
+          Engines::fileBlock* aBlock;
+          int toFollow = 1;
+          int ctr=0;
+          while (toFollow)
+            {
+              ctr++;
+              SCRUTE(ctr);
+              aBlock = fileTransfer->getBlock(fileId);
+              toFollow = aBlock->length();
+              SCRUTE(toFollow);
+              CORBA::Octet *buf = aBlock->get_buffer();
 #if defined(_DEBUG_) || defined(_DEBUG)
-             int nbWri = fwrite(buf, sizeof(CORBA::Octet), toFollow, fp);
-             ASSERT(nbWri == toFollow);
+              int nbWri = fwrite(buf, sizeof(CORBA::Octet), toFollow, fp);
+              ASSERT(nbWri == toFollow);
 #else
-             fwrite(buf, sizeof(CORBA::Octet), toFollow, fp);
+              fwrite(buf, sizeof(CORBA::Octet), toFollow, fp);
 #endif
               delete aBlock;
-           }
-         fclose(fp);
-         MESSAGE("end of transfer");
-         fileTransfer->close(fileId);
-         _theFileRef->addRef(myMachine.c_str(), localFile.c_str());
-         localCopy = localFile;
-       }
+            }
+          fclose(fp);
+          MESSAGE("end of transfer");
+          fileTransfer->close(fileId);
+          _theFileRef->addRef(myMachine.c_str(), localFile.c_str());
+          localCopy = localFile;
+        }
       else
-       {
-         INFOS("open reference file for copy impossible");
-         return "";
-       }
+        {
+          INFOS("open reference file for copy impossible");
+          return "";
+        }
       
     }
   SCRUTE(localCopy);