MythTV  master
remotefile.h
Go to the documentation of this file.
1 #ifndef REMOTEFILE_H_
2 #define REMOTEFILE_H_
3 
4 #include <sys/stat.h>
5 
6 #include <QDateTime>
7 #include <QStringList>
8 #include <QMutex>
9 
10 #include "mythbaseexp.h"
11 #include "mythtimer.h"
12 
13 class MythSocket;
14 class QFile;
15 class ThreadedFileWriter;
16 
18 {
19  public:
20  RemoteFile(const QString &url = "",
21  bool write = false,
22  bool usereadahead = true,
23  int timeout_ms = 2000/*RingBuffer::kDefaultOpenTimeout*/,
24  const QStringList *possibleAuxiliaryFiles = nullptr);
25  ~RemoteFile();
26 
27  bool ReOpen(const QString& newFilename);
28 
29  long long Seek(long long pos, int whence, long long curpos = -1);
30 
31  static bool DeleteFile(const QString &url);
32  static bool Exists(const QString &url, struct stat *fileinfo);
33  static bool Exists(const QString &url);
34  static QString GetFileHash(const QString &url);
35  static QDateTime LastModified(const QString &url);
36  QDateTime LastModified(void) const;
37  static QString FindFile(const QString &filename, const QString &host,
38  const QString &storageGroup, bool useRegex = false,
39  bool allowFallback = false);
40 
41  static QStringList FindFileList(const QString &filename, const QString &host,
42  const QString &storageGroup, bool useRegex = false,
43  bool allowFallback = false);
44  static bool CopyFile(const QString &src, const QString &dst,
45  bool overwrite = false, bool verify = false);
46  static bool MoveFile(const QString &src, const QString &dst,
47  bool overwrite = false);
48 
49  int Write(const void *data, int size);
50  int Read(void *data, int size);
51  void Reset(void);
52  bool SetBlocking(bool m_block = true);
53 
54  bool SaveAs(QByteArray &data);
55 
56  void SetTimeout(bool fast);
57 
58  bool isOpen(void) const;
59  static bool isLocal(const QString &path);
60  bool isLocal(void) const;
61  long long GetFileSize(void) const;
62  long long GetRealFileSize(void);
63 
64  QStringList GetAuxiliaryFiles(void) const
65  { return m_auxfiles; }
66 
67  private:
68  bool Open(void);
69  bool OpenInternal(void);
70  void Close(bool haslock = false);
71  bool CheckConnection(bool repos = true);
72  bool IsConnected(void);
73  bool Resume(bool repos = true);
74  long long SeekInternal(long long pos, int whence, long long curpos = -1);
75 
76  MythSocket *openSocket(bool control);
77 
78  QString m_path;
79  bool m_usereadahead {true};
80  int m_timeout_ms {2000};
81  long long m_filesize {-1};
82  bool m_timeoutisfast {false};
83  long long m_readposition {0LL};
84  long long m_lastposition {0LL};
85  bool m_canresume {false};
86  int m_recordernum {0};
87 
88  mutable QMutex m_lock {QMutex::NonRecursive};
89  MythSocket *m_controlSock {nullptr};
90  MythSocket *m_sock {nullptr};
91  QString m_query {"QUERY_FILETRANSFER %1"};
92 
93  bool m_writemode {false};
94  bool m_completed {false};
96 
97  QStringList m_possibleauxfiles;
98  QStringList m_auxfiles;
99  int m_localFile {-1};
100  ThreadedFileWriter *m_fileWriter {nullptr};
101 };
102 
103 #endif
def write(text, progress=True)
Definition: mythburn.py:279
A QElapsedTimer based timer to replace use of QTime as a timer.
Definition: mythtimer.h:13
QStringList m_auxfiles
Definition: remotefile.h:98
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
static int CopyFile(const MythUtilCommandLineParser &cmdline)
Definition: fileutils.cpp:10
QString m_path
Definition: remotefile.h:78
MythTimer m_lastSizeCheck
Definition: remotefile.h:95
QStringList m_possibleauxfiles
Definition: remotefile.h:97
This class supports the writing of recordings to disk.
Class for communcating between myth backends and frontends.
Definition: mythsocket.h:26
QStringList GetAuxiliaryFiles(void) const
Definition: remotefile.h:64
static qint64 GetFileSize(ProgramInfo *program_info)