From c829c6f8fe1b3ff5f7e100f2431f3ecba784d5b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Fran=C4=8De=C5=A1kin?= Date: Thu, 16 May 2019 10:06:09 +0200 Subject: [PATCH] Set Android Joystick native methods from JNI_OnLoad --- src/Joystick/JoystickAndroid.cc | 8 ++------ src/Joystick/JoystickAndroid.h | 4 ++-- src/main.cc | 9 +++++++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Joystick/JoystickAndroid.cc b/src/Joystick/JoystickAndroid.cc index 19fc10639..7f77b7983 100644 --- a/src/Joystick/JoystickAndroid.cc +++ b/src/Joystick/JoystickAndroid.cc @@ -211,9 +211,7 @@ static JoystickManager *_manager = nullptr; //helper method bool JoystickAndroid::init(JoystickManager *manager) { - if (_manager == nullptr) { - setNativeMethods(manager); - } + _manager = manager; //this gets list of all possible buttons - this is needed to check how many buttons our gamepad supports //instead of the whole logic below we could have just a simple array of hardcoded int values as these 'should' not change @@ -267,12 +265,10 @@ static void jniUpdateAvailableJoysticks(JNIEnv *envA, jobject thizA) } } -void JoystickAndroid::setNativeMethods(JoystickManager *manager) +void JoystickAndroid::setNativeMethods() { qCDebug(JoystickLog) << "Registering Native Functions"; - _manager = manager; - // REGISTER THE C++ FUNCTION WITH JNI JNINativeMethod javaMethods[] { {"nativeUpdateAvailableJoysticks", "()V", reinterpret_cast(jniUpdateAvailableJoysticks)} diff --git a/src/Joystick/JoystickAndroid.h b/src/Joystick/JoystickAndroid.h index 329194ed6..1a0afbdf1 100644 --- a/src/Joystick/JoystickAndroid.h +++ b/src/Joystick/JoystickAndroid.h @@ -21,14 +21,14 @@ public: static bool init(JoystickManager *manager); + static void setNativeMethods(); + static QMap discover(MultiVehicleManager* _multiVehicleManager); private: bool handleKeyEvent(jobject event); bool handleGenericMotionEvent(jobject event); - static void setNativeMethods(JoystickManager *manager); - virtual bool _open(); virtual void _close(); virtual bool _update(); diff --git a/src/main.cc b/src/main.cc index 62012d36c..003c06f96 100644 --- a/src/main.cc +++ b/src/main.cc @@ -78,9 +78,12 @@ int WindowsCrtReportHook(int reportType, char* message, int* returnValue) #endif -#if defined(__android__) && !defined(NO_SERIAL_LINK) +#if defined(__android__) #include +#include "JoystickAndroid.h" +#if !defined(NO_SERIAL_LINK) #include "qserialport.h" +#endif jint JNI_OnLoad(JavaVM* vm, void* reserved) { @@ -90,8 +93,10 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6) != JNI_OK) { return -1; } - + #if !defined(NO_SERIAL_LINK) QSerialPort::setNativeMethods(); + #endif + JoystickAndroid::setNativeMethods(); return JNI_VERSION_1_6; } -- 2.22.0