CuteHMI - Services (CuteHMI.Services.3)
AbstractService.hpp
1#ifndef H_EXTENSIONS_CUTEHMI_SERVICES_3_INCLUDE_CUTEHMI_SERVICES_ABSTRACTSERVICE_HPP
2#define H_EXTENSIONS_CUTEHMI_SERVICES_3_INCLUDE_CUTEHMI_SERVICES_ABSTRACTSERVICE_HPP
3
4#include "internal/common.hpp"
5#include "StateInterface.hpp"
6
7//<CuteHMI.Workarounds.Qt5Compatibility-1.workaround target="Qt" cause="Qt5">
8#include <cutehmi/workarounds/qt5compatibility/qsizetype.hpp>
9//</CuteHMI.Workarounds.Qt5Compatibility-1.workaround>
10
11
12//<CuteHMI.Workarounds.Qt5Compatibility-5.workaround target="Qt" cause="Qt5">
13
14#include <cutehmi/workarounds/qt5compatibility/cutehmiQt6MocInclude.hpp>
15
16namespace cutehmi {
17namespace services {
18
20
21}
22}
23
24CUTEHMI_QT6_MOC_INCLUDE("AbstractServiceController.hpp")
25
26//</CuteHMI.Workarounds.Qt5Compatibility-5.workaround>
27
28
29#include <QObject>
30#include <QString>
31#include <QStateMachine>
32#include <QTimer>
33#include <QQmlEngine>
34#include <QQmlListProperty>
35
36namespace cutehmi {
37namespace services {
38
47class CUTEHMI_SERVICES_API AbstractService:
48 public QObject
49{
50 Q_OBJECT
51 QML_NAMED_ELEMENT(AbstractService)
52 QML_UNCREATABLE("AbstractService is an abstract class")
53
54 public:
55 static constexpr int INITIAL_SHUTDOWN_TIMEOUT = 180000;
56
57 static constexpr int INITIAL_STOP_TIMEOUT = 30000;
58
59 static constexpr int INITIAL_START_TIMEOUT = 30000;
60
61 static constexpr int INITIAL_REPAIR_TIMEOUT = 30000;
62
63 static constexpr const char * INITIAL_NAME = "Unnamed Service";
64
65 Q_PROPERTY(int shutdownTimeout READ shutdownTimeout WRITE setShutdownTimeout NOTIFY shutdownTimeoutChanged)
66
67 Q_PROPERTY(int stopTimeout READ stopTimeout WRITE setStopTimeout NOTIFY stopTimeoutChanged)
68
69 Q_PROPERTY(int startTimeout READ startTimeout WRITE setStartTimeout NOTIFY startTimeoutChanged)
70
71 Q_PROPERTY(int repairTimeout READ repairTimeout WRITE setRepairTimeout NOTIFY repairTimeoutChanged)
72
73 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
74
75 Q_PROPERTY(QString status READ status NOTIFY statusChanged)
76
77 Q_PROPERTY(cutehmi::services::StateInterface * states READ states CONSTANT)
78
79 Q_PROPERTY(QQmlListProperty<cutehmi::services::AbstractServiceController> defaultControllers READ defaultControllerList CONSTANT)
80
81 //<CuteHMI.Services-6.workaround target="Qt5" cause="missing">
82 // Instead of:
83 // QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE
84 // Some workaround code in AbstractService::ControllerListAppend() is provided.
85 //</CuteHMI.Services-6.workaround>
86 Q_PROPERTY(QQmlListProperty<cutehmi::services::AbstractServiceController> controllers READ controllerList CONSTANT)
87
88 ~AbstractService() override;
89
90 int shutdownTimeout() const;
91
98 void setShutdownTimeout(int shutdownTimeout);
99
100 int stopTimeout() const;
101
107 void setStopTimeout(int stopTimeout);
108
109 int startTimeout() const;
110
116 void setStartTimeout(int startTimeout);
117
118 int repairTimeout() const;
119
125 void setRepairTimeout(int repairTimeout);
126
127 QString name() const;
128
129 void setName(const QString & name);
130
131 QString status() const;
132
138 cutehmi::services::StateInterface * states() const;
139
141
143
144 Q_INVOKABLE void appendController(cutehmi::services::AbstractServiceController * controller);
145
146 Q_INVOKABLE void clearControllers();
147
148 public slots:
149 void start();
150
151 void stop();
152
153 void activate();
154
155 signals:
157
159
161
163
165
167
168 void started();
169
170 void stopped();
171
172 void activated();
173
179
180 protected:
182
191 AbstractService(StateInterface * stateInterface, const QString & status, QObject * parent = nullptr, const ControllersContainer * defaultControllers = & DefaultControllers());
192
193 static const ControllersContainer & DefaultControllers();
194
195 const ControllersContainer & controllers() const;
196
198
199 protected slots:
200 void setStatus(const QString & status);
201
202 private:
203 //<CuteHMI.Workarounds.Qt5Compatibility-1.workaround target="Qt" cause="Qt5">
204 static workarounds::qt5compatibility::sizeType ControllerListCount(QQmlListProperty<AbstractServiceController> * property);
205
206 static AbstractServiceController * ControllerListAt(QQmlListProperty<AbstractServiceController> * property, workarounds::qt5compatibility::sizeType index);
207 //</CuteHMI.DataAcquisition-2.workaround target="Qt" cause="Qt5">
208
209 static void ControllerListClear(QQmlListProperty<AbstractServiceController> * property);
210
211 static void ControllerListAppend(QQmlListProperty<AbstractServiceController> * property, AbstractServiceController * value);
212
213 //<CuteHMI.Workarounds.Qt5Compatibility-1.workaround target="Qt" cause="Qt5">
214 static workarounds::qt5compatibility::sizeType DefaultControllerListCount(QQmlListProperty<AbstractServiceController> * property);
215
216 static AbstractServiceController * DefaultControllerListAt(QQmlListProperty<AbstractServiceController> * property, workarounds::qt5compatibility::sizeType index);
217 //</CuteHMI.DataAcquisition-2.workaround target="Qt" cause="Qt5">
218
219 const ControllersContainer * defaultControllerListData() const;
220
221 struct Members {
222 int stopTimeout = INITIAL_STOP_TIMEOUT;
223 int startTimeout = INITIAL_START_TIMEOUT;
224 int repairTimeout = INITIAL_REPAIR_TIMEOUT;
225 int shutdownTimeout = INITIAL_SHUTDOWN_TIMEOUT;
226 QString name = INITIAL_NAME;
227 QString status;
228 StateInterface * stateInterface;
229 ControllersContainer controllers;
232
233 Members(AbstractService * p_parent, StateInterface * p_stateInterface, const QString & p_status, const ControllersContainer * p_defaultControllers):
234 status(p_status),
235 stateInterface(p_stateInterface),
236 controllerList(p_parent, & controllers, & AbstractService::ControllerListAppend, & AbstractService::ControllerListCount, & AbstractService::ControllerListAt, & AbstractService::ControllerListClear),
237 defaultControllerList(p_parent, const_cast<ControllersContainer *>(p_defaultControllers), & AbstractService::DefaultControllerListCount, & AbstractService::DefaultControllerListAt)
238 {
239 }
240 };
241
243};
244
245}
246}
247
248#endif
249
250//(c)C: Copyright © 2022-2023, Michał Policht <michal@policht.pl>. All rights reserved.
251//(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
252//(c)C: This file is a part of CuteHMI.
253//(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.
254//(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.
255//(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/>.
256//(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
257//(c)C: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
258//(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
259//(c)C: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Abstract service controller.
Definition: AbstractServiceController.hpp:38
Abstract service.
Definition: AbstractService.hpp:49
void initialized()
This signal is emitted, when service has performed all the initialization tasks and it is ready to be...
ControllersContainer & controllers()
QList< AbstractServiceController * > ControllersContainer
Definition: AbstractService.hpp:181
State interface.
Definition: StateInterface.hpp:30