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/exec/SegBufferReader.h"
00026 #include "fennel/exec/ExecStreamBufAccessor.h"
00027 #include "fennel/segment/SegInputStream.h"
00028
00029 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/exec/SegBufferReader.cpp#1 $");
00030
00031 SharedSegBufferReader SegBufferReader::newSegBufferReader(
00032 SharedExecStreamBufAccessor &pOutAccessor,
00033 SegmentAccessor const &bufferSegmentAccessor,
00034 PageId firstPageId)
00035 {
00036 return SharedSegBufferReader(
00037 new SegBufferReader(pOutAccessor, bufferSegmentAccessor, firstPageId),
00038 ClosableObjectDestructor());
00039 }
00040
00041 SegBufferReader::SegBufferReader(
00042 SharedExecStreamBufAccessor &pOutAccessorInit,
00043 SegmentAccessor const &bufferSegmentAccessorInit,
00044 PageId firstPageIdInit)
00045 : pOutAccessor(pOutAccessorInit),
00046 bufferSegmentAccessor(bufferSegmentAccessorInit),
00047 firstPageId(firstPageIdInit)
00048 {
00049 }
00050
00051 void SegBufferReader::open(bool destroy)
00052 {
00053 cbLastRead = 0;
00054
00055 if (pByteInputStream) {
00056 pByteInputStream->endPrefetch();
00057 pByteInputStream->seekSegPos(restartPos);
00058 } else {
00059 pByteInputStream =
00060 SegInputStream::newSegInputStream(
00061 bufferSegmentAccessor,
00062 firstPageId);
00063 pByteInputStream->getSegPos(restartPos);
00064 }
00065 if (destroy) {
00066 pByteInputStream->setDeallocate(true);
00067 }
00068 pByteInputStream->startPrefetch();
00069 }
00070
00071 ExecStreamResult SegBufferReader::read()
00072 {
00073 switch (pOutAccessor->getState()) {
00074 case EXECBUF_NONEMPTY:
00075 case EXECBUF_OVERFLOW:
00076 return EXECRC_BUF_OVERFLOW;
00077 case EXECBUF_UNDERFLOW:
00078 case EXECBUF_EMPTY:
00079 break;
00080 case EXECBUF_EOS:
00081 return EXECRC_EOS;
00082 default:
00083 permAssert(false);
00084 }
00085
00086 pByteInputStream->consumeReadPointer(cbLastRead);
00087 PConstBuffer pBuffer = pByteInputStream->getReadPointer(1,&cbLastRead);
00088 if (!pBuffer) {
00089 pOutAccessor->markEOS();
00090 return EXECRC_EOS;
00091 }
00092 pOutAccessor->provideBufferForConsumption(
00093 pBuffer,
00094 pBuffer + cbLastRead);
00095 return EXECRC_BUF_OVERFLOW;
00096 }
00097
00098 void SegBufferReader::closeImpl()
00099 {
00100 pByteInputStream.reset();
00101 }
00102
00103 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/exec/SegBufferReader.cpp#1 $");
00104
00105