00001
00002 #ifndef SIGNALMONITORVALUES_H
00003 #define SIGNALMONITORVALUES_H
00004
00005 #include <vector>
00006 using namespace std;
00007
00008 #include <QStringList>
00009
00010 #include "mythcontext.h"
00011
00012 class SignalMonitorValue
00013 {
00014 typedef vector<SignalMonitorValue> SignalMonitorList;
00015 public:
00016 SignalMonitorValue(const QString& _name, const QString& _noSpaceName,
00017 int _threshold, bool _high_threshold,
00018 int _min, int _max, int _timeout);
00019 virtual ~SignalMonitorValue() { ; }
00020
00021
00022
00023
00025 QString GetName(void) const;
00027 QString GetShortName(void) const;
00029 QString GetStatus() const
00030 {
00031 QString str = (QString::null == noSpaceName) ? "(null)" : noSpaceName;
00032 return QString("%1 %2 %3 %4 %5 %6 %7 %8")
00033 .arg(str).arg(value).arg(threshold).arg(minval).arg(maxval)
00034 .arg(timeout).arg((int)high_threshold).arg((int)set);
00035 }
00037 int GetValue() const { return value; }
00039 int GetMin() const { return minval; }
00041 int GetMax() const { return maxval; }
00044 int GetThreshold() const { return threshold; }
00047 bool IsHighThreshold() const { return high_threshold; }
00049 int GetTimeout() const { return timeout; }
00050
00053 bool IsGood() const
00054 {
00055 return (high_threshold) ? value >= threshold : value <= threshold;
00056 }
00060 int GetNormalizedValue(int newmin, int newmax) const
00061 {
00062 float rangeconv = ((float) (newmax - newmin)) / (GetMax() - GetMin());
00063 int newval = (int) (((GetValue() - GetMin()) * rangeconv) + newmin);
00064 return max( min(newval, newmax), newmin );
00065 }
00066
00067
00068
00069
00070
00071 void SetValue(int _value)
00072 {
00073 set = true;
00074 value = min(max(_value,minval),maxval);
00075 }
00076
00077 void SetMin(int _min) { minval = _min; }
00078
00079 void SetMax(int _max) { maxval = _max; }
00080
00081 void SetThreshold(int _threshold) { threshold = _threshold; }
00082
00083 void SetThreshold(int _threshold, bool _high_threshold) {
00084 threshold = _threshold;
00085 high_threshold = _high_threshold;
00086 }
00087
00090 void SetRange(int _min, int _max) {
00091 minval = _min;
00092 maxval = _max;
00093 }
00094
00095 void SetTimeout(int _timeout) { timeout = _timeout; }
00096
00097
00098
00099
00100 static void Init();
00101 static SignalMonitorValue*
00102 Create(const QString& _name, const QString& _longString);
00103 static SignalMonitorList Parse(const QStringList& list);
00104 static bool AllGood(const SignalMonitorList& slist);
00105 static int MaxWait(const SignalMonitorList& slist);
00106
00107
00108
00109
00110
00111 static QStringList ERROR_NO_CHANNEL;
00112 static QStringList ERROR_NO_LINK;
00113 static QStringList SIGNAL_LOCK;
00114
00115 static bool run_static_init;
00116
00117 QString toString() const
00118 {
00119 QString str = (QString::null == noSpaceName) ? "(null)" : noSpaceName;
00120 return QString("Name(%1) Val(%2) thr(%3%4) range(%5,%6) "
00121 "timeout(%7 ms) %8 set. %9 good.")
00122 .arg(str).arg(value).arg( (high_threshold) ? ">=" : "<=" )
00123 .arg(threshold).arg(minval).arg(maxval)
00124 .arg(timeout).arg( (set) ? "is" : "is NOT" )
00125 .arg( (IsGood()) ? "Is" : "Is NOT" );
00126 }
00127 private:
00128 SignalMonitorValue() :
00129 value(-1), threshold(-1), minval(-1), maxval(-1), timeout(-1),
00130 high_threshold(true), set(false) { }
00131 SignalMonitorValue(const QString& _name, const QString& _noSpaceName,
00132 int _value, int _threshold, bool _high_threshold,
00133 int _min, int _max, int _timeout, bool _set);
00134 bool Set(const QString& _name, const QString& _longString);
00135
00136 QString name;
00137 QString noSpaceName;
00138 int value;
00139 int threshold;
00140 int minval;
00141 int maxval;
00142 int timeout;
00143 bool high_threshold;
00144 bool set;
00145 };
00146
00147 typedef vector<SignalMonitorValue> SignalMonitorList;
00148
00149 #endif // SIGNALMONITORVALUES_H