Skip to content

Commit

Permalink
QT SQL and all QT plugins are out. SQLite is used directly
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev committed Jun 1, 2024
1 parent b75506e commit 32013ea
Show file tree
Hide file tree
Showing 31 changed files with 565 additions and 218 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ else()
endif(CCACHE_FOUND)

# find QT libs
find_package(Qt6 COMPONENTS Core Network Sql Widgets SerialPort QUIET)
find_package(Qt6 COMPONENTS Core Network SerialPort QUIET)

if (Qt6Core_FOUND AND NOT (DO_NOT_USE_QT_VERSION_6_LIBS STREQUAL "ON"))
message( STATUS "Found Qt Version: ${Qt6Core_VERSION}" )
Expand All @@ -74,7 +74,7 @@ ELSE()
message( STATUS "QT version 6 not found. Searching for QT version 5 instead." )
endif()
SET(QT_MIN_VERSION "5.10.0")
find_package(Qt5 COMPONENTS Core Network SerialPort Sql REQUIRED)
find_package(Qt5 COMPONENTS Core Network SerialPort REQUIRED)
message( STATUS "Found Qt Version: ${Qt5Core_VERSION}" )
IF ( "${Qt5Core_VERSION}" VERSION_LESS "${QT_MIN_VERSION}" )
message( FATAL_ERROR "Your Qt version is to old! Minimum required ${QT_MIN_VERSION}" )
Expand Down
31 changes: 2 additions & 29 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,12 @@ set_target_properties(sqlite3 PROPERTIES
)

target_compile_definitions(sqlite3 PUBLIC
SQLITE_THREADSAFE=2
SQLITE_THREADSAFE=1
SQLITE_DEFAULT_MEMSTATUS=0
SQLITE_DEFAULT_SYNCHRONOUS=3
SQLITE_OMIT_AUTHORIZATION
SQLITE_OMIT_AUTOINCREMENT
SQLITE_OMIT_AUTOMATIC_INDEX
SQLITE_OMIT_INCRBLOB
SQLITE_OMIT_AUTORESET
SQLITE_OMIT_AUTOVACUUM
SQLITE_OMIT_BETWEEN_OPTIMIZATION
SQLITE_OMIT_BLOB_LITERAL
SQLITE_OMIT_BTREECOUNT
SQLITE_OMIT_CHECK
SQLITE_OMIT_COMPILEOPTION_DIAGS
SQLITE_OMIT_COMPLETE
SQLITE_OMIT_DEPRECATED
SQLITE_OMIT_FLAG_PRAGMAS
SQLITE_OMIT_EXPLAIN
SQLITE_OMIT_FOREIGN_KEY
SQLITE_OMIT_GET_TABLE
SQLITE_OMIT_LIKE_OPTIMIZATION
SQLITE_OMIT_LOAD_EXTENSION
SQLITE_OMIT_OR_OPTIMIZATION
SQLITE_OMIT_PROGRESS_CALLBACK
SQLITE_OMIT_QUICKBALANCE
SQLITE_OMIT_SCHEMA_PRAGMAS
SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
SQLITE_OMIT_TCL_VARIABLE
SQLITE_OMIT_TEMPDB
SQLITE_OMIT_TRACE
SQLITE_OMIT_TRUNCATE_OPTIMIZATION
SQLITE_OMIT_WAL
SQLITE_OMIT_XFER_OPT)
)

#=============================================================================
# RPi ws281x
Expand Down
2 changes: 1 addition & 1 deletion include/base/AccessManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AccessManager : public QObject
Q_OBJECT
private:
friend class HyperHdrDaemon;
AccessManager(QObject* parent, bool readonlyMode);
AccessManager(QObject* parent);

public:
~AccessManager();
Expand Down
5 changes: 2 additions & 3 deletions include/base/HyperHdrInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class HyperHdrInstance : public QObject
Q_OBJECT

public:
HyperHdrInstance(quint8 instance, bool readonlyMode, bool disableOnstartup, QString name);
HyperHdrInstance(quint8 instance, bool disableOnstartup, QString name);
~HyperHdrInstance();

quint8 getInstanceIndex() const { return _instIndex; }
Expand All @@ -72,7 +72,7 @@ public slots:
int getCurrentPriority() const;
std::list<EffectDefinition> getEffects() const;
int getLedCount() const;
bool getReadOnlyMode() const { return _readOnlyMode; };
bool getReadOnlyMode() const;
QJsonDocument getSetting(settings::type type) const;
int hasLedClock();
void identifyLed(const QJsonObject& params);
Expand Down Expand Up @@ -152,7 +152,6 @@ private slots:
std::vector<ColorRgb> _currentLedColors;
QString _name;

bool _readOnlyMode;
bool _disableOnStartup;

