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

#include <remotefile.h>

Collaboration diagram for RemoteFile:
Collaboration graph
[legend]

Public Member Functions

 RemoteFile (QString url="", bool write=false, bool usereadahead=true, int timeout_ms=2000, 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}
 
int m_timeout_ms {2000}
 
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 {QMutex::NonRecursive}
 
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,
int  timeout_ms = 2000,
const QStringList *  possibleAuxiliaryFiles = nullptr 
)

Definition at line 72 of file remotefile.cpp.

◆ ~RemoteFile()

RemoteFile::~RemoteFile ( )

Definition at line 93 of file remotefile.cpp.

Member Function Documentation

◆ ReOpen()

bool RemoteFile::ReOpen ( const QString &  newFilename)

Definition at line 340 of file remotefile.cpp.

Referenced by FileRingBuffer::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 452 of file remotefile.cpp.

◆ GetFileHash()

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

Definition at line 553 of file remotefile.cpp.

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

◆ LastModified() [1/2]

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

Definition at line 1228 of file remotefile.cpp.

◆ LastModified() [2/2]

QDateTime RemoteFile::LastModified ( void  ) const

Definition at line 1270 of file remotefile.cpp.

Referenced by MythUIHelper::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 1284 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 regex
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 1305 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 677 of file remotefile.cpp.

Referenced by TransferThread::run().

◆ Write()

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

Definition at line 834 of file remotefile.cpp.

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

◆ Read()

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

◆ Reset()

void RemoteFile::Reset ( void  )

Definition at line 746 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 1389 of file remotefile.cpp.

Referenced by CopyFile(), and OpenInternal().

◆ SaveAs()

bool RemoteFile::SaveAs ( QByteArray &  data)

Definition at line 1180 of file remotefile.cpp.

Referenced by Content::GetAlbumArt().

◆ SetTimeout()

void RemoteFile::SetTimeout ( bool  fast)

Definition at line 1193 of file remotefile.cpp.

◆ isOpen()

bool RemoteFile::isOpen ( void  ) const

◆ isLocal() [1/2]

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

Definition at line 108 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 1091 of file remotefile.cpp.

Referenced by CheckRecordings(), CopyFile(), RemoteFileWrapper::GetFileSize(), GetFileSize(), GetRealFileSize(), RemoteAVFormatContext::SeekFunc(), and FileRingBuffer::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 1119 of file remotefile.cpp.

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

◆ GetAuxiliaryFiles()

QStringList RemoteFile::GetAuxiliaryFiles ( void  ) const
inline

Definition at line 64 of file remotefile.h.

Referenced by FileRingBuffer::OpenFile().

◆ Open()

bool RemoteFile::Open ( void  )
private

Definition at line 255 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 268 of file remotefile.cpp.

Referenced by Open(), and Resume().

◆ Close()

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

Definition at line 375 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 1404 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 1421 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 1432 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 766 of file remotefile.cpp.

Referenced by Resume(), and Seek().

◆ openSocket()

MythSocket * RemoteFile::openSocket ( bool  control)
private

Definition at line 121 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_timeout_ms

int RemoteFile::m_timeout_ms {2000}
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 {QMutex::NonRecursive}
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: