00001 #ifndef REMOTEFILE_H_
00002 #define REMOTEFILE_H_
00003
00004 #include <sys/stat.h>
00005
00006 #include <QDateTime>
00007 #include <QStringList>
00008 #include <QMutex>
00009
00010 #include "mythbaseexp.h"
00011
00012 class MythSocket;
00013
00014 class MBASE_PUBLIC RemoteFile
00015 {
00016 public:
00017 RemoteFile(const QString &url = "",
00018 bool write = false,
00019 bool usereadahead = true,
00020 int timeout_ms = 2000,
00021 const QStringList *possibleAuxiliaryFiles = NULL);
00022 ~RemoteFile();
00023
00024 bool Open();
00025 bool ReOpen(QString newFilename);
00026 void Close(void);
00027
00028 long long Seek(long long pos, int whence, long long curpos = -1);
00029
00030 static bool DeleteFile(const QString &url);
00031 static bool Exists(const QString &url, struct stat *fileinfo);
00032 static bool Exists(const QString &url);
00033 static QString GetFileHash(const QString &url);
00034 static QDateTime LastModified(const QString &url);
00035
00036 int Write(const void *data, int size);
00037 int Read(void *data, int size);
00038 void Reset(void);
00039
00040 bool SaveAs(QByteArray &data);
00041
00042 void SetURL(const QString &url) { path = url; }
00043 void SetTimeout(bool fast);
00044
00045 bool isOpen(void) const
00046 { return sock && controlSock; }
00047 long long GetFileSize(void) const
00048 { return filesize; }
00049
00050 const MythSocket *getSocket(void) const
00051 { return sock; }
00052 MythSocket *getSocket(void)
00053 { return sock; }
00054
00055 QStringList GetAuxiliaryFiles(void) const
00056 { return auxfiles; }
00057
00058 private:
00059 MythSocket *openSocket(bool control);
00060
00061 QString path;
00062 bool usereadahead;
00063 int timeout_ms;
00064 long long filesize;
00065 bool timeoutisfast;
00066 long long readposition;
00067 int recordernum;
00068
00069 mutable QMutex lock;
00070 MythSocket *controlSock;
00071 MythSocket *sock;
00072 QString query;
00073
00074 bool writemode;
00075
00076 QStringList possibleauxfiles;
00077 QStringList auxfiles;
00078 };
00079
00080 #endif