00001
00002
00003 #ifndef _PROGRAM_INFO_CACHE_H_
00004 #define _PROGRAM_INFO_CACHE_H_
00005
00006
00007 #include <stdint.h>
00008
00009
00010 #include <vector>
00011 #include <map>
00012 using namespace std;
00013
00014
00015 #include <QWaitCondition>
00016 #include <QDateTime>
00017 #include <QMutex>
00018
00019 class ProgramInfoLoader;
00020 class ProgramInfo;
00021 class QObject;
00022
00023 class ProgramInfoCache
00024 {
00025 friend class ProgramInfoLoader;
00026 public:
00027 ProgramInfoCache(QObject *o);
00028 ~ProgramInfoCache();
00029
00030 void ScheduleLoad(const bool updateUI = true);
00031 bool IsLoadInProgress(void) const;
00032 void WaitForLoadToComplete(void) const;
00033
00034
00035 void Refresh(void);
00036 void Add(const ProgramInfo&);
00037 bool Remove(uint chanid, const QDateTime &recstartts);
00038 bool Update(const ProgramInfo&);
00039 bool UpdateFileSize(uint chanid, const QDateTime &recstartts,
00040 uint64_t filesize);
00041 QString GetRecGroup(uint chanid, const QDateTime &recstartts) const;
00042 void GetOrdered(vector<ProgramInfo*> &list, bool newest_first = false);
00044 bool empty(void) const { return m_cache.empty(); }
00045 ProgramInfo *GetProgramInfo(uint chanid, const QDateTime &recstartts) const;
00046 ProgramInfo *GetProgramInfo(const QString &piKey) const;
00047
00048 private:
00049 void Load(const bool updateUI = true);
00050 void Clear(void);
00051
00052 private:
00053 class PICKey
00054 {
00055 public:
00056 PICKey(uint c, const QDateTime &r) : chanid(c), recstartts(r) { }
00057 uint chanid;
00058 QDateTime recstartts;
00059 };
00060
00061 struct ltkey
00062 {
00063 bool operator()(const PICKey &a, const PICKey &b) const
00064 {
00065 if (a.recstartts == b.recstartts)
00066 return a.chanid < b.chanid;
00067 return (a.recstartts < b.recstartts);
00068 }
00069 };
00070
00071 typedef map<PICKey,ProgramInfo*,ltkey> Cache;
00072
00073 mutable QMutex m_lock;
00074 Cache m_cache;
00075 vector<ProgramInfo*> *m_next_cache;
00076 QObject *m_listener;
00077 bool m_load_is_queued;
00078 uint m_loads_in_progress;
00079 mutable QWaitCondition m_load_wait;
00080 };
00081
00082 #endif // _PROGRAM_INFO_CACHE_H_