Salome HOME
[PortManager] Separate ports according to their owner (this or other application)
[modules/yacs.git] / src / LifeCycleCORBA / SALOME_FileTransferCORBA.cxx
index b2c653586d4aae5a2330ac80a951737393b38798..4033c40717cb80d7267b29cee0d857f7c6cee7ee 100644 (file)
@@ -1,24 +1,25 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  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
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// 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,99 +116,94 @@ 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();
       Engines::ResourcesManager_var resManager = LCC.getResourcesManager();
 
-      Engines::MachineParameters params;
+      Engines::ContainerParameters params;
       LCC.preSet(params);
       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);
+      params.resource_params.hostname = _refMachine.c_str();
+      params.mode = CORBA::string_dup("findorstart");
+      container = contManager->GiveContainer(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);