mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Refactor config API
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user