Salome HOME
CMake: updated CMake procedure mainly to correctly expose targets needed by GUI.
[modules/kernel.git] / src / Container / Salome_file_i.cxx
index a098c06f95707253605a0f90d4e6810891ec9f07..133371596d39e993102267526f71ef5f72de5523 100644 (file)
@@ -1,34 +1,46 @@
-// Copyright (C) 2007  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-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// 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_file_i.cxx
 //  Author : AndrĂ© RIBES, EDF
 //  Module : SALOME
 //  $Header: 
-
+//
 #include "Salome_file_i.hxx"
 #include "utilities.h"
 #include <stdlib.h>
-#include <unistd.h>
 #include "HDFOI.hxx"
-#include <stdlib.h>
+#ifndef WIN32
+# include <unistd.h>
+# define _getcwd getcwd
+# define _open   open
+#else
+# include <direct.h>
+# include <io.h>
+# include <windows.h>
+#endif
+
+/*! \class Salome_file_i
+ *  \brief A class to manage file transfer in %SALOME
+ *
+ */
+
 
 //=============================================================================
 /*! 
 Salome_file_i::Salome_file_i()
 {
   _fileId = 0;
+#ifndef WIN32
   _path_max = 1 + pathconf("/", _PC_PATH_MAX);
+#else
+  _path_max = 32768;
+  //from MSDN:
+  //Note The C Runtime supports path lengths up to 32768 characters in length, but it is up to the operating system, specifically the file system, to support these longer paths. The sum of the fields should not exceed _MAX_PATH for full backwards compatibility with Windows 98 FAT32 file systems. Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003, and Windows Server 2003 NTFS file system supports paths up to 32768 characters in length, but only when using the Unicode APIs. When using long path names, prefix the path with the characters \\?\ and use the Unicode versions of the C Runtime functions.
+  //currently #define _MAX_PATH   260
+#endif
   _state.name = CORBA::string_dup("");
   _state.hdf5_file_name = CORBA::string_dup("");
   _state.number_of_files = 0;
@@ -154,68 +173,66 @@ Salome_file_i::load(const char* hdf5_file) {
 
       if (mode == "all") {
 
-       // Changing path, is now current directory
-       char CurrentPath[_path_max];
-       getcwd(CurrentPath, _path_max);
-       path = CurrentPath;
-
-       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];
+        // 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];
       
-       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,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;
       }
     }
   }
@@ -491,10 +508,8 @@ Salome_file_i::setLocalFile(const char* comp_file_name)
   }
   else
   {
-    file_name = comp_file_name;
-    char CurrentPath[_path_max];
-    getcwd(CurrentPath, _path_max);
-    path = CurrentPath;
+    file_name = comp_file_name;    
+    path = getcwd(NULL, _path_max);;
   }
 
   // Test if this file is already added
@@ -556,9 +571,7 @@ Salome_file_i::setDistributedFile(const char* comp_file_name)
   else
   {
     file_name = comp_file_name;
-    char CurrentPath[_path_max];
-    getcwd(CurrentPath, _path_max);
-    path = CurrentPath;
+    path = getcwd(NULL, _path_max);;
   }
 
   // Test if this file is already added
@@ -616,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);
       }
     }
   }
@@ -656,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);
@@ -682,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);
 
@@ -723,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
@@ -741,12 +754,10 @@ Salome_file_i::recvFiles() {
 
   if (files_not_ok != "")
   {
-    std::cerr << "tutu" << std::endl;
     SALOME::ExceptionStruct es;
     es.type = SALOME::INTERNAL_ERROR;
     std::string text = "files not ready : " + files_not_ok;
     es.text = CORBA::string_dup(text.c_str());
-    std::cerr << "titi" << std::endl;
     throw SALOME::SALOME_Exception(es);
   }
   else
@@ -840,8 +851,12 @@ Salome_file_i::getDistributedFile(std::string file_name)
       aBlock = _fileDistributedSource[file_name]->getBlock(fileId);
       toFollow = aBlock->length();
       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);