CuteHMI - Services (CuteHMI.Services.3)
ServiceGroup.hpp
1#ifndef H_EXTENSIONS_CUTEHMI_SERVICES_3_INCLUDE_CUTEHMI_SERVICES_SERVICEGROUP_HPP
2#define H_EXTENSIONS_CUTEHMI_SERVICES_3_INCLUDE_CUTEHMI_SERVICES_SERVICEGROUP_HPP
3
4#include "internal/common.hpp"
5
6#include "Service.hpp"
7#include "Serviceable.hpp"
8#include "ServiceGroupRule.hpp"
9
10//<CuteHMI.Workarounds.Qt5Compatibility-1.workaround target="Qt" cause="Qt5">
11#include <cutehmi/workarounds/qt5compatibility/qsizetype.hpp>
12//</CuteHMI.Workarounds.Qt5Compatibility-1.workaround>
13
14#include <QQmlEngine>
15#include <QQmlListProperty>
16
17namespace cutehmi {
18namespace services {
19
33class CUTEHMI_SERVICES_API ServiceGroup:
35 public QQmlParserStatus,
36 public Serviceable
37{
38 Q_OBJECT
39 QML_NAMED_ELEMENT(ServiceGroup)
40 Q_INTERFACES(QQmlParserStatus)
41
42 public:
43 enum EventType {
44 CONDITION_CHECK_EVENT = QEvent::User + 1,
45 SUBCLASS_EVENT
46 };
47
48 Q_PROPERTY(int startedCount READ startedCount NOTIFY startedCountChanged)
49
50 Q_PROPERTY(int startingCount READ startingCount NOTIFY startingCountChanged)
51
52 Q_PROPERTY(int stoppingCount READ stoppingCount NOTIFY stoppingCountChanged)
53
54 Q_PROPERTY(int stoppedCount READ stoppedCount NOTIFY stoppedCountChanged)
55
56 Q_PROPERTY(int brokenCount READ brokenCount NOTIFY brokenCountChanged)
57
58 Q_PROPERTY(int repairingCount READ repairingCount NOTIFY repairingCountChanged)
59
60 Q_PROPERTY(int evacuatingCount READ evacuatingCount NOTIFY evacuatingCountChanged)
61
62 Q_PROPERTY(int interruptedCount READ interruptedCount NOTIFY interruptedCountChanged)
63
64 Q_PROPERTY(int activeCount READ activeCount NOTIFY activeCountChanged)
65
66 Q_PROPERTY(int yieldingCount READ yieldingCount NOTIFY yieldingCountChanged)
67
68 Q_PROPERTY(int idlingCount READ idlingCount NOTIFY idlingCountChanged)
69
70 Q_PROPERTY(QQmlListProperty<cutehmi::services::ServiceGroupRule> rules READ ruleList CONSTANT)
71
72 Q_PROPERTY(QQmlListProperty<cutehmi::services::AbstractService> services READ serviceList CONSTANT)
73 Q_CLASSINFO("DefaultProperty", "services")
74
75 static void PostConditionCheckEvent(QStateMachine * stateMachine);
76
77 explicit ServiceGroup(QObject * parent = nullptr);
78
79 ~ServiceGroup() override;
80
81 int startedCount() const;
82
83 int startingCount() const;
84
85 int stoppingCount() const;
86
87 int stoppedCount() const;
88
89 int brokenCount() const;
90
91 int repairingCount() const;
92
93 int evacuatingCount() const;
94
95 int interruptedCount() const;
96
97 int activeCount() const;
98
99 int yieldingCount() const;
100
101 int idlingCount() const;
102
103 QQmlListProperty<cutehmi::services::ServiceGroupRule> ruleList();
104
105 Q_INVOKABLE void appendRule(cutehmi::services::ServiceGroupRule * rule);
106
107 Q_INVOKABLE void clearRules();
108
109 QQmlListProperty<cutehmi::services::AbstractService> serviceList();
110
111 Q_INVOKABLE void appendService(cutehmi::services::AbstractService * service);
112
113 Q_INVOKABLE void clearServices();
114
115 void configureStarting(QState * starting, AssignStatusFunction assignStatus) override;
116
117 void configureStarted(QState * active, const QState * idling, const QState * yielding, AssignStatusFunction assignStatus) override;
118
119 void configureStopping(QState * stopping, AssignStatusFunction assignStatus) override;
120
121 void configureBroken(QState * broken, AssignStatusFunction assignStatus) override;
122
123 void configureRepairing(QState * repairing, AssignStatusFunction assignStatus) override;
124
125 void configureEvacuating(QState * evacuating, AssignStatusFunction assignStatus) override;
126
127 std::unique_ptr<QAbstractTransition> transitionToStarted() const override;
128
129 std::unique_ptr<QAbstractTransition> transitionToStopped() const override;
130
131 std::unique_ptr<QAbstractTransition> transitionToBroken() const override;
132
133 std::unique_ptr<QAbstractTransition> transitionToYielding() const override;
134
135 std::unique_ptr<QAbstractTransition> transitionToIdling() const override;
136
137 void classBegin() override;
138
139 void componentComplete() override;
140
141 public slots:
142 void postConditionCheckEvent() const;
143
144 signals:
145 void startedCountChanged();
146
147 void startingCountChanged();
148
149 void stoppingCountChanged();
150
151 void stoppedCountChanged();
152
153 void brokenCountChanged();
154
155 void repairingCountChanged();
156
157 void evacuatingCountChanged();
158
159 void interruptedCountChanged();
160
161 void activeCountChanged();
162
163 void yieldingCountChanged();
164
165 void idlingCountChanged();
166
167 protected:
169
171
172 static const ControllersContainer & DefaultControllers();
173
174 void setStartedCount(int count);
175
176 void setStartingCount(int count);
177
178 void setStoppingCount(int count);
179
180 void setStoppedCount(int count);
181
182 void setBrokenCount(int count);
183
184 void setRepairingCount(int count);
185
186 void setEvacuatingCount(int count);
187
188 void setInterruptedCount(int count);
189
190 void setActiveCount(int count);
191
192 void setYieldingCount(int count);
193
194 void setIdlingCount(int count);
195
196 const RulesContainer & rules() const;
197
198 RulesContainer & rules();
199
200 const ServicesContainer & services() const;
201
202 ServicesContainer & services();
203
204 Q_SIGNAL void groupBroken();
205
206 Q_SIGNAL void groupStarted();
207
208 Q_SIGNAL void groupStopped();
209
210 protected slots:
211 void handleCounters();
212
213 private:
214 struct ConnectionData {
220 QMetaObject::Connection repairing;
221 QMetaObject::Connection evacuating;
222 QMetaObject::Connection interrupted;
226 };
227
228 typedef QHash<AbstractService *, ConnectionData *> ServiceConnectionsContainer;
229
230 static QString & DefaultStatus();
231
232 //<CuteHMI.Workarounds.Qt5Compatibility-1.workaround target="Qt" cause="Qt5">
233 static workarounds::qt5compatibility::sizeType RuleListCount(QQmlListProperty<ServiceGroupRule> * property);
234
235 static ServiceGroupRule * RuleListAt(QQmlListProperty<ServiceGroupRule> * property, workarounds::qt5compatibility::sizeType index);
236 //</CuteHMI.DataAcquisition-2.workaround target="Qt" cause="Qt5">
237
238 static void RuleListClear(QQmlListProperty<ServiceGroupRule> * property);
239
240 static void RuleListAppend(QQmlListProperty<ServiceGroupRule> * property, ServiceGroupRule * value);
241
242 //<CuteHMI.Workarounds.Qt5Compatibility-1.workaround target="Qt" cause="Qt5">
243 static workarounds::qt5compatibility::sizeType ServiceListCount(QQmlListProperty<AbstractService> * property);
244
245 static AbstractService * ServiceListAt(QQmlListProperty<AbstractService> * property, workarounds::qt5compatibility::sizeType index);
246 //</CuteHMI.DataAcquisition-2.workaround target="Qt" cause="Qt5">
247
248 static void ServiceListClear(QQmlListProperty<AbstractService> * property);
249
250 static void ServiceListAppend(QQmlListProperty<AbstractService> * property, AbstractService * value);
251
252 static void ConnectStateCounters(ConnectionData & connectionData, ServiceGroup * serviceGroup, AbstractService * service);
253
254 static ConnectionData * CreateConnectionDataEntry(ServiceConnectionsContainer & serviceConnections, AbstractService * service);
255
256 static void DeleteConnectionDataEntry(ServiceConnectionsContainer & serviceConnections, AbstractService * service);
257
258 internal::ServiceStateInterface * stateInterface() const;
259
260 void configureStateInterface();
261
262 void configureStoppingOrEvacuating(QState * state, AssignStatusFunction assignStatus);
263
264 void configureStartingOrRepairing(QState * state, AssignStatusFunction assignStatus);
265
266 struct Members {
267 RulesContainer rules;
269 ServicesContainer services;
271 ServiceConnectionsContainer serviceConnections;
272 int stoppedCount;
273 int startingCount;
274 int startedCount;
275 int stoppingCount;
276 int brokenCount;
277 int repairingCount;
278 int evacuatingCount;
279 int interruptedCount;
280 int yieldingCount;
281 int activeCount;
282 int idlingCount;
283 bool qmlBeingParsed;
284
285 Members(ServiceGroup * p_parent):
286 ruleList(p_parent, & rules, & ServiceGroup::RuleListAppend, & ServiceGroup::RuleListCount, & ServiceGroup::RuleListAt, & ServiceGroup::RuleListClear),
287 serviceList(p_parent, & services, & ServiceGroup::ServiceListAppend, & ServiceGroup::ServiceListCount, & ServiceGroup::ServiceListAt, & ServiceGroup::ServiceListClear),
288 stoppedCount(0),
289 startingCount(0),
290 startedCount(0),
291 stoppingCount(0),
292 brokenCount(0),
293 repairingCount(0),
294 evacuatingCount(0),
295 interruptedCount(0),
296 yieldingCount(0),
297 activeCount(0),
298 idlingCount(0),
299 qmlBeingParsed(false)
300 {
301 }
302 };
303
304 MPtr<Members> m;
305};
306
307}
308}
309
310#endif
311
312//(c)C: Copyright © 2022, Michał Policht <michal@policht.pl>. All rights reserved.
313//(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
314//(c)C: This file is a part of CuteHMI.
315//(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.
316//(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.
317//(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/>.
318//(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
319//(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:
320//(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
321//(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.
Definition: AbstractService.hpp:49
Service group.
Definition: ServiceGroup.hpp:37
EventType
Definition: ServiceGroup.hpp:43
Service group rule.
Definition: ServiceGroupRule.hpp:26
Serviceable interface.
Definition: Serviceable.hpp:33
Definition: ServiceStateInterface.hpp:24