MythTV master
signalmonitorvalue.cpp
Go to the documentation of this file.
1#include <algorithm>
2#include <utility>
3
5
7
12
13#define DEBUG_SIGNAL_MONITOR_VALUE 1
14
21{
23 {
24 run_static_init = false;
25 ERROR_NO_CHANNEL<<"error"<<tr("Could not open tuner device");
26 ERROR_NO_LINK<<"error"<<tr("Bad connection to backend");
27
29 QCoreApplication::translate("(Common)", "Signal Lock"),
30 "slock", 0, true, 0, 1, 0ms);
31 slock.SetValue(1);
32 SIGNAL_LOCK<<slock.GetName()<<slock.GetStatus();
33 }
34}
35
37 QString _noSpaceName,
38 int _threshold,
39 bool _high_threshold,
40 int _min, int _max,
41 std::chrono::milliseconds _timeout) :
42 m_name(std::move(_name)),
43 m_noSpaceName(std::move(_noSpaceName)),
44 m_value(0),
45 m_threshold(_threshold),
46 m_minVal(_min), m_maxVal(_max), m_timeout(_timeout),
47 m_highThreshold(_high_threshold)
48{
49 Init();
50#if DEBUG_SIGNAL_MONITOR_VALUE
51 LOG(VB_GENERAL, LOG_DEBUG,
52 QString("SignalMonitorValue(%1, %2, %3, %4, %5, %6, %7, %8, %9)")
53 .arg(m_name, m_noSpaceName) .arg(m_value) .arg(m_threshold)
54 .arg(m_minVal) .arg(m_maxVal) .arg(m_timeout.count()) .arg(m_highThreshold)
55 .arg((m_set ? "true" : "false")));
56#endif
57}
58
60 QString _noSpaceName,
61 int _value, int _threshold,
62 bool _high_threshold,
63 int _min, int _max,
64 std::chrono::milliseconds _timeout,
65 bool _set) :
66 m_name(std::move(_name)),
67 m_noSpaceName(std::move(_noSpaceName)),
68 m_value(_value),
69 m_threshold(_threshold),
70 m_minVal(_min), m_maxVal(_max), m_timeout(_timeout),
71 m_highThreshold(_high_threshold), m_set(_set)
72{
73 Init();
74#if DEBUG_SIGNAL_MONITOR_VALUE
75 LOG(VB_GENERAL, LOG_DEBUG,
76 QString("SignalMonitorValue(%1, %2, %3, %4, %5, %6, %7, %8, %9)")
77 .arg(m_name, m_noSpaceName) .arg(m_value) .arg(m_threshold)
78 .arg(m_minVal) .arg(m_maxVal) .arg(m_timeout.count()) .arg(m_highThreshold)
79 .arg((m_set ? "true" : "false")));
80#endif
81}
82
83QString SignalMonitorValue::GetName(void) const
84{
85 if (m_name.isNull())
86 return {};
87
88 return m_name;
89}
90
92{
93 if (m_noSpaceName.isNull())
94 return {};
95
96 return m_noSpaceName;
97}
98
99bool SignalMonitorValue::Set(const QString& _name, const QString& _longString)
100{
101 m_name = _name;
102 const QString& longString = _longString;
103
104 if (m_name.isEmpty() || longString.isEmpty())
105 return false;
106
107 if (("message" == m_name) || ("error" == m_name))
108 {
109 SetRange(0, 1);
110 SetValue(0);
111 SetThreshold( ("message" == m_name) ? 0 : 1, true );
112 SetTimeout( ("message" == m_name) ? 0ms : -1ms );
114 m_name = longString;
115
116 return true;
117 }
118
119 QStringList vals = longString.split(" ", Qt::SkipEmptyParts);
120 if (8 != vals.size() || "(null)" == vals[0])
121 return false;
122
123 m_noSpaceName = vals[0];
124 SetRange(vals[3].toInt(), vals[4].toInt());
125 SetValue(vals[1].toInt());
126 SetThreshold(vals[2].toInt(), (bool) vals[6].toInt());
127 SetTimeout(std::chrono::milliseconds(vals[5].toInt()));
128
129 m_set = (bool) vals[7].toInt();
130 return true;
131}
132
134 const QString& _longString)
135{
136 auto *smv = new SignalMonitorValue();
137 if (!smv->Set(_name, _longString))
138 {
139 delete smv;
140 return nullptr;
141 }
142 return smv;
143}
144
150{
152 SignalMonitorList monitor_list;
153 for (int i=0; i+1<slist.size(); i+=2)
154 {
155#if DEBUG_SIGNAL_MONITOR_VALUE
156 LOG(VB_GENERAL, LOG_DEBUG,
157 "Parse(" + slist[i] + ", (" + slist[i+1] + "))");
158#endif
159 if (smv.Set(slist[i], slist[i+1]))
160 monitor_list.push_back(smv);
161 else
162 {
163 LOG(VB_GENERAL, LOG_ERR,
164 QString("SignalMonitorValue::Parse(): Error, "
165 "unable to parse (%1, (%2))")
166 .arg(slist[i], slist[i+1]));
167 }
168 }
169 return monitor_list;
170}
171
177{
178 auto isgood = [](const auto & smv){ return smv.IsGood(); };
179 bool good = std::all_of(slist.cbegin(), slist.cend(), isgood);
180#if DEBUG_SIGNAL_MONITOR_VALUE
181 if (!good)
182 {
183 QString msg("AllGood failed on ");
184 for (const auto & smv : slist)
185 {
186 if (!smv.IsGood())
187 {
188 msg += smv.m_noSpaceName;
189 msg += QString("(%1%2%3) ")
190 .arg(smv.GetValue())
191 .arg(smv.m_highThreshold ? "<" : ">")
192 .arg(smv.GetThreshold());
193 }
194 }
195 LOG(VB_GENERAL, LOG_DEBUG, msg);
196 }
197#endif
198 return good;
199}
200
205std::chrono::milliseconds SignalMonitorValue::MaxWait(const SignalMonitorList& slist)
206{
207 std::chrono::milliseconds wait = 0ms;
208 std::chrono::milliseconds minWait = 0s;
209 for (const auto & smv : slist)
210 {
211 wait = std::max(wait, smv.GetTimeout());
212 minWait = std::min(minWait, smv.GetTimeout());
213 }
214 return (minWait < 0ms) ? -1ms : wait;
215}
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.
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)
static bool AllGood(const SignalMonitorList &slist)
Returns true if all the values in the list return true on IsGood().
static QStringList SIGNAL_LOCK
std::chrono::milliseconds m_timeout
bool Set(const QString &_name, const QString &_longString)
static QStringList ERROR_NO_LINK
std::vector< SignalMonitorValue > SignalMonitorList
SignalMonitorValue()=default
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.
QString GetStatus() const
Returns a signal monitor value as one long string.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
STL namespace.
bool
Definition: pxsup2dast.c:31
static float * vals
Definition: tentacle3d.cpp:19