CuteHMI - Shared Database (CuteHMI.SharedDatabase.1)
Database.hpp
1#ifndef H_EXTENSIONS_CUTEHMI_SHAREDDATABASE_1_INCLUDE_CUTEHMI_SHAREDDATABASE_DATABASE_HPP
2#define H_EXTENSIONS_CUTEHMI_SHAREDDATABASE_1_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#include <QQmlEngine>
14
15namespace cutehmi {
16namespace shareddatabase {
17
21class CUTEHMI_SHAREDDATABASE_API Database:
22 public QObject,
24
25{
26 Q_OBJECT
27 QML_NAMED_ELEMENT(Database)
28
29 public:
30 static const char * INITIAL_TYPE;
31 static const char * INITIAL_HOST;
32 static constexpr int INITIAL_PORT = 5432;
33 static const char * INITIAL_NAME;
34 static const char * INITIAL_USER;
35 static const char * INITIAL_PASSWORD;
36 static constexpr bool INITIAL_THREADED = true;
37
41 Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged)
42
43 Q_PROPERTY(QString host READ host WRITE setHost NOTIFY hostChanged)
44
45 Q_PROPERTY(int port READ port WRITE setPort NOTIFY portChanged)
46
47 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
48
49 Q_PROPERTY(QString user READ user WRITE setUser NOTIFY userChanged)
50
51 Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged)
52
53 Q_PROPERTY(QString connectionName READ connectionName WRITE setConnectionName NOTIFY connectionNameChanged)
54
55 Q_PROPERTY(bool threaded READ threaded WRITE setThreaded NOTIFY threadedChanged)
56
57 static bool IsConnected(const QString & connectionName);
58
59 Database(QObject * parent = nullptr);
60
61 ~Database() override;
62
67 QString type() const;
68
73 void setType(const QString & type);
74
79 QString host() const;
80
85 void setHost(const QString & host);
86
91 int port() const;
92
97 void setPort(int port);
98
103 QString name() const;
104
109 void setName(const QString & name);
110
115 QString user() const;
116
121 void setUser(const QString & user);
122
127 QString password() const;
128
133 void setPassword(const QString & password);
134
139 QString connectionName() const;
140
145 void setConnectionName(const QString & connectionName);
146
152 bool threaded() const;
153
158 void setThreaded(bool threaded);
159
160 void configureStarted(QState * active, const QState * idling, const QState * yielding, AssignStatusFunction assignStatus) override;
161
162 void configureStarting(QState * starting, AssignStatusFunction assignStatus) override;
163
164 void configureStopping(QState * stopping, AssignStatusFunction assignStatus) override;
165
166 void configureBroken(QState * broken, AssignStatusFunction assignStatus) override;
167
168 void configureRepairing(QState * repairing, AssignStatusFunction assignStatus) override;
169
170 void configureEvacuating(QState * evacuating, AssignStatusFunction assignStatus) override;
171
172 std::unique_ptr<QAbstractTransition> transitionToStarted() const override;
173
174 std::unique_ptr<QAbstractTransition> transitionToStopped() const override;
175
176 std::unique_ptr<QAbstractTransition> transitionToBroken() const override;
177
178 std::unique_ptr<QAbstractTransition> transitionToYielding() const override;
179
180 std::unique_ptr<QAbstractTransition> transitionToIdling() const override;
181
182 signals:
184
186
188
190
192
194
196
198
199 void connected();
200
202
204
205 private slots:
206 void initializeConnection();
207
208 void closeConnection();
209
210 void onHandlerConnected(QString connectionName);
211
212 void onHandlerDisconnected(QString connectionName);
213
214 private:
215 struct Members {
219 bool threaded = INITIAL_THREADED;
220 };
221
223};
224
225}
226}
227
228#endif
229
230//(c)C: Copyright © 2022, Michał Policht <michal@policht.pl>. All rights reserved.
231//(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
232//(c)C: This file is a part of CuteHMI.
233//(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.
234//(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.
235//(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/>.
236//(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
237//(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:
238//(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
239//(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.
Database.
Definition: Database.hpp:25
static const char * INITIAL_PASSWORD
Definition: Database.hpp:35
void errored(cutehmi::InplaceError error)
static const char * INITIAL_NAME
Definition: Database.hpp:33
static const char * INITIAL_HOST
Definition: Database.hpp:31
static const char * INITIAL_USER
Definition: Database.hpp:34
static const char * INITIAL_TYPE
Definition: Database.hpp:30
Definition: DatabaseConfig.hpp:13
Definition: DatabaseThread.hpp:15