Refactor config API

This commit is contained in:
LordGrey
2024-08-01 23:07:18 +02:00
parent 4a5b0b6bf2
commit c86af5ce79
42 changed files with 1605 additions and 889 deletions

View File

@@ -1,12 +1,7 @@
#pragma once
#ifndef AUTHSTABLE_H
#define AUTHSTABLE_H
// hyperion
#include <db/DBManager.h>
#include <QCryptographicHash>
// qt
#include <QDateTime>
#include <QUuid>
namespace hyperion {
const char DEFAULT_USER[] = "Hyperion";
@@ -21,69 +16,30 @@ class AuthTable : public DBManager
public:
/// construct wrapper with auth table
AuthTable(const QString& rootPath = "", QObject* parent = nullptr, bool readonlyMode = false)
: DBManager(parent)
{
setReadonlyMode(readonlyMode);
if(!rootPath.isEmpty()){
// Init Hyperion database usage
setRootPath(rootPath);
setDatabaseName("hyperion");
}
// init Auth table
setTable("auth");
// create table columns
createTable(QStringList()<<"user TEXT"<<"password BLOB"<<"token BLOB"<<"salt BLOB"<<"comment TEXT"<<"id TEXT"<<"created_at TEXT"<<"last_use TEXT");
};
explicit AuthTable(QObject* parent = nullptr);
///
/// @brief Create a user record, if called on a existing user the auth is recreated
/// @param[in] user The username
/// @param[in] pw The password
/// @param[in] password The password
/// @return true on success else false
///
inline bool createUser(const QString& user, const QString& pw)
{
// new salt
QByteArray salt = QCryptographicHash::hash(QUuid::createUuid().toByteArray(), QCryptographicHash::Sha512).toHex();
QVariantMap map;
map["user"] = user;
map["salt"] = salt;
map["password"] = hashPasswordWithSalt(pw,salt);
map["created_at"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
VectorPair cond;
cond.append(CPair("user",user));
return createRecord(cond, map);
}
bool createUser(const QString& user, const QString& password);
///
/// @brief Test if user record exists
/// @param[in] user The user id
/// @return true on success else false
///
inline bool userExist(const QString& user)
{
VectorPair cond;
cond.append(CPair("user",user));
return recordExists(cond);
}
bool userExist(const QString& user);
///
/// @brief Test if a user is authorized for access with given pw.
/// @param user The user name
/// @param pw The password
/// @return True on success else false
/// @param user The user name
/// @param password The password
/// @return True on success else false
///
inline bool isUserAuthorized(const QString& user, const QString& pw)
{
if(userExist(user) && (calcPasswordHashOfUser(user, pw) == getPasswordHashOfUser(user)))
{
updateUserUsed(user);
return true;
}
return false;
}
bool isUserAuthorized(const QString& user, const QString& password);
///
/// @brief Test if a user token is authorized for access.
@@ -91,197 +47,92 @@ public:
/// @param token The token
/// @return True on success else false
///
inline bool isUserTokenAuthorized(const QString& usr, const QString& token)
{
if(getUserToken(usr) == token.toUtf8())
{
updateUserUsed(usr);
return true;
}
return false;
}
bool isUserTokenAuthorized(const QString& usr, const QString& token);
///
/// @brief Update token of a user. It's an alternate login path which is replaced on startup. This token is NOT hashed(!)
/// @param user The user name
/// @return True on success else false
///
inline bool setUserToken(const QString& user)
{
QVariantMap map;
map["token"] = QCryptographicHash::hash(QUuid::createUuid().toByteArray(), QCryptographicHash::Sha512).toHex();
VectorPair cond;
cond.append(CPair("user", user));
return updateRecord(cond, map);
}
bool setUserToken(const QString& user);
///
/// @brief Get token of a user. This token is NOT hashed(!)
/// @param user The user name
/// @return The token
///
inline const QByteArray getUserToken(const QString& user)
{
QVariantMap results;
VectorPair cond;
cond.append(CPair("user", user));
getRecord(cond, results, QStringList()<<"token");
return results["token"].toByteArray();
}
const QByteArray getUserToken(const QString& user);
///
/// @brief update password of given user. The user should be tested (isUserAuthorized) to verify this change
/// @param user The user name
/// @param newPw The new password to set
/// @return True on success else false
/// @param user The user name
/// @param newassword The new password to set
/// @return True on success else false
///
inline bool updateUserPassword(const QString& user, const QString& newPw)
{
QVariantMap map;
map["password"] = calcPasswordHashOfUser(user, newPw);
VectorPair cond;
cond.append(CPair("user", user));
return updateRecord(cond, map);
}
bool updateUserPassword(const QString& user, const QString& newPassword);
///
/// @brief Reset password of Hyperion user !DANGER! Used in Hyperion main.cpp
/// @return True on success else false
///
inline bool resetHyperionUser()
{
QVariantMap map;
map["password"] = calcPasswordHashOfUser(hyperion::DEFAULT_USER, hyperion::DEFAULT_PASSWORD);
VectorPair cond;
cond.append(CPair("user", hyperion::DEFAULT_USER));
return updateRecord(cond, map);
}
bool resetHyperionUser();
///
/// @brief Update 'last_use' column entry for the corresponding user
/// @param[in] user The user to search for
///
inline void updateUserUsed(const QString& user)
{
QVariantMap map;
map["last_use"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
VectorPair cond;
cond.append(CPair("user", user));
updateRecord(cond, map);
}
void updateUserUsed(const QString& user);
///
/// @brief Test if token record exists, updates last_use on success
/// @param[in] token The token id
/// @return true on success else false
///
inline bool tokenExist(const QString& token)
{
QVariantMap map;
map["last_use"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
VectorPair cond;
cond.append(CPair("token", hashToken(token)));
if(recordExists(cond))
{
// update it
createRecord(cond,map);
return true;
}
return false;
}
bool tokenExist(const QString& token);
///
/// @brief Create a new token record with comment
/// @param[in] token The token id as plaintext
/// @param[in] comment The comment for the token (eg a human readable identifier)
/// @param[in] id The id for the token
/// @param[in] identifier The identifier for the token
/// @return true on success else false
///
inline bool createToken(const QString& token, const QString& comment, const QString& id)
{
QVariantMap map;
map["comment"] = comment;
map["id"] = idExist(id) ? QUuid::createUuid().toString().remove("{").remove("}").left(5) : id;
map["created_at"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
VectorPair cond;
cond.append(CPair("token", hashToken(token)));
return createRecord(cond, map);
}
bool createToken(const QString& token, const QString& comment, const QString& identifier);
///
/// @brief Delete token record by id
/// @param[in] id The token id
/// @brief Delete token record by identifier
/// @param[in] identifier The token identifier
/// @return true on success else false
///
inline bool deleteToken(const QString& id)
{
VectorPair cond;
cond.append(CPair("id", id));
return deleteRecord(cond);
}
bool deleteToken(const QString& identifier);
///
/// @brief Rename token record by id
/// @param[in] id The token id
/// @brief Rename token record by identifier
/// @param[in] identifier The token identifier
/// @param[in] comment The new comment
/// @return true on success else false
///
inline bool renameToken(const QString &id, const QString &comment)
{
QVariantMap map;
map["comment"] = comment;
VectorPair cond;
cond.append(CPair("id", id));
return updateRecord(cond, map);
}
bool renameToken(const QString &identifier, const QString &comment);
///
/// @brief Get all 'comment', 'last_use' and 'id' column entries
/// @return A vector of all lists
///
inline const QVector<QVariantMap> getTokenList()
{
QVector<QVariantMap> results;
getRecords(results, QStringList() << "comment" << "id" << "last_use");
return results;
}
const QVector<QVariantMap> getTokenList();
///
/// @brief Test if id exists
/// @param[in] id The id
/// @brief Test if identifier exists
/// @param[in] identifier The identifier
/// @return true on success else false
///
inline bool idExist(const QString& id)
{
VectorPair cond;
cond.append(CPair("id", id));
return recordExists(cond);
}
bool identifierExist(const QString& identifier);
///
/// @brief Get the passwort hash of a user from db
/// @param user The user name
/// @return password as hash
///
inline const QByteArray getPasswordHashOfUser(const QString& user)
{
QVariantMap results;
VectorPair cond;
cond.append(CPair("user", user));
getRecord(cond, results, QStringList()<<"password");
return results["password"].toByteArray();
}
const QByteArray getPasswordHashOfUser(const QString& user);
///
/// @brief Calc the password hash of a user based on user name and password
@@ -289,36 +140,22 @@ public:
/// @param pw The password
/// @return The calced password hash
///
inline const QByteArray calcPasswordHashOfUser(const QString& user, const QString& pw)
{
// get salt
QVariantMap results;
VectorPair cond;
cond.append(CPair("user", user));
getRecord(cond, results, QStringList()<<"salt");
// calc
return hashPasswordWithSalt(pw,results["salt"].toByteArray());
}
const QByteArray calcPasswordHashOfUser(const QString& user, const QString& password);
///
/// @brief Create a password hash of plaintex password + salt
/// @param pw The plaintext password
/// @param password The plaintext password
/// @param salt The salt
/// @return The password hash with salt
///
inline const QByteArray hashPasswordWithSalt(const QString& pw, const QByteArray& salt)
{
return QCryptographicHash::hash(pw.toUtf8().append(salt), QCryptographicHash::Sha512).toHex();
}
const QByteArray hashPasswordWithSalt(const QString& password, const QByteArray& salt);
///
/// @brief Create a token hash
/// @param token The plaintext token
/// @return The token hash
///
inline const QByteArray hashToken(const QString& token)
{
return QCryptographicHash::hash(token.toUtf8(), QCryptographicHash::Sha512).toHex();
}
const QByteArray hashToken(const QString& token);
};
#endif // AUTHSTABLE_H

View File

@@ -0,0 +1,22 @@
#ifndef CONFIGIMPORTEXPORT_H
#define CONFIGIMPORTEXPORT_H
#include <db/DBManager.h>
#include <QFile>
#include <QJsonDocument>
class ConfigImportExport : public DBManager
{
public:
ConfigImportExport(QObject* parent = nullptr);
// TODO: Check naming seConfiguration
QPair<bool, QStringList> importJson(const QString& configFile);
bool exportJson(const QString& path = "") const;
QPair<bool, QStringList> setConfiguration(const QJsonObject& config);
QJsonObject getConfiguration(const QList<quint8>& instances = {}, bool addGlobalConfig = true, const QStringList& instanceFilteredTypes = {}, const QStringList& globalFilterTypes = {} ) const;
};
#endif // CONFIGIMPORTEXPORT_H

View File

@@ -5,6 +5,9 @@
#include <QVariant>
#include <QPair>
#include <QVector>
#include <QFileInfo>
#include <QDir>
#include <QThreadStorage>
class QSqlDatabase;
class QSqlQuery;
@@ -26,13 +29,22 @@ class DBManager : public QObject
Q_OBJECT
public:
DBManager(QObject* parent = nullptr);
~DBManager() override;
explicit DBManager(QObject* parent = nullptr);
static void initializeDatabase(const QDir& dataDirectory, bool isReadOnly);
static QDir getDataDirectory() { return _dataDirectory;}
static QDir getDirectory() { return _databaseDirectory;}
static QFileInfo getFileInfo() { return _databaseFile;}
static bool isReadOnly() { return _isReadOnly; }
///
/// @brief Sets the database in read-only mode.
/// Updates will not written to the tables
/// @param[in] readOnly True read-only, false - read/write
///
static void setReadonly(bool isReadOnly) { _isReadOnly = isReadOnly; }
/// set root path
void setRootPath(const QString& rootPath);
/// define the database to work with
void setDatabaseName(const QString& dbn) { _dbn = dbn; };
/// set a table to work with
void setTable(const QString& table);
@@ -98,6 +110,18 @@ public:
///
bool getRecords(QVector<QVariantMap>& results, const QStringList& tColumns = QStringList(), const QStringList& tOrder = QStringList()) const;
///
/// @brief Get data of multiple records, you need to specify the columns. This search is without conditions. Good to grab all data from db
/// @param[in] conditions condition to search for (WHERE)
/// @param[out] results results of query
/// @param[in] tColumns target columns to search in (optional) if not provided returns all columns
/// @param[in] tOrder target order columns with order by ASC/DESC (optional)
/// @return True on success else false
///
bool getRecords(const VectorPair& conditions, QVector<QVariantMap>& results, const QStringList& tColumns = {}, const QStringList& tOrder = {}) const;
bool getRecords(const QString& condition, const QVariantList& bindValues, QVector<QVariantMap>& results, const QStringList& tColumns = {}, const QStringList& tOrder = {}) const;
///
/// @brief Delete a record determined by conditions
/// @param[in] conditions conditions of the row to delete it (WHERE)
@@ -119,23 +143,26 @@ public:
///
bool deleteTable(const QString& table) const;
///
/// @brief Sets a table in read-only mode.
/// Updates will not written to the table
/// @param[in] readOnly True read-only, false - read/write
///
void setReadonlyMode(bool readOnly) { _readonlyMode = readOnly; };
bool executeQuery(QSqlQuery& query) const;
protected:
Logger* _log;
private:
static QDir _dataDirectory;
static QDir _databaseDirectory;
static QFileInfo _databaseFile;
static QThreadStorage<QSqlDatabase> _databasePool;
static bool _isReadOnly;
Logger* _log;
/// databse connection & file name, defaults to hyperion
QString _dbn = "hyperion";
/// table in database
QString _table;
/// databse connection & file name, defaults to hyperion
QString _dbn = "hyperion";
bool _readonlyMode;
/// table in database
QString _table;
/// addBindValue to query given by QVariantList
void doAddBindValue(QSqlQuery& query, const QVariantList& variants) const;
/// addBindValues to query given by QVariantList
void addBindValues(QSqlQuery& query, const QVariantList& variants) const;
QString constructExecutedQuery(const QSqlQuery& query) const;
};

View File

@@ -1,11 +1,7 @@
#pragma once
#ifndef INSTANCETABLE_H
#define INSTANCETABLE_H
// db
#include <db/DBManager.h>
#include <db/SettingsTable.h>
// qt
#include <QDateTime>
///
/// @brief Hyperion instance manager specific database interface. prepares also the Hyperion database for all follow up usage (Init QtSqlConnection) along with db name
@@ -14,22 +10,7 @@ class InstanceTable : public DBManager
{
public:
InstanceTable(const QString& rootPath, QObject* parent = nullptr, bool readonlyMode = false)
: DBManager(parent)
{
setReadonlyMode(readonlyMode);
// Init Hyperion database usage
setRootPath(rootPath);
setDatabaseName("hyperion");
// Init instance table
setTable("instances");
createTable(QStringList()<<"instance INTEGER"<<"friendly_name TEXT"<<"enabled INTEGER DEFAULT 0"<<"last_use TEXT");
// start/create the first Hyperion instance index 0
createInstance();
};
explicit InstanceTable(QObject* parent = nullptr);
///
/// @brief Create a new Hyperion instance entry, the name needs to be unique
@@ -37,53 +18,19 @@ public:
/// @param[out] inst The id that has been assigned
/// @return True on success else false
///
inline bool createInstance(const QString& name, quint8& inst)
{
VectorPair fcond;
fcond.append(CPair("friendly_name",name));
bool createInstance(const QString& name, quint8& inst);
// check duplicate
if(!recordExists(fcond))
{
inst = 0;
VectorPair cond;
cond.append(CPair("instance",inst));
// increment to next avail index
while(recordExists(cond))
{
inst++;
cond.removeFirst();
cond.append(CPair("instance",inst));
}
// create
QVariantMap data;
data["friendly_name"] = name;
data["instance"] = inst;
VectorPair lcond;
return createRecord(lcond, data);
}
return false;
}
///
/// @brief Create first Hyperion instance entry, if index 0 is not found.
///
void createDefaultInstance();
///
/// @brief Delete a Hyperion instance
/// @param inst The id that has been assigned
/// @return True on success else false
///
inline bool deleteInstance(quint8 inst)
{
VectorPair cond;
cond.append(CPair("instance",inst));
if(deleteRecord(cond))
{
// delete settings entries
SettingsTable settingsTable(inst);
settingsTable.deleteInstance();
return true;
}
return false;
}
bool deleteInstance(quint8 inst);
///
/// @brief Assign a new name for the given instance
@@ -91,141 +38,59 @@ public:
/// @param name The new name of the instance
/// @return True on success else false (instance not found)
///
inline bool saveName(quint8 inst, const QString& name)
{
VectorPair fcond;
fcond.append(CPair("friendly_name",name));
// check duplicate
if(!recordExists(fcond))
{
if(instanceExist(inst))
{
VectorPair cond;
cond.append(CPair("instance",inst));
QVariantMap data;
data["friendly_name"] = name;
return updateRecord(cond, data);
}
}
return false;
}
bool saveName(quint8 inst, const QString& name);
///
/// @brief Get all instances with all columns
/// @param justEnabled return just enabled instances if true
/// @param onlyEnabled return only enabled instances if true
/// @return The found instances
///
inline QVector<QVariantMap> getAllInstances(bool justEnabled = false)
{
QVector<QVariantMap> results;
getRecords(results, QStringList(), QStringList() << "instance ASC");
if(justEnabled)
{
for (auto it = results.begin(); it != results.end();)
{
if( ! (*it)["enabled"].toBool())
{
it = results.erase(it);
continue;
}
++it;
}
}
return results;
}
QVector<QVariantMap> getAllInstances(bool onlyEnabled = false);
///
/// @brief Get all instance IDs
/// @param onlyEnabled return only enabled instance IDs if true
/// @return The found instances
///
QList<quint8> getAllInstanceIDs (bool onlyEnabled = false);
///
/// @brief Test if instance record exists
/// @param[in] user The user id
/// @return true on success else false
///
inline bool instanceExist(quint8 inst)
{
VectorPair cond;
cond.append(CPair("instance",inst));
return recordExists(cond);
}
bool instanceExist(quint8 inst);
///
/// @brief Get instance name by instance index
/// @param index The index to search for
/// @return The name of this index, may return NOT FOUND if not found
///
inline const QString getNamebyIndex(quint8 index)
{
QVariantMap results;
VectorPair cond;
cond.append(CPair("instance", index));
getRecord(cond, results, QStringList("friendly_name"));
QString name = results["friendly_name"].toString();
return name.isEmpty() ? "NOT FOUND" : name;
}
QString getNamebyIndex(quint8 index);
///
/// @brief Update 'last_use' timestamp
/// @param inst The instance to update
/// @return True on success else false
///
inline void setLastUse(quint8 inst)
{
VectorPair cond;
cond.append(CPair("instance", inst));
QVariantMap map;
map["last_use"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
updateRecord(cond, map);
}
bool setLastUse(quint8 inst);
///
/// @brief Update 'enabled' column by instance index
/// @param inst The instance to update
/// @param newState True when enabled else false
/// @return True on success else false
///
inline void setEnable(quint8 inst, bool newState)
{
VectorPair cond;
cond.append(CPair("instance", inst));
QVariantMap map;
map["enabled"] = newState;
updateRecord(cond, map);
}
bool setEnable(quint8 inst, bool newState);
///
/// @brief Get state of 'enabled' column by instance index
/// @param inst The instance to get
/// @return True when enabled else false
///
inline bool isEnabled(quint8 inst)
{
VectorPair cond;
cond.append(CPair("instance", inst));
QVariantMap results;
getRecord(cond, results);
return results["enabled"].toBool();
}
bool isEnabled(quint8 inst);
private:
///
/// @brief Create first Hyperion instance entry, if index 0 is not found.
///
inline void createInstance()
{
if(instanceExist(0))
setEnable(0, true);
else
{
QVariantMap data;
data["friendly_name"] = "First LED Hardware instance";
VectorPair cond;
cond.append(CPair("instance", 0));
if(createRecord(cond, data))
setEnable(0, true);
else
throw std::runtime_error("Failed to create Hyperion root instance in db! This should never be the case...");
}
}
};
#endif // INSTANCETABLE_H

View File

@@ -1,14 +1,9 @@
#pragma once
#ifndef METATABLE_H
#define METATABLE_H
// hyperion
#include <db/DBManager.h>
// qt
#include <QDateTime>
#include <QUuid>
#include <QNetworkInterface>
#include <QCryptographicHash>
///
/// @brief meta table specific database interface
///
@@ -17,47 +12,13 @@ class MetaTable : public DBManager
public:
/// construct wrapper with plugins table and columns
MetaTable(QObject* parent = nullptr, bool readonlyMode = false)
: DBManager(parent)
{
setReadonlyMode(readonlyMode);
setTable("meta");
createTable(QStringList()<<"uuid TEXT"<<"created_at TEXT");
};
explicit MetaTable(QObject* parent = nullptr);
///
/// @brief Get the uuid, if the uuid is not set it will be created
/// @return The uuid
///
inline QString getUUID() const
{
QVector<QVariantMap> results;
getRecords(results, QStringList() << "uuid");
for(const auto & entry : results)
{
if(!entry["uuid"].toString().isEmpty())
return entry["uuid"].toString();
}
// create new uuidv5 based on net adapter MAC, save to db and return
QString hash;
foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces())
{
if (!(interface.flags() & QNetworkInterface::IsLoopBack))
{
hash = QCryptographicHash::hash(interface.hardwareAddress().toLocal8Bit(),QCryptographicHash::Sha1).toHex();
break;
}
}
const QString newUuid = QUuid::createUuidV5(QUuid(), hash).toString().mid(1, 36);
VectorPair cond;
cond.append(CPair("uuid",newUuid));
QVariantMap map;
map["created_at"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
createRecord(cond, map);
return newUuid;
}
QString getUUID() const;
};
#endif // METATABLE_H

View File

@@ -1,12 +1,12 @@
#pragma once
#ifndef SETTINGSTABLE_H
#define SETTINGSTABLE_H
// hyperion
#include <db/DBManager.h>
// qt
#include <QDateTime>
#include <QJsonDocument>
const int GLOABL_INSTANCE_ID = 0;
///
/// @brief settings table db interface
///
@@ -15,14 +15,7 @@ class SettingsTable : public DBManager
public:
/// construct wrapper with settings table
SettingsTable(quint8 instance, QObject* parent = nullptr)
: DBManager(parent)
, _hyperion_inst(instance)
{
setTable("settings");
// create table columns
createTable(QStringList()<<"type TEXT"<<"config TEXT"<<"hyperion_inst INTEGER"<<"updated_at TEXT");
};
SettingsTable(quint8 instance, QObject* parent = nullptr);
///
/// @brief Create or update a settings record
@@ -30,19 +23,7 @@ public:
/// @param[in] config The configuration data
/// @return true on success else false
///
inline bool createSettingsRecord(const QString& type, const QString& config) const
{
QVariantMap map;
map["config"] = config;
map["updated_at"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
VectorPair cond;
cond.append(CPair("type",type));
// when a setting is not global we are searching also for the instance
if(!isSettingGlobal(type))
cond.append(CPair("AND hyperion_inst",_hyperion_inst));
return createRecord(cond, map);
}
bool createSettingsRecord(const QString& type, const QString& config) const;
///
/// @brief Test if record exist, type can be global setting or local (instance)
@@ -50,76 +31,33 @@ public:
/// @param[in] hyperion_inst The instance of hyperion assigned (might be empty)
/// @return true on success else false
///
inline bool recordExist(const QString& type) const
{
VectorPair cond;
cond.append(CPair("type",type));
// when a setting is not global we are searching also for the instance
if(!isSettingGlobal(type))
cond.append(CPair("AND hyperion_inst",_hyperion_inst));
return recordExists(cond);
}
bool recordExist(const QString& type) const;
///
/// @brief Get 'config' column of settings entry as QJsonDocument
/// @param[in] type The settings type
/// @return The QJsonDocument
///
inline QJsonDocument getSettingsRecord(const QString& type) const
{
QVariantMap results;
VectorPair cond;
cond.append(CPair("type",type));
// when a setting is not global we are searching also for the instance
if(!isSettingGlobal(type))
cond.append(CPair("AND hyperion_inst",_hyperion_inst));
getRecord(cond, results, QStringList("config"));
return QJsonDocument::fromJson(results["config"].toByteArray());
}
QJsonDocument getSettingsRecord(const QString& type) const;
///
/// @brief Get 'config' column of settings entry as QString
/// @param[in] type The settings type
/// @return The QString
///
inline QString getSettingsRecordString(const QString& type) const
{
QVariantMap results;
VectorPair cond;
cond.append(CPair("type",type));
// when a setting is not global we are searching also for the instance
if(!isSettingGlobal(type))
cond.append(CPair("AND hyperion_inst",_hyperion_inst));
getRecord(cond, results, QStringList("config"));
return results["config"].toString();
}
QString getSettingsRecordString(const QString& type) const;
///
/// @brief Delete all settings entries associated with this instance, called from InstanceTable of HyperionIManager
///
inline void deleteInstance() const
{
VectorPair cond;
cond.append(CPair("hyperion_inst",_hyperion_inst));
deleteRecord(cond);
}
void deleteInstance() const;
inline bool isSettingGlobal(const QString& type) const
{
// list of global settings
QStringList list;
// server port services
list << "jsonServer" << "protoServer" << "flatbufServer" << "forwarder" << "webConfig" << "network"
// capture
<< "framegrabber" << "grabberV4L2" << "grabberAudio"
//Events
<< "osEvents" << "cecEvents" << "schedEvents"
// other
<< "logger" << "general";
static const QVector<QString>& getGlobalSettingTypes();
return list.contains(type);
}
static bool isSettingGlobal(const QString& type);
private:
const quint8 _hyperion_inst;
};
#endif // SETTINGSTABLE_H