From 4870212610b467e6fca26639b8fb129c04f300dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Fri, 18 Jun 2021 10:45:11 +0800 Subject: Hide icclient types away from the interface --- client.cxx | 36 ++++++++++++++++++------------------ qicclient.hxx | 7 +++++-- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/client.cxx b/client.cxx index 7932ac8..c4e574b 100644 --- a/client.cxx +++ b/client.cxx @@ -4,19 +4,21 @@ #include "qicclient.hxx" #include "qicclient/ord.hxx" -static QICClient::Client* client; +namespace QICClient { -static void responseHandler(icclient_response* response) -{ - client->emitResponse(response); -} + static Client* client; -static void catalogCallback(icclient_catalog* catalog) -{ - client->emitCatalog(catalog); -} + static void resultsHandler(icclient_response* response) + { + client->emitResults(QString{response->data}); + icclient_free_response(response); + } -namespace QICClient { + static void catalogCallback(icclient_catalog* catalog) + { + client->emitCatalog(new Catalog{catalog}); + icclient_free_catalog(catalog); + } Client::Client(char const* sampleURL, char const* image_Dir, char const* certificate) { @@ -31,12 +33,12 @@ namespace QICClient { void Client::results(QString const& prodGroup) { - icclient_results(prodGroup.toLatin1().constData(), responseHandler, nullptr); + icclient_results(prodGroup.toLatin1().constData(), resultsHandler, nullptr); } void Client::allProducts() { - icclient_allproducts(responseHandler, nullptr); + icclient_allproducts(resultsHandler, nullptr); } void Client::strapResults(QString const& prodGroup) @@ -49,16 +51,14 @@ namespace QICClient { icclient_allproducts(nullptr, catalogCallback); } - void Client::emitResponse(icclient_response* response) + void Client::emitResults(QString const& results) { - emit gotResults(QString{response->data}); - icclient_free_response(response); + emit gotResults(results); } - void Client::emitCatalog(icclient_catalog* catalog) + void Client::emitCatalog(Catalog* catalog) { - emit gotCatalog(new Catalog{catalog}); - icclient_free_catalog(catalog); + emit gotCatalog(catalog); } void Client::flyPage(QString const& sku,void (*handler)(icclient_response*)) diff --git a/qicclient.hxx b/qicclient.hxx index df9da45..3b7f0d5 100644 --- a/qicclient.hxx +++ b/qicclient.hxx @@ -22,9 +22,10 @@ namespace QICClient { * \param certificate Path to the CA certificate file. */ Client(char const* sampleURL, char const* image_Dir, char const* certificate = nullptr); + /*! + * \brief Destructor. + */ ~Client(); - void emitResponse(icclient_response* response); - void emitCatalog(icclient_catalog* catalog); /*! * \brief For fetching data about a specific product. * \param sku The SKU of the item to order. @@ -38,6 +39,8 @@ namespace QICClient { * \param order The order. */ void order(QString const& sku, Catalog const& catalog, Ord& order); + void emitResults(QString const& response); + void emitCatalog(Catalog* catalog); public slots: /*! -- cgit v1.2.3