1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SALOME_FileTransfer_i.cxx
23 // Author : Paul RASCLE, EDF
27 #include "SALOME_FileTransfer_i.hxx"
28 #include "utilities.h"
30 /*! \class fileTransfer_i
31 \brief A class to manage file transfer in SALOME
35 //=============================================================================
37 * Default constructor,
39 //=============================================================================
41 fileTransfer_i::fileTransfer_i()
43 MESSAGE("fileTransfer_i::fileTransfer_i");
47 //=============================================================================
51 //=============================================================================
53 fileTransfer_i::~fileTransfer_i()
55 MESSAGE("fileTransfer_i::~fileTransfer_i");
59 //=============================================================================
60 /*! \brief open the given file
62 * CORBA method: try to open the file. If the file is readable, return
63 * a positive integer else return 0;
64 * \param fileName path to the file to be transfered
65 * \return fileId = positive integer > 0 if open OK.
67 //=============================================================================
69 CORBA::Long fileTransfer_i::open(const char* fileName)
71 MESSAGE(" fileTransfer_i::open " << fileName);
72 int aKey = _fileKey++;
75 if ((fp = fopen(fileName,"rb")) == NULL)
77 INFOS("file " << fileName << " is not readable");
80 _fileAccess[aKey] = fp;
84 //=============================================================================
85 /*! \brief close a file
87 * CORBA method: close the file associated to the fileId given at open.
88 * \param fileId got in return from open method
90 //=============================================================================
92 void fileTransfer_i::close(CORBA::Long fileId)
94 MESSAGE("fileTransfer_i::close");
96 if (! (fp = _fileAccess[fileId]) )
98 INFOS(" no FILE structure associated to fileId " <<fileId);
103 #define FILEBLOCK_SIZE 256*1024
105 //=============================================================================
106 /*! \brief get a data block from a file
108 * CORBA method: get a block of data from the file associated to the fileId
110 * \param fileId got in return from open method
111 * \return an octet sequence. Last one is empty.
113 //=============================================================================
115 Engines::fileBlock* fileTransfer_i::getBlock(CORBA::Long fileId)
117 MESSAGE("fileTransfer_i::getBlock");
118 Engines::fileBlock* aBlock = new Engines::fileBlock;
121 if (! (fp = _fileAccess[fileId]) )
123 INFOS(" no FILE structure associated to fileId " <<fileId);
127 // use replace member function for sequence to avoid copy
128 // see Advanced CORBA Programming with C++ pp 187-194
131 buf = Engines::fileBlock::allocbuf(FILEBLOCK_SIZE);
132 int nbRed = fread(buf, sizeof(CORBA::Octet), FILEBLOCK_SIZE, fp);
134 aBlock->replace(nbRed, nbRed, buf, 1); // 1 means give ownership