diff options
author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-06-10 18:34:21 +0800 |
---|---|---|
committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-06-10 18:34:21 +0800 |
commit | 5dfc6c0c97686ff01539fdf9548678fa507c5167 (patch) | |
tree | 7fe8694bbc01ff46e62ab7297d1ff566195e877e | |
parent | d9451494b1bdf20d2a434154e70c53e56639f5bc (diff) |
Anticipate asynchronous data fetch
-rw-r--r-- | client.cxx | 21 | ||||
-rw-r--r-- | qicclient/client.hxx | 2 |
2 files changed, 19 insertions, 4 deletions
@@ -2,6 +2,7 @@ #include <memory> #include <QObject> #include <icclient/typedefs.h> +#include <icclient/catalog.h> #include <icclient/client.h> #include "qicclient/catalog.hxx" #ifndef __EMSCRIPTEN__ @@ -9,10 +10,19 @@ #endif #include "qicclient/client.hxx" +static QICClient::Client *client; + +static void callback(icclient_catalog* catalog) +{ + client->emitCatalog(catalog); + icclient_catalog_free(catalog); +} + namespace QICClient { Client::Client(char const* url, char const* certificate) { + client = this; icclient_init(url, certificate); } @@ -24,15 +34,18 @@ namespace QICClient { void Client::results(QString const& prodGroup, icclient_handler handler) { icclient_catalog* catalog = nullptr; - icclient_results(prodGroup.toLatin1().constData(), handler, &catalog); - if (catalog) emit gotResults(new Catalog{catalog}); + icclient_results(prodGroup.toLatin1().constData(), callback, &catalog, handler); } void Client::allProducts(icclient_handler handler) { icclient_catalog* catalog = nullptr; - icclient_allproducts(handler, &catalog); - if (catalog) emit gotResults(new Catalog{catalog}); + icclient_allproducts(callback, &catalog, handler); + } + + void Client::emitCatalog(icclient_catalog* catalog) + { + emit gotResults(new Catalog{catalog}); } void Client::flyPage(QString const& sku,icclient_handler handler) diff --git a/qicclient/client.hxx b/qicclient/client.hxx index dfe1888..d508b16 100644 --- a/qicclient/client.hxx +++ b/qicclient/client.hxx @@ -38,6 +38,8 @@ namespace QICClient { */ void allProducts(icclient_handler handler); + void emitCatalog(icclient_catalog *catalog); + /*! * \brief For fetching data about a specific product. * \param sku The SKU of the item to order. |