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 runningServices READ runningServices NOTIFY runningServicesChanged)
49 
50  int maxActiveServices() const;
51 
52  void setMaxActiveServices(int maxActiveServices);
53 
54  int repairInterval() const;
55 
56  void setRepairInterval(int repairInterval);
57 
58  int runningServices() const;
59 
60  public slots:
64  void start();
65 
69  void stop();
70 
71  signals:
72  void maxActiveServicesChanged();
73 
74  void repairIntervalChanged();
75 
76  void runningServicesChanged();
77 
78  protected:
79  explicit ServiceManager(QObject * parent = nullptr);
80 
81  void add(Service * service);
82 
83  void remove(Service * service);
84 
85  void manage(Service * service);
86 
87  void leave(Service * service);
88 
89  private:
91  typedef QMultiHash<const internal::StateInterface *, QMetaObject::Connection> StateInterfaceConnectionsContainer;
92 
93  struct Members {
94  int activeServices;
95  int runningServices;
96  int maxActiveServices;
97  int repairInterval;
99  YieldingServicesContainer yieldingServices;
100  StateInterfaceConnectionsContainer stateInterfaceConnections; // The only way to disconnect particular lambda from particular emitter is to store its connection.
101 
102  Members():
103  activeServices(0),
104  runningServices(0),
105  maxActiveServices(INITIAL_MAX_ACTIVE_SERVICES),
106  repairInterval(INITIAL_REPAIR_INTERVAL),
107  services(new ServiceListModel)
108  {
109  }
110  };
111 
112  MPtr<Members> m;
113 };
114 
115 }
116 }
117 
118 #endif
119 
120 //(c)C: Copyright © 2019, Michał Policht <michal@policht.pl>. All rights reserved.
121 //(c)C: This file is a part of CuteHMI.
122 //(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.
123 //(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.
124 //(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