00001 /*************************************************************************** 00002 ringbuffer.h - description 00003 ------------------- 00004 begin : Sun March 21 2004 00005 copyright : (C) 2004 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_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 <qstring.h> 00026 #include <stdio.h> 00027 00028 class FileRingBuffer 00029 { 00030 public: 00031 FileRingBuffer(const QString &filename, Q_UINT64 max_size); 00032 ~FileRingBuffer(); 00033 00034 bool resize(const QString &filename, Q_UINT64 new_max_size); 00035 00036 size_t addData (const char *src, size_t size); 00037 size_t takeData(char *dst, size_t size); 00038 Q_UINT64 removeData(Q_UINT64 size); 00039 00040 const QString &getFileName () const { return m_FileName; } 00041 Q_UINT64 getMaxSize() const { return m_MaxSize; } 00042 Q_UINT64 getRealSize() const { return m_RealSize; } 00043 Q_UINT64 getFillSize() const { return m_FillSize; } 00044 Q_UINT64 getFreeSize() const { return (m_Start + m_FillSize > m_RealSize) ? m_RealSize - m_FillSize : m_MaxSize - m_FillSize; } 00045 00046 void clear(); 00047 00048 bool error() const { return m_error; } 00049 const QString &errorString() const { return m_errorString; } 00050 00051 protected: 00052 Q_UINT64 getFreeSpace(Q_UINT64 &size); // returns position in file + size 00053 Q_UINT64 removeFreeSpace(Q_UINT64 size); 00054 00055 Q_UINT64 getData(Q_UINT64 &size); // returns position in file + size 00056 00057 00058 int m_FileIdx; 00059 QString m_BaseFileName; 00060 QString m_FileName; 00061 FILE *m_File; 00062 Q_UINT64 m_Start; 00063 Q_UINT64 m_MaxSize; 00064 Q_UINT64 m_RealSize; 00065 Q_UINT64 m_FillSize; 00066 00067 QString m_errorString; 00068 bool m_error; 00069 }; 00070 00071 #endif