diff options
| author | Erik Prabowo Kamal <erik@darapsa.co.id> | 2019-08-23 15:36:18 +0800 | 
|---|---|---|
| committer | Erik Prabowo Kamal <erik@darapsa.co.id> | 2019-08-23 15:36:18 +0800 | 
| commit | f14878b05ee885f1747feab256011b4da72ae778 (patch) | |
| tree | e9415590ecccaa1fe30b20a49f418990d650302f | |
| parent | c592064dda137e81cee7a421bb68fa83535542bd (diff) | |
Started to use cURL
| -rw-r--r-- | kelakon.pro | 11 | ||||
| -rw-r--r-- | main.cxx | 10 | ||||
| -rw-r--r-- | networkworker.cxx | 16 | ||||
| -rw-r--r-- | networkworker.hxx | 17 | ||||
| -rw-r--r-- | rtclient.c | 33 | ||||
| -rw-r--r-- | rtclient.h | 15 | 
6 files changed, 101 insertions, 1 deletions
| diff --git a/kelakon.pro b/kelakon.pro index fb0d403..e0e0d89 100644 --- a/kelakon.pro +++ b/kelakon.pro @@ -1,6 +1,15 @@  QT += quickcontrols2 +HEADERS += \ +	rtclient.h \ +	networkworker.hxx +  SOURCES += \ -    main.cxx +	rtclient.c \ +	networkworker.cxx \ +	main.cxx  RESOURCES += kelakon.qrc + +LIBS += \ +	-lcurl @@ -1,11 +1,21 @@  #include <QGuiApplication>  #include <QQmlApplicationEngine> +#include <QThread> +#include "networkworker.hxx"  int main(int argc, char* argv[])  {  	QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);  	QGuiApplication app(argc, argv);  	QQmlApplicationEngine engine; + +	Kelakon::NetworkWorker worker{}; +	QThread thread; +	worker.moveToThread(&thread); +  	engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + +	thread.start(); +  	return app.exec();  } diff --git a/networkworker.cxx b/networkworker.cxx new file mode 100644 index 0000000..928e4e8 --- /dev/null +++ b/networkworker.cxx @@ -0,0 +1,16 @@ +#include "rtclient.h" +#include "networkworker.hxx" + +namespace Kelakon { + +	NetworkWorker::NetworkWorker(QObject* parent) +		: QObject{parent} +	{ +		rtclient_init(); +	} + +	NetworkWorker::~NetworkWorker() +	{ +		rtclient_cleanup(); +	} +} diff --git a/networkworker.hxx b/networkworker.hxx new file mode 100644 index 0000000..c08743f --- /dev/null +++ b/networkworker.hxx @@ -0,0 +1,17 @@ +#ifndef NETWORKWORKER_HXX +#define NETWORKWORKER_HXX + +#include <QObject> + +namespace Kelakon { + +	class NetworkWorker : public QObject +	{ +		Q_OBJECT +		public: +			explicit NetworkWorker(QObject* parent = Q_NULLPTR); +			virtual ~NetworkWorker(); +	}; +} + +#endif // NETWORKWORKER_HXX diff --git a/rtclient.c b/rtclient.c new file mode 100644 index 0000000..1be0579 --- /dev/null +++ b/rtclient.c @@ -0,0 +1,33 @@ +#ifdef DEBUG +#ifdef ANDROID +#include <android/log.h> +#else +#include <stdio.h> +#endif // ANDROID +#endif // DEBUG +#include <stdbool.h> +#include <curl/curl.h> +#include "rtclient.h" + +static CURL *handle = NULL; + +bool rtclient_init() +{ +	curl_global_init(CURL_GLOBAL_SSL); +	handle = curl_easy_init(); +	if (handle) { +		curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1L); +#ifdef DEBUG +		curl_easy_setopt(handle, CURLOPT_VERBOSE, 1L); +#endif +	} + +	return (bool)handle; +} + +void rtclient_cleanup() +{ +	if (handle) +		curl_easy_cleanup(handle); +	curl_global_cleanup(); +} diff --git a/rtclient.h b/rtclient.h new file mode 100644 index 0000000..53b8a51 --- /dev/null +++ b/rtclient.h @@ -0,0 +1,15 @@ +#ifndef RTCLIENT_H +#define RTCLIENT_H + +#ifdef __cplusplus +extern "C" { +#endif + +	bool rtclient_init(); +	void rtclient_cleanup(); + +#ifdef __cplusplus +} +#endif + +#endif // RTCLIENT_H |