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                : emw-kradio@nocabal.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 <QtCore/QSemaphore>
00026 #include <QtCore/QString>
00027 #include <kdemacros.h>
00028 
00029 class KDE_EXPORT MultiBuffer
00030 {
00031 public:
00032     MultiBuffer(size_t n_buffers, size_t buffersize);
00033     ~MultiBuffer();
00034 
00035     char *lockWriteBuffer     (size_t &bufferSize);
00036     bool  unlockWriteBuffer   (size_t bufferSize); // return value: complete buffer full / ready for read
00037     void  unlockAllWriteBuffers();
00038     char *wait4ReadBuffer     (size_t &buffer_fill);
00039     char *getCurrentReadBuffer(size_t &buffer_fill) const;
00040 
00041     const QString &getErrorString() const { return m_errorString; }
00042     bool           hasError()       const { return m_error; }
00043     void           resetError();
00044 
00045     size_t  getWriteBufferFill()  const { return (m_currentReadBuffer != m_currentWriteBuffer) ? m_buffersFill[m_currentWriteBuffer] : 0; }
00046     size_t  getAvailableWriteBuffer()  const;
00047     size_t  getAvailableReadBuffers()   const;
00048     size_t  getCurrentReadBufferIdx()  const { return m_currentReadBuffer; }
00049     size_t  getCurrentWriteBufferIdx() const { return m_currentWriteBuffer; }
00050 
00051 protected:
00052 
00053     size_t             m_nBuffers;
00054     size_t             m_BufferSize;
00055 
00056     char             **m_buffers;
00057     size_t            *m_buffersFill;
00058     size_t             m_currentReadBuffer;
00059     size_t             m_currentWriteBuffer;
00060     QSemaphore         m_readLock;
00061 
00062     QString            m_errorString;
00063     bool               m_error;
00064 };
00065 
00066 #endif

Generated on Tue Jun 2 19:19:57 2009 for kradio4 by  doxygen 1.5.8