CuteHMI - Shared Database (CuteHMI.SharedDatabase.0)
Database.hpp
1 #ifndef H_EXTENSIONS_CUTEHMI_SHAREDDATABASE_0_INCLUDE_CUTEHMI_SHAREDDATABASE_DATABASE_HPP
2 #define H_EXTENSIONS_CUTEHMI_SHAREDDATABASE_0_INCLUDE_CUTEHMI_SHAREDDATABASE_DATABASE_HPP
3 
4 #include "internal/common.hpp"
5 #include "internal/DatabaseConfig.hpp"
6 #include "internal/DatabaseConnectionHandler.hpp"
7 #include "internal/DatabaseThread.hpp"
8 
9 #include <cutehmi/services/Serviceable.hpp>
10 #include <cutehmi/macros.hpp>
11 
12 #include <QObject>
13 
14 namespace cutehmi {
15 namespace shareddatabase {
16 
20 class CUTEHMI_SHAREDDATABASE_API Database:
21  public QObject,
23 
24 {
25  Q_OBJECT
26 
27  public:
28  static const char * INITIAL_TYPE;
29  static const char * INITIAL_HOST;
30  static constexpr int INITIAL_PORT = 5432;
31  static const char * INITIAL_NAME;
32  static const char * INITIAL_USER;
33  static const char * INITIAL_PASSWORD;
34  static constexpr bool INITIAL_THREADED = true;
35 
39  Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged)
40 
41  Q_PROPERTY(QString host READ host WRITE setHost NOTIFY hostChanged)
42 
43  Q_PROPERTY(int port READ port WRITE setPort NOTIFY portChanged)
44 
45  Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
46 
47  Q_PROPERTY(QString user READ user WRITE setUser NOTIFY userChanged)
48 
49  Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged)
50 
51  Q_PROPERTY(QString connectionName READ connectionName WRITE setConnectionName NOTIFY connectionNameChanged)
52 
53  Q_PROPERTY(bool threaded READ threaded WRITE setThreaded NOTIFY threadedChanged)
54 
55  static bool IsConnected(const QString & connectionName);
56 
57  Database(QObject * parent = nullptr);
58 
59  ~Database() override;
60 
65  QString type() const;
66 
71  void setType(const QString & type);
72 
77  QString host() const;
78 
83  void setHost(const QString & host);
84 
89  int port() const;
90 
95  void setPort(int port);
96 
101  QString name() const;
102 
107  void setName(const QString & name);
108 
113  QString user() const;
114 
119  void setUser(const QString & user);
120 
125  QString password() const;
126 
131  void setPassword(const QString & password);
132 
137  QString connectionName() const;
138 
143  void setConnectionName(const QString & connectionName);
144 
150  bool threaded() const;
151 
156  void setThreaded(bool threaded);
157 
158  virtual std::unique_ptr<ServiceStatuses> configureStarted(QState * active, const QState * idling, const QState * yielding) override;
159 
160  virtual std::unique_ptr<ServiceStatuses> configureStarting(QState * starting) override;
161 
162  virtual std::unique_ptr<ServiceStatuses> configureStopping(QState * stopping) override;
163 
164  virtual std::unique_ptr<ServiceStatuses> configureBroken(QState * broken) override;
165 
166  virtual std::unique_ptr<ServiceStatuses> configureRepairing(QState * repairing) override;
167 
168  virtual std::unique_ptr<ServiceStatuses> configureEvacuating(QState * evacuating) override;
169 
170  virtual std::unique_ptr<QAbstractTransition> transitionToStarted() const override;
171 
172  virtual std::unique_ptr<QAbstractTransition> transitionToStopped() const override;
173 
174  virtual std::unique_ptr<QAbstractTransition> transitionToBroken() const override;
175 
176  virtual std::unique_ptr<QAbstractTransition> transitionToYielding() const override;
177 
178  virtual std::unique_ptr<QAbstractTransition> transitionToIdling() const override;
179 
180  signals:
181  void typeChanged();
182 
183  void hostChanged();
184 
185  void portChanged();
186 
187  void nameChanged();
188 
189  void userChanged();
190 
191  void passwordChanged();
192 
193  void connectionNameChanged();
194 
195  void threadedChanged();
196 
197  void connected();
198 
199  void disconnected();
200 
201  void errored(InplaceError error);
202 
203  private slots:
204  void initializeConnection();
205 
206  void closeConnection();
207 
208  void onHandlerConnected(QString connectionName);
209 
210  void onHandlerDisconnected(QString connectionName);
211 
212  private:
213  struct Members {
217  bool threaded = INITIAL_THREADED;
218  };
219 
220  MPtr<Members> m;
221 };
222 
223 }
224 }
225 
226 #endif
227 
228 //(c)C: Copyright © 2020, Michał Policht <michal@policht.pl>. All rights reserved.
229 //(c)C: This file is a part of CuteHMI.
230 //(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.
231 //(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.
232 //(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/>.
QState
cutehmi::shareddatabase::internal::DatabaseConfig
Definition: DatabaseConfig.hpp:12
cutehmi::shareddatabase::Database::INITIAL_NAME
static const char * INITIAL_NAME
Definition: Database.hpp:31
cutehmi::shareddatabase::Database::INITIAL_USER
static const char * INITIAL_USER
Definition: Database.hpp:32
cutehmi::InplaceError
cutehmi::MPtr< Members >
QObject
cutehmi::shareddatabase::Database::INITIAL_PASSWORD
static const char * INITIAL_PASSWORD
Definition: Database.hpp:33
cutehmi
QString
cutehmi::services::Serviceable
QAbstractTransition
cutehmi::shareddatabase::Database::INITIAL_HOST
static const char * INITIAL_HOST
Definition: Database.hpp:29
cutehmi::shareddatabase::internal::DatabaseThread
Definition: DatabaseThread.hpp:13
std
cutehmi::shareddatabase::Database::INITIAL_TYPE
static const char * INITIAL_TYPE
Definition: Database.hpp:28
cutehmi::shareddatabase::Database
Database.
Definition: Database.hpp:20
QHash
std::unique_ptr