00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _MATRIX_FILE_CACHE_H_
00017 #define _MATRIX_FILE_CACHE_H_
00018
00019 #include "base/ResizeableBitset.h"
00020
00021 #include "FileReadThread.h"
00022
00023 #include <sys/types.h>
00024 #include <QString>
00025 #include <QMutex>
00026 #include <map>
00027
00028 class MatrixFile : public QObject
00029 {
00030 Q_OBJECT
00031
00032 public:
00033 enum Mode { ReadOnly, ReadWrite };
00034
00058 MatrixFile(QString fileBase, Mode mode, size_t cellSize, bool eagerCache);
00059 virtual ~MatrixFile();
00060
00061 Mode getMode() const { return m_mode; }
00062
00063 size_t getWidth() const { return m_width; }
00064 size_t getHeight() const { return m_height; }
00065 size_t getCellSize() const { return m_cellSize; }
00066
00067 void resize(size_t width, size_t height);
00068 void reset();
00069
00070 bool haveSetColumnAt(size_t x) const { return m_columnBitset->get(x); }
00071 void getColumnAt(size_t x, void *data);
00072 void setColumnAt(size_t x, const void *data);
00073
00074 void suspend();
00075
00076 protected:
00077 int m_fd;
00078 Mode m_mode;
00079 int m_flags;
00080 mode_t m_fmode;
00081 size_t m_cellSize;
00082 size_t m_width;
00083 size_t m_height;
00084 size_t m_headerSize;
00085 QString m_fileName;
00086 size_t m_defaultCacheWidth;
00087 size_t m_prevX;
00088
00089 struct Cache {
00090 size_t x;
00091 size_t width;
00092 char *data;
00093 };
00094
00095 Cache m_cache;
00096 bool m_eagerCache;
00097
00098 bool getFromCache(size_t x, size_t ystart, size_t ycount, void *data);
00099 void primeCache(size_t x, bool left);
00100
00101 void resume();
00102
00103 bool seekTo(size_t x, size_t y);
00104
00105 static FileReadThread *m_readThread;
00106 int m_requestToken;
00107
00108 size_t m_requestingX;
00109 size_t m_requestingWidth;
00110 char *m_spareData;
00111
00112 static std::map<QString, int> m_refcount;
00113 static QMutex m_refcountMutex;
00114 QMutex m_fdMutex;
00115 QMutex m_cacheMutex;
00116
00117 typedef std::map<QString, ResizeableBitset *> ResizeableBitsetMap;
00118 static ResizeableBitsetMap m_columnBitsets;
00119 static QMutex m_columnBitsetWriteMutex;
00120 ResizeableBitset *m_columnBitset;
00121 };
00122
00123 #endif
00124