summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kelakon.pro29
-rw-r--r--main.cxx10
-rw-r--r--networkworker.cxx16
-rw-r--r--networkworker.hxx17
-rw-r--r--rtclient.c33
-rw-r--r--rtclient.h15
6 files changed, 119 insertions, 1 deletions
diff --git a/kelakon.pro b/kelakon.pro
index cbd9221..c91ba3e 100644
--- a/kelakon.pro
+++ b/kelakon.pro
@@ -1,10 +1,37 @@
QT += quickcontrols2
+HEADERS += \
+ rtclient.h \
+ networkworker.hxx
+
SOURCES += \
- main.cxx
+ rtclient.c \
+ networkworker.cxx \
+ main.cxx
RESOURCES += kelakon.qrc
+LIBS += \
+ -lcurl
+
+contains(ANDROID_TARGET_ARCH,arm64-v8a) {
+ QMAKE_CFLAGS += -I/usr/local/aarch64-linux-android/sysroot/usr/include
+ LIBS += -L/usr/local/aarch64-linux-android/sysroot/usr/lib
+ ANDROID_EXTRA_LIBS += \
+ /usr/local/aarch64-linux-android/sysroot/usr/lib/libcrypto.so \
+ /usr/local/aarch64-linux-android/sysroot/usr/lib/libssl.so \
+ /usr/local/aarch64-linux-android/sysroot/usr/lib/libcurl.so
+}
+
+contains(ANDROID_TARGET_ARCH,armeabi-v7a) {
+ QMAKE_CFLAGS += -I/usr/local/arm-linux-androideabi/sysroot/usr/include
+ LIBS += -L/usr/local/arm-linux-androideabi/sysroot/usr/lib
+ ANDROID_EXTRA_LIBS += \
+ /usr/local/arm-linux-androideabi/sysroot/usr/lib/libcrypto.so \
+ /usr/local/arm-linux-androideabi/sysroot/usr/lib/libssl.so \
+ /usr/local/arm-linux-androideabi/sysroot/usr/lib/libcurl.so
+}
+
android {
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
}
diff --git a/main.cxx b/main.cxx
index 94f8599..0108135 100644
--- a/main.cxx
+++ b/main.cxx
@@ -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