X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FLifeCycleCORBA%2FSALOME_FileTransferCORBA.cxx;h=fce9c4905a8c38d2b384d3f289c260ee871d4cc5;hb=54c311c4540ce9169bcb2d291f27d222162a04f0;hp=a608f2196997c3e195a8fd93040840550d5519fd;hpb=e6bfea36374791cd31c274a2f97df90dc60ddaf3;p=modules%2Fkernel.git diff --git a/src/LifeCycleCORBA/SALOME_FileTransferCORBA.cxx b/src/LifeCycleCORBA/SALOME_FileTransferCORBA.cxx index a608f2196..fce9c4905 100644 --- a/src/LifeCycleCORBA/SALOME_FileTransferCORBA.cxx +++ b/src/LifeCycleCORBA/SALOME_FileTransferCORBA.cxx @@ -1,34 +1,40 @@ -// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// -// 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 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 -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// 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 // +// 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 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 +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + // File : SALOME_FileTransferCORBA.cxx // Author : Paul RASCLE, EDF // Module : SALOME // $Header$ - +// #include "SALOME_FileTransferCORBA.hxx" #include "SALOME_LifeCycleCORBA.hxx" #include "utilities.h" -#include "OpUtil.hxx" +#include "Basics_Utils.hxx" +#include + +/*! \class SALOME_FileTransferCORBA + \brief A class to manage file transfer in SALOME (CORBA context) -using namespace std; +*/ //============================================================================= /*! @@ -42,39 +48,39 @@ 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; - if (_refMachine.empty() or _origFileName.empty()) + if (_refMachine.empty() || _origFileName.empty()) { INFOS("bad parameters: machine and file name must be given"); } @@ -92,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); @@ -108,92 +115,98 @@ string SALOME_FileTransferCORBA::getLocalFile(string localFile) if (CORBA::is_nil(_theFileRef)) { - if (_refMachine.empty() or _origFileName.empty()) - { - INFOS("not enough parameters: machine and file name must be given"); - return ""; - } + if (_refMachine.empty() || _origFileName.empty()) + { + 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; LCC.preSet(params); params.container_name = _containerName.c_str(); params.hostname = _refMachine.c_str(); - Engines::MachineList_var listOfMachines = - contManager->GetFittingResources(params, ""); - - 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 = 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(); - int nbWri = fwrite(buf, sizeof(CORBA::Octet), toFollow, fp); - ASSERT(nbWri == toFollow); - } - MESSAGE("end of transfer"); - fileTransfer->close(fileId); - _theFileRef->addRef(myMachine.c_str(), localFile.c_str()); - localCopy = localFile; - } + { + 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); +#else + 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; + } else - { - INFOS("open reference file for copy impossible"); - return ""; - } + { + INFOS("open reference file for copy impossible"); + return ""; + } } SCRUTE(localCopy);