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(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-2020, Michał Policht <michal@policht.pl>. All rights reserved.
128 //(c)C: This file is a part of CuteHMI.
129 //(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.
130 //(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.
131 //(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/>.
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