Update Options and Start Work On OZW Logging Adapter

This commit is contained in:
Justin Hammond 2019-06-20 12:30:29 +08:00
parent 3233eb2353
commit dab8eb04c7
11 changed files with 179 additions and 28 deletions

View file

@ -0,0 +1,55 @@
#ifndef QTOZWLOGGING_H
#define QTOZWLOGGING_H
#include <QObject>
#include <QAbstractTableModel>
#include <QDateTime>
class QTOZW_Logging : public QAbstractTableModel {
Q_OBJECT
public:
enum LoggingColumns {
TimeStamp,
Node,
Level,
Message,
Count
};
Q_ENUM(LoggingColumns)
enum LoggingLevels {
Always,
Fatal,
Error,
Warning,
Alert,
Info,
Debug,
StreamDetail,
Internal,
LogLevelCount
};
Q_ENUM(LoggingLevels)
struct QTOZW_LogEntry {
QDateTime s_time;
quint8 s_node;
LoggingColumns s_level;
QString s_msg;
};
QTOZW_Logging(QObject *parent = nullptr);
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
protected:
QTOZW_LogEntry getLogData(int);
QVector<QTOZW_LogEntry> m_logData;
};
#endif // QTOZWLOGGING_H

View file

@ -51,11 +51,11 @@ public:
Q_PROPERTY(bool EnableSIS READ EnableSIS WRITE setEnableSIS NOTIFY EnableSISChanged)
Q_PROPERTY(bool AssumeAwake READ AssumeAwake WRITE setAssumeAwake NOTIFY AssumeAwakeChanged)
Q_PROPERTY(bool NotifyOnDriverUnload READ NotifyOnDriverUnload WRITE setNotifyOnDriverUnload NOTIFY NotifyOnDriverUnloadChanged)
Q_PROPERTY(QString SecurityStrategy READ SecurityStrategy WRITE setSecurityStrategy NOTIFY SecurityStrategyChanged)
Q_PROPERTY(OptionList SecurityStrategy READ SecurityStrategy WRITE setSecurityStrategy NOTIFY SecurityStrategyChanged)
Q_PROPERTY(QString CustomSecuredCC READ CustomSecuredCC WRITE setCustomSecuredCC NOTIFY CustomSecuredCCChanged)
Q_PROPERTY(bool EnforceSecureReception READ EnforceSecureReception WRITE setEnforceSecureReception NOTIFY EnforceSecureReceptionChanged)
Q_PROPERTY(bool AutoUpdateConfigFile READ AutoUpdateConfigFile WRITE setAutoUpdateConfigFile NOTIFY AutoUpdateConfigFileChanged)
Q_PROPERTY(QString ReloadAfterUpdate READ ReloadAfterUpdate WRITE setReloadAfterUpdate NOTIFY ReloadAfterUpdateChanged)
Q_PROPERTY(OptionList ReloadAfterUpdate READ ReloadAfterUpdate WRITE setReloadAfterUpdate NOTIFY ReloadAfterUpdateChanged)
Q_PROPERTY(QString Language READ Language WRITE setLanguage NOTIFY LanguageChanged)
Q_PROPERTY(bool IncludeInstanceLabels READ IncludeInstanceLabels WRITE setIncludeInstanceLabels NOTIFY IncludeInstanceLabelsChanged)
@ -85,11 +85,11 @@ public:
bool EnableSIS() const;
bool AssumeAwake() const;
bool NotifyOnDriverUnload() const;
QString SecurityStrategy() const;
OptionList SecurityStrategy() const;
QString CustomSecuredCC() const;
bool EnforceSecureReception() const;
bool AutoUpdateConfigFile() const;
QString ReloadAfterUpdate() const;
OptionList ReloadAfterUpdate() const;
QString Language() const;
bool IncludeInstanceLabels() const;
@ -119,11 +119,11 @@ public:
void setEnableSIS(bool EnableSIS);
void setAssumeAwake(bool AssumeAwake);
void setNotifyOnDriverUnload(bool NotifyOnDriverUnload);
void setSecurityStrategy(QString SecurityStrategy);
void setSecurityStrategy(OptionList SecurityStrategy);
void setCustomSecuredCC(QString CustomSecuredCC);
void setEnforceSecureReception(bool EnforceSecureReception);
void setAutoUpdateConfigFile(bool AutoUpdateConfigFile);
void setReloadAfterUpdate(QString ReloadAfterUpdate);
void setReloadAfterUpdate(OptionList ReloadAfterUpdate);
void setLanguage(QString Language);
void setIncludeInstanceLabels(bool IncludeInstanceLabels);
@ -166,11 +166,11 @@ Q_SIGNALS:
void EnableSISChanged(bool EnableSIS);
void AssumeAwakeChanged(bool AssumeAwake);
void NotifyOnDriverUnloadChanged(bool NotifyOnDriverUnload);
void SecurityStrategyChanged(QString SecurityStrategy);
void SecurityStrategyChanged(OptionList SecurityStrategy);
void CustomSecuredCCChanged(QString CustomSecuredCC);
void EnforceSecureReceptionChanged(bool EnforceSecureReception);
void AutoUpdateConfigFileChanged(bool AutoUpdateConfigFile);
void ReloadAfterUpdateChanged(QString ReloadAfterUpdate);
void ReloadAfterUpdateChanged(OptionList ReloadAfterUpdate);
void LanguageChanged(QString Language);
void IncludeInstanceLabelsChanged(bool IncludeInstanceLabels);
//void error(QTOZWOptionsReplica::QTOZWOptionsErrorCodes errorcode);

