00001 #ifndef _PROGRAM_INFO_UPDATER_H_
00002 #define _PROGRAM_INFO_UPDATER_H_
00003
00004
00005 #include <stdint.h>
00006
00007
00008 #include <vector>
00009 using namespace std;
00010
00011
00012 #include <QWaitCondition>
00013 #include <QDateTime>
00014 #include <QRunnable>
00015 #include <QMutex>
00016 #include <QHash>
00017
00018 typedef enum PIAction {
00019 kPIAdd,
00020 kPIDelete,
00021 kPIUpdate,
00022 kPIUpdateFileSize,
00023 } PIAction;
00024
00025 class PIKey
00026 {
00027 public:
00028 PIKey(uint c, const QDateTime &r) : chanid(c), recstartts(r) {}
00029
00030 uint chanid;
00031 QDateTime recstartts;
00032
00033 bool operator==(const PIKey &other) const
00034 {
00035 return (chanid == other.chanid &&
00036 recstartts == other.recstartts);
00037 }
00038 };
00039 uint qHash(const PIKey &k);
00040
00041 class PIKeyAction : public PIKey
00042 {
00043 public:
00044 PIKeyAction(uint c, const QDateTime &r, PIAction a) :
00045 PIKey(c, r), action(a) { }
00046
00047 PIAction action;
00048 };
00049
00050 class PIKeyData
00051 {
00052 public:
00053 PIKeyData(PIAction a, uint64_t f) : action(a), filesize(f) { }
00054 PIAction action;
00055 uint64_t filesize;
00056 };
00057
00058 class ProgramInfoUpdater : public QRunnable
00059 {
00060 public:
00061 ProgramInfoUpdater() : isRunning(false) { setAutoDelete(false); }
00062
00063 void insert(uint chanid, const QDateTime &recstartts,
00064 PIAction action, uint64_t filesize = 0ULL);
00065 void run(void);
00066
00067 private:
00068 QMutex lock;
00069 QWaitCondition moreWork;
00070 bool isRunning;
00071 vector<PIKeyAction> needsAddDelete;
00072 QHash<PIKey,PIKeyData> needsUpdate;
00073 };
00074
00075 #endif // _PROGRAM_INFO_UPDATER_H_