• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

include/roc/Sorter.h (r4864/r3193)

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          // only because of losses of epoch markers tmBoundary is expanded, normally should be about 0x4100
00013 
00014          enum TimesConstants { tmLastValid = 0x3fffffff, tmEmpty = tmLastValid + 100, tmFailure = tmLastValid + 200, tmBoundary = 0x8100, tmFrontShift = 0x10000000 };
00015 
00016          unsigned     fRocId;
00017 
00018          unsigned     fIntBufMaxSize;    // maximum number of hits in intern buffer
00019          unsigned     fExtBufMaxSize;    // maximum size of extern buffer by addData
00020 
00021          Message     *fIntBuf;
00022          uint32_t    *fIntBufTimes;
00023          unsigned     fIntBufSize;   // number of hits in internal buffer
00024          uint32_t     fIntBufFrontEpoch;  // basis epoch number of intern buffers
00025          bool         fIsIntBufFrontEpoch; // true if we have value for fIntBufFrontEpoch
00026          uint32_t     fIntBufCurrEpoch; // current epoch of intern buffer in special form
00027          uint32_t     fIntBufCurrRealEpoch; // current epoch of intern buffer in real form
00028          uint32_t     fIntBuffCurrMaxTm;  // current maxtm of intern buffer
00029 
00030          unsigned     fAccumMissed;    // accumulated missed hits from epochs to write at generated epoch
00031          uint32_t     fLastOutEpoch;   // value of last written epoch to output
00032 
00033          void*        fFillBuffer;     // buffer to fill
00034          unsigned     fFillTotalSize;  // total size of external buffer in bytes
00035          unsigned     fFillSize;       // already filled size in messages
00036          int          fFillFormat;    // data format of fill buffer
00037 
00038          void*         fInternOutBuf;     // internal output buffer, which can be used for output
00039          unsigned      fInternOutBufSize; // size of internal output buffer in messages
00040          int           fInternOutFormat;  // data format of fill buffer
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          // is data in internal buffer
00054          bool isInternData() const { return fIntBufSize > 0; }
00055 
00056          // Add messages as they come from ROC
00057          // Normally no more than 243 messages should be added - size of UDP packet
00058          // Return true if buffer is already filled
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          // clean all messages from buffers, can continue filling
00064          void cleanBuffers();
00065 
00066          // number of messages, filled in output buffer
00067          unsigned sizeFilled() const { return fFillSize; }
00068 
00069          void* filledBuf() const { return fFillBuffer; }
00070 
00071          // skip num messages in output buffer
00072          bool shiftFilledData(unsigned num);
00073 
00074          // initialize variables to be able fill external buffer
00075          // return false, if buffer size is too small
00076          // if buf==0, internal buffer of specified size will be allocated
00077          bool startFill(void* buf, unsigned totalsize, int fmt = formatNormal);
00078 
00079          // Stop filling of external buffer, next messages goes into internal (if exists)
00080          void stopFill();
00081    };
00082 
00083 }
00084 
00085 #endif

Generated on Tue Dec 10 2013 04:52:23 for ROCsoft by  doxygen 1.7.1