MythTV  master
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
RemoteFile Class Reference

#include <libmythbase/remotefile.h>

Collaboration diagram for RemoteFile:
[legend]

Public Member Functions

 RemoteFile (QString url="", bool write=false, bool usereadahead=true, std::chrono::milliseconds timeout=2s, const QStringList *possibleAuxiliaryFiles=nullptr)
 
 ~RemoteFile ()
 
bool ReOpen (const QString &newFilename)
 
long long Seek (long long pos, int whence, long long curpos=-1)
 
QDateTime LastModified (void) const
 
int Write (const void *data, int size)
 
int Read (void *data, int size)
 
void Reset (void)
 
bool SetBlocking (bool m_block=true)
 Set write blocking mode for the ThreadedFileWriter instance. More...
 
bool SaveAs (QByteArray &data)
 
void SetTimeout (bool fast)
 
bool isOpen (void) const
 
bool isLocal (void) const
 
long long GetFileSize (void) const
 GetFileSize: returns the remote file's size at the time it was first opened Will query the server in order to get the size. More...
 
long long GetRealFileSize (void)
 GetRealFileSize: returns the current remote file's size. More...
 
QStringList GetAuxiliaryFiles (void) const
 

Static Public Member Functions

static bool DeleteFile (const QString &url)
 
static bool Exists (const QString &url, struct stat *fileinfo)
 
static bool Exists (const QString &url)
 
static QString GetFileHash (const QString &url)
 
static QDateTime LastModified (const QString &url)
 
static QString FindFile (const QString &filename, const QString &host, const QString &storageGroup, bool useRegex=false, bool allowFallback=false)
 Search all BE's for a file in the give storage group. More...
 
static QStringList FindFileList (const QString &filename, const QString &host, const QString &storageGroup, bool useRegex=false, bool allowFallback=false)
 Search all BE's for files in the give storage group. More...
 
static bool CopyFile (const QString &src, const QString &dst, bool overwrite=false, bool verify=false)
 
static bool MoveFile (const QString &src, const QString &dst, bool overwrite=false)
 
static bool isLocal (const QString &path)
 

Private Member Functions

bool Open (void)
 
bool OpenInternal (void)
 Attempts to resume from a disconnected step. More...
 
void Close (bool haslock=false)
 
bool CheckConnection (bool repos=true)
 Check current connection and re-establish it if lost. More...
 
bool IsConnected (void)
 Check if both the control and data sockets are currently connected. More...
 
bool Resume (bool repos=true)
 Attempts to resume from a disconnected step. More...
 
long long SeekInternal (long long pos, int whence, long long curpos=-1)
 
MythSocketopenSocket (bool control)
 

Private Attributes

QString m_path
 
bool m_useReadAhead {true}
 
std::chrono::milliseconds m_timeoutMs {2s}
 
long long m_fileSize {-1}
 
bool m_timeoutIsFast {false}
 
long long m_readPosition {0LL}
 
long long m_lastPosition {0LL}
 
bool m_canResume {false}
 
int m_recorderNum {0}
 
QMutex m_lock
 
MythSocketm_controlSock {nullptr}
 
MythSocketm_sock {nullptr}
 
QString m_query {"QUERY_FILETRANSFER %1"}
 
bool m_writeMode {false}
 
bool m_completed {false}
 
MythTimer m_lastSizeCheck
 
QStringList m_possibleAuxFiles
 
QStringList m_auxFiles
 
int m_localFile {-1}
 
ThreadedFileWriterm_fileWriter {nullptr}
 

Detailed Description

Definition at line 17 of file remotefile.h.

Constructor & Destructor Documentation

◆ RemoteFile()

RemoteFile::RemoteFile ( QString  url = "",
bool  write = false,
bool  usereadahead = true,
std::chrono::milliseconds  timeout = 2s,
const QStringList *  possibleAuxiliaryFiles = nullptr 
)
explicit

Definition at line 68 of file remotefile.cpp.

◆ ~RemoteFile()

