5#include <QReadWriteLock>
9#include "libmythbase/mythconfig.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));
241 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythFileSeek(%1, %2, %3)")
242 .arg(FileID).arg(Offset).arg(Whence));
246 result =
s_buffers[FileID]->Seek(Offset, Whence);
260 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythFileTell(%1)").arg(FileID));
264 result =
s_buffers[FileID]->Seek(0, SEEK_CUR);
278 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythFileRead(%1, %2, %3)")
279 .arg(FileID).arg(
reinterpret_cast<long long>(
Buffer)).arg(Count));
297 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythFileWrite(%1, %2, %3)")
298 .arg(FileID).arg(
reinterpret_cast<long long>(
Buffer)).arg(Count));
314 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythfileStat('%1', %2)")
315 .arg(Path).arg(
reinterpret_cast<long long>(
Buf)));
317 if (strncmp(Path,
"myth://", 7) == 0)
324 return stat(Path,
Buf);
329 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythFileStatFD(%1, %2)")
330 .arg(FileID).arg(
reinterpret_cast<long long>(
Buf)));
350 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythFileExists('%1', '%2')")
354 if (strncmp(Path,
"myth://", 7) == 0)
358 return static_cast<int>(ret);
369 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Too many directories are open.");
370 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"GetNextDirID: '%1'").arg(
id));
377 LOG(VB_FILE, LOG_DEBUG, QString(
"MythDirCheck: '%1'").arg(DirID));
386 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythDirOpen: '%1'").arg(DirName));
388 if (strncmp(DirName,
"myth://", 7) != 0)
390 DIR *dir = opendir(DirName);
405 QString storageGroup = qurl.userName();
408 if (storageGroup.isEmpty())
409 storageGroup =
"Default";
411 list <<
"QUERY_SG_GETFILELIST" << qurl.host() << storageGroup;
413 QString path = qurl.path();
414 if (!qurl.fragment().isEmpty())
415 path +=
"#" + qurl.fragment();
421 if ((!ok) || ((list.size() == 1) && (list[0] ==
"EMPTY LIST")))
438 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythDirClose: '%1'").arg(DirID));
461 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythDirRead: '%1'").arg(DirID));
469 char* result = strdup(
s_remotedirs[DirID][pos].toLocal8Bit().constData());
479 return strdup(dir->d_name);
bool SendReceiveStringList(QStringList &strlist, bool quickTimeout=false, bool block=true)
Send a message to the backend and wait for a response.
bool operator==(MythIOCallback rhs) const
MythIOCallback(void *Object, callback_t Callback)
static bool Exists(const QString &url, struct stat *fileinfo)
static void(* m_callback)(void *, QString &)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
static QReadWriteLock s_fileWrapperLock
static QReadWriteLock s_dirWrapperLock
char * MythDirRead(int DirID)
static int GetNextDirID(void)
static QHash< int, QString > s_filenames
static QMutex s_callbackLock
static QHash< int, int > s_remotedirPositions
int MythDirClose(int DirID)
ssize_t MythFileRead(int FileID, void *Buffer, size_t Count)
static QHash< int, DIR * > s_localdirs
int MythFileExists(const char *Path, const char *File)
static int GetNextFileID(void)
int MythDirOpen(const char *DirName)
static QMultiHash< QString, MythIOCallback > s_fileOpenCallbacks
off_t MythFileSeek(int FileID, off_t Offset, int Whence)
int MythfileClose(int FileID)
static QHash< int, RemoteFile * > s_remotefiles
void MythFileOpenRegisterCallback(const char *Pathname, void *Object, callback_t Func)
int MythDirCheck(int DirID)
int MythFileOpen(const char *Pathname, int Flags)
int MythFileCheck(int Id)
int MythFileStat(const char *Path, struct stat *Buf)
int MythFileStatFD(int FileID, struct stat *Buf)
static QHash< int, QString > s_dirnames
ssize_t MythFileWrite(int FileID, void *Buffer, size_t Count)
static QHash< int, MythMediaBuffer * > s_buffers
static QHash< int, QStringList > s_remotedirs
off_t MythFileTell(int FileID)
static QHash< int, int > s_localfiles
void(* callback_t)(void *)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
def read(device=None, features=[])
def write(text, progress=True)