Go to the documentation of this file.00001 #ifndef ROC_SORTER_H
00002 #define ROC_SORTER_H
00003
00004 #include "roc/Message.h"
00005
00006 #include "roc/Iterator.h"
00007
00008 namespace roc {
00009
00010 class Sorter {
00011 protected:
00012
00013
00014 enum TimesConstants { tmLastValid = 0x3fffffff, tmEmpty = tmLastValid + 100, tmFailure = tmLastValid + 200, tmBoundary = 0x8100, tmFrontShift = 0x10000000 };
00015
00016 unsigned fRocId;
00017
00018 unsigned fIntBufMaxSize;
00019 unsigned fExtBufMaxSize;
00020
00021 Message *fIntBuf;
00022 uint32_t *fIntBufTimes;
00023 unsigned fIntBufSize;
00024 uint32_t fIntBufFrontEpoch;
00025 bool fIsIntBufFrontEpoch;
00026 uint32_t fIntBufCurrEpoch;
00027 uint32_t fIntBufCurrRealEpoch;
00028 uint32_t fIntBuffCurrMaxTm;
00029
00030 unsigned fAccumMissed;
00031 uint32_t fLastOutEpoch;
00032
00033 void* fFillBuffer;
00034 unsigned fFillTotalSize;
00035 unsigned fFillSize;
00036 int fFillFormat;
00037
00038 void* fInternOutBuf;
00039 unsigned fInternOutBufSize;
00040 int fInternOutFormat;
00041
00042 bool flushBuffer(void* data, unsigned num_msg, int fmt, bool force = false);
00043
00044 bool checkLastEpoch(roc::Message* data, unsigned indx, const roc::Iterator& iter);
00045
00046 public:
00047 explicit Sorter(unsigned maxinpbuf = 1024,
00048 unsigned intern_out_buf = 1024,
00049 int intern_out_fmt = roc::formatNormal,
00050 unsigned intbuf = 128);
00051 virtual ~Sorter();
00052
00053
00054 bool isInternData() const { return fIntBufSize > 0; }
00055
00056
00057
00058
00059 bool addData(void* data, unsigned datalen, int fmt, bool flush_data = false);
00060
00061 bool flush() { return flushBuffer(0, 0, formatNormal, true); }
00062
00063
00064 void cleanBuffers();
00065
00066
00067 unsigned sizeFilled() const { return fFillSize; }
00068
00069 void* filledBuf() const { return fFillBuffer; }
00070
00071
00072 bool shiftFilledData(unsigned num);
00073
00074
00075
00076
00077 bool startFill(void* buf, unsigned totalsize, int fmt = formatNormal);
00078
00079
00080 void stopFill();
00081 };
00082
00083 }
00084
00085 #endif