ringbuffer.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           ringbuffer.h  -  description
00003                              -------------------
00004     begin                : Sun March 21 2004
00005     copyright            : (C) 2004 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_RING_BUFFER_H
00019 #define _KRADIO_RING_BUFFER_H
00020 
00021 #ifdef HAVE_CONFIG_H
00022 #include <config.h>
00023 #endif
00024 
00025 #include <sys/types.h>
00026 #include <kdemacros.h>
00027 #include <QtCore/QSemaphore>
00028 
00029 class KDE_EXPORT RingBuffer
00030 {
00031 public:
00032     RingBuffer(size_t size, bool synchronized = false);
00033     ~RingBuffer();
00034 
00035     bool       resize(size_t new_size);
00036 
00037     size_t     addData (const char *src, size_t size);
00038     size_t     takeData(char *dst, size_t size, bool lock = true);
00039 
00040     char      *getFreeSpace(size_t &size);
00041     size_t     removeFreeSpace(size_t size);
00042 
00043     char      *getData(size_t &size);
00044     size_t     removeData(size_t size);
00045 
00046     size_t     getSize()     const;
00047     size_t     getFillSize() const;
00048     size_t     getFreeSize() const;
00049 
00050     void       clear();
00051 
00052     void       lockTransaction() const;
00053     void       unlockTransaction() const;
00054 
00055 protected:
00056     void       lock()   const;
00057     void       unlock() const;
00058 
00059     char      *m_Buffer;
00060     size_t     m_Start;
00061     size_t     m_Size,
00062                m_FillSize;
00063 
00064     bool               m_synchronized;
00065     mutable QSemaphore m_synchronizer;
00066     mutable QSemaphore m_transactionSynchronizer;
00067 };
00068 
00069 #endif

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