kradio4  r778
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fileringbuffer.h
Go to the documentation of this file.
1 /***************************************************************************
2  ringbuffer.h - description
3  -------------------
4  begin : Sun March 21 2004
5  copyright : (C) 2004 by Martin Witte
6  email : emw-kradio@nocabal.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef _KRADIO_FILE_RING_BUFFER_H
19 #define _KRADIO_FILE_RING_BUFFER_H
20 
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24 
25 #include <kdemacros.h>
26 #include <QtCore/QString>
27 #include <stdio.h>
28 
29 class KDE_EXPORT FileRingBuffer
30 {
31 public:
32  FileRingBuffer(const QString &filename, quint64 max_size);
33  ~FileRingBuffer();
34 
35  bool resize(const QString &filename, quint64 new_max_size);
36 
37  size_t addData (const char *src, size_t size);
38  size_t takeData(char *dst, size_t size);
39  quint64 removeData(quint64 size);
40 
41  const QString &getFileName() const { return m_FileName; }
42  quint64 getMaxSize () const { return m_MaxSize; }
43  quint64 getRealSize() const { return m_RealSize; }
44  quint64 getFillSize() const { return m_FillSize; }
45  quint64 getFreeSize() const { return (m_Start + m_FillSize > m_RealSize) ? m_RealSize - m_FillSize : m_MaxSize - m_FillSize; }
46 
47  void clear();
48 
49  bool error() const { return m_error; }
50  const QString &errorString() const { return m_errorString; }
51 
52 protected:
53  quint64 getFreeSpace(quint64 &size); // returns position in file + size
54  quint64 removeFreeSpace(quint64 size);
55 
56  quint64 getData(quint64 &size); // returns position in file + size
57 
58 
59  int m_FileIdx;
60  QString m_BaseFileName;
61  QString m_FileName;
62  FILE *m_File;
63  quint64 m_Start;
64  quint64 m_MaxSize;
65  quint64 m_RealSize;
66  quint64 m_FillSize;
67 
68  QString m_errorString;
69  bool m_error;
70 };
71 
72 #endif