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
17class ProgramInfo;
18class QObject;
19
21{
22 friend class ProgramInfoLoader;
23
24 public:
25 enum UpdateState : std::uint8_t {
26 PIC_NONE = 0x00,
30 };
32
33 explicit ProgramInfoCache(QObject *o)
34 : m_listener(o) {}
36
37 void ScheduleLoad(bool updateUI = true);
38 bool IsLoadInProgress(void) const;
39 void WaitForLoadToComplete(void) const;
40
41 // All the following public methods must only be called from the UI Thread.
42 void Refresh(void);
43 void Add(const ProgramInfo &pginfo);
44 bool Remove(uint recordingID);
45 ProgramInfoCache::UpdateStates Update(const ProgramInfo &pginfo);
46 void UpdateFileSize(uint recordingID, uint64_t filesize, UpdateStates flags);
47 void GetOrdered(std::vector<ProgramInfo*> &list, bool newest_first = false);
49 bool empty(void) const { return m_cache.empty(); }
50 ProgramInfo *GetRecordingInfo(uint recordingID) const;
51
52 private:
53 void Load(bool updateUI = true);
54 void Clear(void);
55
56 private:
57 // NOTE: Hash would be faster for lookups and updates, but we need a sorted
58 // list for to rebuild the full list. Question is, which is done more?
59 // We could store a hash, but sort the vector in GetOrdered which might
60 // be a suitable compromise, fractionally slower initial load but faster
61 // scrolling and updates
62 using Cache = QHash<uint,ProgramInfo*>;
63
64 mutable QMutex m_lock;
66 std::vector<ProgramInfo*> *m_nextCache {nullptr};
67 QObject *m_listener {nullptr};
68 bool m_loadIsQueued {false};
70 mutable QWaitCondition m_loadWait;
71};
72
73Q_DECLARE_OPERATORS_FOR_FLAGS(ProgramInfoCache::UpdateStates)
74
75#endif // PROGRAM_INFO_CACHE_H
void GetOrdered(std::vector< ProgramInfo * > &list, bool newest_first=false)
void Add(const ProgramInfo &pginfo)
Adds a ProgramInfo to the cache.
QHash< uint, ProgramInfo * > Cache
bool Remove(uint recordingID)
Marks a ProgramInfo in the cache for deletion on the next call to Refresh().
bool IsLoadInProgress(void) const
void Load(bool updateUI=true)
ProgramInfoCache(QObject *o)
std::vector< ProgramInfo * > * m_nextCache
void Refresh(void)
Refreshed the cache.
Q_DECLARE_FLAGS(UpdateStates, UpdateState)
void UpdateFileSize(uint recordingID, uint64_t filesize, UpdateStates flags)
Updates a ProgramInfo in the cache.
QWaitCondition m_loadWait
void ScheduleLoad(bool updateUI=true)
ProgramInfoCache::UpdateStates Update(const ProgramInfo &pginfo)
Updates a ProgramInfo in the cache.
void WaitForLoadToComplete(void) const
ProgramInfo * GetRecordingInfo(uint recordingID) const
void Clear(void)
Clears the cache, m_lock must be held when this is called.
bool empty(void) const
Holds information on recordings and videos.
Definition: programinfo.h:68
unsigned int uint
Definition: freesurround.h:24