RandomAccessFileDevice.cpp

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/device/RandomAccessFileDevice.cpp#10 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 The Eigenbase Project
00005 // Copyright (C) 2005-2009 SQLstream, Inc.
00006 // Copyright (C) 2005-2009 LucidEra, Inc.
00007 // Portions Copyright (C) 1999-2009 John V. Sichi
00008 //
00009 // This program is free software; you can redistribute it and/or modify it
00010 // under the terms of the GNU General Public License as published by the Free
00011 // Software Foundation; either version 2 of the License, or (at your option)
00012 // any later version approved by The Eigenbase Project.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with this program; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 #include "fennel/common/CommonPreamble.h"
00025 #include "fennel/device/RandomAccessFileDevice.h"
00026 #include "fennel/device/RandomAccessRequest.h"
00027 
00028 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/device/RandomAccessFileDevice.cpp#10 $");
00029 
00030 RandomAccessFileDevice::RandomAccessFileDevice(
00031     std::string filename,DeviceMode mode,FileSize initialSize)
00032     : FileDevice(filename,mode,initialSize)
00033 {
00034 }
00035 
00036 RandomAccessFileDevice::RandomAccessFileDevice(
00037     std::string filename,DeviceMode mode)
00038     : FileDevice(filename,mode,FileSize(0))
00039 {
00040 }
00041 
00042 RandomAccessDevice::~RandomAccessDevice()
00043 {
00044 }
00045 
00046 FileSize RandomAccessFileDevice::getSizeInBytes()
00047 {
00048     return FileDevice::getSizeInBytes();
00049 }
00050 
00051 void RandomAccessFileDevice::setSizeInBytes(FileSize cbNew)
00052 {
00053     FileDevice::setSizeInBytes(cbNew);
00054 }
00055 
00056 void RandomAccessFileDevice::transfer(RandomAccessRequest const &request)
00057 {
00058     assert(request.pDevice == this);
00059     FileDevice::transfer(request);
00060 }
00061 
00062 void RandomAccessFileDevice::prepareTransfer(RandomAccessRequest &request)
00063 {
00064     assert(request.pDevice == this);
00065 
00066 #ifdef USE_AIO_H
00067     int aio_lio_opcode =
00068         (request.type == RandomAccessRequest::READ)
00069         ? LIO_READ : LIO_WRITE;
00070     FileSize cbOffset = request.cbOffset;
00071     for (RandomAccessRequest::BindingListIter
00072              bindingIter(request.bindingList);
00073          bindingIter; ++bindingIter)
00074     {
00075         RandomAccessRequestBinding *pBinding = bindingIter;
00076         pBinding->aio_fildes = handle;
00077         pBinding->aio_lio_opcode = aio_lio_opcode;
00078         // TODO:  initialize constant fields below only once
00079         pBinding->aio_buf = pBinding->getBuffer();
00080         pBinding->aio_nbytes = pBinding->getBufferSize();
00081         pBinding->aio_reqprio = 0;
00082         pBinding->aio_offset = cbOffset;
00083         cbOffset += pBinding->aio_nbytes;
00084     }
00085     assert(cbOffset == request.cbOffset + request.cbTransfer);
00086 #endif
00087 
00088 #ifdef USE_LIBAIO_H
00089     FileSize cbOffset = request.cbOffset;
00090     for (RandomAccessRequest::BindingListIter
00091              bindingIter(request.bindingList);
00092          bindingIter; ++bindingIter)
00093     {
00094         RandomAccessRequestBinding *pBinding = bindingIter;
00095 
00096         if (request.type == RandomAccessRequest::READ) {
00097             io_prep_pread(
00098                 pBinding, handle, pBinding->getBuffer(),
00099                 pBinding->getBufferSize(), cbOffset);
00100         } else {
00101             io_prep_pwrite(
00102                 pBinding, handle, pBinding->getBuffer(),
00103                 pBinding->getBufferSize(), cbOffset);
00104         }
00105         cbOffset += pBinding->getBufferSize();
00106     }
00107     assert(cbOffset == request.cbOffset + request.cbTransfer);
00108 #endif
00109 }
00110 
00111 void RandomAccessFileDevice::flush()
00112 {
00113     FileDevice::flush();
00114 }
00115 
00116 int RandomAccessFileDevice::getHandle()
00117 {
00118     return handle;
00119 }
00120 
00121 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/device/RandomAccessFileDevice.cpp#10 $");
00122 
00123 // End RandomAccessFileDevice.cpp

Generated on Mon Jun 22 04:00:18 2009 for Fennel by  doxygen 1.5.1