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