MythTV  master
programinfocache.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 // vim:set sw=4 ts=4 expandtab:
3 #ifndef PROGRAM_INFO_CACHE_H
4 #define PROGRAM_INFO_CACHE_H
5 
6 // C++ headers
7 #include <cstdint>
8 #include <vector>
9 
10 // Qt headers
11 #include <QWaitCondition>
12 #include <QDateTime>
13 #include <QMutex>
14 #include <QHash>
15 
16 class ProgramInfoLoader;
17 class ProgramInfo;
18 class QObject;
19 
21 {
22  friend class ProgramInfoLoader;
23  public:
24  explicit ProgramInfoCache(QObject *o)
25  : m_listener(o) {}
27 
28  void ScheduleLoad(bool updateUI = true);
29  bool IsLoadInProgress(void) const;
30  void WaitForLoadToComplete(void) const;
31 
32  // All the following public methods must only be called from the UI Thread.
33  void Refresh(void);
34  void Add(const ProgramInfo &pginfo);
35  bool Remove(uint recordingID);
36  bool Update(const ProgramInfo &pginfo);
37  bool UpdateFileSize(uint recordingID, uint64_t filesize);
38  QString GetRecGroup(uint recordingID) const;
39  void GetOrdered(std::vector<ProgramInfo*> &list, bool newest_first = false);
41  bool empty(void) const { return m_cache.empty(); }
42  ProgramInfo *GetRecordingInfo(uint recordingID) const;
43 
44  private:
45  void Load(bool updateUI = true);
46  void Clear(void);
47 
48  private:
49  // NOTE: Hash would be faster for lookups and updates, but we need a sorted
50  // list for to rebuild the full list. Question is, which is done more?
51  // We could store a hash, but sort the vector in GetOrdered which might
52  // be a suitable compromise, fractionally slower initial load but faster
53  // scrolling and updates
54  using Cache = QHash<uint,ProgramInfo*>;
55 
56  mutable QMutex m_lock;
58  std::vector<ProgramInfo*> *m_nextCache {nullptr};
59  QObject *m_listener {nullptr};
60  bool m_loadIsQueued {false};
62  mutable QWaitCondition m_loadWait;
63 };
64 
65 #endif // PROGRAM_INFO_CACHE_H
ProgramInfoCache::Add
void Add(const ProgramInfo &pginfo)
Adds a ProgramInfo to the cache.
Definition: programinfocache.cpp:203
ProgramInfoCache::m_cache
Cache m_cache
Definition: programinfocache.h:57
ProgramInfoCache::m_loadIsQueued
bool m_loadIsQueued
Definition: programinfocache.h:60
ProgramInfoCache::GetRecGroup
QString GetRecGroup(uint recordingID) const
Returns the ProgramInfo::recgroup or an empty string if not found.
Definition: programinfocache.cpp:187
ProgramInfoCache::ProgramInfoCache
ProgramInfoCache(QObject *o)
Definition: programinfocache.h:24
ProgramInfoCache::Update
bool Update(const ProgramInfo &pginfo)
Updates a ProgramInfo in the cache.
Definition: programinfocache.cpp:152
ProgramInfoCache
Definition: programinfocache.h:20
ProgramInfoCache::GetOrdered
void GetOrdered(std::vector< ProgramInfo * > &list, bool newest_first=false)
Definition: programinfocache.cpp:244
ProgramInfoCache::empty
bool empty(void) const
Definition: programinfocache.h:41
ProgramInfoCache::m_listener
QObject * m_listener
Definition: programinfocache.h:59
ProgramInfoCache::m_loadsInProgress
uint m_loadsInProgress
Definition: programinfocache.h:61
ProgramInfoCache::ScheduleLoad
void ScheduleLoad(bool updateUI=true)
Definition: programinfocache.cpp:57
ProgramInfoCache::GetRecordingInfo
ProgramInfo * GetRecordingInfo(uint recordingID) const
Definition: programinfocache.cpp:255
ProgramInfoCache::Refresh
void Refresh(void)
Refreshed the cache.
Definition: programinfocache.cpp:116
uint
unsigned int uint
Definition: compat.h:144
ProgramInfoCache::WaitForLoadToComplete
void WaitForLoadToComplete(void) const
Definition: programinfocache.cpp:99
ProgramInfoCache::IsLoadInProgress
bool IsLoadInProgress(void) const
Definition: programinfocache.cpp:93
ProgramInfoCache::Load
void Load(bool updateUI=true)
Definition: programinfocache.cpp:69
ProgramInfoCache::m_lock
QMutex m_lock
Definition: programinfocache.h:56
ProgramInfoLoader
Definition: programinfocache.cpp:31
ProgramInfo
Holds information on recordings and videos.
Definition: programinfo.h:67
ProgramInfoCache::m_loadWait
QWaitCondition m_loadWait
Definition: programinfocache.h:62
ProgramInfoCache::~ProgramInfoCache
~ProgramInfoCache()
Definition: programinfocache.cpp:46
ProgramInfoCache::Remove
bool Remove(uint recordingID)
Marks a ProgramInfo in the cache for deletion on the next call to Refresh().
Definition: programinfocache.cpp:216
ProgramInfoCache::Cache
QHash< uint, ProgramInfo * > Cache
Definition: programinfocache.h:54
ProgramInfoCache::UpdateFileSize
bool UpdateFileSize(uint recordingID, uint64_t filesize)
Updates a ProgramInfo in the cache.
Definition: programinfocache.cpp:168
ProgramInfoCache::Clear
void Clear(void)
Clears the cache, m_lock must be held when this is called.
Definition: programinfocache.cpp:266
ProgramInfoCache::m_nextCache
std::vector< ProgramInfo * > * m_nextCache
Definition: programinfocache.h:58