View file

@ -35,11 +35,11 @@ class QTOZWOptions {
PROP(bool EnableSIS READWRITE)
PROP(bool AssumeAwake READWRITE)
PROP(bool NotifyOnDriverUnload READWRITE)
PROP(QString SecurityStrategy READWRITE)
PROP(OptionList SecurityStrategy READWRITE)
PROP(QString CustomSecuredCC READWRITE)
PROP(bool EnforceSecureReception READWRITE)
PROP(bool AutoUpdateConfigFile READWRITE)
PROP(QString ReloadAfterUpdate READWRITE)
PROP(OptionList ReloadAfterUpdate READWRITE)
PROP(QString Language READWRITE)
PROP(bool IncludeInstanceLabels READWRITE)

View file

@ -6,6 +6,7 @@
Q_DECLARE_LOGGING_CATEGORY(manager);
Q_DECLARE_LOGGING_CATEGORY(valueModel);
Q_DECLARE_LOGGING_CATEGORY(nodeModel);
Q_DECLARE_LOGGING_CATEGORY(logModel);
Q_DECLARE_LOGGING_CATEGORY(associationModel);
Q_DECLARE_LOGGING_CATEGORY(notifications);

View file

@ -51,11 +51,11 @@ private Q_SLOTS:
void pvt_EnableSISChanged(bool value);
void pvt_AssumeAwakeChanged(bool value);
void pvt_NotifyOnDriverUnloadChanged(bool value);
void pvt_SecurityStrategyChanged(QString value);
void pvt_SecurityStrategyChanged(OptionList value);
void pvt_CustomSecuredCCChanged(QString value);
void pvt_EnforceSecureReceptionChanged(bool value);
void pvt_AutoUpdateConfigFileChanged(bool value);
void pvt_ReloadAfterUpdateChanged(QString value);
void pvt_ReloadAfterUpdateChanged(OptionList value);
void pvt_LanguageChanged(QString value);
void pvt_IncludeInstanceLabelsChanged(bool value);

View file

@ -38,6 +38,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += source/qtopenzwave.cpp \
source/qtozwlogging.cpp \
source/qtozwoptions.cpp \
source/qtozwoptions_p.cpp \
source/qt_pods.cpp \
@ -54,6 +55,7 @@ SOURCES += source/qtopenzwave.cpp \
HEADERS += include/qt-openzwave/qtopenzwave.h \
include/qt-openzwave/qtozw_pods.h \
include/qt-openzwave/qtozwlogging.h \
include/qt-openzwave/qtozwoptions.h \
include/qtozwoptions_p.h \
include/qt-openzwave_global.h \ \

View file

@ -8,6 +8,7 @@ Q_LOGGING_CATEGORY(valueModel, "ozw.values");
Q_LOGGING_CATEGORY(nodeModel, "ozw.nodes");
Q_LOGGING_CATEGORY(associationModel, "ozw.assocations");
Q_LOGGING_CATEGORY(notifications, "ozw.notifications");
Q_LOGGING_CATEGORY(logModel, "ozw.logging");
QTOpenZwave::QTOpenZwave

View file

@ -0,0 +1,68 @@
#include "include/qt-openzwave/qtozwlogging.h"
#include "include/qtozw_logging.h"
QTOZW_Logging::QTOZW_Logging(QObject *parent)
: QAbstractTableModel(parent)
{
}
int QTOZW_Logging::rowCount(const QModelIndex &parent) const {
if (parent.isValid())
return 0;
return this->m_logData.count();
}
int QTOZW_Logging::columnCount(const QModelIndex &parent) const {
if (parent.isValid())
return 0;
return LoggingColumns::Count;
}
QVariant QTOZW_Logging::data(const QModelIndex &index, int role) const {
if (!index.isValid())
return QVariant();
if (index.row() >= this->rowCount(index.parent()) || index.row() < 0)
return QVariant();
if (role == Qt::DisplayRole) {
}
return QVariant();
}
QVariant QTOZW_Logging::headerData(int section, Qt::Orientation orientation, int role) const {
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Horizontal) {
switch (static_cast<LoggingColumns>(section)) {
case TimeStamp:
return tr("TimeStamp");
case Node:
return tr("Node");
case Level:
return tr("Level");
case Message:
return tr("Message");
case Count:
return QVariant();
}
}
return QVariant();
}
Qt::ItemFlags QTOZW_Logging::flags(const QModelIndex &index) const {
if (!index.isValid())
return Qt::NoItemFlags;
return QAbstractTableModel::flags(index);
}
QTOZW_Logging::QTOZW_LogEntry QTOZW_Logging::getLogData(int pos) {
if (this->m_logData.size() <= pos)
return this->m_logData.at(pos);
qCWarning(logModel) << "Can't find LogEntry at " << pos;
return QTOZW_LogEntry();
}

