X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FContainer%2FSalome_file_i.cxx;h=41ff72e14107065ee5ff36c8a18bc5123f89b98f;hb=3ce0546302001755828c8476425a60c6ab61ac92;hp=525dcc08da6ced0ca99abbe5fdf1079fe2b1a24b;hpb=7d2fe213bdf5bf962ce11e253020c9d3e0bc1cce;p=modules%2Fkernel.git diff --git a/src/Container/Salome_file_i.cxx b/src/Container/Salome_file_i.cxx index 525dcc08d..41ff72e14 100644 --- a/src/Container/Salome_file_i.cxx +++ b/src/Container/Salome_file_i.cxx @@ -1,24 +1,22 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2024 CEA, EDF, 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, or (at your option) any later version. // -// 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. // -// 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_file_i.cxx // Author : André RIBES, EDF // Module : SALOME @@ -38,6 +36,11 @@ # include #endif +/*! \class Salome_file_i + * \brief A class to manage file transfer in %SALOME + * + */ + //============================================================================= /*! @@ -88,7 +91,7 @@ Salome_file_i::load(const char* hdf5_file) { HDFfile *hdf_file; HDFgroup *hdf_group; HDFdataset *hdf_dataset; - int size; + size_t size; int fd; char * value; char * buffer; @@ -170,66 +173,66 @@ Salome_file_i::load(const char* hdf5_file) { if (mode == "all") { - // Changing path, is now current directory - path = getcwd(NULL, _path_max); + // Changing path, is now current directory + path = getcwd(NULL, _path_max); - std::string group_name("GROUP"); - group_name += file_name; - hdf_group = new HDFgroup(group_name.c_str(),hdf_file); - hdf_group->OpenOnDisk(); - hdf_dataset = new HDFdataset("FILE DATASET",hdf_group); - hdf_dataset->OpenOnDisk(); - size = hdf_dataset->GetSize(); - buffer = new char[size]; + std::string group_name("GROUP"); + group_name += file_name; + hdf_group = new HDFgroup(group_name.c_str(),hdf_file); + hdf_group->OpenOnDisk(); + hdf_dataset = new HDFdataset("FILE DATASET",hdf_group); + hdf_dataset->OpenOnDisk(); + size = hdf_dataset->GetSize(); + buffer = new char[size]; - if ( (fd = ::open(file_name.c_str(),O_RDWR|O_CREAT,00666)) <0) { - SALOME::ExceptionStruct es; - es.type = SALOME::INTERNAL_ERROR; - std::string text = "open failed"; - es.text = CORBA::string_dup(text.c_str()); - throw SALOME::SALOME_Exception(es); - }; - hdf_dataset->ReadFromDisk(buffer); - if ( write(fd,buffer,size) <0) { - SALOME::ExceptionStruct es; - es.type = SALOME::INTERNAL_ERROR; - std::string text = "write failed"; - es.text = CORBA::string_dup(text.c_str()); - throw SALOME::SALOME_Exception(es); - }; - // Close the target file - ::close(fd); - - Engines::file infos; - infos.file_name = CORBA::string_dup(file_name.c_str()); - infos.path = CORBA::string_dup(path.c_str()); - infos.type = CORBA::string_dup(type.c_str()); - infos.source_file_name = CORBA::string_dup(source_file_name.c_str()); - infos.status = CORBA::string_dup(status.c_str()); - - _fileManaged[file_name] = infos; - - // Update Salome_file state - _state.number_of_files++; - _state.files_ok = true; + if ( (fd = ::open(file_name.c_str(),O_RDWR|O_CREAT,00666)) <0) { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + std::string text = "open failed"; + es.text = CORBA::string_dup(text.c_str()); + throw SALOME::SALOME_Exception(es); + } + hdf_dataset->ReadFromDisk(buffer); + if ( write(fd,buffer,(unsigned int)size) <0) { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + std::string text = "write failed"; + es.text = CORBA::string_dup(text.c_str()); + throw SALOME::SALOME_Exception(es); + } + // Close the target file + ::close(fd); + + Engines::file infos; + infos.file_name = CORBA::string_dup(file_name.c_str()); + infos.path = CORBA::string_dup(path.c_str()); + infos.type = CORBA::string_dup(type.c_str()); + infos.source_file_name = CORBA::string_dup(source_file_name.c_str()); + infos.status = CORBA::string_dup(status.c_str()); + + _fileManaged[file_name] = infos; + + // Update Salome_file state + _state.number_of_files++; + _state.files_ok = true; } else { - Engines::file infos; - infos.file_name = CORBA::string_dup(file_name.c_str()); - infos.path = CORBA::string_dup(path.c_str()); - infos.type = CORBA::string_dup(type.c_str()); - infos.source_file_name = CORBA::string_dup(source_file_name.c_str()); - infos.status = CORBA::string_dup(status.c_str()); - // Infos for parallel extensions... - infos.node = 0; - infos.container = Engines::Container::_duplicate(_container); - - _fileManaged[file_name] = infos; - - // Update Salome_file state - _state.number_of_files++; - if (status != "ok") - _state.files_ok = false; + Engines::file infos; + infos.file_name = CORBA::string_dup(file_name.c_str()); + infos.path = CORBA::string_dup(path.c_str()); + infos.type = CORBA::string_dup(type.c_str()); + infos.source_file_name = CORBA::string_dup(source_file_name.c_str()); + infos.status = CORBA::string_dup(status.c_str()); + // Infos for parallel extensions... + infos.node = 0; + infos.container = Engines::Container::_duplicate(_container); + + _fileManaged[file_name] = infos; + + // Update Salome_file state + _state.number_of_files++; + if (status != "ok") + _state.files_ok = false; } } } @@ -370,7 +373,7 @@ Salome_file_i::save_all(const char* hdf5_file) { } // For each file we create two groups - // First group contains file's informations + // First group contains file's information // Second group contains the file // At the end we create a group and a dataset containing the names // of all the files. @@ -498,7 +501,7 @@ Salome_file_i::setLocalFile(const char* comp_file_name) std::string cp_file_name(comp_file_name); std::size_t index = cp_file_name.rfind("/"); - if (index != -1) + if (index != std::string::npos) { file_name = cp_file_name.substr(index+1); path = cp_file_name.substr(0,index+1); @@ -524,7 +527,7 @@ Salome_file_i::setLocalFile(const char* comp_file_name) if(fopen(comp_file_name,"rb") != NULL) status = "ok"; - // Adding file with is informations + // Adding file with its information Engines::file infos; infos.file_name = CORBA::string_dup(file_name.c_str()); infos.path = CORBA::string_dup(path.c_str()); @@ -560,7 +563,7 @@ Salome_file_i::setDistributedFile(const char* comp_file_name) std::string cp_file_name(comp_file_name); std::size_t index = cp_file_name.rfind("/"); - if (index != -1) + if (index != std::string::npos) { file_name = cp_file_name.substr(index+1); path = cp_file_name.substr(0,index+1); @@ -582,7 +585,7 @@ Salome_file_i::setDistributedFile(const char* comp_file_name) throw SALOME::SALOME_Exception(es); } - // Adding file with his informations + // Adding file with its information Engines::file infos; infos.file_name = CORBA::string_dup(file_name.c_str()); infos.path = CORBA::string_dup(path.c_str()); @@ -626,7 +629,7 @@ Salome_file_i::connect(Engines::Salome_file_ptr source_Salome_file) _t_fileDistributedSource::iterator it = _fileDistributedSource.find(file_name); if (it == _fileDistributedSource.end()) { - _fileDistributedSource[file_name] = Engines::Salome_file::_duplicate(source_Salome_file); + _fileDistributedSource[file_name] = Engines::Salome_file::_duplicate(source_Salome_file); } } } @@ -666,7 +669,7 @@ Salome_file_i::connect(Engines::Salome_file_ptr source_Salome_file) //============================================================================= void Salome_file_i::connectDistributedFile(const char * file_name, - Engines::Salome_file_ptr source_Salome_file) + Engines::Salome_file_ptr source_Salome_file) { // Test if this file is added _t_fileManaged::iterator it = _fileManaged.find(file_name); @@ -692,7 +695,7 @@ Salome_file_i::connectDistributedFile(const char * file_name, //============================================================================= void Salome_file_i::setDistributedSourceFile(const char* file_name, - const char * source_file_name) + const char * source_file_name) { std::string fname(file_name); @@ -733,12 +736,12 @@ Salome_file_i::recvFiles() { if (std::string(file_infos.type.in()) == "local") { if (std::string(file_infos.status.in()) == "not_ok") - result = checkLocalFile(file_infos.file_name.in()); + result = checkLocalFile(file_infos.file_name.in()); } else { if (std::string(file_infos.status.in()) == "not_ok") - result = getDistributedFile(file_infos.file_name.in()); + result = getDistributedFile(file_infos.file_name.in()); } // if the result is false // we add this file to files_not_ok @@ -880,7 +883,7 @@ Salome_file_i::getDistributedFile(std::string file_name) */ //============================================================================= void -Salome_file_i::removeFile(const char* file_name) +Salome_file_i::removeFile(const char* /*file_name*/) { MESSAGE("Salome_file_i::removeFile : NOT YET IMPLEMENTED"); } @@ -906,7 +909,7 @@ Engines::files* Salome_file_i::getFilesInfos() { Engines::files * infos = new Engines::files(); - infos->length(_fileManaged.size()); + infos->length((CORBA::ULong)_fileManaged.size()); _t_fileManaged::iterator begin = _fileManaged.begin(); _t_fileManaged::iterator end = _fileManaged.end(); @@ -959,7 +962,7 @@ Salome_file_i::getSalome_fileState() /*! * CORBA method: try to open the file given. If the file is readable, return * a positive integer else return 0; - * \param fileName file name to be transfered + * \param fileName file name to be transferred * \return fileId = positive integer > 0 if open OK. */ //============================================================================= @@ -1055,8 +1058,8 @@ Salome_file_i::getBlock(CORBA::Long fileId) // see Advanced CORBA Programming with C++ pp 187-194 CORBA::Octet *buf; buf = Engines::fileBlock::allocbuf(FILEBLOCK_SIZE); - int nbRed = fread(buf, sizeof(CORBA::Octet), FILEBLOCK_SIZE, fp); - aBlock->replace(nbRed, nbRed, buf, 1); // 1 means give ownership + size_t nbRed = fread(buf, sizeof(CORBA::Octet), FILEBLOCK_SIZE, fp); + aBlock->replace((CORBA::ULong)nbRed, (CORBA::ULong)nbRed, buf, 1); // 1 means give ownership //!< TODO: conversion from size_t to CORBA::ULong return aBlock; }