00001 #ifndef _LIVETVCHAIN_H_
00002 #define _LIVETVCHAIN_H_
00003
00004 #include <QString>
00005 #include <QDateTime>
00006 #include <QMutex>
00007 #include <QList>
00008
00009 #include "mythtvexp.h"
00010
00011 class ProgramInfo;
00012 class MythSocket;
00013
00014 struct MTV_PUBLIC LiveTVChainEntry
00015 {
00016 uint chanid;
00017 QDateTime starttime;
00018 QDateTime endtime;
00019 bool discontinuity;
00020 QString hostprefix;
00021 QString cardtype;
00022 QString channum;
00023 QString inputname;
00024 };
00025
00026 class MTV_PUBLIC LiveTVChain
00027 {
00028 public:
00029 LiveTVChain();
00030 ~LiveTVChain();
00031
00032 QString InitializeNewChain(const QString &seed);
00033 void LoadFromExistingChain(const QString &id);
00034
00035 void SetHostPrefix(const QString &prefix);
00036 void SetCardType(const QString &type);
00037
00038 void DestroyChain(void);
00039
00040 void AppendNewProgram(ProgramInfo *pginfo, QString channum,
00041 QString inputname, bool discont);
00042 void FinishedRecording(ProgramInfo *pginfo);
00043 void DeleteProgram(ProgramInfo *pginfo);
00044
00045 void ReloadAll();
00046
00047
00048 QString GetID(void) const { return m_id; }
00049 int GetCurPos(void) const { return m_curpos; }
00050 int ProgramIsAt(uint chanid, const QDateTime &starttime) const;
00051 int ProgramIsAt(const ProgramInfo &pginfo) const;
00052 int GetLengthAtCurPos(void);
00053 int TotalSize(void) const;
00054 bool HasNext(void) const;
00055 bool HasPrev(void) const { return (m_curpos > 0); }
00056 ProgramInfo *GetProgramAt(int at) const;
00058 bool NeedsToSwitch(void) const
00059 { return (m_switchid >= 0 && m_jumppos == 0); }
00061 bool NeedsToJump(void) const
00062 { return (m_switchid >= 0 && m_jumppos != 0); }
00063 QString GetChannelName(int pos = -1) const;
00064 QString GetInputName(int pos = -1) const;
00065 QString GetCardType(int pos = -1) const;
00066
00067
00068 void SetProgram(const ProgramInfo &pginfo);
00069 void SwitchTo(int num);
00070 void SwitchToNext(bool up);
00071 void ClearSwitch(void);
00072 ProgramInfo *GetSwitchProgram(bool &discont, bool &newtype, int &newid);
00073
00074
00075 void JumpTo(int num, int pos);
00076 void JumpToNext(bool up, int pos);
00077 int GetJumpPos(void);
00078
00079
00080 void SetHostSocket(MythSocket *sock);
00081 bool IsHostSocket(const MythSocket *sock) const;
00082 uint HostSocketCount(void) const;
00083 void DelHostSocket(MythSocket *sock);
00084
00085 QString toString() const;
00086
00087 private:
00088 void BroadcastUpdate();
00089 void GetEntryAt(int at, LiveTVChainEntry &entry) const;
00090 static ProgramInfo *EntryToProgram(const LiveTVChainEntry &entry);
00091
00092 QString m_id;
00093 QList<LiveTVChainEntry> m_chain;
00094 int m_maxpos;
00095 mutable QMutex m_lock;
00096
00097 QString m_hostprefix;
00098 QString m_cardtype;
00099
00100 int m_curpos;
00101 uint m_cur_chanid;
00102 QDateTime m_cur_startts;
00103
00104 int m_switchid;
00105 LiveTVChainEntry m_switchentry;
00106
00107 int m_jumppos;
00108
00109 mutable QMutex m_sockLock;
00110 QList<MythSocket*> m_inUseSocks;
00111 };
00112
00113 #endif
00114