Skip to content

Commit

Permalink
fix up Configuration Dialog Crash before connecting/opening local - O…
Browse files Browse the repository at this point in the history
  • Loading branch information
Fishwaldo committed Jun 9, 2020
1 parent 337e488 commit dae38b6
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 39 deletions.
7 changes: 5 additions & 2 deletions qt-openzwave/include/qt-openzwave/qtozwoptions.h
Expand Up @@ -44,8 +44,8 @@ class QTOPENZWAVESHARED_EXPORT QTOZWOptions : public QTOZWReplicaBase {
friend class QTOZWManager;
Q_OBJECT
public:
QTOZWOptions(ConnectionType::Type type, QObject *parent = nullptr);

QTOZWOptions(ConnectionType::Type type, QString localConfigPath = QString(), QString localUserPath = QString(), QObject *parent = nullptr);
~QTOZWOptions();
Q_PROPERTY(QString ConfigPath READ ConfigPath WRITE setConfigPath NOTIFY ConfigPathChanged)
Q_PROPERTY(QString UserPath READ UserPath WRITE setUserPath NOTIFY UserPathChanged)
Q_PROPERTY(bool Logging READ Logging WRITE setLogging NOTIFY LoggingChanged)
Expand Down Expand Up @@ -201,11 +201,14 @@ class QTOPENZWAVESHARED_EXPORT QTOZWOptions : public QTOZWReplicaBase {

private:
void connectSignals();
void disconnectSignals();


QTOZWOptions_Internal *d_ptr_internal;
QTOZWOptionsReplica *d_ptr_replica;
QRemoteObjectReplica::State m_optionState;
QString m_localConfigPath;
QString m_localUserPath;
};


Expand Down
7 changes: 7 additions & 0 deletions qt-openzwave/include/qt-openzwave/qtozwreplica.h
Expand Up @@ -88,6 +88,13 @@ class QTOPENZWAVESHARED_EXPORT QTOZWReplicaBase : public QObject {
this->d_ptr_replica->setProperty(#x, QVariant::fromValue<y>(x)); \
}

#define DISCONNECT_DPTR(x) if (this->getConnectionType() == ConnectionType::Type::Local) { \
if (this->d_ptr_replica) \
QObject::disconnect(this->d_ptr_replica, SIGNAL(x));\
} else { \
if (this->d_ptr_internal) \
QObject::disconnect(this->d_ptr_internal, SIGNAL(x)); \
};

#else

Expand Down
1 change: 1 addition & 0 deletions qt-openzwave/include/qtozw_logging.h
Expand Up @@ -39,5 +39,6 @@ Q_DECLARE_LOGGING_CATEGORY(associationModel);
Q_DECLARE_LOGGING_CATEGORY(notifications);
Q_DECLARE_LOGGING_CATEGORY(libopenzwave);
Q_DECLARE_LOGGING_CATEGORY(qtrowebsocket);
Q_DECLARE_LOGGING_CATEGORY(options);

#endif // QTOZW_LOGGING_H
2 changes: 0 additions & 2 deletions qt-openzwave/include/qtozwmanager_p.h
Expand Up @@ -63,7 +63,6 @@ class QTOZWManager_Internal : public QTOZWManagerSimpleSource
QTOZW_Nodes *getNodeModel();
QTOZW_ValueIds *getValueModel();
QTOZW_Associations *getAssociationModel();
QTOZWOptions_Internal *getOptions();
QTOZWLog_Internal *getLog();
bool setLog(QTOZWLog_Internal *);

Expand Down Expand Up @@ -202,7 +201,6 @@ public Q_SLOTS:
bool convertValueID(quint64 vidKey);


QTOZWOptions_Internal *m_options;
OpenZWave::Manager *m_manager;
QTOZW_Nodes_internal *m_nodeModel;
QTOZW_ValueIds_internal *m_valueModel;
Expand Down
4 changes: 3 additions & 1 deletion qt-openzwave/include/qtozwoptions_p.h
Expand Up @@ -42,7 +42,7 @@ class QTOZWOptions_Internal : public QTOZWOptionsSimpleSource
{
Q_OBJECT
public:
QTOZWOptions_Internal(QObject *parent = nullptr);
QTOZWOptions_Internal(QString localConfigPath, QString localUserPath, QObject *parent = nullptr);

public Q_SLOTS:
bool AddOptionBool(QString option, bool value);
Expand Down Expand Up @@ -92,6 +92,8 @@ private Q_SLOTS:
bool populateProperties();
bool m_updating;
OpenZWave::Options *m_options;
QString m_localConfigPath;
QString m_localUserPath;
};

#endif // QTOZWOPTIONS_P_H
1 change: 1 addition & 0 deletions qt-openzwave/source/qtopenzwave.cpp
Expand Up @@ -13,6 +13,7 @@ Q_LOGGING_CATEGORY(notifications, "ozw.notifications");
Q_LOGGING_CATEGORY(logModel, "ozw.logging");
Q_LOGGING_CATEGORY(libopenzwave, "ozw.library");
Q_LOGGING_CATEGORY(qtrowebsocket, "ozw.remote");
Q_LOGGING_CATEGORY(options, "ozw.options");


QTOpenZwave::QTOpenZwave
Expand Down
20 changes: 15 additions & 5 deletions qt-openzwave/source/qtozwmanager.cpp
Expand Up @@ -44,11 +44,18 @@

QTOZWManager::QTOZWManager(QObject *parent)
: QTOZWReplicaBase(ConnectionType::Type::Invalid, parent),
d_ptr_internal(nullptr),
d_ptr_replica(nullptr),
m_managerState(QRemoteObjectReplica::State::Uninitialized),
m_ozwoptions(nullptr),
m_optionsState(QRemoteObjectReplica::State::Uninitialized),
m_log(nullptr),
m_logState(QRemoteObjectReplica::State::Uninitialized),
m_nodeModel(nullptr),
m_nodeState(false),
m_valueModel(nullptr),
m_valuesState(false),
m_associationModel(nullptr),
m_associationsState(false),
m_running(false),
m_ozwconfigpath(""),
Expand Down Expand Up @@ -78,14 +85,12 @@ bool QTOZWManager::initilizeSource(bool enableServer) {

qCDebug(manager) << "Database Path: " << QFileInfo(this->m_ozwconfigpath.append("/")).absoluteFilePath() << " User Path" << QFileInfo(this->m_ozwuserpath.append("/")).absoluteFilePath();

OpenZWave::Options::Create(QFileInfo(this->m_ozwconfigpath.append("/")).absoluteFilePath().toStdString(), QFileInfo(this->m_ozwuserpath.append("/")).absoluteFilePath().toStdString(), "");

/* Initilize our QTOZWManager Class */

this->m_log = new QTOZWLog(ConnectionType::Type::Local, this);
connect(this, &QTOZWManager::readyChanged, this->m_log, &QTOZWLog::setReady);

this->m_ozwoptions = new QTOZWOptions(ConnectionType::Type::Local, this);
this->m_ozwoptions = new QTOZWOptions(ConnectionType::Type::Local, this->m_ozwconfigpath, this->m_ozwuserpath, this);
connect(this, &QTOZWManager::readyChanged, this->m_ozwoptions, &QTOZWOptions::setReady);

this->d_ptr_internal = new QTOZWManager_Internal(this);
Expand Down Expand Up @@ -216,7 +221,7 @@ bool QTOZWManager::initilizeReplica(QUrl remote) {
this->m_log = new QTOZWLog(ConnectionType::Type::Remote, this);
connect(this, &QTOZWManager::readyChanged, this->m_log, &QTOZWLog::setReady);

this->m_ozwoptions = new QTOZWOptions(ConnectionType::Type::Remote, this);
this->m_ozwoptions = new QTOZWOptions(ConnectionType::Type::Remote, QString(), QString(), this);
connect(this, &QTOZWManager::readyChanged, this->m_ozwoptions, &QTOZWOptions::setReady);

this->m_webSockClient = new QWebSocket();
Expand Down Expand Up @@ -432,7 +437,12 @@ QAbstractItemModel *QTOZWManager::getAssociationModel() {
}

QTOZWOptions *QTOZWManager::getOptions() {
return this->m_ozwoptions;
if (this->m_ozwoptions) {
return this->m_ozwoptions;
} else {
return this->m_ozwoptions = new QTOZWOptions(this->getConnectionType(), this->m_ozwconfigpath, this->m_ozwuserpath, this);
}

}

QTOZWLog *QTOZWManager::getLog() {
Expand Down
20 changes: 4 additions & 16 deletions qt-openzwave/source/qtozwmanager_p.cpp
Expand Up @@ -34,15 +34,6 @@ QTOZWManager_Internal::QTOZWManager_Internal(QObject *parent)
: QTOZWManagerSimpleSource (parent)
{
this->setObjectName("QTOZW_Manager");

try {
qCDebug(manager) << "OpenZWave Options Class Creating";
this->m_options = new QTOZWOptions_Internal(this);
qCDebug(manager) << "OpenZWave Options Class Set";
} catch (OpenZWave::OZWException &e) {
qCWarning(manager) << "Failed to Load Options Class" << QString(e.GetMsg().c_str());
return;
}
this->m_nodeModel = new QTOZW_Nodes_internal(this);
QObject::connect(this->m_nodeModel, &QTOZW_Nodes_internal::dataChanged, this, &QTOZWManager_Internal::pvt_nodeModelDataChanged);
this->m_valueModel = new QTOZW_ValueIds_internal(this);
Expand Down Expand Up @@ -451,11 +442,12 @@ QByteArray QTOZWManager_Internal::GetMetaDataProductPic(quint8 _node) {
if (!this->checkHomeId() || !this->checkNodeId(_node))
return QByteArray();
try {
this->m_options->GetOptionAsString("ConfigPath");
QString path(this->m_options->GetOptionAsString("ConfigPath"));
std::string ozwpath;
OpenZWave::Options::Get()->GetOptionAsString("ConfigPath", &ozwpath);
QString path(ozwpath.c_str());
path.append(QString::fromStdString(this->m_manager->GetMetaData(this->homeId(), _node, OpenZWave::Node::MetaDataFields::MetaData_ProductPic)));
qCDebug(manager) << "ProductPic Path: " << path;
if (path == this->m_options->GetOptionAsString("ConfigPath"))
if (path == QString(ozwpath.c_str()))
return QByteArray();
QFile file(path);
if (!file.open(QIODevice::ReadOnly)) return QByteArray();
Expand Down Expand Up @@ -1282,10 +1274,6 @@ QTOZW_Associations *QTOZWManager_Internal::getAssociationModel() {
return static_cast<QTOZW_Associations *>(this->m_associationsModel);
}

QTOZWOptions_Internal *QTOZWManager_Internal::getOptions() {
return this->m_options;
}

QTOZWLog_Internal *QTOZWManager_Internal::getLog() {
return this->m_log;
}
Expand Down
59 changes: 54 additions & 5 deletions qt-openzwave/source/qtozwoptions.cpp
Expand Up @@ -36,18 +36,28 @@
#define REP_PUBLIC_CLASS QTOZWOptions


QTOZWOptions::QTOZWOptions(ConnectionType::Type type, QObject *parent)
: QTOZWReplicaBase(type, parent)
QTOZWOptions::QTOZWOptions(ConnectionType::Type type, QString localConfigPath, QString localUserPath, QObject *parent)
: QTOZWReplicaBase(type, parent),
d_ptr_internal(nullptr),
d_ptr_replica(nullptr),
m_localConfigPath(localConfigPath),
m_localUserPath(localUserPath)
{
#ifndef Q_OS_WASM
if (this->getConnectionType() == ConnectionType::Type::Local) {
this->d_ptr_internal = new QTOZWOptions_Internal(this);
if ((this->getConnectionType() == ConnectionType::Type::Local) || (this->getConnectionType() == ConnectionType::Invalid)) {
if (this->getConnectionType() == ConnectionType::Type::Invalid)
this->setConnectionType(ConnectionType::Type::Local);
this->d_ptr_internal = new QTOZWOptions_Internal(m_localConfigPath, m_localUserPath, this);
connectSignals();
} else if (this->getConnectionType() == ConnectionType::Type::Remote) {
qDebug() << "Nothing to do till we connect";
qCDebug(options) << "Nothing to do till we connect";
}
#endif
}
QTOZWOptions::~QTOZWOptions() {
}



bool QTOZWOptions::initilizeBase() {
return true;
Expand All @@ -74,11 +84,50 @@ bool QTOZWOptions::initilizeReplica(QRemoteObjectNode *m_replicaNode) {
this->d_ptr_replica = m_replicaNode->acquire<QTOZWOptionsReplica>("QTOZWOptions");
QObject::connect(this->d_ptr_replica, &QTOZWOptionsReplica::stateChanged, this, &QTOZWOptions::onOptionStateChange);

disconnectSignals();

connectSignals();

return true;
}

void QTOZWOptions::disconnectSignals() {
DISCONNECT_DPTR(ConfigPathChanged);
DISCONNECT_DPTR(UserPathChanged);
DISCONNECT_DPTR(LoggingChanged);
DISCONNECT_DPTR(LogFileNameChanged);
DISCONNECT_DPTR(AppendLogFileChanged);
DISCONNECT_DPTR(ConsoleOutputChanged);
DISCONNECT_DPTR(SaveLogLevelChanged);
DISCONNECT_DPTR(QueueLogLevelChanged);
DISCONNECT_DPTR(DumpTriggerLevelChanged);
DISCONNECT_DPTR(AssociateChanged);
DISCONNECT_DPTR(ExcludeChanged);
DISCONNECT_DPTR(IncludeChanged);
DISCONNECT_DPTR(NotifyTransactionsChanged);
DISCONNECT_DPTR(InterfaceChanged);
DISCONNECT_DPTR(SaveConfigurationChanged);
DISCONNECT_DPTR(DriverMaxAttemptsChanged);
DISCONNECT_DPTR(PollIntervalChanged);
DISCONNECT_DPTR(IntervalBetweenPollsChanged);
DISCONNECT_DPTR(SuppressValueRefreshChanged);
DISCONNECT_DPTR(PerformReturnRoutesChanged);
DISCONNECT_DPTR(NetworkKeyChanged);
DISCONNECT_DPTR(RefreshAllUserCodesChanged);
DISCONNECT_DPTR(RetryTimeoutChanged);
DISCONNECT_DPTR(EnableSISChanged);
DISCONNECT_DPTR(AssumeAwakeChanged);
DISCONNECT_DPTR(NotifyOnDriverUnloadChanged);
DISCONNECT_DPTR(SecurityStrategyChanged);
DISCONNECT_DPTR(CustomSecuredCCChanged);
DISCONNECT_DPTR(EnforceSecureReceptionChanged);
DISCONNECT_DPTR(AutoUpdateConfigFileChanged);
DISCONNECT_DPTR(ReloadAfterUpdateChanged);
DISCONNECT_DPTR(LanguageChanged);
DISCONNECT_DPTR(IncludeInstanceLabelsChanged);

}

void QTOZWOptions::connectSignals() {
CONNECT_DPTR(ConfigPathChanged);
CONNECT_DPTR(UserPathChanged);
Expand Down
12 changes: 7 additions & 5 deletions qt-openzwave/source/qtozwoptions_p.cpp
Expand Up @@ -27,21 +27,23 @@

#include "qtozwoptions_p.h"
#include "platform/Log.h"
#include "qtozw_logging.h"


QTOZWOptions_Internal::QTOZWOptions_Internal(QObject *parent)
QTOZWOptions_Internal::QTOZWOptions_Internal(QString localConfigPath, QString localUserPath, QObject *parent)
: QTOZWOptionsSimpleSource (parent),
m_updating(false)
m_updating(false),
m_localConfigPath(localConfigPath),
m_localUserPath(localUserPath)
{
this->setObjectName("QTOZW_Options");

this->m_options = OpenZWave::Options::Get();
if (!this->m_options) {
/* Not Created...Bail Out*/
emit this->error(QTOZWOptionsErrorCodes::NoOptionClass);
return;
this->m_options = OpenZWave::Options::Create(QFileInfo(m_localConfigPath.append("/")).absoluteFilePath().toStdString(), QFileInfo(m_localUserPath.append("/")).absoluteFilePath().toStdString(), "");
}


this->populateProperties();

connect(this, &QTOZWOptionsSimpleSource::ConfigPathChanged, this, &QTOZWOptions_Internal::pvt_ConfigPathChanged);
Expand Down
3 changes: 0 additions & 3 deletions qt-openzwave/source/qtozwreplica.cpp
@@ -1,17 +1,14 @@
#include "qt-openzwave/qtozwreplica.h"
#include "qtozw_logging.h"


QTOZWReplicaBase::QTOZWReplicaBase(ConnectionType::Type connectionType, QObject *parent) :
QObject(parent),
m_connectionType(connectionType),
m_ready(false)
{

}
QTOZWReplicaBase::~QTOZWReplicaBase()
{

}

ConnectionType::Type QTOZWReplicaBase::getConnectionType() const
Expand Down

0 comments on commit dae38b6

Please sign in to comment.