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