MythTV master
signalmonitorvalue.h
Go to the documentation of this file.
1// -*- Mode: c++ -*-
2#ifndef SIGNALMONITORVALUES_H
3#define SIGNALMONITORVALUES_H
4
5#include <vector>
6
7// Qt headers
8#include <QStringList>
9#include <QCoreApplication>
10
12
14{
15 Q_DECLARE_TR_FUNCTIONS(SignalMonitorValue)
16
18 public:
19 SignalMonitorValue(QString _name, QString _noSpaceName,
20 int _threshold, bool _high_threshold,
21 int _min, int _max, std::chrono::milliseconds _timeout);
22 virtual ~SignalMonitorValue() { ; } /* forces class to have vtable */
23
24 // // // // // // // // // // // // // // // // // // // // // // // //
25 // Gets // // // // // // // // // // // // // // // // // // // // //
26
28 QString GetName(void) const;
30 QString GetShortName(void) const;
32 QString GetStatus() const
33 {
34 QString str = m_noSpaceName.isNull() ? "(null)" : m_noSpaceName;
35 return QString("%1 %2 %3 %4 %5 %6 %7 %8")
36 .arg(str).arg(m_value).arg(m_threshold).arg(m_minVal).arg(m_maxVal)
37 .arg(m_timeout.count()).arg((int)m_highThreshold).arg((int)m_set);
38 }
40 int GetValue() const { return m_value; }
42 int GetMin() const { return m_minVal; }
44 int GetMax() const { return m_maxVal; }
47 int GetThreshold() const { return m_threshold; }
50 bool IsHighThreshold() const { return m_highThreshold; }
52 std::chrono::milliseconds GetTimeout() const { return m_timeout; }
53
56 bool IsGood() const
57 {
59 }
63 int GetNormalizedValue(int newmin, int newmax) const
64 {
65 float rangeconv = ((float) (newmax - newmin)) / (GetMax() - GetMin());
66 int newval = (int) (((GetValue() - GetMin()) * rangeconv) + newmin);
67 return std::clamp(newval, newmin, newmax);
68 }
69
70
71 // // // // // // // // // // // // // // // // // // // // // // // //
72 // Sets // // // // // // // // // // // // // // // // // // // // //
73
74 void SetValue(int _value)
75 {
76 m_set = true;
78 }
79
80 void SetMin(int _min) { m_minVal = _min; }
81
82 void SetMax(int _max) { m_maxVal = _max; }
83
84 void SetThreshold(int _threshold) { m_threshold = _threshold; }
85
86 void SetThreshold(int _threshold, bool _high_threshold) {
87 m_threshold = _threshold;
88 m_highThreshold = _high_threshold;
89 }
90
93 void SetRange(int _min, int _max) {
94 m_minVal = _min;
95 m_maxVal = _max;
96 }
97
98 void SetTimeout(std::chrono::milliseconds _timeout) { m_timeout = _timeout; }
99
100 // // // // // // // // // // // // // // // // // // // // // // // //
101 // Static Methods // // // // // // // // // // // // // // // // // //
102
103 static void Init();
104 static SignalMonitorValue*
105 Create(const QString& _name, const QString& _longString);
106 static SignalMonitorList Parse(const QStringList& slist);
107 static bool AllGood(const SignalMonitorList& slist);
108 static std::chrono::milliseconds MaxWait(const SignalMonitorList& slist);
109
110
111 // // // // // // // // // // // // // // // // // // // // // // // //
112 // Constants // // // // // // // // // // // // // // // // // // //
113
114 static QStringList ERROR_NO_CHANNEL;
115 static QStringList ERROR_NO_LINK;
116 static QStringList SIGNAL_LOCK;
117 // variable for initializing constants after translator installed
118 static bool run_static_init;
119
120 QString toString() const
121 {
122 QString str = m_noSpaceName.isNull() ? "(null)" : m_noSpaceName;
123 return QString("Name(%1) Val(%2) thr(%3%4) range(%5,%6) "
124 "timeout(%7 ms) %8 set. %9 good.")
125 .arg(str).arg(m_value).arg( (m_highThreshold) ? ">=" : "<=" )
126 .arg(m_threshold).arg(m_minVal).arg(m_maxVal)
127 .arg(m_timeout.count())
128 .arg(m_set ? "is" : "is NOT",
129 IsGood() ? "Is" : "Is NOT" );
130 }
131 private:
133 SignalMonitorValue(QString _name, QString _noSpaceName,
134 int _value, int _threshold, bool _high_threshold,
135 int _min, int _max, std::chrono::milliseconds _timeout, bool _set);
136 bool Set(const QString& _name, const QString& _longString);
137
138 QString m_name;
140 int m_value {-1};
141 int m_threshold {-1};
142 int m_minVal {-1};
143 int m_maxVal {-1};
144 std::chrono::milliseconds m_timeout {-1ms};
145 bool m_highThreshold {true}; // false when we must be below threshold
146 bool m_set {false}; // false until value initially set
147};
148
149using SignalMonitorList = std::vector<SignalMonitorValue>;
150
151#endif // SIGNALMONITORVALUES_H
QString GetShortName(void) const
Returns a space free name of the value. Used by GetStatus().
void SetTimeout(std::chrono::milliseconds _timeout)
void SetThreshold(int _threshold)
static void Init()
Initializes the some static constants needed by SignalMonitorValue.
void SetRange(int _min, int _max)
Sets the minimum and maximum values.
std::chrono::milliseconds GetTimeout() const
Returns how long to wait for a good value in milliseconds.
static std::chrono::milliseconds MaxWait(const SignalMonitorList &slist)
Returns the maximum timeout value in the signal monitor list.
static SignalMonitorValue * Create(const QString &_name, const QString &_longString)
int GetThreshold() const
Returns the threshold at which the value is considered "good".
static bool AllGood(const SignalMonitorList &slist)
Returns true if all the values in the list return true on IsGood().
static QStringList SIGNAL_LOCK
int GetMin() const
Returns smallest value possible, used for signal monitor bars.
std::chrono::milliseconds m_timeout
bool IsHighThreshold() const
Returns true if values greater than the threshold are considered good, false otherwise.
int GetValue() const
Returns the value.
bool Set(const QString &_name, const QString &_longString)
int GetNormalizedValue(int newmin, int newmax) const
Returns the value normalized to the [newmin, newmax] range.
static QStringList ERROR_NO_LINK
int GetMax() const
Returns greatest value possible, used for signal monitor bars.
QString toString() const
void SetThreshold(int _threshold, bool _high_threshold)
std::vector< SignalMonitorValue > SignalMonitorList
void SetMax(int _max)
SignalMonitorValue()=default
bool IsGood() const
Returns true if the value is equal to the threshold, or on the right side of the threshold (depends o...
QString GetName(void) const
Returns the long name of this value.
static QStringList ERROR_NO_CHANNEL
void SetValue(int _value)
static SignalMonitorList Parse(const QStringList &slist)
Converts a list of strings to SignalMonitorValue classes.
void SetMin(int _min)
QString GetStatus() const
Returns a signal monitor value as one long string.
STL namespace.
static eu8 clamp(eu8 value, eu8 low, eu8 high)
Definition: pxsup2dast.c:206
std::vector< SignalMonitorValue > SignalMonitorList