MythTV  master
fileserverutil.cpp
Go to the documentation of this file.
1 #include <unistd.h>
2 #include <cstdlib> // for llabs
3 
4 #include <QtGlobal>
5 #if defined(Q_OS_DARWIN) || defined(__FreeBSD__)
6 #include <sys/param.h>
7 #include <sys/mount.h>
8 #elif __linux__
9 #include <sys/vfs.h>
10 #endif
11 
12 #include <QMutex>
13 #include <QFile>
14 #include <QMap>
15 
16 #include "libmyth/programinfo.h"
17 
19 
21  ReferenceCounter("DeleteHandler")
22 {
23 }
24 
26  ReferenceCounter(QString("DeleteHandler:%1").arg(filename)),
27  m_path(filename)
28 {
29 }
30 
32 {
33  Close();
34 }
35 
37 {
38  if (m_fd >= 0)
39  close(m_fd);
40  m_fd = -1;
41 }
42 
43 static QMap <QString, QString> recordingPathCache;
44 static QMutex recordingPathLock;
45 
46 QString GetPlaybackURL(ProgramInfo *pginfo, bool storePath)
47 {
48  QString result = "";
49  QMutexLocker locker(&recordingPathLock);
50  QString cacheKey = QString("%1:%2").arg(pginfo->GetChanID())
52  if ((recordingPathCache.contains(cacheKey)) &&
53  (QFile::exists(recordingPathCache[cacheKey])))
54  {
55  result = recordingPathCache[cacheKey];
56  if (!storePath)
57  recordingPathCache.remove(cacheKey);
58  }
59  else
60  {
61  locker.unlock();
62  result = pginfo->GetPlaybackURL(false, true);
63  locker.relock();
64  if (storePath && result.startsWith("/"))
65  recordingPathCache[cacheKey] = result;
66  }
67 
68  return result;
69 }
70 
71 /* vim: set expandtab tabstop=4 shiftwidth=4: */
DeleteHandler::m_fd
int m_fd
Definition: fileserverutil.h:40
recordingPathLock
static QMutex recordingPathLock
Definition: fileserverutil.cpp:44
DeleteHandler::DeleteHandler
DeleteHandler(void)
Definition: fileserverutil.cpp:20
ProgramInfo::GetRecordingStartTime
QDateTime GetRecordingStartTime(void) const
Approximate time the recording started.
Definition: programinfo.h:404
close
#define close
Definition: compat.h:43
fileserverutil.h
programinfo.h
GetPlaybackURL
QString GetPlaybackURL(ProgramInfo *pginfo, bool storePath)
Definition: fileserverutil.cpp:46
ProgramInfo::GetChanID
uint GetChanID(void) const
This is the unique key used in the database to locate tuning information.
Definition: programinfo.h:372
ProgramInfo
Holds information on recordings and videos.
Definition: programinfo.h:67
recordingPathCache
static QMap< QString, QString > recordingPathCache
Definition: fileserverutil.cpp:43
ProgramInfo::GetPlaybackURL
QString GetPlaybackURL(bool checkMaster=false, bool forceCheckLocal=false)
Returns filename or URL to be used to play back this recording.
Definition: programinfo.cpp:2546
MythDate::ISODate
@ ISODate
Default UTC.
Definition: mythdate.h:17
DeleteHandler::~DeleteHandler
~DeleteHandler(void) override
Definition: fileserverutil.cpp:31
DeleteHandler::Close
void Close(void)
Definition: fileserverutil.cpp:36
build_compdb.filename
filename
Definition: build_compdb.py:21
ReferenceCounter
General purpose reference counter.
Definition: referencecounter.h:26