Salome HOME
0021063: [CEA 434] Compilation using gnu compiler v4.5
[modules/kernel.git] / src / LifeCycleCORBA / SALOME_FileTransferCORBA.cxx
index b2c653586d4aae5a2330ac80a951737393b38798..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
 #include "SALOME_LifeCycleCORBA.hxx"
 #include "utilities.h"
 #include "Basics_Utils.hxx"
+#include <cstdio>
+
+/*! \class SALOME_FileTransferCORBA
+    \brief A class to manage file transfer in SALOME (CORBA context)
 
-using namespace std;
+*/
 
 //=============================================================================
 /*! 
@@ -43,35 +48,35 @@ SALOME_FileTransferCORBA::SALOME_FileTransferCORBA()
 }
 
 //=============================================================================
-/*! 
- *  Constructor to use when we get a fileRef CORBA object from a component.
+/*! \brief Constructor to use when we get a fileRef CORBA object from a component
+ *
  *  \param aFileRef file reference CORBA object
  */
 //=============================================================================
 
 SALOME_FileTransferCORBA::SALOME_FileTransferCORBA(Engines::fileRef_ptr
-                                                  aFileRef)
+                                                   aFileRef)
 {
   MESSAGE("SALOME_FileTransferCORBA::SALOME_FileTransferCORBA(aFileRef)");
   _theFileRef = aFileRef;
 }
 
 //=============================================================================
-/*! 
- *  Constructor to use when we have the file name and machine from which to
- *  copy, plus an optional Container name on the machine.
+/*! \brief Constructor to use when we have the file name and machine from which to
+ *         copy, plus an optional Container name on the machine.
+ *
  *  \param refMachine    the machine on which is the file to transfer
  *  \param origFileName  abolute file path on refMachine
  *  \param containerName default container name used (FactoryServer) if empty
  */
 //=============================================================================
 
-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;
@@ -93,15 +98,16 @@ SALOME_FileTransferCORBA::~SALOME_FileTransferCORBA()
 }
 
 //=============================================================================
-/*! 
- *  CORBA method: get a local copy of the reference file.
+/*! \brief Get a local copy of the reference file
+ *
+ *  CORBA method
  *  \param  localFile optional absolute path to store the copy
  *  \return the file name (absolute path) of the copy, may be different from
  *          localFile parameter if the copy was already done before the call
  */
 //=============================================================================
 
-string SALOME_FileTransferCORBA::getLocalFile(string localFile)
+std::string SALOME_FileTransferCORBA::getLocalFile(std::string localFile)
 {
   MESSAGE("SALOME_FileTransferCORBA::getLocalFile " << localFile);
 
@@ -110,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();
@@ -124,85 +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("imposssible 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);