static std::atomic<bool> _signalTerminate;
Expand Down
3 changes: 1 addition & 2 deletions include/base/HyperHdrManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private slots:
private:
friend class HyperHdrDaemon;

HyperHdrManager(const QString& rootPath, bool readonlyMode);
HyperHdrManager(const QString& rootPath);

void startAll(bool disableOnStartup);

Expand All @@ -124,7 +124,6 @@ private slots:
QMap<quint8, std::shared_ptr<HyperHdrInstance>> _runningInstances;
QMap<quint8, std::shared_ptr<HyperHdrInstance>> _startingInstances;

bool _readonlyMode;
int _fireStarter;

QMap<quint8, PendingRequests> _pendingRequests;
Expand Down
5 changes: 2 additions & 3 deletions include/base/InstanceConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,22 @@ class InstanceConfig : public QObject
Q_OBJECT

public:
InstanceConfig(bool master, quint8 instanceIndex, QObject* parent, bool readonlyMode);
InstanceConfig(bool master, quint8 instanceIndex, QObject* parent);
~InstanceConfig();

bool upgradeDB(QJsonObject& dbConfig);
bool saveSettings(QJsonObject config, bool correct = false);
QJsonDocument getSetting(settings::type type) const;
void saveSetting(settings::type key, QString saveData);
QJsonObject getSettings() const;

bool isReadOnlyMode();
signals:
void SignalInstanceSettingsChanged(settings::type type, const QJsonDocument& data);

private:
Logger* _log;
std::unique_ptr<SettingsTable> _sTable;
QJsonObject _qconfig;
bool _readonlyMode;