RemoteFile::~RemoteFile ( )

Definition at line 91 of file remotefile.cpp.

Member Function Documentation

◆ ReOpen()

bool RemoteFile::ReOpen ( const QString &  newFilename)

Definition at line 338 of file remotefile.cpp.

Referenced by MythFileBuffer::ReOpen().

◆ Seek()

long long RemoteFile::Seek ( long long  pos,
int  whence,
long long  curpos = -1 
)

◆ DeleteFile()

bool RemoteFile::DeleteFile ( const QString &  url)
static

◆ Exists() [1/2]

bool RemoteFile::Exists ( const QString &  url,
struct stat *  fileinfo 
)
static

◆ Exists() [2/2]

bool RemoteFile::Exists ( const QString &  url)
static

Definition at line 451 of file remotefile.cpp.

◆ GetFileHash()

QString RemoteFile::GetFileHash ( const QString &  url)
static

Definition at line 552 of file remotefile.cpp.

Referenced by UpdateHashes(), and VideoMetadata::VideoFileHash().

◆ LastModified() [1/2]

QDateTime RemoteFile::LastModified ( const QString &  url)
static

Definition at line 1233 of file remotefile.cpp.

◆ LastModified() [2/2]

QDateTime RemoteFile::LastModified ( void  ) const

Definition at line 1271 of file remotefile.cpp.

Referenced by MythUIThemeCache::LoadCacheImage().

◆ FindFile()

QString RemoteFile::FindFile ( const QString &  filename,
const QString &  host,
const QString &  storageGroup,
bool  useRegex = false,
bool  allowFallback = false 
)
static

Search all BE's for a file in the give storage group.

Parameters
filenamethe partial path and filename to look for
hostsearch this host first if given or default to the master BE if empty
storageGroupthe name of the storage group to search
useRegexif true filename is assumed to be a regex expression of files to find
allowFallbackif false only 'host' will be searched otherwise all host will be searched until a match is found
Returns
a QString containing the myth URL pointing to the first file found or empty list if not found

Definition at line 1285 of file remotefile.cpp.

Referenced by MusicMetadata::Filename(), MythImage::Load(), and ImportCoverArtDialog::updateStatus().

◆ FindFileList()

QStringList RemoteFile::FindFileList ( const QString &  filename,
const QString &  host,
const QString &  storageGroup,
bool  useRegex = false,
bool  allowFallback = false 
)
static

Search all BE's for files in the give storage group.

Parameters
filenamethe partial path and filename to look for or regular espression (QRegularExpression)
hostsearch this host first if given or default to the master BE if empty
storageGroupthe name of the storage group to search
useRegexif true filename is assumed to be a regex expression of files to find
allowFallbackif false only 'host' will be searched otherwise all host will be searched until a match is found
Returns
a QStringList list containing the myth URL's pointing to the file or empty list if not found

Definition at line 1306 of file remotefile.cpp.

Referenced by FindFile(), and findIcon().

◆ CopyFile()

bool RemoteFile::CopyFile ( const QString &  src,
const QString &  dst,
bool  overwrite = false,
bool  verify = false 
)
static

◆ MoveFile()

bool RemoteFile::MoveFile ( const QString &  src,
const QString &  dst,
bool  overwrite = false 
)
static

Definition at line 676 of file remotefile.cpp.

Referenced by TransferThread::run().

◆ Write()

int RemoteFile::Write ( const void *  data,
int  size 
)

Definition at line 835 of file remotefile.cpp.

Referenced by CopyFile(), MetadataImageDownload::run(), and MythMediaBuffer::Write().

◆ Read()

int RemoteFile::Read ( void *  data,
int  size 
)

◆ Reset()

void RemoteFile::Reset ( void  )

Definition at line 745 of file remotefile.cpp.

◆ SetBlocking()

bool RemoteFile::SetBlocking ( bool  block = true)

Set write blocking mode for the ThreadedFileWriter instance.

Parameters
blockfalse if not blocking, true if blocking
Returns
old mode value

