2 // Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // 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 //=============================================================================
32 * Default constructor,
34 //=============================================================================
36 fileTransfer_i::fileTransfer_i()
38 MESSAGE("fileTransfer_i::fileTransfer_i");
42 //=============================================================================
46 //=============================================================================
48 fileTransfer_i::~fileTransfer_i()
50 MESSAGE("fileTransfer_i::~fileTransfer_i");
54 //=============================================================================
56 * CORBA method: try to open the file given. If the file is readable, return
57 * a positive integer else return 0;
58 * \param fileName path to the file to be transfered
59 * \return fileId = positive integer > 0 if open OK.
61 //=============================================================================
63 CORBA::Long fileTransfer_i::open(const char* fileName)
65 MESSAGE(" fileTransfer_i::open " << fileName);
66 int aKey = _fileKey++;
69 if ((fp = fopen(fileName,"rb")) == NULL)
71 INFOS("file " << fileName << " is not readable");
74 _fileAccess[aKey] = fp;
78 //=============================================================================
80 * CORBA method: close the file associated to the fileId given at open.
81 * \param fileId got in return from open method
83 //=============================================================================
85 void fileTransfer_i::close(CORBA::Long fileId)
87 MESSAGE("fileTransfer_i::close");
89 if (! (fp = _fileAccess[fileId]) )
91 INFOS(" no FILE structure associated to fileId " <<fileId);
96 //=============================================================================
98 * CORBA method: get a block of data from the file associated to the fileId
100 * \param fileId got in return from open method
101 * \return an octet sequence. Last one is empty.
103 //=============================================================================
105 #define FILEBLOCK_SIZE 256*1024
107 Engines::fileBlock* fileTransfer_i::getBlock(CORBA::Long fileId)
109 MESSAGE("fileTransfer_i::getBlock");
110 Engines::fileBlock* aBlock = new Engines::fileBlock;
113 if (! (fp = _fileAccess[fileId]) )
115 INFOS(" no FILE structure associated to fileId " <<fileId);
119 // use replace member function for sequence to avoid copy
120 // see Advanced CORBA Programming with C++ pp 187-194
123 buf = Engines::fileBlock::allocbuf(FILEBLOCK_SIZE);
124 int nbRed = fread(buf, sizeof(CORBA::Octet), FILEBLOCK_SIZE, fp);
126 aBlock->replace(nbRed, nbRed, buf, 1); // 1 means give ownership