fileringbuffer.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_FILE_RING_BUFFER_H
00019 #define _KRADIO_FILE_RING_BUFFER_H
00020 
00021 #ifdef HAVE_CONFIG_H
00022 #include <config.h>
00023 #endif
00024 
00025 #include <kdemacros.h>
00026 #include <QtCore/QString>
00027 #include <stdio.h>
00028 
00029 class KDE_EXPORT FileRingBuffer
00030 {
00031 public:
00032     FileRingBuffer(const QString &filename, quint64 max_size);
00033     ~FileRingBuffer();
00034 
00035     bool       resize(const QString &filename, quint64 new_max_size);
00036 
00037     size_t     addData (const char *src, size_t size);
00038     size_t     takeData(char *dst, size_t size);
00039     quint64    removeData(quint64 size);
00040 
00041     const QString &getFileName() const { return m_FileName; }
00042     quint64        getMaxSize () const { return m_MaxSize;  }
00043     quint64        getRealSize() const { return m_RealSize; }
00044     quint64        getFillSize() const { return m_FillSize; }
00045     quint64        getFreeSize() const { return (m_Start + m_FillSize > m_RealSize) ? m_RealSize - m_FillSize : m_MaxSize - m_FillSize; }
00046 
00047     void           clear();
00048 
00049     bool           error()       const { return m_error; }
00050     const QString &errorString() const { return m_errorString; }
00051 
00052 protected:
00053     quint64     getFreeSpace(quint64 &size);  // returns position in file + size
00054     quint64     removeFreeSpace(quint64 size);
00055 
00056     quint64     getData(quint64  &size);  // returns position in file + size
00057 
00058 
00059     int        m_FileIdx;
00060     QString    m_BaseFileName;
00061     QString    m_FileName;
00062     FILE      *m_File;
00063     quint64    m_Start;
00064     quint64    m_MaxSize;
00065     quint64    m_RealSize;
00066     quint64    m_FillSize;
00067 
00068     QString   m_errorString;
00069     bool      m_error;
00070 };
00071 
00072 #endif

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