CuteHMI - Services (CuteHMI.Services.2)
Service.hpp
1 #ifndef H_EXTENSIONS_CUTEHMI_SERVICES_2_INCLUDE_CUTEHMI_SERVICES_SERVICE_HPP
2 #define H_EXTENSIONS_CUTEHMI_SERVICES_2_INCLUDE_CUTEHMI_SERVICES_SERVICE_HPP
3 
4 #include "internal/common.hpp"
5 #include "internal/StateInterface.hpp"
6 #include "Serviceable.hpp"
7 
8 #include <QString>
9 #include <QVariant>
10 #include <QObject>
11 #include <QStateMachine>
12 #include <QTimer>
13 
14 namespace cutehmi {
15 namespace services {
16 
22 class CUTEHMI_SERVICES_API Service:
23  public QObject
24 {
25  Q_OBJECT
26 
27  friend class ServiceManager;
28 
29  public:
30  static constexpr int INITIAL_STOP_TIMEOUT = 30000;
31  static constexpr int INITIAL_START_TIMEOUT = 30000;
32  static constexpr int INITIAL_REPAIR_TIMEOUT = 30000;
33  static constexpr const char * INITIAL_NAME = "Unnamed Service";
34 
35  Q_PROPERTY(int stopTimeout READ stopTimeout WRITE setStopTimeout NOTIFY stopTimeoutChanged)
36  Q_PROPERTY(int startTimeout READ startTimeout WRITE setStartTimeout NOTIFY startTimeoutChanged)
37  Q_PROPERTY(int repairTimeout READ repairTimeout WRITE setRepairTimeout NOTIFY repairTimeoutChanged)
38  Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
39  Q_PROPERTY(QString status READ status NOTIFY statusChanged)
40  Q_PROPERTY(QVariant serviceable READ serviceable WRITE setServiceable NOTIFY serviceableChanged)
41 
42  Q_CLASSINFO("DefaultProperty", "serviceable")
43 
44  Service(QObject * parent = nullptr);
45 
46  ~Service() override;
47 
48  int stopTimeout() const;
49 
55  void setStopTimeout(int stopTimeout);
56 
57  int startTimeout() const;
58 
64  void setStartTimeout(int startTimeout);
65 
66  int repairTimeout() const;
67 
73  void setRepairTimeout(int repairTimeout);
74 
75  QString name() const;
76 
77  void setName(const QString & name);
78 
79  QString status() const;
80 
87  void setServiceable(QVariant serviceable);
88 
93  QVariant serviceable() const;
94 
95  public slots:
96  void start();
97 
98  void stop();
99 
100  signals:
101  void stopTimeoutChanged();
102 
103  void startTimeoutChanged();
104 
105  void repairTimeoutChanged();
106 
107  void nameChanged();
108 
109  void statusChanged();
110 
111  void serviceableChanged();
112 
113  void started();
114 
115  void stopped();
116 
117  void activated();
118 
119  protected:
120  internal::StateInterface * stateInterface();
121 
122  const internal::StateInterface * stateInterface() const;
123 
124  protected slots:
125  void activate();
126 
127  void setStatus(const QString & status);
128 
129  private:
130  static QString & DefaultStatus();
131 
132  void destroyStateMachine();
133 
134  void initializeStateMachine(Serviceable & serviceable);
135 
136  void addTransition(QState * source, QState * target, std::unique_ptr<QAbstractTransition>);
137 
138  void addStatuses(std::unique_ptr<Serviceable::ServiceStatuses> statuses);
139 
140  struct Members {
141  int stopTimeout = INITIAL_STOP_TIMEOUT;
142  int startTimeout = INITIAL_START_TIMEOUT;
143  int repairTimeout = INITIAL_REPAIR_TIMEOUT;
144  QString name = INITIAL_NAME;
145  QString status;
146  Serviceable * serviceable = nullptr;
147  QStateMachine * stateMachine = nullptr;
148  internal::StateInterface * stateInterface = nullptr;
149  QTimer timeoutTimer;
150  QState * lastNotifiableState = nullptr;
151  };
152 
153  MPtr<Members> m;
154 };
155 
156 }
157 }
158 
159 #endif
160 
161 //(c)C: Copyright © 2019-2020, Michał Policht <michal@policht.pl>. All rights reserved.
162 //(c)C: This file is a part of CuteHMI.
163 //(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.
164 //(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.
165 //(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
QStateMachine
cutehmi::services::Service
Service.
Definition: Service.hpp:22
cutehmi::services::internal::StateInterface
Definition: StateInterface.hpp:16
cutehmi::MPtr< Members >
QObject
cutehmi
QString
cutehmi::services::Serviceable
Serviceable interface.
Definition: Serviceable.hpp:29
QAbstractTransition
std
cutehmi::services::ServiceManager
Service manager.
Definition: ServiceManager.hpp:22
QVariant