Go to the documentation of this file.
5 #include <QReadWriteLock>
9 #include "libmythbase/mythconfig.h"
27 #include <sys/types.h>
62 #define LOC QString("MythIOWrap: ")
75 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Too many files are open.");
77 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"GetNextFileID: '%1'").arg(
id));
84 QString path(Pathname);
93 if (Object == it.value().m_object)
96 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Removing fileopen callback for %1").arg(path));
104 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Added fileopen callback for %1").arg(path));
110 LOG(VB_FILE, LOG_DEBUG, QString(
"MythFileCheck: '%1')").arg(Id));
117 LOG(VB_FILE, LOG_DEBUG, QString(
"MythFileOpen('%1', %2)").arg(Pathname).arg(Flags));
119 struct stat fileinfo {};
124 if (S_ISDIR(fileinfo.st_mode))
131 if (strncmp(Pathname,
"myth://", 7) != 0)
133 int lfd = open(Pathname, Flags);
148 if ((fileinfo.st_size < 512) && (fileinfo.st_mtime < (time(
nullptr) - 300)))
150 if (Flags & O_WRONLY)
159 if (Flags & O_WRONLY)
189 QString path(Pathname);
194 if (path.startsWith(it.key())) {
195 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Calling callback %1 for %2")
196 .arg(it.key()).arg((qulonglong)it.value().m_callback));
197 it.value().m_callback(it.value().m_object);
207 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythfileClose: '%1").arg(FileID));
239 # define lseek _lseeki64
241 # define off_t off64_t
247 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythFileSeek(%1, %2, %3)")
248 .arg(FileID).arg(Offset).arg(Whence));
252 result =
s_buffers[FileID]->Seek(Offset, Whence);
266 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythFileTell(%1)").arg(FileID));
270 result =
s_buffers[FileID]->Seek(0, SEEK_CUR);
289 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythFileRead(%1, %2, %3)")
290 .arg(FileID).arg(
reinterpret_cast<long long>(
Buffer)).arg(Count));
308 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythFileWrite(%1, %2, %3)")
309 .arg(FileID).arg(
reinterpret_cast<long long>(
Buffer)).arg(Count));
325 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythfileStat('%1', %2)")
326 .arg(Path).arg(
reinterpret_cast<long long>(
Buf)));
328 if (strncmp(Path,
"myth://", 7) == 0)
335 return stat(Path,
Buf);
340 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythFileStatFD(%1, %2)")
341 .arg(FileID).arg(
reinterpret_cast<long long>(
Buf)));
361 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythFileExists('%1', '%2')")
365 if (strncmp(Path,
"myth://", 7) == 0)
368 ret = QFile::exists(QString(
"%1/%2").arg(Path, File));
369 return static_cast<int>(ret);
380 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Too many directories are open.");
381 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"GetNextDirID: '%1'").arg(
id));
388 LOG(VB_FILE, LOG_DEBUG, QString(
"MythDirCheck: '%1'").arg(DirID));
397 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythDirOpen: '%1'").arg(DirName));
399 if (strncmp(DirName,
"myth://", 7) != 0)
401 DIR *dir = opendir(DirName);
416 QString storageGroup = qurl.userName();
419 if (storageGroup.isEmpty())
420 storageGroup =
"Default";
422 list <<
"QUERY_SG_GETFILELIST" << qurl.host() << storageGroup;
424 QString path = qurl.path();
425 if (!qurl.fragment().isEmpty())
426 path +=
"#" + qurl.fragment();
432 if ((!ok) || ((list.size() == 1) && (list[0] ==
"EMPTY LIST")))
449 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythDirClose: '%1'").arg(DirID));
472 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythDirRead: '%1'").arg(DirID));
480 char* result = strdup(
s_remotedirs[DirID][pos].toLocal8Bit().constData());
488 struct dirent *dir =
nullptr;
490 if ((dir = readdir(
s_localdirs[DirID])) !=
nullptr)
491 return strdup(dir->d_name);
int MythFileStatFD(int FileID, struct stat *Buf)
static QHash< int, DIR * > s_localdirs
int MythDirClose(int DirID)
bool SendReceiveStringList(QStringList &strlist, bool quickTimeout=false, bool block=true)
Send a message to the backend and wait for a response.
void(* callback_t)(void *)
static bool Exists(const QString &url, struct stat *fileinfo)
def read(device=None, features=[])
char * MythDirRead(int DirID)
static QHash< int, QString > s_dirnames
def write(text, progress=True)
int MythfileClose(int FileID)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
int MythFileCheck(int Id)
void MythFileOpenRegisterCallback(const char *Pathname, void *Object, callback_t Func)
ssize_t MythFileRead(int FileID, void *Buffer, size_t Count)
static void(* m_callback)(void *, QString &)
static QMultiHash< QString, MythIOCallback > s_fileOpenCallbacks
static QHash< int, QStringList > s_remotedirs
static QHash< int, MythMediaBuffer * > s_buffers
static QHash< int, int > s_localfiles
off_t MythFileTell(int FileID)
static QReadWriteLock s_dirWrapperLock
int MythFileStat(const char *Path, struct stat *Buf)
static QHash< int, int > s_remotedirPositions
static int GetNextFileID(void)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
bool operator==(MythIOCallback rhs) const
static QHash< int, QString > s_filenames
static int GetNextDirID(void)
static QMutex s_callbackLock
int MythFileOpen(const char *Pathname, int Flags)
MythIOCallback(void *Object, callback_t Callback)
int MythDirOpen(const char *DirName)
static QHash< int, RemoteFile * > s_remotefiles
static QReadWriteLock s_fileWrapperLock
int MythDirCheck(int DirID)
ssize_t MythFileWrite(int FileID, void *Buffer, size_t Count)
off_t MythFileSeek(int FileID, off_t Offset, int Whence)
int MythFileExists(const char *Path, const char *File)