Torc  0.1
torccontrol.h
Go to the documentation of this file.
1 #ifndef TORCCONTROL_H
2 #define TORCCONTROL_H
3 
4 // Qt
5 #include <QMap>
6 #include <QObject>
7 #include <QStringList>
8 
9 // Torc
10 #include "torchttpservice.h"
11 #include "torcdevice.h"
12 
13 #define CONTROLS_DIRECTORY QStringLiteral("controls")
14 
15 class TorcControl : public TorcDevice, public TorcHTTPService
16 {
17  friend class TorcControls;
18 
19  Q_OBJECT
20  Q_CLASSINFO("Version", "1.0.0")
21 
22  public:
23  enum Type
24  {
28  };
29 
30  Q_ENUM(Type)
31 
32  static bool ParseTimeString (const QString &Time, int &Days, int &Hours,
33  int &Minutes, int &Seconds, quint64 &DurationInSeconds);
34  static QString DurationToString (int Days, quint64 Duration);
35 
36  protected:
37  TorcControl(TorcControl::Type Type, const QVariantMap &Details);
38  virtual ~TorcControl() = default;
39 
40  public:
41  virtual bool Validate (void);
42  virtual TorcControl::Type GetType (void) const = 0;
43  virtual bool IsPassthrough (void);
44  virtual bool AllowInputs (void) const;
45  bool IsKnownInput (const QString &Input) const;
46  bool IsKnownOutput (const QString &Output) const;
47  QString GetUIName (void) override;
48 
49  public slots:
50  // TorcHTTPService
51  void SubscriberDeleted (QObject *Subscriber);
52 
53  void InputValueChanged (double Value);
54  void InputValidChanged (bool Valid);
55 
56  protected:
57  void Graph (QByteArray* Data);
58  bool Finish (void);
59  void InputValidChangedPriv (QObject* Input, bool Valid);
60  void CheckInputValues (void);
61  void SetValue (double Value) override;
62  void SetValid (bool Valid) override;
63  virtual void CalculateOutput (void) = 0;
64  bool CheckForCircularReferences (const QString &UniqueId, const QString &Path) const;
65 
66  protected:
67  bool m_parsed;
69  QStringList m_inputList;
70  QStringList m_outputList;
71  QMap<QObject*,QString> m_inputs;
72  QMap<QObject*,QString> m_outputs;
73  QMap<QObject*,double> m_inputValues;
74  QMap<QObject*,double> m_lastInputValues;
75  QMap<QObject*,bool> m_inputValids;
77 };
78 
79 #endif // TORCCONTROL_H
static bool ParseTimeString(const QString &Time, int &Days, int &Hours, int &Minutes, int &Seconds, quint64 &DurationInSeconds)
Parse a Torc time string into days, hours, minutes and, if present, seconds.
Definition: torccontrol.cpp:36
bool IsKnownInput(const QString &Input) const
virtual bool Validate(void)
void InputValidChangedPriv(QObject *Input, bool Valid)
void InputValidChanged(bool Valid)
QMap< QObject *, QString > m_inputs
Definition: torccontrol.h:71
bool m_validated
Definition: torccontrol.h:68
virtual TorcControl::Type GetType(void) const =0
virtual void CalculateOutput(void)=0
QMap< QObject *, double > m_inputValues
Definition: torccontrol.h:73
bool m_allInputsValid
Definition: torccontrol.h:76
void InputValueChanged(double Value)
virtual bool AllowInputs(void) const
Most controls have an input side.
void SubscriberDeleted(QObject *Subscriber)
QMap< QObject *, double > m_lastInputValues
Definition: torccontrol.h:74
bool m_parsed
Definition: torccontrol.h:67
void SetValid(bool Valid) override
void SetValue(double Value) override
QStringList m_inputList
Definition: torccontrol.h:69
static QString DurationToString(int Days, quint64 Duration)
bool IsKnownOutput(const QString &Output) const
virtual bool IsPassthrough(void)
Only certain logic controls can be passthrough.
void Graph(QByteArray *Data)
Add this control to the state graph.
void CheckInputValues(void)
QString GetUIName(void) override
bool Finish(void)
Finish setup of the control.
bool CheckForCircularReferences(const QString &UniqueId, const QString &Path) const
QMap< QObject *, bool > m_inputValids
Definition: torccontrol.h:75
QStringList m_outputList
Definition: torccontrol.h:70
QMap< QObject *, QString > m_outputs
Definition: torccontrol.h:72