Definition at line 1392 of file remotefile.cpp.

Referenced by CopyFile(), and OpenInternal().

◆ SaveAs()

bool RemoteFile::SaveAs ( QByteArray &  data)

Definition at line 1183 of file remotefile.cpp.

Referenced by V2Content::GetAlbumArt().

◆ SetTimeout()

void RemoteFile::SetTimeout ( bool  fast)

Definition at line 1196 of file remotefile.cpp.

◆ isOpen()

bool RemoteFile::isOpen ( void  ) const

◆ isLocal() [1/2]

bool RemoteFile::isLocal ( const QString &  path)
static

Definition at line 106 of file remotefile.cpp.

◆ isLocal() [2/2]

bool RemoteFile::isLocal ( void  ) const

◆ GetFileSize()

long long RemoteFile::GetFileSize ( void  ) const

GetFileSize: returns the remote file's size at the time it was first opened Will query the server in order to get the size.

If file isn't being modified by the server, that value will be cached

Definition at line 1094 of file remotefile.cpp.

Referenced by CheckRecordings(), CopyFile(), RemoteFileWrapper::GetFileSize(), GetFileSize(), GetRealFileSize(), ArchiveRemoteAVFormatContext::SeekFunc(), RemoteAVFormatContext::SeekFunc(), and MythFileBuffer::SeekInternal().

◆ GetRealFileSize()

long long RemoteFile::GetRealFileSize ( void  )

GetRealFileSize: returns the current remote file's size.

Will query the server in order to get the size. If file isn't being modified by the server, that value will be cached. A QUERY_SIZE myth request will be made. If the server doesn't support this command the size will be queried using a QUERY_FILE_EXISTS request Avoid using GetRealFileSize from the GUI thread

Definition at line 1122 of file remotefile.cpp.

Referenced by MythFileBuffer::GetRealFileSizeInternal(), and SaveAs().

◆ GetAuxiliaryFiles()

QStringList RemoteFile::GetAuxiliaryFiles ( void  ) const
inline

Definition at line 64 of file remotefile.h.

Referenced by MythFileBuffer::OpenFile().

◆ Open()

bool RemoteFile::Open ( void  )
private

Definition at line 253 of file remotefile.cpp.

Referenced by RemoteFile(), and ReOpen().

◆ OpenInternal()

bool RemoteFile::OpenInternal ( void  )
private

Attempts to resume from a disconnected step.

Must have lock

Returns
True if reconnection succeeded

Definition at line 266 of file remotefile.cpp.

Referenced by Open(), and Resume().

◆ Close()

void RemoteFile::Close ( bool  haslock = false)
private

Definition at line 373 of file remotefile.cpp.

Referenced by CopyFile(), OpenInternal(), ReOpen(), Resume(), and ~RemoteFile().

◆ CheckConnection()

bool RemoteFile::CheckConnection ( bool  repos = true)
private

Check current connection and re-establish it if lost.

Returns
True if connection is working
Parameters
reposBool indicating if we are to reposition to the last known location if reconnection is required

Definition at line 1407 of file remotefile.cpp.

Referenced by GetRealFileSize(), Read(), ReOpen(), SeekInternal(), SetTimeout(), and Write().

◆ IsConnected()

bool RemoteFile::IsConnected ( void  )
private

Check if both the control and data sockets are currently connected.

Returns
True if both sockets are connected

Definition at line 1424 of file remotefile.cpp.

Referenced by CheckConnection().

◆ Resume()

bool RemoteFile::Resume ( bool  repos = true)
private

Attempts to resume from a disconnected step.

Must have lock

Returns
True if reconnection succeeded
Parameters
reposBool indicating if we are to reposition to the last known location

Definition at line 1435 of file remotefile.cpp.

Referenced by CheckConnection(), and Read().

◆ SeekInternal()

long long RemoteFile::SeekInternal ( long long  pos,
int  whence,
long long  curpos = -1 
)
private

