CuteHMI - Shared Database (CuteHMI.SharedDatabase.0)
DatabaseWorker.hpp
1 #ifndef H_EXTENSIONS_CUTEHMI_SHAREDDATABASE_0_INCLUDE_CUTEHMI_SHAREDDATABASE_DATABASEWORKER_HPP
2 #define H_EXTENSIONS_CUTEHMI_SHAREDDATABASE_0_INCLUDE_CUTEHMI_SHAREDDATABASE_DATABASEWORKER_HPP
3 
4 #include "internal/common.hpp"
5 
6 #include <cutehmi/Worker.hpp>
7 
8 #include <QSqlDatabase>
9 
10 namespace cutehmi {
11 namespace shareddatabase {
12 
16 class CUTEHMI_SHAREDDATABASE_API DatabaseWorker:
17  public QObject
18 {
19  Q_OBJECT
20 
21  public:
28  explicit DatabaseWorker(const QString & connectionName, std::function<void(QSqlDatabase & db)> task = nullptr);
29 
34  void setTask(std::function<void(QSqlDatabase & db)> task);
35 
43  virtual void job(QSqlDatabase & db);
44 
51  void wait() const;
52 
59  bool isReady() const;
60 
67  bool isWorking() const;
68 
72  void work();
73 
74  signals:
78  void started();
79 
83  void ready();
84 
88  void striked(const QString & reason);
89 
90  protected:
95  QThread * dbThread() const;
96 
104  QSqlDatabase * db();
105 
113  const QSqlDatabase * db() const;
114 
115  private slots:
116  void updateDbThread(const QString & connectionName);
117 
118  private:
119  void instantiateWorker();
120 
121  struct Members {
122  const QString connectionName;
123  std::function<void(QSqlDatabase & db)> task;
126  };
127 
128  MPtr<Members> m;
129 };
130 
131 }
132 }
133 
134 #endif
135 
136 //(c)C: Copyright © 2020, Michał Policht <michal@policht.pl>. All rights reserved.
137 //(c)C: This file is a part of CuteHMI.
138 //(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.
139 //(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.
140 //(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/>.
QThread
std::function
QSqlDatabase
cutehmi::MPtr< Members >
QObject
cutehmi
QString
cutehmi::shareddatabase::DatabaseWorker
Database worker.
Definition: DatabaseWorker.hpp:16
std::unique_ptr