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 Q_OBJECT
26 QML_NAMED_ELEMENT(Database)
27
28 public:
29 static const char * INITIAL_TYPE;
30 static const char * INITIAL_HOST;
31 static constexpr int INITIAL_PORT = 5432;
32 static const char * INITIAL_NAME;
33 static const char * INITIAL_USER;
34 static const char * INITIAL_PASSWORD;
35 static constexpr bool INITIAL_THREADED = true;
36
40 Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged)
41
42 Q_PROPERTY(QString host READ host WRITE setHost NOTIFY hostChanged)
43
44 Q_PROPERTY(int port READ port WRITE setPort NOTIFY portChanged)
45
46 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
47
48 Q_PROPERTY(QString user READ user WRITE setUser NOTIFY userChanged)
49
50 Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged)
51
52 Q_PROPERTY(QString connectionName READ connectionName WRITE setConnectionName NOTIFY connectionNameChanged)
53
54 Q_PROPERTY(bool threaded READ threaded WRITE setThreaded NOTIFY threadedChanged)
55
56 static bool IsConnected(const QString & connectionName);
57
58 Database(QObject * parent = nullptr);
59
60 ~Database() override;
61
66 QString type() const;
67
72 void setType(const QString & type);
73
78 QString host() const;
79
84 void setHost(const QString & host);
85
90 int port() const;
91
96 void setPort(int port);
97
102 QString name() const;
103
108 void setName(const QString & name);
109
114 QString user() const;
115
120 void setUser(const QString & user);
121
126 QString password() const;
127
132 void setPassword(const QString & password);
133
138 QString connectionName() const;
139
144 void setConnectionName(const QString & connectionName);
145
151 bool threaded() const;
152
157 void setThreaded(bool threaded);
158
159 void configureStarted(QState * active, const QState * idling, const QState * yielding, AssignStatusFunction assignStatus) override;
160
161 void configureStarting(QState * starting, AssignStatusFunction assignStatus) override;
162
163 void configureStopping(QState * stopping, AssignStatusFunction assignStatus) override;
164
165 void configureBroken(QState * broken, AssignStatusFunction assignStatus) override;
166
167 void configureRepairing(QState * repairing, AssignStatusFunction assignStatus) override;
168
169 void configureEvacuating(QState * evacuating, AssignStatusFunction assignStatus) override;
170
171 std::unique_ptr<QAbstractTransition> transitionToStarted() const override;
172
173 std::unique_ptr<QAbstractTransition> transitionToStopped() const override;
174
175 std::unique_ptr<QAbstractTransition> transitionToBroken() const override;
176
177 std::unique_ptr<QAbstractTransition> transitionToYielding() const override;
178
179 std::unique_ptr<QAbstractTransition> transitionToIdling() const override;
180
181 signals:
183
185
187
189
191
193
195
197
198 void connected();
199
201
203
204 private slots:
205 void initializeConnection();
206
207 void closeConnection();
208
209 void onHandlerConnected(QString connectionName);
210
211 void onHandlerDisconnected(QString connectionName);
212
213 private:
214 struct Members {
218 bool threaded = INITIAL_THREADED;
219 };
220
222};
223
224}
225}
226
227#endif
228
229//(c)C: Copyright © 2022-2024, Michał Policht <michal@policht.pl>. All rights reserved.
230//(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
231//(c)C: This file is a part of CuteHMI.
232//(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.
233//(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.
234//(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/>.
235//(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
236//(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:
237//(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
238//(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:24
static const char * INITIAL_PASSWORD
Definition: Database.hpp:34
void errored(cutehmi::InplaceError error)
static const char * INITIAL_NAME
Definition: Database.hpp:32
static const char * INITIAL_HOST
Definition: Database.hpp:30
static const char * INITIAL_USER
Definition: Database.hpp:33
static const char * INITIAL_TYPE
Definition: Database.hpp:29
Definition: DatabaseConfig.hpp:13
Definition: DatabaseThread.hpp:15