3#if QT_VERSION >= QT_VERSION_CHECK(6,5,0)
4#include <QtSystemDetection>
9#include <QReadWriteLock>
65#define LOC QString("MythIOWrap: ")
76 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Too many files are open.");
78 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"GetNextFileID: '%1'").arg(
id));
85 QString path(Pathname);
94 if (Object == it.value().m_object)
97 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Removing fileopen callback for %1").arg(path));
105 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Added fileopen callback for %1").arg(path));
111 LOG(VB_FILE, LOG_DEBUG, QString(
"MythFileCheck: '%1')").arg(Id));
118 LOG(VB_FILE, LOG_DEBUG, QString(
"MythFileOpen('%1', %2)").arg(Pathname).arg(Flags));
120 struct stat fileinfo {};
125 if (S_ISDIR(fileinfo.st_mode))
132 if (strncmp(Pathname,
"myth://", 7) != 0)
134 int lfd = open(Pathname, Flags);
149 if ((fileinfo.st_size < 512) && (fileinfo.st_mtime < (time(
nullptr) - 300)))
151 if (Flags & O_WRONLY)
160 if (Flags & O_WRONLY)
190 QString path(Pathname);
195 if (path.startsWith(it.key())) {
196 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Calling callback %1 for %2")
197 .arg(it.key()).arg((qulonglong)it.value().m_callback));
198 it.value().m_callback(it.value().m_object);
208 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythfileClose: '%1").arg(FileID));
242 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythFileSeek(%1, %2, %3)")
243 .arg(FileID).arg(Offset).arg(Whence));
247 result =
s_buffers[FileID]->Seek(Offset, Whence);
261 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythFileTell(%1)").arg(FileID));
265 result =
s_buffers[FileID]->Seek(0, SEEK_CUR);
279 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythFileRead(%1, %2, %3)")
280 .arg(FileID).arg(
reinterpret_cast<long long>(
Buffer)).arg(Count));
298 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythFileWrite(%1, %2, %3)")
299 .arg(FileID).arg(
reinterpret_cast<long long>(
Buffer)).arg(Count));
315 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythfileStat('%1', %2)")
316 .arg(Path).arg(
reinterpret_cast<long long>(
Buf)));
318 if (strncmp(Path,
"myth://", 7) == 0)
325 return stat(Path,
Buf);
330 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythFileStatFD(%1, %2)")
331 .arg(FileID).arg(
reinterpret_cast<long long>(
Buf)));
351 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythFileExists('%1', '%2')")
355 if (strncmp(Path,
"myth://", 7) == 0)
359 return static_cast<int>(ret);
370 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Too many directories are open.");
371 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"GetNextDirID: '%1'").arg(
id));
378 LOG(VB_FILE, LOG_DEBUG, QString(
"MythDirCheck: '%1'").arg(DirID));
387 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythDirOpen: '%1'").arg(DirName));
389 if (strncmp(DirName,
"myth://", 7) != 0)
391 DIR *dir = opendir(DirName);
406 QString storageGroup = qurl.userName();
409 if (storageGroup.isEmpty())
410 storageGroup =
"Default";
412 list <<
"QUERY_SG_GETFILELIST" << qurl.host() << storageGroup;
414 QString path = qurl.path();
415 if (!qurl.fragment().isEmpty())
416 path +=
"#" + qurl.fragment();
422 if ((!ok) || ((list.size() == 1) && (list[0] ==
"EMPTY LIST")))
439 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythDirClose: '%1'").arg(DirID));
462 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"MythDirRead: '%1'").arg(DirID));
470 std::string result =
s_remotedirs[DirID][pos].toLocal8Bit().constData();
480 return { 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
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)
std::string MythDirRead(int DirID)
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(*)(void *) callback_t
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
def read(device=None, features=[])
def write(text, progress=True)