SegBufferReader.cpp

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/exec/SegBufferReader.cpp#1 $
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) 2004-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/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     // If previously opened, restart from the beginning
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 // End SegBufferReader.cpp

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