CuteHMI - Services (CuteHMI.Services.2)
ServiceManager.hpp
1 #ifndef H_EXTENSIONS_CUTEHMI_SERVICES_2_INCLUDE_CUTEHMI_SERVICES_SERVICEMANAGER_HPP
2 #define H_EXTENSIONS_CUTEHMI_SERVICES_2_INCLUDE_CUTEHMI_SERVICES_SERVICEMANAGER_HPP
3 
4 #include "internal/common.hpp"
5 #include "ServiceListModel.hpp"
6 
7 #include <cutehmi/Singleton.hpp>
8 
9 #include <QQueue>
10 #include <QMultiHash>
11 
12 namespace cutehmi {
13 namespace services {
14 
22 class CUTEHMI_SERVICES_API ServiceManager:
23  public QObject,
24  public Singleton<ServiceManager>
25 {
26  Q_OBJECT
27 
28  friend class Singleton<ServiceManager>;
29  friend class Service;
30 
31  public:
32  static constexpr int INITIAL_MAX_ACTIVE_SERVICES = 1;
33  static constexpr int INITIAL_REPAIR_INTERVAL = 10000;
34 
38  Q_PROPERTY(int maxActiveServices READ maxActiveServices WRITE setMaxActiveServices NOTIFY maxActiveServicesChanged)
39 
40 
43  Q_PROPERTY(int repairInterval READ repairInterval WRITE setRepairInterval NOTIFY repairIntervalChanged)
44 
48  Q_PROPERTY(int runningCount READ runningCount NOTIFY runningCountChanged)
49 
53  Q_PROPERTY(cutehmi::services::ServiceListModel * model READ model CONSTANT)
54 
55  int maxActiveServices() const;
56 
57  void setMaxActiveServices(int maxActiveServices);
58 
59  int repairInterval() const;
60 
61  void setRepairInterval(int repairInterval);
62 
63  int runningCount() const;
64 
65  ServiceListModel * model() const;
66 
67  public slots:
71  void start();
72 
76  void stop();
77 
78  signals:
79  void maxActiveServicesChanged();
80 
81  void repairIntervalChanged();
82 
83  void runningCountChanged();
84 
85  protected:
86  explicit ServiceManager(QObject * parent = nullptr);
87 
88  void add(Service * service);
89 
90  void remove(Service * service);
91 
92  void manage(Service * service);
93 
94  void leave(Service * service);
95 
96  private:
98  typedef QMultiHash<const internal::StateInterface *, QMetaObject::Connection> StateInterfaceConnectionsContainer;
99 
100  struct Members {
101  int activeServices;
102  int runningCount;
103  int maxActiveServices;
104  int repairInterval;
106  YieldingServicesContainer yieldingServices;
107  StateInterfaceConnectionsContainer stateInterfaceConnections; // The only way to disconnect particular lambda from particular emitter is to store its connection.
108 
109  Members():
110  activeServices(0),
111  runningCount(0),
112  maxActiveServices(INITIAL_MAX_ACTIVE_SERVICES),
113  repairInterval(INITIAL_REPAIR_INTERVAL),
114  model(new ServiceListModel)
115  {
116  }
117  };
118 
119  MPtr<Members> m;
120 };
121 
122 }
123 }
124 
125 #endif
126 
127 //(c)C: Copyright © 2019-2021, Michał Policht <michal@policht.pl>. All rights reserved.
128 //(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
129 //(c)C: This file is a part of CuteHMI.
130 //(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.
131 //(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.
132 //(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/>.
133 //(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
134 //(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:
135 //(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
136 //(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.
QMultiHash
cutehmi::services::Service
Service.
Definition: Service.hpp:22
cutehmi::MPtr< Members >
QObject
cutehmi
QQueue
cutehmi::services::ServiceManager
Service manager.
Definition: ServiceManager.hpp:22
QMetaObject
std::unique_ptr
cutehmi::services::ServiceListModel
Notification list model.
Definition: ServiceListModel.hpp:15
cutehmi::Singleton