QAfbWebsocketClient: Allows null callback (FIX) 30/21630/1 7.99.2 7.99.3 8.0.0 8.0.1 8.0.2 halibut/7.99.2 halibut/7.99.3 halibut/8.0.0 halibut/8.0.1 halibut/8.0.2 halibut_7.99.2 halibut_7.99.3 halibut_8.0.0 halibut_8.0.1 halibut_8.0.2
authorJosé Bollo <jose.bollo@iot.bzh>
Thu, 13 Jun 2019 14:12:22 +0000 (16:12 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Thu, 13 Jun 2019 14:12:22 +0000 (16:12 +0200)
Don't passing a callback is a valid model.
But the library should not crash in that case.
This fix the uissue.

Bug-AGL: SPEC-2520

Change-Id: I6e6f3e6b617cfcf251ac910db5fa27832c2713a1
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
qafbwebsocketclient.cpp

index 0cbc274..c0e5e71 100644 (file)
@@ -85,8 +85,9 @@ void QAfbWebsocketClient::close()
  */
 void QAfbWebsocketClient::call(const QString& api, const QString& verb, const QJsonValue& arg, closure_t closure)
 {
-    QString callId = QString::number(m_nextCallId);
-    m_closures[callId] = closure;
+    QString callId = QString::number(m_nextCallId++);
+    if (closure)
+        m_closures[callId] = closure;
 
     QJsonArray msg;
     msg.append(2); // Call
@@ -94,8 +95,6 @@ void QAfbWebsocketClient::call(const QString& api, const QString& verb, const QJ
     msg.append(api + "/" + verb);
     msg.append(arg);
 
-    m_nextCallId++;
-
     QJsonDocument value;
     value.setArray(msg);