Definition at line 765 of file remotefile.cpp.

Referenced by Resume(), and Seek().

◆ openSocket()

MythSocket * RemoteFile::openSocket ( bool  control)
private

Definition at line 119 of file remotefile.cpp.

Referenced by OpenInternal().

Member Data Documentation

◆ m_path

QString RemoteFile::m_path
private

◆ m_useReadAhead

bool RemoteFile::m_useReadAhead {true}
private

Definition at line 79 of file remotefile.h.

Referenced by openSocket(), and RemoteFile().

◆ m_timeoutMs

std::chrono::milliseconds RemoteFile::m_timeoutMs {2s}
private

Definition at line 80 of file remotefile.h.

Referenced by openSocket(), and RemoteFile().

◆ m_fileSize

long long RemoteFile::m_fileSize {-1}
private

Definition at line 81 of file remotefile.h.

Referenced by GetFileSize(), GetRealFileSize(), and openSocket().

◆ m_timeoutIsFast

bool RemoteFile::m_timeoutIsFast {false}
private

Definition at line 82 of file remotefile.h.

Referenced by SetTimeout().

◆ m_readPosition

long long RemoteFile::m_readPosition {0LL}
private

Definition at line 83 of file remotefile.h.

Referenced by Resume(), and SeekInternal().

◆ m_lastPosition

long long RemoteFile::m_lastPosition {0LL}
private

Definition at line 84 of file remotefile.h.

Referenced by Read(), Resume(), SeekInternal(), and Write().

◆ m_canResume

bool RemoteFile::m_canResume {false}
private

Definition at line 85 of file remotefile.h.

Referenced by CheckConnection(), and OpenInternal().

◆ m_recorderNum

int RemoteFile::m_recorderNum {0}
private

Definition at line 86 of file remotefile.h.

Referenced by Close(), GetRealFileSize(), openSocket(), Read(), ReOpen(), SeekInternal(), SetTimeout(), and Write().

◆ m_lock

QMutex RemoteFile::m_lock
mutableprivate

Definition at line 88 of file remotefile.h.

Referenced by Close(), GetFileSize(), GetRealFileSize(), Open(), Read(), ReOpen(), Reset(), Seek(), SetTimeout(), and Write().

◆ m_controlSock

MythSocket* RemoteFile::m_controlSock {nullptr}
private

◆ m_sock

MythSocket* RemoteFile::m_sock {nullptr}
private

◆ m_query

QString RemoteFile::m_query {"QUERY_FILETRANSFER %1"}
private

Definition at line 91 of file remotefile.h.

Referenced by Close(), GetRealFileSize(), Read(), ReOpen(), SeekInternal(), SetTimeout(), and Write().

◆ m_writeMode

bool RemoteFile::m_writeMode {false}
private

◆ m_completed

bool RemoteFile::m_completed {false}
private

Definition at line 94 of file remotefile.h.

Referenced by GetRealFileSize().

◆ m_lastSizeCheck

MythTimer RemoteFile::m_lastSizeCheck
private

Definition at line 95 of file remotefile.h.

Referenced by GetRealFileSize().

◆ m_possibleAuxFiles

QStringList RemoteFile::m_possibleAuxFiles
private

Definition at line 97 of file remotefile.h.

Referenced by openSocket(), and RemoteFile().

◆ m_auxFiles

QStringList RemoteFile::m_auxFiles
private

Definition at line 98 of file remotefile.h.

Referenced by openSocket().

◆ m_localFile

int RemoteFile::m_localFile {-1}
private

Definition at line 99 of file remotefile.h.

Referenced by Close(), isOpen(), OpenInternal(), Read(), and SeekInternal().

◆ m_fileWriter

ThreadedFileWriter* RemoteFile::m_fileWriter {nullptr}
private

Definition at line 100 of file remotefile.h.

Referenced by Close(), GetFileSize(), isOpen(), OpenInternal(), SeekInternal(), SetBlocking(), and Write().


The documentation for this class was generated from the following files: