Torc  0.1
torcsysteminput.cpp
Go to the documentation of this file.
1 /* Class TorcSystemInput
2 *
3 * This file is part of the Torc project.
4 *
5 * Copyright (C) Mark Kendall 2018
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 * USA.
21 */
22 
23 // Torc
24 
25 #include "torclocalcontext.h"
26 #include "torcsysteminput.h"
27 
38 TorcSystemInput::TorcSystemInput(double Value, const QVariantMap &Details)
39  : TorcInput(TorcInput::Started, Value, 0, 1, QStringLiteral("SystemStarted"), Details),
40  m_shutdownDelay(0)
41 {
43  SetValid(true);
44 
45  if (Details.contains(QStringLiteral("delay")))
46  {
47  bool ok = false;
48  uint delay = Details.value(QStringLiteral("delay")).toInt(&ok);
49  if (ok && (delay > 0))
50  {
52  m_shutdownDelay = delay;
53  }
54  else
55  {
56  LOG(VB_GENERAL, LOG_WARNING, QStringLiteral("Failed to parse meaningful value for delay (>0)"));
57  }
58  }
59 }
60 
62 {
64 }
65 
67 {
68  return TorcInput::Started;
69 }
70 
72 {
73  return QStringList() << tr("System started") << tr("Shutdown delay %1").arg(m_shutdownDelay);
74 }
75 
76 bool TorcSystemInput::event(QEvent *Event)
77 {
78  if (Event && (Event->type() == TorcEvent::TorcEventType))
79  {
80  TorcEvent* torcevent = dynamic_cast<TorcEvent*>(Event);
81  if (torcevent)
82  {
83  switch (torcevent->GetEvent())
84  {
85  case Torc::Stop:
86  case Torc::TorcWillStop:
87  SetValue(0.0);
88  break;
89  case Torc::Start:
90  SetValue(1.0);
91  break;
92  default: break;
93  }
94  }
95  }
96 
97  return TorcInput::event(Event);
98 }
TorcInput::Type GetType(void) override
TorcLocalContext * gLocalContext
QStringList GetDescription(void) override
int GetEvent(void)
Return the Torc action associated with this event.
Definition: torcevent.cpp:65
void SetValid(bool Valid) final
Definition: torcinput.cpp:143
void SetValue(double Value) override
Update the inputs value.
Definition: torcinput.cpp:90
static Type TorcEventType
Register TorcEventType with QEvent.
Definition: torcevent.h:19
A general purpose event object.
Definition: torcevent.h:9
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: torclogging.h:20
void AddObserver(QObject *Observer)
brief Register the given object to receive events.
TorcSystemInput(double Value, const QVariantMap &Details)
void SetShutdownDelay(uint Delay)
void RemoveObserver(QObject *Observer)
brief Deregister the given object.
bool event(QEvent *Event) override