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  explicit RemoteFile(QString url = "",
21  bool write = false,
22  bool usereadahead = true,
23  std::chrono::milliseconds timeout = 2s/*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  std::chrono::milliseconds m_timeoutMs {2s};
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;
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
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
RemoteFile::m_path
QString m_path
Definition: remotefile.h:78
MythTimer
A QElapsedTimer based timer to replace use of QTime as a timer.
Definition: mythtimer.h:13
mythbaseexp.h
CopyFile
static int CopyFile(const MythUtilCommandLineParser &cmdline)
Definition: fileutils.cpp:10
mythburn.write
def write(text, progress=True)
Definition: mythburn.py:308
RemoteFile::m_lastSizeCheck
MythTimer m_lastSizeCheck
Definition: remotefile.h:95
RemoteFile
Definition: remotefile.h:17
MythSocket
Class for communcating between myth backends and frontends.
Definition: mythsocket.h:25
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
GetFileSize
static qint64 GetFileSize(ProgramInfo *program_info)
Definition: mythcommflag.cpp:623
RemoteFile::GetAuxiliaryFiles
QStringList GetAuxiliaryFiles(void) const
Definition: remotefile.h:64
RemoteFile::m_lock
QMutex m_lock
Definition: remotefile.h:88
RemoteFile::m_auxFiles
QStringList m_auxFiles
Definition: remotefile.h:98
ThreadedFileWriter
This class supports the writing of recordings to disk.
Definition: threadedfilewriter.h:42
mythtimer.h
RemoteFile::m_possibleAuxFiles
QStringList m_possibleAuxFiles
Definition: remotefile.h:97
build_compdb.filename
filename
Definition: build_compdb.py:21