CuteHMI - Data Acquisition (CuteHMI.DataAcquisition.0)
RecencyWriter.hpp
1 #ifndef H_EXTENSIONS_CUTEHMI_DATAACQUISITION_0_INCLUDE_CUTEHMI_DATAACQUISITION_RECENCYWRITER_HPP
2 #define H_EXTENSIONS_CUTEHMI_DATAACQUISITION_0_INCLUDE_CUTEHMI_DATAACQUISITION_RECENCYWRITER_HPP
3 
4 #include "internal/common.hpp"
5 #include "internal/RecencyCollective.hpp"
6 #include "AbstractWriter.hpp"
7 
8 #include <cutehmi/services/Serviceable.hpp>
9 
10 #include <QTimer>
11 
12 namespace cutehmi {
13 namespace dataacquisition {
14 
15 class CUTEHMI_DATAACQUISITION_API RecencyWriter:
16  public AbstractWriter
17 {
18  Q_OBJECT
19 
20  public:
21  static constexpr int INITIAL_INTERVAL = 1000;
22 
29  Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged)
30 
31  RecencyWriter(QObject * parent = nullptr);
32 
33  int interval() const;
34 
35  void setInterval(int interval);
36 
37  virtual std::unique_ptr<ServiceStatuses> configureStarting(QState * starting) override;
38 
39  virtual std::unique_ptr<ServiceStatuses> configureStarted(QState * active, const QState * idling, const QState * yielding) override;
40 
41  virtual std::unique_ptr<ServiceStatuses> configureStopping(QState * stopping) override;
42 
43  virtual std::unique_ptr<ServiceStatuses> configureBroken(QState * broken) override;
44 
45  virtual std::unique_ptr<ServiceStatuses> configureRepairing(QState * repairing) override;
46 
47  virtual std::unique_ptr<ServiceStatuses> configureEvacuating(QState * evacuating) override;
48 
49  virtual std::unique_ptr<QAbstractTransition> transitionToStarted() const override;
50 
51  virtual std::unique_ptr<QAbstractTransition> transitionToStopped() const override;
52 
53  virtual std::unique_ptr<QAbstractTransition> transitionToBroken() const override;
54 
55  virtual std::unique_ptr<QAbstractTransition> transitionToYielding() const override;
56 
57  virtual std::unique_ptr<QAbstractTransition> transitionToIdling() const override;
58 
59  signals:
60  void intervalChanged();
61 
62  CUTEHMI_PROTECTED_SIGNALS:
63  void updateTimerStarted();
64 
65  void updateTimerStopped();
66 
67  private slots:
68  void updateValues();
69 
70  void onSchemaChanged();
71 
72  void startUpdateTimer();
73 
74  void stopUpdateTimer();
75 
76  private:
77  std::unique_ptr<services::Serviceable::ServiceStatuses> configureStartingOrRepairing(QState * parent);
78 
79  struct Members
80  {
81  internal::RecencyCollective dbCollective;
82  QTimer updateTimer;
83  int interval;
84 
85  Members():
86  interval(INITIAL_INTERVAL)
87  {
88  }
89  };
90 
91  MPtr<Members> m;
92 };
93 
94 }
95 }
96 
97 #endif
98 
99 //(c)C: Copyright © 2020, Michał Policht <michal@policht.pl>. All rights reserved.
100 //(c)C: This file is a part of CuteHMI.
101 //(c)C: CuteHMI is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
102 //(c)C: CuteHMI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
103 //(c)C: You should have received a copy of the GNU Lesser General Public License along with CuteHMI. If not, see <https://www.gnu.org/licenses/>.
QTimer
QState
cutehmi::dataacquisition::internal::RecencyCollective
Definition: RecencyCollective.hpp:13
cutehmi::MPtr< Members >
QObject
cutehmi::dataacquisition::RecencyWriter
Definition: RecencyWriter.hpp:15
cutehmi
cutehmi::dataacquisition::AbstractWriter
Abstract database writer.
Definition: AbstractWriter.hpp:19
std::unique_ptr