aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Chu <ryan.chu@qt.io>2018-06-15 09:38:33 +0200
committerRyan Chu <ryan.chu@qt.io>2018-06-15 19:48:11 +0000
commit7a5d72b2c59a157305c139b54cdb09c34d99e727 (patch)
tree2963fa0e7850fedda5c46d55c374dbeb93ba0cfe
parentd870b6d262a2f22ca7793c6336717bd5101e8fc7 (diff)
Return error status to inform the user when client registration fails
When connecting a client id to the Kaltiot-service provider fails, the error status of Kaltiot SDK should be returned to the user application. So I rework some functions and return the error status from the Kaltiot library to the user application. To prevent memory leak, the new client instance should be saved when connecting the client to a provider, and then released when removing the client. Change-Id: I1e6248882a400cfcca78af5f1151cc61b6c954ed Reviewed-by: Ryan Chu <ryan.chu@qt.io> Reviewed-by: Ari Salmi <snowgrains@snowgrains.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
-rw-r--r--src/cloudmessaging/qcloudmessagingprovider.cpp10
-rw-r--r--src/cloudmessagingembeddedkaltiot/qcloudmessagingembeddedkaltiotclient.cpp16
-rw-r--r--src/cloudmessagingembeddedkaltiot/qcloudmessagingembeddedkaltiotclient.h2
3 files changed, 12 insertions, 16 deletions
diff --git a/src/cloudmessaging/qcloudmessagingprovider.cpp b/src/cloudmessaging/qcloudmessagingprovider.cpp
index 0c276d4..18f159c 100644
--- a/src/cloudmessaging/qcloudmessagingprovider.cpp
+++ b/src/cloudmessaging/qcloudmessagingprovider.cpp
@@ -138,14 +138,11 @@ QString QCloudMessagingProvider::connectClientToProvider(const QString &clientId
connect(serviceClient, &QCloudMessagingClient::clientStateChanged,
this, &QCloudMessagingProvider::clientStateChanged);
- serviceClient->connectClient(clientId, parameters);
-
d->m_QtCloudMessagingClients.insert(clientId, serviceClient);
- return clientId;
+ return serviceClient->connectClient(clientId, parameters);
}
}
-
return QString();
}
@@ -195,13 +192,10 @@ void QCloudMessagingProvider::disconnectClient(const QString &clientId,
bool QCloudMessagingProvider::removeClient(const QString &clientId)
{
if (!d->m_providerId.isEmpty() && d->m_QtCloudMessagingClients[clientId]) {
-
disconnectClient(clientId);
- d->m_QtCloudMessagingClients.remove(clientId);
-
+ delete d->m_QtCloudMessagingClients.take(clientId);
return true;
}
-
return false;
}
diff --git a/src/cloudmessagingembeddedkaltiot/qcloudmessagingembeddedkaltiotclient.cpp b/src/cloudmessagingembeddedkaltiot/qcloudmessagingembeddedkaltiotclient.cpp
index c1325dd..6a239b7 100644
--- a/src/cloudmessagingembeddedkaltiot/qcloudmessagingembeddedkaltiotclient.cpp
+++ b/src/cloudmessagingembeddedkaltiot/qcloudmessagingembeddedkaltiotclient.cpp
@@ -84,7 +84,7 @@ QString QCloudMessagingEmbeddedKaltiotClient::connectClient(const QString &clien
for (int i = 0; i < channels.count(); i++) {
bool new_channel = true;
- for (int j = 0; i < d->m_channels.count(); j++) {
+ for (int j = 0; j < d->m_channels.count(); j++) {
if (channels[i] == d->m_channels[j])
new_channel = false;
}
@@ -94,7 +94,10 @@ QString QCloudMessagingEmbeddedKaltiotClient::connectClient(const QString &clien
}
setClientToken(clientId);
- make_kaltiot_client_registration();
+
+ if (!make_kaltiot_client_registration())
+ return QString();
+
runBackgroundThread();
return d->m_address;
}
@@ -124,7 +127,7 @@ void QCloudMessagingEmbeddedKaltiotClient::runBackgroundThread()
/*!
* \brief QCloudMessagingEmbeddedKaltiotClient::make_kaltiot_client_registration
*/
-void QCloudMessagingEmbeddedKaltiotClient::make_kaltiot_client_registration()
+bool QCloudMessagingEmbeddedKaltiotClient::make_kaltiot_client_registration()
{
#ifdef EMBEDDED_AND_DESKTOP_OS
@@ -140,10 +143,8 @@ void QCloudMessagingEmbeddedKaltiotClient::make_kaltiot_client_registration()
ks_gw_client_init(&d->m_kaltiot_client_instance);
- if (!ks_gw_client_connect(&d->m_kaltiot_client_instance, NULL)) {
- // Failed to connect!;
- return;
- }
+ if (!ks_gw_client_connect(&d->m_kaltiot_client_instance, NULL))
+ return false; // Failed to connect!;
if (d->m_rid.isEmpty()) {
d->m_rid = d->m_client_settings.value("clients/" + d->m_address + "/rid").toString();
@@ -182,6 +183,7 @@ void QCloudMessagingEmbeddedKaltiotClient::make_kaltiot_client_registration()
setClientToken(d->m_rid);
#endif
+ return true;
}
/*!
diff --git a/src/cloudmessagingembeddedkaltiot/qcloudmessagingembeddedkaltiotclient.h b/src/cloudmessagingembeddedkaltiot/qcloudmessagingembeddedkaltiotclient.h
index e592efa..1584c38 100644
--- a/src/cloudmessagingembeddedkaltiot/qcloudmessagingembeddedkaltiotclient.h
+++ b/src/cloudmessagingembeddedkaltiot/qcloudmessagingembeddedkaltiotclient.h
@@ -83,7 +83,7 @@ public:
ks_gw_client_instance_t *getKaltiotEngineInstance();
private:
- void make_kaltiot_client_registration();
+ bool make_kaltiot_client_registration();
void runBackgroundThread();
QScopedPointer<QCloudMessagingEmbeddedKaltiotClientPrivate> d;