From 5223084ae20e1229e86bdb4e6244a1778a8900f7 Mon Sep 17 00:00:00 2001 From: ribes Date: Thu, 19 Jul 2007 09:00:41 +0000 Subject: [PATCH] - Adding Salome_file into kernel : it proposes a new way to manage files. It will be used into services ports in supervisor schemas - HDF is now not depending on CAS. - Parallel version of Salome_file is not yet finished. --- idl/SALOME_Component.idl | 25 +- src/Container/Makefile.am | 1 - src/Container/Salome_file_i.cxx | 224 ++++++++++++++++-- src/Container/Salome_file_i.hxx | 17 +- src/Container/TestSalome_file.cxx | 16 +- src/HDFPersist/HDFascii.cc | 221 ++++++++++++----- src/HDFPersist/HDFascii.hxx | 4 +- src/HDFPersist/HDFcontainerObject.cc | 2 +- src/HDFPersist/HDFcontainerObject.hxx | 4 +- src/HDFPersist/HDFdataset.hxx | 4 +- src/HDFPersist/HDFexport.hxx | 39 +++ src/HDFPersist/HDFfile.hxx | 4 +- src/HDFPersist/HDFgroup.hxx | 4 +- src/HDFPersist/HDFinternalObject.hxx | 4 +- src/HDFPersist/HDFobject.cc | 2 +- src/HDFPersist/HDFobject.hxx | 4 +- src/HDFPersist/Makefile.am | 11 +- src/ParallelContainer/Makefile.am | 1 - .../SALOME_ParallelComponent_i.cxx | 153 ++++++++++++ .../SALOME_ParallelComponent_i.hxx | 23 ++ 20 files changed, 650 insertions(+), 113 deletions(-) create mode 100644 src/HDFPersist/HDFexport.hxx diff --git a/idl/SALOME_Component.idl b/idl/SALOME_Component.idl index 5c8746f32..8c0a3cc36 100644 --- a/idl/SALOME_Component.idl +++ b/idl/SALOME_Component.idl @@ -497,13 +497,32 @@ module Engines Add a Distributed file to the Salome_file. \param comp_file_name name of the file with the path. - \param source_Salome_file Salome_file that managed the distributed version of the file. \exception raised if the file is already added into the Salome_file. */ - void setDistributedFile(in string comp_file_name, - in Engines::Salome_file source_Salome_file) raises (SALOME::SALOME_Exception); + void setDistributedFile(in string comp_file_name) raises (SALOME::SALOME_Exception); + + /*! + Connect a Salome_file with another Salome_file. + It works only if the Salome_file managed only one file + + \param source_Salome_file Salome_file that managed the distributed version of the file. + + \exception raised if there is more or less than one file. + */ + void connect(in Engines::Salome_file source_Salome_file) raises (SALOME::SALOME_Exception); + /*! + Connect the managed file file_name to a Salome_file. + + \param file_name name of the file without the path. + \param source_Salome_file Salome_file that managed the distributed version of the file. + + \exception raised if the file doesn't exist. + */ + void connectDistributedFile(in string file_name, + in Engines::Salome_file source_Salome_file) raises (SALOME::SALOME_Exception); + /*! Connect the file_name with a Distributed file_name. diff --git a/src/Container/Makefile.am b/src/Container/Makefile.am index 2ccd098c9..4c8b65729 100644 --- a/src/Container/Makefile.am +++ b/src/Container/Makefile.am @@ -64,7 +64,6 @@ dist_salomescript_SCRIPTS=\ COMMON_CPPFLAGS=\ @PYTHON_INCLUDES@ \ @MPI_INCLUDES@ \ - @CAS_CPPFLAGS@ @CAS_CXXFLAGS@ \ @QT_MT_INCLUDES@ \ -I$(srcdir)/../Basics \ -I$(srcdir)/../SALOMELocalTrace \ diff --git a/src/Container/Salome_file_i.cxx b/src/Container/Salome_file_i.cxx index 43fe8b1b5..aef2e21bf 100644 --- a/src/Container/Salome_file_i.cxx +++ b/src/Container/Salome_file_i.cxx @@ -56,6 +56,12 @@ Salome_file_i::~Salome_file_i() { } +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::load + */ +//============================================================================= void Salome_file_i::load(const char* hdf5_file) { _state.hdf5_file_name = CORBA::string_dup(hdf5_file); @@ -218,6 +224,12 @@ Salome_file_i::load(const char* hdf5_file) { } } +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::save + */ +//============================================================================= void Salome_file_i::save(const char* hdf5_file) { _state.hdf5_file_name = CORBA::string_dup(hdf5_file); @@ -319,6 +331,12 @@ Salome_file_i::save(const char* hdf5_file) { } } +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::save_all + */ +//============================================================================= void Salome_file_i::save_all(const char* hdf5_file) { @@ -444,6 +462,12 @@ Salome_file_i::save_all(const char* hdf5_file) { } } +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::setLocalFile + */ +//============================================================================= void Salome_file_i::setLocalFile(const char* comp_file_name) { @@ -499,9 +523,14 @@ Salome_file_i::setLocalFile(const char* comp_file_name) _state.files_ok = false; } +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::setDistributedFile + */ +//============================================================================= void -Salome_file_i::setDistributedFile(const char* comp_file_name, - Engines::Salome_file_ptr source_Salome_file) +Salome_file_i::setDistributedFile(const char* comp_file_name) { std::string file_name(""); std::string path(""); @@ -525,17 +554,17 @@ Salome_file_i::setDistributedFile(const char* comp_file_name, } // Test if this file is already added - //_t_fileManaged::iterator it = _fileManaged.find(file_name); - //if (it != _fileManaged.end()) - //{ - // SALOME::ExceptionStruct es; - // es.type = SALOME::INTERNAL_ERROR; - // std::string text = "file already added"; - // es.text = CORBA::string_dup(text.c_str()); - // throw SALOME::SALOME_Exception(es); - //} + _t_fileManaged::iterator it = _fileManaged.find(file_name); + if (it != _fileManaged.end()) + { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + std::string text = "file already added"; + es.text = CORBA::string_dup(text.c_str()); + throw SALOME::SALOME_Exception(es); + } - // Adding file with is informations + // Adding file with his informations Engines::file infos; infos.file_name = CORBA::string_dup(file_name.c_str()); infos.path = CORBA::string_dup(path.c_str()); @@ -544,33 +573,100 @@ Salome_file_i::setDistributedFile(const char* comp_file_name, infos.status = CORBA::string_dup(status.c_str()); _fileManaged[file_name] = infos; - _fileDistributedSource[file_name] = Engines::Salome_file::_duplicate(source_Salome_file); // Update Salome_file state _state.number_of_files++; _state.files_ok = false; } +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::connect + */ +//============================================================================= +void +Salome_file_i::connect(Engines::Salome_file_ptr source_Salome_file) +{ + // We can connect this Salome_file if there is only one file managed + // by the Salome_file + std::string fname; + if (_fileManaged.size() == 1) + { + // only one file managed + _t_fileManaged::iterator it = _fileManaged.begin(); + fname = it->first; + _fileDistributedSource[fname] = Engines::Salome_file::_duplicate(source_Salome_file); + } + else + { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + std::string text = "cannot connect"; + es.text = CORBA::string_dup(text.c_str()); + throw SALOME::SALOME_Exception(es); + } +} +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::connectDistributedFile + */ +//============================================================================= +void +Salome_file_i::connectDistributedFile(const char * file_name, + Engines::Salome_file_ptr source_Salome_file) +{ + // Test if this file is added + _t_fileManaged::iterator it = _fileManaged.find(file_name); + if (it == _fileManaged.end()) + { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + std::string text = "file is not added"; + es.text = CORBA::string_dup(text.c_str()); + throw SALOME::SALOME_Exception(es); + } + else + { + _fileDistributedSource[file_name] = Engines::Salome_file::_duplicate(source_Salome_file); + } +} + +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::setDistributedSourceFile + */ +//============================================================================= void Salome_file_i::setDistributedSourceFile(const char* file_name, const char * source_file_name) { std::string fname(file_name); - // Test if this file is managed + // Test if this file is added _t_fileManaged::iterator it = _fileManaged.find(fname); if (it == _fileManaged.end()) { SALOME::ExceptionStruct es; es.type = SALOME::INTERNAL_ERROR; - std::string text = "file is not managed"; + std::string text = "file is not added"; es.text = CORBA::string_dup(text.c_str()); throw SALOME::SALOME_Exception(es); } - - _fileManaged[fname].source_file_name = CORBA::string_dup(source_file_name); + else + { + _fileManaged[fname].source_file_name = CORBA::string_dup(source_file_name); + } } +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::recvFiles + */ +//============================================================================= void Salome_file_i::recvFiles() { @@ -582,6 +678,7 @@ Salome_file_i::recvFiles() { { bool result = true; Engines::file file_infos = begin->second; + // Test if the file is local or distributed if (std::string(file_infos.type.in()) == "local") { if (std::string(file_infos.status.in()) == "not_ok") @@ -592,6 +689,8 @@ Salome_file_i::recvFiles() { if (std::string(file_infos.status.in()) == "not_ok") result = getDistributedFile(file_infos.file_name.in()); } + // if the result is false + // we add this file to files_not_ok if (!result) { files_not_ok.append(" "); @@ -607,11 +706,20 @@ Salome_file_i::recvFiles() { es.text = CORBA::string_dup(text.c_str()); throw SALOME::SALOME_Exception(es); } - - // We change the state of the Salome_file - _state.files_ok = true; + else + { + // We change the state of the Salome_file + _state.files_ok = true; + } } +//============================================================================= +/*! + * local C++ method : This method is used by revFiles to check if a local + * managed file is ok. + * \param fileName name of the file + */ +//============================================================================= bool Salome_file_i::checkLocalFile(std::string file_name) { @@ -633,6 +741,17 @@ Salome_file_i::checkLocalFile(std::string file_name) return result; } +//============================================================================= +/*! + * local C++ method : this method is used by recvFiles to get a + * distributed file from is distributed source. + * If there is no source_file_name for the file, it tries to get + * the file from the source. In this case, the source distributed file has to managed + * only one file to be able to the send the file. + * + * \param fileName name of the file + */ +//============================================================================= bool Salome_file_i::getDistributedFile(std::string file_name) { @@ -695,27 +814,57 @@ Salome_file_i::getDistributedFile(std::string file_name) return result; } +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::removeFile + */ +//============================================================================= void Salome_file_i::removeFile(const char* file_name) { MESSAGE("Salome_file_i::removeFile : NOT YET IMPLEMENTED"); } +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::deleteFile + */ +//============================================================================= void Salome_file_i::deleteFile(const char* file_name) { MESSAGE("Salome_file_i::deleteFile : NOT YET IMPLEMENTED"); } +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::removeFiles + */ +//============================================================================= void Salome_file_i::removeFiles() { MESSAGE("Salome_file_i::removeFiles : NOT YET IMPLEMENTED"); } +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::deleteFiles + */ +//============================================================================= void Salome_file_i::deleteFiles() { MESSAGE("Salome_file_i::deleteFiles : NOT YET IMPLEMENTED"); } +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::recvFiles + */ +//============================================================================= Engines::files* Salome_file_i::getFilesInfos() { @@ -732,6 +881,12 @@ Salome_file_i::getFilesInfos() { return infos; } +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::getFileInfos + */ +//============================================================================= Engines::file* Salome_file_i::getFileInfos(const char* file_name) { @@ -751,6 +906,12 @@ Salome_file_i::getFileInfos(const char* file_name) { return infos; } +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::getSalome_fileState + */ +//============================================================================= Engines::SfState* Salome_file_i::getSalome_fileState() { @@ -761,7 +922,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 path to the file to be transfered + * \param fileName file name to be transfered * \return fileId = positive integer > 0 if open OK. */ //============================================================================= @@ -772,14 +933,31 @@ Salome_file_i::open(const char* file_name) int aKey = 0; std::string fname(file_name); + if (fname == "") { + // We enter in the simple case where the user + // has not used setDistributedSourceFile. + // In this case we try to see if the Salome_file + if (_fileManaged.size() == 1) + { + // only one file managed + _t_fileManaged::iterator it = _fileManaged.begin(); + fname = it->first; + } + else + { + // we can't choose the file so : + return aKey; + } + } + _t_fileManaged::iterator it = _fileManaged.find(fname); if (it == _fileManaged.end()) { return aKey; } - std::string comp_file_name(_fileManaged[file_name].path.in()); - comp_file_name.append(_fileManaged[file_name].file_name.in()); + std::string comp_file_name(_fileManaged[fname].path.in()); + comp_file_name.append(fname); MESSAGE("Salome_file_i::open " << comp_file_name); FILE* fp; if ((fp = fopen(comp_file_name.c_str(),"rb")) == NULL) diff --git a/src/Container/Salome_file_i.hxx b/src/Container/Salome_file_i.hxx index bcdd6d17b..b8432cd01 100644 --- a/src/Container/Salome_file_i.hxx +++ b/src/Container/Salome_file_i.hxx @@ -49,8 +49,12 @@ class CONTAINER_EXPORT Salome_file_i: // Adding files virtual void setLocalFile(const char* comp_file_name); - virtual void setDistributedFile(const char* comp_file_name, - Engines::Salome_file_ptr source_Salome_file); + virtual void setDistributedFile(const char* comp_file_name); + + // Configure DistributedFile + virtual void connect(Engines::Salome_file_ptr source_Salome_file); + virtual void connectDistributedFile(const char * file_name, + Engines::Salome_file_ptr source_Salome_file); virtual void setDistributedSourceFile(const char* file_name, const char * source_file_name); @@ -64,7 +68,7 @@ class CONTAINER_EXPORT Salome_file_i: virtual void deleteFiles(); - // Informations methods + // Informations methods: virtual Engines::files* getFilesInfos(); virtual Engines::file* getFileInfos(const char* file_name); virtual Engines::SfState* getSalome_fileState(); @@ -80,8 +84,15 @@ class CONTAINER_EXPORT Salome_file_i: virtual bool getDistributedFile(std::string file_name); protected: + + // Contains a relation between a file ID (int) with + // a fd descriptor (FILE*) open on the file. typedef std::map _t_fileAccess; + + // Contains the informations of the files managed by the Salome_file. typedef std::map _t_fileManaged; + + // Contains the CORBA reference for each distributed file managed. typedef std::map _t_fileDistributedSource; int _fileId; diff --git a/src/Container/TestSalome_file.cxx b/src/Container/TestSalome_file.cxx index f89558b06..76d3b031f 100644 --- a/src/Container/TestSalome_file.cxx +++ b/src/Container/TestSalome_file.cxx @@ -2,6 +2,7 @@ #include #include #include +#include "HDFascii.hxx" using namespace std; @@ -73,8 +74,9 @@ int main (int argc, char * argv[]) cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl; cerr << "Test of setDistributedFile()" << endl; - file.setDistributedFile("/tmp/toto_distributed", file2_ref); - file.setDistributedSourceFile("toto_distributed", "toto_distributed_source"); + file.setDistributedFile("/tmp/toto_distributed"); + file.connectDistributedFile("toto_distributed", file2_ref); +// file.setDistributedSourceFile("toto_distributed", "toto_distributed_source"); infos = file.getFileInfos("toto_distributed"); print_infos(infos); @@ -139,4 +141,14 @@ int main (int argc, char * argv[]) } state = file5.getSalome_fileState(); print_state(state); + + // Test of ConvertFromHDFToASCII + // and ConvertFromASCIIToHDF + cerr << "Test of ConvertFromASCIIToHDF" << endl; + HDFascii::ConvertFromASCIIToHDF("/tmp/toto"); // RETURN NULL ! + cerr << "Test of ConvertFromHDFToASCII" << endl; + cerr << HDFascii::ConvertFromHDFToASCII("test2.hdf", false) << endl; + cerr << HDFascii::ConvertFromHDFToASCII("test2.hdf", true) << endl; + + cerr << "End of tests" << endl; } diff --git a/src/HDFPersist/HDFascii.cc b/src/HDFPersist/HDFascii.cc index 4d3d58f39..1408f71be 100644 --- a/src/HDFPersist/HDFascii.cc +++ b/src/HDFPersist/HDFascii.cc @@ -26,16 +26,20 @@ #include "HDFOI.hxx" -#include -#include -#include -#include -#include +//#include +//#include +//#include +//#include +//#include #include #include #include #include +#include +#include +#include +#include #ifdef WNT #include @@ -57,6 +61,9 @@ char* makeName(char* name); char* restoreName(char* name); void write_float64(FILE* fp, hdf_float64* value); void read_float64(FILE* fp, hdf_float64* value); +bool directoryExists(const char* dir); +bool createDirectory(const char* dir); +bool is_readable( const std::string & file ); #define MAX_STRING_SIZE 65535 #define MAX_ID_SIZE 20 @@ -104,13 +111,15 @@ char* HDFascii::ConvertFromHDFToASCII(const char* thePath, bool isReplace, const char* theExtension) { - TCollection_AsciiString aPath((char*)thePath); + //TCollection_AsciiString aPath((char*)thePath); + std::string aPath((char*)thePath); if(!isReplace) { if(theExtension == NULL) aPath += ".asc"; else aPath += (char*)theExtension; } - TCollection_AsciiString aFileName(aPath); + //TCollection_AsciiString aFileName(aPath); + std::string aFileName(aPath); if(isReplace) aFileName=aPath+".ascii_tmp"; HDFfile *hdf_file = new HDFfile((char*)thePath); @@ -119,7 +128,8 @@ char* HDFascii::ConvertFromHDFToASCII(const char* thePath, char name[HDF_NAME_MAX_LEN+1]; int nbsons = hdf_file->nInternalObjects(), nbAttr = hdf_file->nAttributes(); - FILE* fp = fopen(aFileName.ToCString(), "w"); + //FILE* fp = fopen(aFileName.ToCString(), "w"); + FILE* fp = fopen(aFileName.c_str(), "w"); fprintf(fp, "%s\n", ASCIIHDF_ID); fprintf(fp, "%i\n", nbsons+nbAttr); @@ -131,7 +141,8 @@ char* HDFascii::ConvertFromHDFToASCII(const char* thePath, hdf_attribute = 0; } - for (Standard_Integer i=0; iInternalObjectIndentify(i,name); if (strncmp(name, "INTERNAL_COMPLEX",16) == 0) continue; @@ -156,17 +167,24 @@ char* HDFascii::ConvertFromHDFToASCII(const char* thePath, delete hdf_file; if(isReplace) { - OSD_Path anOSDPath(aFileName); - OSD_File anOSDFile(anOSDPath); - if(anOSDFile.Exists()) - anOSDFile.Move(aPath); - else +// OSD_Path anOSDPath(aFileName); +// OSD_File anOSDFile(anOSDPath); +// if(anOSDFile.Exists()) +// anOSDFile.Move(aPath); +// else +// return NULL; + if(access (aFileName.c_str() , F_OK ) == 0) { + rename(aFileName.c_str(), aPath.c_str()); + } + else return NULL; } - int length = strlen(aPath.ToCString()); + //int length = strlen(aPath.ToCString()); + int length = strlen(aPath.c_str()); char *new_str = new char[ 1+length ]; - strcpy(new_str , aPath.ToCString()) ; + //strcpy(new_str , aPath.ToCString()) ; + strcpy(new_str , aPath.c_str()) ; return new_str; } @@ -180,7 +198,10 @@ void SaveGroupInASCIIfile(HDFgroup *hdf_group, FILE* fp, int ident) { hdf_group->OpenOnDisk(); - TCollection_AsciiString anIdent(ident, '\t'); + //TCollection_AsciiString anIdent(ident, '\t'); + std::ostringstream oss; + oss << ident; + std::string anIdent(oss.str()); int nbsons = hdf_group->nInternalObjects(), nbAttr = hdf_group->nAttributes(); /*fprintf(fp, "%s%s\n", anIdent.ToCString(), GROUP_ID);*/ @@ -241,8 +262,14 @@ void SaveDatasetInASCIIfile(HDFdataset *hdf_dataset, FILE* fp, int ident) hdf_byte_order order = hdf_dataset->GetOrder(); int nbAttr = hdf_dataset->nAttributes(); - TCollection_AsciiString anIdent(ident, '\t'); - TCollection_AsciiString anIdentChild(ident+1, '\t'); +// TCollection_AsciiString anIdent(ident, '\t'); +// TCollection_AsciiString anIdentChild(ident+1, '\t'); + std::ostringstream oss; + std::ostringstream oss2; + oss << ident; + oss2 << ident+1; + std::string anIdent(oss.str()); + std::string anIdentChild(oss2.str()); char* name = makeName(hdf_dataset->GetName()); @@ -341,8 +368,14 @@ void SaveAttributeInASCIIfile(HDFattribute *hdf_attribute, FILE* fp, int ident) hdf_type type = hdf_attribute->GetType(); - TCollection_AsciiString anIdent(ident, '\t'); - TCollection_AsciiString anIdentChild(ident+1, '\t'); + //TCollection_AsciiString anIdent(ident, '\t'); + //TCollection_AsciiString anIdentChild(ident+1, '\t'); + std::ostringstream oss; + std::ostringstream oss2; + oss << ident; + oss2 << ident+1; + std::string anIdent(oss.str()); + std::string anIdentChild(oss2.str()); char* name = makeName(hdf_attribute->GetName()); int size = hdf_attribute->GetSize(); @@ -397,11 +430,15 @@ void SaveAttributeInASCIIfile(HDFattribute *hdf_attribute, FILE* fp, int ident) char* HDFascii::ConvertFromASCIIToHDF(const char* thePath) { // Get a temporary directory to store a file - TCollection_AsciiString aTmpDir = GetTmpDir(), aFileName("hdf_from_ascii.hdf"); + //TCollection_AsciiString aTmpDir = GetTmpDir(), aFileName("hdf_from_ascii.hdf"); + std::string aTmpDir = GetTmpDir(); + std::string aFileName("hdf_from_ascii.hdf"); // Build a full file name of temporary file - TCollection_AsciiString aFullName = aTmpDir + aFileName; + //TCollection_AsciiString aFullName = aTmpDir + aFileName; + std::string aFullName = aTmpDir + aFileName; - HDFfile *hdf_file = new HDFfile(aFullName.ToCString()); + //HDFfile *hdf_file = new HDFfile(aFullName.ToCString()); + HDFfile *hdf_file = new HDFfile((char *) aFullName.c_str()); hdf_file->CreateOnDisk(); FILE *fp = fopen(thePath, "r"); @@ -450,9 +487,15 @@ char* HDFascii::ConvertFromASCIIToHDF(const char* thePath) hdf_file->CloseOnDisk(); delete hdf_file; - int length = strlen(aTmpDir.ToCString()); + //int length = strlen(aTmpDir.ToCString()); + int length = strlen(aTmpDir.c_str()); + cerr << "length : " << length << endl; char *new_str = new char[ 1+length ]; - strcpy(new_str , aTmpDir.ToCString()) ; + //strcpy(new_str , aTmpDir.ToCString()) ; + strcpy(new_str , aTmpDir.c_str()) ; + + cerr << "test ::: " << aTmpDir << endl; + cerr << "test ::: " << new_str << endl; return new_str; } @@ -677,83 +720,115 @@ char* GetTmpDir() { //Find a temporary directory to store a file - TCollection_AsciiString aTmpDir; + //TCollection_AsciiString aTmpDir; + std::string aTmpDir; #ifdef WNT char *aTmp; aTmp = getenv("TMP"); - if(aTmp != NULL) - aTmpDir = TCollection_AsciiString(aTmp); - else - aTmpDir = TCollection_AsciiString("C:\\"); + if(aTmp != NULL) { +// aTmpDir = TCollection_AsciiString(aTmp); + aTmpDir = std::string(aTmp); + } + else { +// aTmpDir = TCollection_AsciiString("C:\\"); + aTmpDir = std::string("C:\\"); + } #else - aTmpDir = TCollection_AsciiString("/tmp/"); + //aTmpDir = TCollection_AsciiString("/tmp/"); + aTmpDir = std::string("/tmp/"); #endif srand((unsigned int)time(NULL)); int aRND = 999 + (int)(100000.0*rand()/(RAND_MAX+1.0)); //Get a random number to present a name of a sub directory - TCollection_AsciiString aSubDir(aRND); - if(aSubDir.Length() <= 1) aSubDir = TCollection_AsciiString("123409876"); +// TCollection_AsciiString aSubDir(aRND); +// if(aSubDir.Length() <= 1) aSubDir = TCollection_AsciiString("123409876"); + std::ostringstream oss; + oss << aRND; + std::string aSubDir(oss.str()); + if(aSubDir.length() <= 1) aSubDir = std::string("123409876"); aTmpDir += aSubDir; //Get RND sub directory #ifdef WIN32 - if(aTmpDir.Value(aTmpDir.Length()) != '\\') aTmpDir+='\\'; +// if(aTmpDir.Value(aTmpDir.Length()) != '\\') aTmpDir+='\\'; + if(aTmpDir[aTmpDir.length()-1] != '\\') aTmpDir+='\\'; #else - if(aTmpDir.Value(aTmpDir.Length()) != '/') aTmpDir+='/'; +// if(aTmpDir.Value(aTmpDir.Length()) != '/') aTmpDir+='/'; + if(aTmpDir[aTmpDir.length()-1] != '/') aTmpDir+='/'; #endif - OSD_Path aPath(aTmpDir); - OSD_Directory aDir(aPath); +// OSD_Path aPath(aTmpDir); +// OSD_Directory aDir(aPath); + std::string aDir(aTmpDir); - for(aRND = 0; aDir.Exists(); aRND++) { - aTmpDir.Insert((aTmpDir.Length() - 1), TCollection_AsciiString(aRND)); //Build a unique directory name - aPath = OSD_Path(aTmpDir); - aDir = OSD_Directory(aPath); - } + //std::cerr << "temp dir .... : " << aTmpDir << std::endl; - OSD_Protection aProtection(OSD_RW, OSD_RWX, OSD_RX, OSD_RX); - aDir.Build(aProtection); + for(aRND = 0; directoryExists(aDir.c_str()); aRND++) { + //aTmpDir.Insert((aTmpDir.Length() - 1), TCollection_AsciiString(aRND)); //Build a unique directory name + aTmpDir.insert((aTmpDir.length() - 1), oss.str()); //Build a unique directory name + std::cerr << "Tempory directory exist, changing name ..." << std::endl; + std::cerr << "temp dir .... : " << aTmpDir << std::endl; + aDir = std::string(aTmpDir); +// aPath = OSD_Path(aTmpDir); +// aDir = OSD_Directory(aPath); + } - int length = strlen(aTmpDir.ToCString()); + //OSD_Protection aProtection(OSD_RW, OSD_RWX, OSD_RX, OSD_RX); + //aDir.Build(aProtection); + createDirectory(aDir.c_str()); + //int length = strlen(aTmpDir.ToCString()); + int length = strlen(aTmpDir.c_str()); char *new_str = new char[ 1+length ]; - strcpy(new_str , aTmpDir.ToCString()); - + //strcpy(new_str , aTmpDir.ToCString()); + strcpy(new_str , aTmpDir.c_str()); return new_str; } char* makeName(char* name) { - TCollection_AsciiString aName(name), aNewName; - Standard_Integer i, length = aName.Length(); + //TCollection_AsciiString aName(name), aNewName; + std::string aName(name), aNewName; + //Standard_Integer i, length = aName.Length(); + int i, length = aName.length(); char replace = (char)19; for(i=1; i<=length; i++) { - if(aName.Value(i) == ' ') aNewName+=replace; - else aNewName += aName.Value(i); + //if(aName.Value(i) == ' ') aNewName+=replace; + //else aNewName += aName.Value(i); + if(aName[i] == ' ') aNewName+=replace; + else aNewName += aName[i]; } - length = strlen(aNewName.ToCString()); + //length = strlen(aNewName.ToCString()); + length = strlen(aNewName.c_str()); char *new_str = new char[ 1+length ]; - strcpy(new_str , aNewName.ToCString()) ; + //strcpy(new_str , aNewName.ToCString()) ; + strcpy(new_str , aNewName.c_str()) ; return new_str; } char* restoreName(char* name) { - TCollection_AsciiString aName(name), aNewName; - Standard_Integer i, length = aName.Length(); + //TCollection_AsciiString aName(name), aNewName; + std::string aName(name), aNewName; + //Standard_Integer i, length = aName.Length(); + int i, length = aName.length(); char replace = (char)19; for(i=1; i<=length; i++) { - if(aName.Value(i) == replace) aNewName+=' '; - else aNewName += aName.Value(i); + //if(aName.Value(i) == replace) aNewName+=' '; + //else aNewName += aName.Value(i); + if(aName[i] == replace) aNewName+=' '; + else aNewName += aName[i]; } - length = strlen(aNewName.ToCString()); + //length = strlen(aNewName.ToCString()); + length = strlen(aNewName.c_str()); char *new_str = new char[ 1+length ]; - strcpy(new_str , aNewName.ToCString()) ; + //strcpy(new_str , aNewName.ToCString()) ; + strcpy(new_str , aNewName.c_str()) ; return new_str; } @@ -775,3 +850,29 @@ void read_float64(FILE* fp, hdf_float64* value) array[i] = (unsigned char)tmp; } } + +bool directoryExists(const char* dir) +{ + DIR* dhandle = opendir(dir); + + if (dhandle != NULL) + { + closedir(dhandle); + return true; + } + else + { + return false; + } +} + +bool createDirectory(const char* dir) +{ + return mkdir(dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 0; +} + +bool is_readable( const std::string & file ) +{ + std::ifstream fichier( file.c_str() ); + return !fichier.fail(); +} diff --git a/src/HDFPersist/HDFascii.hxx b/src/HDFPersist/HDFascii.hxx index 5cbe219bd..999b17352 100644 --- a/src/HDFPersist/HDFascii.hxx +++ b/src/HDFPersist/HDFascii.hxx @@ -28,10 +28,10 @@ #ifndef __HDFascii_H__ #define __HDFascii_H__ -#include +#include "HDFexport.hxx" -class Standard_EXPORT HDFascii +class HDF_EXPORT HDFascii { public: diff --git a/src/HDFPersist/HDFcontainerObject.cc b/src/HDFPersist/HDFcontainerObject.cc index 70ecf2e13..04324b3b7 100644 --- a/src/HDFPersist/HDFcontainerObject.cc +++ b/src/HDFPersist/HDFcontainerObject.cc @@ -30,7 +30,7 @@ extern "C" } #include "HDFcontainerObject.hxx" #include "HDFexception.hxx" -#include "utilities.h" +//#include "utilities.h" using namespace std; HDFcontainerObject::HDFcontainerObject(char *name) diff --git a/src/HDFPersist/HDFcontainerObject.hxx b/src/HDFPersist/HDFcontainerObject.hxx index fef43ed21..ea8881e32 100644 --- a/src/HDFPersist/HDFcontainerObject.hxx +++ b/src/HDFPersist/HDFcontainerObject.hxx @@ -33,9 +33,9 @@ extern "C" } #include "HDFobject.hxx" #include "HDFinternalObject.hxx" -#include +#include "HDFexport.hxx" -class Standard_EXPORT HDFcontainerObject : public HDFinternalObject +class HDF_EXPORT HDFcontainerObject : public HDFinternalObject { private : HDFinternalObject *_firstson; diff --git a/src/HDFPersist/HDFdataset.hxx b/src/HDFPersist/HDFdataset.hxx index 3eff4f0df..8375497ea 100644 --- a/src/HDFPersist/HDFdataset.hxx +++ b/src/HDFPersist/HDFdataset.hxx @@ -33,9 +33,9 @@ extern "C" } #include "HDFinternalObject.hxx" #include "HDFcontainerObject.hxx" -#include +#include "HDFexport.hxx" -class Standard_EXPORT HDFdataset : public HDFinternalObject +class HDF_EXPORT HDFdataset : public HDFinternalObject { private : HDFcontainerObject *_father; diff --git a/src/HDFPersist/HDFexport.hxx b/src/HDFPersist/HDFexport.hxx new file mode 100644 index 000000000..21b64d34e --- /dev/null +++ b/src/HDFPersist/HDFexport.hxx @@ -0,0 +1,39 @@ +// Copyright (C) 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : HDFexport.hxx +// Author : Andre Ribes - EDF R&D +// Module : SALOME + +#ifndef _HDF_export_HXX_ +#define _HDF_export_HXX_ + +#ifdef WNT + #if defined WIN32 + #define HDF_EXPORT __declspec( dllimport ) + #else + #define HDF_EXPORT + #endif +#else + #define HDF_EXPORT +#endif + +#endif diff --git a/src/HDFPersist/HDFfile.hxx b/src/HDFPersist/HDFfile.hxx index 431dc001e..51c9aa7f1 100644 --- a/src/HDFPersist/HDFfile.hxx +++ b/src/HDFPersist/HDFfile.hxx @@ -32,9 +32,9 @@ extern "C" #include "HDFtypes.h" } #include "HDFcontainerObject.hxx" -#include +#include "HDFexport.hxx" -class Standard_EXPORT HDFfile : public HDFcontainerObject +class HDF_EXPORT HDFfile : public HDFcontainerObject { private : hdf_access_mode _access_mode; diff --git a/src/HDFPersist/HDFgroup.hxx b/src/HDFPersist/HDFgroup.hxx index 2641650e1..01c969d92 100644 --- a/src/HDFPersist/HDFgroup.hxx +++ b/src/HDFPersist/HDFgroup.hxx @@ -32,9 +32,9 @@ extern "C" #include "HDFtypes.h" } #include "HDFcontainerObject.hxx" -#include +#include "HDFexport.hxx" -class Standard_EXPORT HDFgroup : public HDFcontainerObject +class HDF_EXPORT HDFgroup : public HDFcontainerObject { private : HDFcontainerObject *_father; diff --git a/src/HDFPersist/HDFinternalObject.hxx b/src/HDFPersist/HDFinternalObject.hxx index fa05249de..06921850d 100644 --- a/src/HDFPersist/HDFinternalObject.hxx +++ b/src/HDFPersist/HDFinternalObject.hxx @@ -32,9 +32,9 @@ extern "C" #include "HDFtypes.h" } #include "HDFobject.hxx" -#include +#include "HDFexport.hxx" -class Standard_EXPORT HDFinternalObject : public HDFobject +class HDF_EXPORT HDFinternalObject : public HDFobject { private : HDFinternalObject *_previousbrother; diff --git a/src/HDFPersist/HDFobject.cc b/src/HDFPersist/HDFobject.cc index 42bb19b0b..1a032278a 100644 --- a/src/HDFPersist/HDFobject.cc +++ b/src/HDFPersist/HDFobject.cc @@ -30,7 +30,7 @@ extern "C" #include "hdfi.h" #include } -#include "utilities.h" +//#include "utilities.h" using namespace std; HDFobject::HDFobject(char *name) diff --git a/src/HDFPersist/HDFobject.hxx b/src/HDFPersist/HDFobject.hxx index a011003c1..e1396985a 100644 --- a/src/HDFPersist/HDFobject.hxx +++ b/src/HDFPersist/HDFobject.hxx @@ -31,9 +31,9 @@ extern "C" { #include "HDFtypes.h" } -#include +#include -class Standard_EXPORT HDFobject { +class HDF_EXPORT HDFobject { protected : char *_name; hdf_idt _id; diff --git a/src/HDFPersist/Makefile.am b/src/HDFPersist/Makefile.am index 92cb42c97..5e1925c9c 100644 --- a/src/HDFPersist/Makefile.am +++ b/src/HDFPersist/Makefile.am @@ -42,7 +42,8 @@ salomeinclude_HEADERS = \ HDFtypes.h \ HDFconvert.hxx \ hdfi.h \ - HDFascii.hxx + HDFascii.hxx \ + HDFexport.hxx # Libraries targets lib_LTLIBRARIES = libSalomeHDFPersist.la @@ -88,11 +89,13 @@ libSalomeHDFPersist_la_SOURCES =\ HDFascii.cc libSalomeHDFPersist_la_LDFLAGS = -no-undefined -version-info=0:0:0 -libSalomeHDFPersist_la_CPPFLAGS = @CAS_CPPFLAGS@ @HDF5_INCLUDES@ -DPCLINUX \ + +#libSalomeHDFPersist_la_CPPFLAGS = @CAS_CPPFLAGS@ @HDF5_INCLUDES@ -DPCLINUX \ +libSalomeHDFPersist_la_CPPFLAGS = @HDF5_INCLUDES@ -DPCLINUX \ -I$(srcdir)/../SALOMELocalTrace \ -I$(srcdir)/../Basics -libSalomeHDFPersist_la_LIBADD = @CAS_KERNEL@ @HDF5_LIBS@ - +#libSalomeHDFPersist_la_LIBADD = @CAS_KERNEL@ @HDF5_LIBS@ +libSalomeHDFPersist_la_LIBADD = @HDF5_LIBS@ EXTRA_DIST = \ test1.c \ diff --git a/src/ParallelContainer/Makefile.am b/src/ParallelContainer/Makefile.am index a3cff1e38..4fc7ec173 100644 --- a/src/ParallelContainer/Makefile.am +++ b/src/ParallelContainer/Makefile.am @@ -53,7 +53,6 @@ COMMON_CPPFLAGS= -I$(top_srcdir)/src/Container \ -I$(top_builddir)/salome_adm/unix \ -I$(top_builddir)/idl \ -I$(top_srcdir)/src/SALOMETraceCollector \ - @CAS_CPPFLAGS@ @CAS_CXXFLAGS@ \ @CORBA_CXXFLAGS@ \ @CORBA_INCLUDES@ \ @PACO_INCLUDES@ diff --git a/src/ParallelContainer/SALOME_ParallelComponent_i.cxx b/src/ParallelContainer/SALOME_ParallelComponent_i.cxx index ddcd47d80..f215c2291 100644 --- a/src/ParallelContainer/SALOME_ParallelComponent_i.cxx +++ b/src/ParallelContainer/SALOME_ParallelComponent_i.cxx @@ -770,3 +770,156 @@ Engines::TMPFile* Engines_Parallel_Component_i::DumpPython(CORBA::Object_ptr the isValidScript = true; return aStreamFile._retn(); } + +Engines::Salome_file_ptr +Engines_Parallel_Component_i::getInputServiceSalome_file(const char* service_name, + const char* Salome_file_name) +{ + // Try to find the service, if it doesn't exist, we throw an exception. + _Service_file_map_it = _Input_Service_file_map.find(service_name); + if (_Service_file_map_it == _Input_Service_file_map.end()) { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "service doesn't have salome files"; + throw SALOME::SALOME_Exception(es); + } + _t_Salome_file_map * _map = _Input_Service_file_map[service_name]; + + // Try to find the Salome_file ... + _Salome_file_map_it = _map->find(Salome_file_name); + if (_Salome_file_map_it == _map->end()) { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "service doesn't have this Salome_file"; + throw SALOME::SALOME_Exception(es); + } + Salome_file_i * Sfile = (*_map)[Salome_file_name]; + + return Sfile->_this(); +} + +Engines::Salome_file_ptr +Engines_Parallel_Component_i::setInputFileToService(const char* service_name, + const char* Salome_file_name) +{ + // Try to find the service, if it doesn't exist, we add it. + _Service_file_map_it = _Input_Service_file_map.find(service_name); + if (_Service_file_map_it == _Input_Service_file_map.end()) { + _t_Salome_file_map * _map = new _t_Salome_file_map(); + _Input_Service_file_map[service_name] = _map; + } + _t_Salome_file_map * _map = _Input_Service_file_map[service_name]; + + // Try to find the Salome_file ... + _Salome_file_map_it = _map->find(Salome_file_name); + if (_Salome_file_map_it == _map->end()) { + Salome_file_i * Sfile = new Salome_file_i(); + (*_map)[Salome_file_name] = Sfile; + } + else { + // Salome_file_name already added into the service + // throw Exception + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "Salome_file_name already added"; + throw SALOME::SALOME_Exception(es); + } + Salome_file_i * Sfile = (*_map)[Salome_file_name]; + + return Sfile->_this(); +} + +void +Engines_Parallel_Component_i::checkInputServiceFiles(const char* service_name) +{ + // Try to find the service, if it doesn't exist, nothing to do. + _Service_file_map_it = _Input_Service_file_map.find(service_name); + if (_Service_file_map_it != _Input_Service_file_map.end()) { + _t_Salome_file_map * _map = _Input_Service_file_map[service_name]; + _t_Salome_file_map::iterator begin = _map->begin(); + _t_Salome_file_map::iterator end = _map->end(); + + for(;begin!=end;begin++) { + Salome_file_i * file = begin->second; + file->recvFiles(); + } + } + +} + +Engines::Salome_file_ptr +Engines_Parallel_Component_i::getOutputServiceSalome_file(const char* service_name, + const char* Salome_file_name) +{ + // Try to find the service, if it doesn't exist, we throw an exception. + _Service_file_map_it = _Output_Service_file_map.find(service_name); + if (_Service_file_map_it == _Output_Service_file_map.end()) { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "service doesn't have salome files"; + throw SALOME::SALOME_Exception(es); + } + _t_Salome_file_map * _map = _Output_Service_file_map[service_name]; + + // Try to find the Salome_file ... + _Salome_file_map_it = _map->find(Salome_file_name); + if (_Salome_file_map_it == _map->end()) { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "service doesn't have this Salome_file"; + throw SALOME::SALOME_Exception(es); + } + Salome_file_i * Sfile = (*_map)[Salome_file_name]; + + return Sfile->_this(); +} + +Engines::Salome_file_ptr +Engines_Parallel_Component_i::setOutputFileToService(const char* service_name, + const char* Salome_file_name) +{ + // Try to find the service, if it doesn't exist, we add it. + _Service_file_map_it = _Output_Service_file_map.find(service_name); + if (_Service_file_map_it == _Output_Service_file_map.end()) { + _t_Salome_file_map * _map = new _t_Salome_file_map(); + _Output_Service_file_map[service_name] = _map; + } + _t_Salome_file_map * _map = _Output_Service_file_map[service_name]; + + // Try to find the Salome_file ... + _Salome_file_map_it = _map->find(Salome_file_name); + if (_Salome_file_map_it == _map->end()) { + Salome_file_i * Sfile = new Salome_file_i(); + (*_map)[Salome_file_name] = Sfile; + } + else { + // Salome_file_name already added into the service + // throw Exception + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "Salome_file_name already added"; + throw SALOME::SALOME_Exception(es); + } + Salome_file_i * Sfile = (*_map)[Salome_file_name]; + + return Sfile->_this(); +} + +void +Engines_Parallel_Component_i::checkOutputServiceFiles(const char* service_name) +{ + // Try to find the service, if it doesn't exist, nothing to do. + _Service_file_map_it = _Output_Service_file_map.find(service_name); + if (_Service_file_map_it != _Output_Service_file_map.end()) { + _t_Salome_file_map * _map = _Output_Service_file_map[service_name]; + _t_Salome_file_map::iterator begin = _map->begin(); + _t_Salome_file_map::iterator end = _map->end(); + + for(;begin!=end;begin++) { + Salome_file_i * file = begin->second; + file->recvFiles(); + } + } + +} + diff --git a/src/ParallelContainer/SALOME_ParallelComponent_i.hxx b/src/ParallelContainer/SALOME_ParallelComponent_i.hxx index 07c3bb104..1025e49ff 100644 --- a/src/ParallelContainer/SALOME_ParallelComponent_i.hxx +++ b/src/ParallelContainer/SALOME_ParallelComponent_i.hxx @@ -41,6 +41,7 @@ #include "NOTIFICATION.hxx" #include "RegistryConnexion.hxx" +#include "Salome_file_i.hxx" class Engines_Parallel_Container_i; @@ -98,6 +99,18 @@ public: CORBA::Boolean isPublished, CORBA::Boolean& isValidScript); + virtual Engines::Salome_file_ptr getInputServiceSalome_file(const char* service_name, + const char* Salome_file_name); + virtual Engines::Salome_file_ptr getOutputServiceSalome_file(const char* service_name, + const char* Salome_file_name); + + virtual void checkInputServiceFiles(const char* service_name); + virtual Engines::Salome_file_ptr setInputFileToService(const char* service_name, + const char* Salome_file_name); + + virtual void checkOutputServiceFiles(const char* service_name); + virtual Engines::Salome_file_ptr setOutputFileToService(const char* service_name, + const char* Salome_file_name); // --- local C++ methods @@ -135,6 +148,16 @@ protected: NOTIFICATION_Supplier* _notifSupplier; std::map_fieldsDict; + // Map Salome_file_name to Salome_file* + typedef std::map _t_Salome_file_map; + // Map Service_name to _Salome_file_map + typedef std::map _t_Service_file_map; + + _t_Service_file_map _Input_Service_file_map; + _t_Service_file_map _Output_Service_file_map; + _t_Service_file_map::iterator _Service_file_map_it; + _t_Salome_file_map::iterator _Salome_file_map_it; + std::string _serviceName ; std::string _graphName ; std::string _nodeName ; -- 2.39.2