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 using namespace std;
10 
11 // Qt headers
12 #include <QWaitCondition>
13 #include <QDateTime>
14 #include <QMutex>
15 #include <QHash>
16 
17 class ProgramInfoLoader;
18 class ProgramInfo;
19 class QObject;
20 
22 {
23  friend class ProgramInfoLoader;
24  public:
25  explicit ProgramInfoCache(QObject *o)
26  : m_listener(o) {}
28 
29  void ScheduleLoad(const bool updateUI = true);
30  bool IsLoadInProgress(void) const;
31  void WaitForLoadToComplete(void) const;
32 
33  // All the following public methods must only be called from the UI Thread.
34  void Refresh(void);
35  void Add(const ProgramInfo&);
36  bool Remove(uint recordingID);
37  bool Update(const ProgramInfo&);
38  bool UpdateFileSize(uint recordingID, uint64_t filesize);
39  QString GetRecGroup(uint recordingID) const;
40  void GetOrdered(vector<ProgramInfo*> &list, bool newest_first = false);
42  bool empty(void) const { return m_cache.empty(); }
43  ProgramInfo *GetRecordingInfo(uint recordingID) const;
44 
45  private:
46  void Load(const bool updateUI = true);
47  void Clear(void);
48 
49  private:
50  // NOTE: Hash would be faster for lookups and updates, but we need a sorted
51  // list for to rebuild the full list. Question is, which is done more?
52  // We could store a hash, but sort the vector in GetOrdered which might
53  // be a suitable compromise, fractionally slower initial load but faster
54  // scrolling and updates
55  typedef QHash<uint,ProgramInfo*> Cache;
56 
57  mutable QMutex m_lock;
59  vector<ProgramInfo*> *m_next_cache {nullptr};
60  QObject *m_listener {nullptr};
61  bool m_load_is_queued {false};
62  uint m_loads_in_progress {0};
63  mutable QWaitCondition m_load_wait;
64 };
65 
66 #endif // _PROGRAM_INFO_CACHE_H_
ProgramInfoCache & m_cache
QWaitCondition m_load_wait
static void UpdateFileSize(ProgramInfo *program_info)
unsigned int uint
Definition: compat.h:140
Holds information on recordings and videos.
Definition: programinfo.h:66
QHash< uint, ProgramInfo * > Cache
ProgramInfoCache(QObject *o)
bool empty(void) const
#define Clear(a)