From 6334496c8cb8ebb652fd48395487964edbcdfb69 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 2 Feb 2018 16:51:08 +0100 Subject: [PATCH] update endpoints when a device is paired on the fly --- libguh-core/awsconnector.cpp | 11 +++++++++++ libguh-core/awsconnector.h | 4 +++- libguh-core/cloudnotifications.cpp | 14 +++++++++++++- libguh-core/cloudnotifications.h | 1 + 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/libguh-core/awsconnector.cpp b/libguh-core/awsconnector.cpp index 8546aafe..22bbd8f7 100644 --- a/libguh-core/awsconnector.cpp +++ b/libguh-core/awsconnector.cpp @@ -47,6 +47,7 @@ AWSConnector::AWSConnector(QObject *parent) : QObject(parent) m_disconnectContextData = std::shared_ptr(new DisconnectContext(this)); m_subscriptionContextData = std::shared_ptr(new SubscriptionContext(this)); + qRegisterMetaType(); m_clientName = readSyncedNameCache(); } @@ -160,6 +161,7 @@ void AWSConnector::setupSubscriptions() subscriptions.append(QString("%1/device/users/response").arg(m_clientId)); subscriptions.append(QString("%1/pair/response").arg(m_clientId)); subscriptions.append(QString("%1/notify/response").arg(m_clientId)); + subscriptions.append(QString("%1/notify/info/endpoint").arg(m_clientId)); subscribe(subscriptions); // fetch previous pairings @@ -475,6 +477,15 @@ ResponseCode AWSConnector::onSubscriptionReceivedCallback(util::String topic_nam int status = jsonDoc.toVariant().toMap().value("status").toInt(); qCDebug(dcAWS()) << "Push notification reply for transaction" << transactionId << " Status:" << status << jsonDoc.toVariant().toMap().value("message").toString(); emit connector->pushNotificationSent(transactionId, status); + } else if (topic == QString("%1/notify/info/endpoint").arg(connector->m_clientId)) { + QVariantMap endpoint = jsonDoc.toVariant().toMap().value("newPushNotificationsEndpoint").toMap(); + Q_ASSERT(endpoint.keys().count() == 1); + QString cognitoId = endpoint.keys().first(); + PushNotificationsEndpoint ep; + ep.userId = cognitoId; + ep.endpointId = endpoint.value(cognitoId).toMap().value("endpointId").toString(); + ep.displayName = endpoint.value(cognitoId).toMap().value("displayName").toString(); + emit connector->pushNotificationEndpointAdded(ep); } else { qCWarning(dcAWS) << "Unhandled subscription received!" << topic << QString::fromStdString(payload); } diff --git a/libguh-core/awsconnector.h b/libguh-core/awsconnector.h index 810868ae..c9280827 100644 --- a/libguh-core/awsconnector.h +++ b/libguh-core/awsconnector.h @@ -63,7 +63,8 @@ signals: void disconnected(); void devicePaired(const QString &cognritoUserId, int errorCode, const QString &message); void webRtcHandshakeMessageReceived(const QString &transactionId, const QVariantMap &data); - void pushNotificationEndpointsUpdated(const QList pushNotificationEndpoints); + void pushNotificationEndpointsUpdated(const QList pushNotificationEndpoints); + void pushNotificationEndpointAdded(const AWSConnector::PushNotificationsEndpoint &pushNotificationEndpoint); void pushNotificationSent(int id, int status); private slots: @@ -134,5 +135,6 @@ private: static AWSConnector* s_instance; static QHash s_requestMap; }; +Q_DECLARE_METATYPE(AWSConnector::PushNotificationsEndpoint) #endif // AWSCONNECTOR_H diff --git a/libguh-core/cloudnotifications.cpp b/libguh-core/cloudnotifications.cpp index 69025177..efafe263 100644 --- a/libguh-core/cloudnotifications.cpp +++ b/libguh-core/cloudnotifications.cpp @@ -38,6 +38,7 @@ CloudNotifications::CloudNotifications(AWSConnector* awsConnector, QObject *pare m_awsConnector(awsConnector) { connect(m_awsConnector, &AWSConnector::pushNotificationEndpointsUpdated, this, &CloudNotifications::pushNotificationEndpointsUpdated); + connect(m_awsConnector, &AWSConnector::pushNotificationEndpointAdded, this, &CloudNotifications::pushNotificationEndpointAdded); connect(m_awsConnector, &AWSConnector::pushNotificationSent, this, &CloudNotifications::pushNotificationSent); } @@ -135,7 +136,6 @@ QJsonObject CloudNotifications::metaData() const DeviceManager::DeviceSetupStatus CloudNotifications::setupDevice(Device *device) { - qWarning() << "--------------------------------------------------------------------- setupDevice" << device->id() << device->name(); Q_UNUSED(device) return DeviceManager::DeviceSetupStatusSuccess; } @@ -201,6 +201,18 @@ void CloudNotifications::pushNotificationEndpointsUpdated(const QList &endpoints); + void pushNotificationEndpointAdded(const AWSConnector::PushNotificationsEndpoint &endpoint); void pushNotificationSent(int id, int status); private: