00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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