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