multibuffer.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           multibuffer.h
00003                              -------------------
00004     begin                : Sat Aug 20 2005
00005     copyright            : (C) 2005 by Martin Witte
00006     email                : witte@kawo1.rwth-aachen.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef KRADIO_MULTIBUFFER_H
00019 #define KRADIO_MULTIBUFFER_H
00020 
00021 #ifdef HAVE_CONFIG_H
00022 #include <config.h>
00023 #endif
00024 
00025 #include <qsemaphore.h>
00026 #include <qstring.h>
00027 
00028 class MultiBuffer
00029 {
00030 public:
00031     MultiBuffer(size_t n_buffers, size_t buffersize);
00032     ~MultiBuffer();
00033 
00034     char *lockWriteBuffer     (size_t &bufferSize);
00035     bool  unlockWriteBuffer   (size_t bufferSize); // return value: complete buffer full / ready for read
00036     void  unlockAllWriteBuffers();
00037     char *wait4ReadBuffer     (size_t &buffer_fill);
00038     char *getCurrentReadBuffer(size_t &buffer_fill) const;
00039 
00040     const QString &getErrorString() const { return m_errorString; }
00041     bool           hasError()       const { return m_error; }
00042     void           resetError();
00043 
00044     size_t  getWriteBufferFill()  const { return (m_currentReadBuffer != m_currentWriteBuffer) ? m_buffersFill[m_currentWriteBuffer] : 0; }
00045     size_t  getAvailableWriteBuffer()  const;
00046     size_t  getAvailableReadBuffers()   const;
00047     size_t  getCurrentReadBufferIdx()  const { return m_currentReadBuffer; }
00048     size_t  getCurrentWriteBufferIdx() const { return m_currentWriteBuffer; }
00049 
00050 protected:
00051 
00052     size_t             m_nBuffers;
00053     size_t             m_BufferSize;
00054 
00055     char             **m_buffers;
00056     size_t            *m_buffersFill;
00057     size_t             m_currentReadBuffer;
00058     size_t             m_currentWriteBuffer;
00059     QSemaphore         m_readLock;
00060 
00061     QString            m_errorString;
00062     bool               m_error;
00063 };
00064 
00065 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 28 Jan 2011 for kradio by  doxygen 1.6.1