View file

@ -31,7 +31,14 @@ bool QTOZWManager::initilizeSource(bool enableServer) {
return false;
}
qCDebug(manager) << "Database Path: " << this->m_ozwdatabasepath.path().append("/") << " User Path" << this->m_ozwuserpath.path().append("/");
OpenZWave::Options::Create(this->m_ozwdatabasepath.path().append("/").toStdString(), this->m_ozwuserpath.path().append("/").toStdString(), "");
QString dbPath = this->m_ozwdatabasepath.path();
QString userPath = this->m_ozwuserpath.path();
/* OZW expects the paths to end with a / otherwise it treats it as a file */
if (dbPath.at(dbPath.size()) != "/")
dbPath.append("/");
if (userPath.at(userPath.size()) != "/")
userPath.append("/");
OpenZWave::Options::Create(dbPath.toStdString(), userPath.toStdString(), "");
this->d_ptr_internal = new QTOZWManager_Internal(this);
this->m_ozwoptions = new QTOZWOptions(QTOZWOptions::connectionType::Local, this);
if (enableServer) {

View file

@ -188,7 +188,7 @@ bool QTOZWOptions::AssumeAwake() const {
bool QTOZWOptions::NotifyOnDriverUnload() const {
CALL_DPTR_PROP(NotifyTransactions());
}
QString QTOZWOptions::SecurityStrategy() const {
OptionList QTOZWOptions::SecurityStrategy() const {
CALL_DPTR_PROP(SecurityStrategy());
}
QString QTOZWOptions::CustomSecuredCC() const {
@ -200,7 +200,7 @@ bool QTOZWOptions::EnforceSecureReception() const {
bool QTOZWOptions::AutoUpdateConfigFile() const {
CALL_DPTR_PROP(AutoUpdateConfigFile());
}
QString QTOZWOptions::ReloadAfterUpdate() const {
OptionList QTOZWOptions::ReloadAfterUpdate() const {
CALL_DPTR_PROP(ReloadAfterUpdate());
}
QString QTOZWOptions::Language() const {
@ -209,7 +209,6 @@ QString QTOZWOptions::Language() const {
bool QTOZWOptions::IncludeInstanceLabels() const {
CALL_DPTR_PROP(IncludeInstanceLabels());
}
void QTOZWOptions::setConfigPath(QString ConfigPath) {
CALL_DPTR_PROP_SET(ConfigPath);
}
@ -288,8 +287,8 @@ void QTOZWOptions::setAssumeAwake(bool AssumeAwake) {
void QTOZWOptions::setNotifyOnDriverUnload(bool NotifyOnDriverUnload) {
CALL_DPTR_PROP_SET(NotifyOnDriverUnload);
}
void QTOZWOptions::setSecurityStrategy(QString SecurityStrategy) {
CALL_DPTR_PROP_SET(SecurityStrategy);
void QTOZWOptions::setSecurityStrategy(OptionList SecurityStrategy) {
CALL_DPTR_PROP_SET_TYPE(SecurityStrategy, OptionList);
}
void QTOZWOptions::setCustomSecuredCC(QString CustomSecuredCC) {
CALL_DPTR_PROP_SET(CustomSecuredCC);
@ -300,8 +299,8 @@ void QTOZWOptions::setEnforceSecureReception(bool EnforceSecureReception) {
void QTOZWOptions::setAutoUpdateConfigFile(bool AutoUpdateConfigFile) {
CALL_DPTR_PROP_SET(AutoUpdateConfigFile);
}
void QTOZWOptions::setReloadAfterUpdate(QString ReloadAfterUpdate) {
CALL_DPTR_PROP_SET(ReloadAfterUpdate);
void QTOZWOptions::setReloadAfterUpdate(OptionList ReloadAfterUpdate) {
CALL_DPTR_PROP_SET_TYPE(ReloadAfterUpdate, OptionList);
}
void QTOZWOptions::setLanguage(QString Language) {
CALL_DPTR_PROP_SET(Language);

View file

@ -150,11 +150,23 @@ bool QTOZWOptions_Internal::populateProperties() {
this->setEnableSIS(this->GetOptionAsBool("EnableSIS"));
this->setAssumeAwake(this->GetOptionAsBool("AssumeAwake"));
this->setNotifyOnDriverUnload(this->GetOptionAsBool("NotifyOnDriverUnload"));
this->setSecurityStrategy(this->GetOptionAsString("SecurityStrategy"));
{
OptionList secstrategy;
secstrategy.setEnums(QStringList() << "Essential" << "Supported" << "Custom");
QString strategy = this->GetOptionAsString("SecurityStrategy");
secstrategy.setSelected(strategy);
this->setSecurityStrategy(secstrategy);
}
this->setCustomSecuredCC(this->GetOptionAsString("CustomSecuredCC"));
this->setEnforceSecureReception(this->GetOptionAsBool("EnforceSecureReception"));
this->setAutoUpdateConfigFile(this->GetOptionAsBool("AutoUpdateConfigFile"));
this->setReloadAfterUpdate(this->GetOptionAsString("ReloadAfterUpdate"));
{
OptionList reloadoption;
reloadoption.setEnums(QStringList() << "Never" << "Immediate" << "Awake");
QString strategy = this->GetOptionAsString("ReloadAfterUpdate");
reloadoption.setSelected(strategy);
this->setReloadAfterUpdate(reloadoption);
}
this->setLanguage(this->GetOptionAsString("Language"));
this->setIncludeInstanceLabels(this->GetOptionAsBool("IncludeInstanceLabels"));
this->m_updating = false;
@ -164,12 +176,18 @@ bool QTOZWOptions_Internal::populateProperties() {
void QTOZWOptions_Internal::pvt_ConfigPathChanged(QString value) {
if (this->m_updating)
return;
// this->m_options->AddOptionString("ConfigPath", value.toStdString(), false);
/* OZW expects the paths to end with a / otherwise it treats it as a file */
if (value.at(value.size()) != "/")
value.append("/");
this->m_options->AddOptionString("ConfigPath", value.toStdString(), false);
}
void QTOZWOptions_Internal::pvt_UserPathChanged(QString value) {
if (this->m_updating)
return;
// this->m_options->AddOptionString("UserPath", value.toStdString(), false);
/* OZW expects the paths to end with a / otherwise it treats it as a file */
if (value.at(value.size()) != "/")
value.append("/");
this->m_options->AddOptionString("UserPath", value.toStdString(), false);
}
void QTOZWOptions_Internal::pvt_LoggingChanged(bool value) {
if (this->m_updating)
@ -291,10 +309,10 @@ void QTOZWOptions_Internal::pvt_NotifyOnDriverUnloadChanged(bool value) {
return;
this->m_options->AddOptionBool("NotifyOnDriverUnload", value);
}
void QTOZWOptions_Internal::pvt_SecurityStrategyChanged(QString value) {
void QTOZWOptions_Internal::pvt_SecurityStrategyChanged(OptionList value) {
if (this->m_updating)
return;
this->m_options->AddOptionString("SecurityStrategy", value.toStdString(), false);
this->m_options->AddOptionString("SecurityStrategy", value.getSelectedName().toStdString(), false);
}
void QTOZWOptions_Internal::pvt_CustomSecuredCCChanged(QString value) {
if (this->m_updating)
@ -311,10 +329,10 @@ void QTOZWOptions_Internal::pvt_AutoUpdateConfigFileChanged(bool value) {
return;
this->m_options->AddOptionBool("AutoUpdateConfigFile", value);
}
void QTOZWOptions_Internal::pvt_ReloadAfterUpdateChanged(QString value) {
void QTOZWOptions_Internal::pvt_ReloadAfterUpdateChanged(OptionList value) {
if (this->m_updating)
return;
this->m_options->AddOptionString("ReloadAfterUpdate", value.toStdString(), false);
this->m_options->AddOptionString("ReloadAfterUpdate", value.getSelectedName().toStdString(), false);
}
void QTOZWOptions_Internal::pvt_LanguageChanged(QString value) {
if (this->m_updating)