MythTV  master
signalmonitorvalue.cpp
Go to the documentation of this file.
1 #include <algorithm>
2 using namespace std;
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  const QString& _noSpaceName,
37  int _threshold,
38  bool _high_threshold,
39  int _min, int _max,
40  int _timeout) :
41  m_name(_name),
42  m_noSpaceName(_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)")
52  .arg(m_name) .arg(m_noSpaceName) .arg(m_value) .arg(m_threshold)
53  .arg(m_minVal) .arg(m_maxVal) .arg(m_timeout) .arg(m_highThreshold)
54  .arg((m_set ? "true" : "false")));
55 #endif
56 }
57 
59  const QString& _noSpaceName,
60  int _value, int _threshold,
61  bool _high_threshold,
62  int _min, int _max,
63  int _timeout, bool _set) :
64  m_name(_name),
65  m_noSpaceName(_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)")
75  .arg(m_name) .arg(m_noSpaceName) .arg(m_value) .arg(m_threshold)
76  .arg(m_minVal) .arg(m_maxVal) .arg(m_timeout) .arg(m_highThreshold)
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  QStringList vals = longString.split(" ", QString::SkipEmptyParts);
118 
119  if (8 != vals.size() || "(null)" == vals[0])
120  return false;
121 
122  m_noSpaceName = vals[0];
123  SetRange(vals[3].toInt(), vals[4].toInt());
124  SetValue(vals[1].toInt());
125  SetThreshold(vals[2].toInt(), (bool) vals[6].toInt());
126  SetTimeout(vals[5].toInt());
127 
128  m_set = (bool) vals[7].toInt();
129  return true;
130 }
131 
133  const QString& _longString)
134 {
136  if (!smv->Set(_name, _longString))
137  {
138  delete smv;
139  return nullptr;
140  }
141  return smv;
142 }
143 
149 {
150  SignalMonitorValue smv;
151  SignalMonitorList monitor_list;
152  for (int i=0; i+1<slist.size(); i+=2)
153  {
154 #if DEBUG_SIGNAL_MONITOR_VALUE
155  LOG(VB_GENERAL, LOG_DEBUG,
156  "Parse(" + slist[i] + ", (" + slist[i+1] + "))");
157 #endif
158  if (smv.Set(slist[i], slist[i+1]))
159  monitor_list.push_back(smv);
160  else
161  {
162  LOG(VB_GENERAL, LOG_ERR,
163  QString("SignalMonitorValue::Parse(): Error, "
164  "unable to parse (%1, (%2))")
165  .arg(slist[i]).arg(slist[i+1]));
166  }
167  }
168  return monitor_list;
169 }
170 
176 {
177  bool good = true;
178  SignalMonitorList::const_iterator it = slist.begin();
179  for (; it != slist.end(); ++it)
180  good &= it->IsGood();
181 #if DEBUG_SIGNAL_MONITOR_VALUE
182  if (!good)
183  {
184  QString msg("AllGood failed on ");
185  it = slist.begin();
186  for (; it != slist.end(); ++it)
187  if (!it->IsGood())
188  {
189  msg += it->m_noSpaceName;
190  msg += QString("(%1%2%3) ")
191  .arg(it->GetValue())
192  .arg(it->m_highThreshold ? "<" : ">")
193  .arg(it->GetThreshold());
194  }
195  LOG(VB_GENERAL, LOG_DEBUG, msg);
196  }
197 #endif
198  return good;
199 }
200 
206 {
207  int wait = 0, minWait = 0;
208  SignalMonitorList::const_iterator it = slist.begin();
209  for (; it != slist.end(); ++it)
210  {
211  wait = max(wait, it->GetTimeout());
212  minWait = min(minWait, it->GetTimeout());
213  }
214  return (minWait<0) ? -1 : wait;
215 }
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
vector< SignalMonitorValue > SignalMonitorList
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().
#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
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)