static QJsonObject _schemaJson;
static QMutex _lockerSettingsManager;
Expand Down
2 changes: 1 addition & 1 deletion include/db/AuthTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AuthTable : public DBManager
{

public:
AuthTable(bool readonlyMode);
AuthTable();
bool createUser(const QString& user, const QString& pw);
void savePipewire(const QString& wToken);
bool userExist(const QString& user);
Expand Down
16 changes: 9 additions & 7 deletions include/db/DBManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

#include <utils/Logger.h>

class QSqlDatabase;
class QSqlQuery;
class SqlDatabase;
class SqlQuery;

typedef QPair<QString, QVariant> CPair;
typedef QVector<CPair> VectorPair;
Expand All @@ -28,10 +28,12 @@ class DBManager
public:
virtual ~DBManager();

static void initializeDatabaseFilename(QFileInfo databaseName);
static void initializeDatabaseFilename(QFileInfo databaseName, bool readOnlyMode);
static bool isReadOnlyMode();

void setTable(const QString& table);

QSqlDatabase getDB() const;
SqlDatabase* getDB() const;

bool createTable(QStringList& columns) const;
bool createColumn(const QString& column) const;
Expand All @@ -43,7 +45,6 @@ class DBManager
bool deleteRecord(const VectorPair& conditions) const;
bool tableExists(const QString& table) const;
bool deleteTable(const QString& table) const;
void setReadonlyMode(bool readOnly);

const QJsonObject getBackup();
QString restoreBackup(const QJsonObject& backupData);
Expand All @@ -57,8 +58,9 @@ class DBManager
QString _table;

bool _readonlyMode;
void doAddBindValue(QSqlQuery& query, const QVariantList& variants) const;
void doAddBindValue(SqlQuery& query, const QVariantList& variants) const;

static QFileInfo _databaseName;
static QThreadStorage<QSqlDatabase> _databasePool;
static QThreadStorage<SqlDatabase*> _databasePool;
static bool _readOnlyMode;
};
2 changes: 1 addition & 1 deletion include/db/InstanceTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class InstanceTable : public DBManager
{

public:
InstanceTable(bool readonlyMode);
InstanceTable();

bool createInstance(const QString& name, quint8& inst);
bool deleteInstance(quint8 inst);
Expand Down
2 changes: 1 addition & 1 deletion include/db/MetaTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class MetaTable : public DBManager
{

public:
MetaTable(bool readonlyMode = false);
MetaTable();

QString getUUID() const;
};
92 changes: 92 additions & 0 deletions include/db/SQLite.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#pragma once

/* SQLite.h
*
* MIT License
*
* Copyright (c) 2020-2024 awawa-dev
*
* Project homesite: https://github.com/awawa-dev/HyperHDR
*
* 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:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* 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.
*/

#include <vector>
#include <QString>
#include <QByteArray>
#include <QVariant>

struct sqlite3;
struct sqlite3_stmt;

class SqlDatabase
{
friend class SqlQuery;
bool _readOnly;
QString _databaseName;
sqlite3* _handle;

public:
SqlDatabase(QString databaseName, bool _readOnly);
~SqlDatabase();

QString databaseName();
bool open();
QString error();
bool transaction();
bool commit();
bool rollback();
bool doesColumnExist(QString table, QString column);
bool doesTableExist(QString table);
bool isEmpty();
};

class SqlRecord
{
friend class SqlQuery;
std::vector<std::pair<QString, QVariant>> _result;

public:
QString fieldName(int index);
QVariant value(int index);
size_t count();
};

class SqlQuery
{
SqlDatabase* _connection;
sqlite3_stmt* _prepared;
int _paramIndex;
int _rowIndex;
int _stepResult;

public:
SqlQuery(SqlDatabase* connection);
~SqlQuery();
bool prepare(QString query);
bool exec();
bool exec(QString query);
bool addInt(int x);
bool addDouble(double x);
bool addBlob(QByteArray ar);
bool addString(QString s);

SqlRecord record();
bool next();
};
6 changes: 3 additions & 3 deletions sources/base/AccessManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

using namespace hyperhdr;

AccessManager::AccessManager(QObject* parent, bool readonlyMode)
AccessManager::AccessManager(QObject* parent)
: QObject(parent)
, _authTable(new AuthTable(readonlyMode))
, _metaTable(new MetaTable(readonlyMode))
, _authTable(new AuthTable())
, _metaTable(new MetaTable())
, _pendingRequests()
, _authRequired(true)
, _timer(new QTimer(this))
Expand Down
10 changes: 7 additions & 3 deletions sources/base/HyperHdrInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
std::atomic<bool> HyperHdrInstance::_signalTerminate(false);
std::atomic<int> HyperHdrInstance::_totalRunningCount(0);

HyperHdrInstance::HyperHdrInstance(quint8 instance, bool readonlyMode, bool disableOnStartup, QString name)
HyperHdrInstance::HyperHdrInstance(quint8 instance, bool disableOnStartup, QString name)
: QObject()
, _instIndex(instance)
, _bootEffect(QTime::currentTime().addSecs(5))
Expand All @@ -88,7 +88,6 @@ HyperHdrInstance::HyperHdrInstance(quint8 instance, bool readonlyMode, bool disa
, _ledGridSize()
, _currentLedColors()
, _name((name.isEmpty()) ? QString("INSTANCE%1").arg(instance) : name)
, _readOnlyMode(readonlyMode)
, _disableOnStartup(disableOnStartup)
{
_totalRunningCount++;
Expand Down Expand Up @@ -141,7 +140,7 @@ void HyperHdrInstance::start()

Info(_log, "Starting the instance");

_instanceConfig = std::unique_ptr<InstanceConfig>(new InstanceConfig(false, _instIndex, this, _readOnlyMode));
_instanceConfig = std::unique_ptr<InstanceConfig>(new InstanceConfig(false, _instIndex, this));
_componentController = std::unique_ptr<ComponentController>(new ComponentController(this, _disableOnStartup));
connect(_componentController.get(), &ComponentController::SignalComponentStateChanged, this, &HyperHdrInstance::SignalComponentStateChanged);
_ledString = LedString::createLedString(getSetting(settings::type::LEDS).array(), LedString::createColorOrder(getSetting(settings::type::DEVICE).object()));
Expand Down Expand Up @@ -425,6 +424,11 @@ int HyperHdrInstance::getLedCount() const
return static_cast<int>(_ledString.leds().size());
}

bool HyperHdrInstance::getReadOnlyMode() const
{
return _instanceConfig->isReadOnlyMode();
}

void HyperHdrInstance::setSourceAutoSelect(bool state)
{
_muxer->setSourceAutoSelectEnabled(state);
Expand Down
6 changes: 2 additions & 4 deletions sources/base/HyperHdrManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ QString HyperHdrManager::getRootPath()
return _rootPath;
}

HyperHdrManager::HyperHdrManager(const QString& rootPath, bool readonlyMode)
HyperHdrManager::HyperHdrManager(const QString& rootPath)
: _log(Logger::getInstance("HYPER_MANAGER"))
, _instanceTable(new InstanceTable(readonlyMode))
, _instanceTable(new InstanceTable())
, _rootPath(rootPath)
, _readonlyMode(readonlyMode)
, _fireStarter(0)
{
qRegisterMetaType<InstanceState>("InstanceState");
Expand Down Expand Up @@ -286,7 +285,6 @@ bool HyperHdrManager::startInstance(quint8 inst, QObject* caller, int tan, bool

auto hyperhdr = std::shared_ptr<HyperHdrInstance>(
new HyperHdrInstance(inst,
_readonlyMode,
disableOnStartup,
_instanceTable->getNamebyIndex(inst)),
[](HyperHdrInstance* oldInstance) {
Expand Down
Loading

0 comments on commit 32013ea

Please sign in to comment.