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