MythTV  master
fileserverutil.cpp
Go to the documentation of this file.
1 #include <unistd.h>
2 #include <cstdlib> // for llabs
3 
4 #include "mythconfig.h"
5 #if CONFIG_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 
17 #include "programinfo.h"
18 
20  ReferenceCounter("DeleteHandler"), m_fd(-1), m_size(0)
21 {
22 }
23 
25  ReferenceCounter(QString("DeleteHandler:%1").arg(filename)),
26  m_path(filename), m_fd(-1), m_size(0)
27 {
28 }
29 
31 {
32  Close();
33 }
34 
36 {
37  if (m_fd >= 0)
38  close(m_fd);
39  m_fd = -1;
40 }
41 
42 static QMap <QString, QString> recordingPathCache;
43 static QMutex recordingPathLock;
44 
45 QString GetPlaybackURL(ProgramInfo *pginfo, bool storePath)
46 {
47  QString result = "";
48  QMutexLocker locker(&recordingPathLock);
49  QString cacheKey = QString("%1:%2").arg(pginfo->GetChanID())
51  if ((recordingPathCache.contains(cacheKey)) &&
52  (QFile::exists(recordingPathCache[cacheKey])))
53  {
54  result = recordingPathCache[cacheKey];
55  if (!storePath)
56  recordingPathCache.remove(cacheKey);
57  }
58  else
59  {
60  locker.unlock();
61  result = pginfo->GetPlaybackURL(false, true);
62  locker.relock();
63  if (storePath && result.startsWith("/"))
64  recordingPathCache[cacheKey] = result;
65  }
66 
67  return result;
68 }
69 
70 /* vim: set expandtab tabstop=4 shiftwidth=4: */
General purpose reference counter.
void Close(void)
Holds information on recordings and videos.
Definition: programinfo.h:66
static QMap< QString, QString > recordingPathCache
#define close
Definition: compat.h:16
static QMutex recordingPathLock
uint GetChanID(void) const
This is the unique key used in the database to locate tuning information.
Definition: programinfo.h:364
QString GetPlaybackURL(ProgramInfo *pginfo, bool storePath)
QDateTime GetRecordingStartTime(void) const
Approximate time the recording started.
Definition: programinfo.h:396
Default UTC.
Definition: mythdate.h:14
QString GetPlaybackURL(bool checkMaster=false, bool forceCheckLocal=false)
Returns filename or URL to be used to play back this recording.