00001
00002
00003
00004 #ifndef SIGNALMONITOR_H
00005 #define SIGNALMONITOR_H
00006
00007
00008 #include <vector>
00009 #include <algorithm>
00010 using namespace std;
00011
00012
00013 #include <QWaitCondition>
00014 #include <QMutex>
00015
00016
00017 #include "signalmonitorlistener.h"
00018 #include "signalmonitorvalue.h"
00019 #include "channelbase.h"
00020 #include "mythtimer.h"
00021 #include "cardutil.h"
00022 #include "mthread.h"
00023
00024 #define DBG_SM(FUNC, MSG) LOG(VB_CHANNEL, LOG_DEBUG, \
00025 QString("SM(%1)::%2: %3") .arg(channel->GetDevice()).arg(FUNC).arg(<MSG));
00026
00027 inline QString sm_flags_to_string(uint64_t);
00028
00029 class TVRec;
00030
00031 class SignalMonitor : protected MThread
00032 {
00033 public:
00035 static inline bool IsRequired(const QString &cardtype);
00036 static inline bool IsSupported(const QString &cardtype);
00037 static SignalMonitor *Init(QString cardtype, int db_cardnum,
00038 ChannelBase *channel);
00039 virtual ~SignalMonitor();
00040
00041
00042
00043
00044 virtual void Start();
00045 virtual void Stop();
00046
00047
00048
00049
00050 virtual void AddFlags(uint64_t _flags);
00051 virtual void RemoveFlags(uint64_t _flags);
00052 bool HasFlags(uint64_t _flags) const;
00053 bool HasAnyFlag(uint64_t _flags) const;
00054 uint64_t GetFlags(void) const { return flags; }
00055 virtual bool HasExtraSlowTuning(void) const { return false; }
00056
00057
00058
00059
00062 bool GetNotifyFrontend() const { return notify_frontend; }
00064 int GetUpdateRate() const { return update_rate; }
00065 virtual QStringList GetStatusList(void) const;
00066
00069 bool HasSignalLock(void) const
00070 {
00071 QMutexLocker locker(&statusLock);
00072 return scriptStatus.IsGood() && signalLock.IsGood();
00073 }
00074
00075 virtual bool IsAllGood(void) const { return HasSignalLock(); }
00076 bool IsErrored(void) const { return !error.isEmpty(); }
00077
00078
00079
00080
00086 void SetNotifyFrontend(bool notify) { notify_frontend = notify; }
00087
00092 void SetMonitoring(TVRec * parent, bool EITscan, bool monitor)
00093 { pParent = parent; eit_scan = EITscan, tablemon = monitor; }
00094
00101 void SetUpdateRate(int msec)
00102 { update_rate = max(msec, (int)minimum_update_rate); }
00103
00104
00105
00106 void AddListener(SignalMonitorListener *listener);
00107 void RemoveListener(SignalMonitorListener *listener);
00108 void SendMessage(SignalMonitorMessageType type,
00109 const SignalMonitorValue &val);
00110 void SendMessageAllGood(void);
00111 virtual void EmitStatus(void);
00112
00113 protected:
00114 SignalMonitor(int db_cardnum, ChannelBase *_channel,
00115 uint64_t wait_for_mask);
00116
00117 virtual void run(void);
00118
00120 virtual void UpdateValues(void);
00121
00122 public:
00125 static const uint64_t kDTVSigMon_PATSeen = 0x0000000001ULL;
00128 static const uint64_t kDTVSigMon_PMTSeen = 0x0000000002ULL;
00131 static const uint64_t kDTVSigMon_MGTSeen = 0x0000000004ULL;
00134 static const uint64_t kDTVSigMon_VCTSeen = 0x0000000008ULL;
00136 static const uint64_t kDTVSigMon_TVCTSeen = 0x0000000010ULL;
00138 static const uint64_t kDTVSigMon_CVCTSeen = 0x0000000020ULL;
00141 static const uint64_t kDTVSigMon_NITSeen = 0x0000000040ULL;
00144 static const uint64_t kDTVSigMon_SDTSeen = 0x0000000080ULL;
00146 static const uint64_t kFWSigMon_PowerSeen = 0x0000000100ULL;
00148 static const uint64_t kDTVSigMon_CryptSeen = 0x0000000200ULL;
00149
00151 static const uint64_t kDTVSigMon_PATMatch = 0x0000001000ULL;
00153 static const uint64_t kDTVSigMon_PMTMatch = 0x0000002000ULL;
00155 static const uint64_t kDTVSigMon_MGTMatch = 0x0000004000ULL;
00157 static const uint64_t kDTVSigMon_VCTMatch = 0x0000008000ULL;
00159 static const uint64_t kDTVSigMon_TVCTMatch = 0x0000010000ULL;
00161 static const uint64_t kDTVSigMon_CVCTMatch = 0x0000020000ULL;
00163 static const uint64_t kDTVSigMon_NITMatch = 0x0000040000ULL;
00165 static const uint64_t kDTVSigMon_SDTMatch = 0x0000080000ULL;
00167 static const uint64_t kFWSigMon_PowerMatch = 0x0000100000ULL;
00169 static const uint64_t kDTVSigMon_CryptMatch = 0x0000200000ULL;
00170
00171 static const uint64_t kDTVSigMon_WaitForPAT = 0x0001000000ULL;
00172 static const uint64_t kDTVSigMon_WaitForPMT = 0x0002000000ULL;
00173 static const uint64_t kDTVSigMon_WaitForMGT = 0x0004000000ULL;
00174 static const uint64_t kDTVSigMon_WaitForVCT = 0x0008000000ULL;
00175 static const uint64_t kDTVSigMon_WaitForNIT = 0x0010000000ULL;
00176 static const uint64_t kDTVSigMon_WaitForSDT = 0x0020000000ULL;
00177 static const uint64_t kSigMon_WaitForSig = 0x0040000000ULL;
00178 static const uint64_t kFWSigMon_WaitForPower= 0x0080000000ULL;
00179 static const uint64_t kDTVSigMon_WaitForCrypt=0x0100000000ULL;
00180
00181 static const uint64_t kDTVSigMon_WaitForAll = 0x01FF000000ULL;
00182
00184 static const uint64_t kDVBSigMon_WaitForSNR = 0x1000000000ULL;
00186 static const uint64_t kDVBSigMon_WaitForBER = 0x2000000000ULL;
00188 static const uint64_t kDVBSigMon_WaitForUB = 0x4000000000ULL;
00190 static const uint64_t kDVBSigMon_WaitForPos = 0x8000000000ULL;
00191
00192 protected:
00193 ChannelBase *channel;
00194 TVRec *pParent;
00195 int capturecardnum;
00196 volatile uint64_t flags;
00197 int update_rate;
00198 uint minimum_update_rate;
00199 bool update_done;
00200 bool notify_frontend;
00201 bool tablemon;
00202 bool eit_scan;
00203 QString error;
00204
00205 SignalMonitorValue signalLock;
00206 SignalMonitorValue signalStrength;
00207 SignalMonitorValue scriptStatus;
00208
00209 vector<SignalMonitorListener*> listeners;
00210
00211 QMutex startStopLock;
00212 QWaitCondition startStopWait;
00213 volatile bool running;
00214 volatile bool exit;
00215
00216 mutable QMutex statusLock;
00217 mutable QMutex listenerLock;
00218 };
00219
00220 inline QString sm_flags_to_string(uint64_t flags)
00221 {
00222 QString str("Seen(");
00223 if (SignalMonitor::kDTVSigMon_PATSeen & flags)
00224 str += "PAT,";
00225 if (SignalMonitor::kDTVSigMon_PMTSeen & flags)
00226 str += "PMT,";
00227 if (SignalMonitor::kDTVSigMon_MGTSeen & flags)
00228 str += "MGT,";
00229 if (SignalMonitor::kDTVSigMon_VCTSeen & flags)
00230 str += "VCT,";
00231 if (SignalMonitor::kDTVSigMon_TVCTSeen & flags)
00232 str += "TVCT,";
00233 if (SignalMonitor::kDTVSigMon_CVCTSeen & flags)
00234 str += "CVCT,";
00235 if (SignalMonitor::kDTVSigMon_NITSeen & flags)
00236 str += "NIT,";
00237 if (SignalMonitor::kDTVSigMon_SDTSeen & flags)
00238 str += "SDT,";
00239 if (SignalMonitor::kFWSigMon_PowerSeen & flags)
00240 str += "STB,";
00241 if (SignalMonitor::kDTVSigMon_CryptSeen & flags)
00242 str += "Crypt,";
00243
00244 str += ") Match(";
00245 if (SignalMonitor::kDTVSigMon_PATMatch & flags)
00246 str += "PAT,";
00247 if (SignalMonitor::kDTVSigMon_PMTMatch & flags)
00248 str += "PMT,";
00249 if (SignalMonitor::kDTVSigMon_MGTMatch & flags)
00250 str += "MGT,";
00251 if (SignalMonitor::kDTVSigMon_VCTMatch & flags)
00252 str += "VCT,";
00253 if (SignalMonitor::kDTVSigMon_TVCTMatch & flags)
00254 str += "TVCT,";
00255 if (SignalMonitor::kDTVSigMon_CVCTMatch & flags)
00256 str += "CVCT,";
00257 if (SignalMonitor::kDTVSigMon_NITMatch & flags)
00258 str += "NIT,";
00259 if (SignalMonitor::kDTVSigMon_SDTMatch & flags)
00260 str += "SDT,";
00261 if (SignalMonitor::kFWSigMon_PowerMatch & flags)
00262 str += "STB,";
00263 if (SignalMonitor::kDTVSigMon_CryptMatch & flags)
00264 str += "Crypt,";
00265
00266 str += ") Wait(";
00267 if (SignalMonitor::kDTVSigMon_WaitForPAT & flags)
00268 str += "PAT,";
00269 if (SignalMonitor::kDTVSigMon_WaitForPMT & flags)
00270 str += "PMT,";
00271 if (SignalMonitor::kDTVSigMon_WaitForMGT & flags)
00272 str += "MGT,";
00273 if (SignalMonitor::kDTVSigMon_WaitForVCT & flags)
00274 str += "VCT,";
00275 if (SignalMonitor::kDTVSigMon_WaitForNIT & flags)
00276 str += "NIT,";
00277 if (SignalMonitor::kDTVSigMon_WaitForSDT & flags)
00278 str += "SDT,";
00279 if (SignalMonitor::kSigMon_WaitForSig & flags)
00280 str += "Sig,";
00281 if (SignalMonitor::kFWSigMon_WaitForPower& flags)
00282 str += "STB,";
00283 if (SignalMonitor::kDTVSigMon_WaitForCrypt & flags)
00284 str += "Crypt,";
00285
00286 if (SignalMonitor::kDVBSigMon_WaitForSNR & flags)
00287 str += "SNR,";
00288 if (SignalMonitor::kDVBSigMon_WaitForBER & flags)
00289 str += "BER,";
00290 if (SignalMonitor::kDVBSigMon_WaitForUB & flags)
00291 str += "UB,";
00292 if (SignalMonitor::kDVBSigMon_WaitForPos & flags)
00293 str += "Pos,";
00294
00295 str += ")";
00296 return str;
00297 }
00298
00299 inline bool SignalMonitor::IsRequired(const QString &cardtype)
00300 {
00301 return (cardtype != "IMPORT" && cardtype != "DEMO");
00302 }
00303
00304 inline bool SignalMonitor::IsSupported(const QString &cardtype)
00305 {
00306 return IsRequired(cardtype);
00307 }
00308
00309
00310 #endif // SIGNALMONITOR_H