fix caching the synced name
This commit is contained in:
parent
afcd034596
commit
038b5036e3
@ -46,6 +46,8 @@ AWSConnector::AWSConnector(QObject *parent) : QObject(parent)
|
|||||||
// awsiotsdk::util::Logging::InitializeAWSLogging(p_log_system);
|
// awsiotsdk::util::Logging::InitializeAWSLogging(p_log_system);
|
||||||
m_disconnectContextData = std::shared_ptr<awsiotsdk::DisconnectCallbackContextData>(new DisconnectContext(this));
|
m_disconnectContextData = std::shared_ptr<awsiotsdk::DisconnectCallbackContextData>(new DisconnectContext(this));
|
||||||
m_subscriptionContextData = std::shared_ptr<awsiotsdk::mqtt::SubscriptionHandlerContextData>(new SubscriptionContext(this));
|
m_subscriptionContextData = std::shared_ptr<awsiotsdk::mqtt::SubscriptionHandlerContextData>(new SubscriptionContext(this));
|
||||||
|
|
||||||
|
m_clientName = readSyncedNameCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
AWSConnector::~AWSConnector()
|
AWSConnector::~AWSConnector()
|
||||||
@ -179,7 +181,7 @@ void AWSConnector::onPairingsRetrieved(const QVariantList &pairings)
|
|||||||
}
|
}
|
||||||
subscribe(topics);
|
subscribe(topics);
|
||||||
|
|
||||||
if (!readNameSyncedFlag()) {
|
if (readSyncedNameCache() != m_clientName) {
|
||||||
setName();
|
setName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,7 +210,7 @@ void AWSConnector::setDeviceName(const QString &deviceName)
|
|||||||
{
|
{
|
||||||
if (m_clientName != deviceName) {
|
if (m_clientName != deviceName) {
|
||||||
m_clientName = deviceName;
|
m_clientName = deviceName;
|
||||||
storeNameSyncedFlag(false);
|
storeSyncedNameCache(QString());
|
||||||
if (isConnected()) {
|
if (isConnected()) {
|
||||||
setName();
|
setName();
|
||||||
}
|
}
|
||||||
@ -272,7 +274,7 @@ void AWSConnector::onDisconnected()
|
|||||||
if (needReRegistering) {
|
if (needReRegistering) {
|
||||||
qCDebug(dcAWS) << "Trying to reregister the device in the cloud";
|
qCDebug(dcAWS) << "Trying to reregister the device in the cloud";
|
||||||
storeRegisteredFlag(false);
|
storeRegisteredFlag(false);
|
||||||
storeNameSyncedFlag(false);
|
storeSyncedNameCache(QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_shouldReconnect) {
|
if (m_shouldReconnect) {
|
||||||
@ -411,7 +413,7 @@ ResponseCode AWSConnector::onSubscriptionReceivedCallback(util::String topic_nam
|
|||||||
} else if (topic == QString("%1/device/name/response").arg(connector->m_clientId)) {
|
} else if (topic == QString("%1/device/name/response").arg(connector->m_clientId)) {
|
||||||
qCDebug(dcAWS) << "Set device name in cloud with status:" << jsonDoc.toVariant().toMap().value("status").toInt();
|
qCDebug(dcAWS) << "Set device name in cloud with status:" << jsonDoc.toVariant().toMap().value("status").toInt();
|
||||||
if (jsonDoc.toVariant().toMap().value("status").toInt() == 200) {
|
if (jsonDoc.toVariant().toMap().value("status").toInt() == 200) {
|
||||||
connector->storeNameSyncedFlag(true);
|
connector->storeSyncedNameCache(connector->m_clientName);
|
||||||
}
|
}
|
||||||
} else if (topic.startsWith(QString("%1/eu-west-1:").arg(connector->m_clientId)) && !topic.contains("reply")) {
|
} else if (topic.startsWith(QString("%1/eu-west-1:").arg(connector->m_clientId)) && !topic.contains("reply")) {
|
||||||
static QStringList dupes;
|
static QStringList dupes;
|
||||||
@ -453,14 +455,14 @@ bool AWSConnector::readRegisteredFlag() const
|
|||||||
return settings.value("registered", false).toBool();
|
return settings.value("registered", false).toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AWSConnector::storeNameSyncedFlag(bool synced)
|
void AWSConnector::storeSyncedNameCache(const QString &syncedName)
|
||||||
{
|
{
|
||||||
QSettings settings(GuhSettings::storagePath() + "/cloudstatus.conf", QSettings::IniFormat);
|
QSettings settings(GuhSettings::storagePath() + "/cloudstatus.conf", QSettings::IniFormat);
|
||||||
settings.setValue("nameSynced", synced);
|
settings.setValue("syncedName", syncedName);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AWSConnector::readNameSyncedFlag()
|
QString AWSConnector::readSyncedNameCache()
|
||||||
{
|
{
|
||||||
QSettings settings(GuhSettings::storagePath() + "/cloudstatus.conf", QSettings::IniFormat);
|
QSettings settings(GuhSettings::storagePath() + "/cloudstatus.conf", QSettings::IniFormat);
|
||||||
return settings.value("nameSynced", false).toBool();
|
return settings.value("syncedName", QString()).toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -90,8 +90,8 @@ private:
|
|||||||
void storeRegisteredFlag(bool registered);
|
void storeRegisteredFlag(bool registered);
|
||||||
bool readRegisteredFlag() const;
|
bool readRegisteredFlag() const;
|
||||||
|
|
||||||
void storeNameSyncedFlag(bool synced);
|
void storeSyncedNameCache(const QString &syncedName);
|
||||||
bool readNameSyncedFlag();
|
QString readSyncedNameCache();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<awsiotsdk::network::MbedTLSConnection> m_networkConnection;
|
std::shared_ptr<awsiotsdk::network::MbedTLSConnection> m_networkConnection;
|
||||||
|
|||||||
Reference in New Issue
Block a user