mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
JNIHelpers: Add a mechanism for loading optional JNI classes
This commit is contained in:
parent
3d8a97c1c1
commit
2e5ecceea8
2 changed files with 19 additions and 3 deletions
|
|
@ -377,7 +377,6 @@ void JNIClassBase::initialise (JNIEnv* env, jobject context)
|
||||||
if (classRef == nullptr)
|
if (classRef == nullptr)
|
||||||
classRef = GlobalRefImpl { LocalRef { env->FindClass (classPath) } };
|
classRef = GlobalRefImpl { LocalRef { env->FindClass (classPath) } };
|
||||||
|
|
||||||
jassert (classRef != nullptr);
|
|
||||||
initialiseFields (env);
|
initialiseFields (env);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -246,7 +246,8 @@ public:
|
||||||
JNIClassBase (const char* classPath, int minSDK, const uint8* byteCode, size_t byteCodeSize);
|
JNIClassBase (const char* classPath, int minSDK, const uint8* byteCode, size_t byteCodeSize);
|
||||||
virtual ~JNIClassBase();
|
virtual ~JNIClassBase();
|
||||||
|
|
||||||
operator jclass() const noexcept { return classRef; }
|
jclass getJclass() const { return classRef; }
|
||||||
|
operator jclass() const noexcept { return getJclass(); }
|
||||||
|
|
||||||
static void initialiseAllClasses (JNIEnv*, jobject context);
|
static void initialiseAllClasses (JNIEnv*, jobject context);
|
||||||
static void releaseAllClasses (JNIEnv*);
|
static void releaseAllClasses (JNIEnv*);
|
||||||
|
|
@ -293,7 +294,7 @@ template <typename T, size_t N> constexpr auto numBytes (const T (&) [N]) { retu
|
||||||
#define DECLARE_JNI_FIELD(fieldID, stringName, signature) jfieldID fieldID;
|
#define DECLARE_JNI_FIELD(fieldID, stringName, signature) jfieldID fieldID;
|
||||||
#define DECLARE_JNI_CALLBACK(fieldID, stringName, signature)
|
#define DECLARE_JNI_CALLBACK(fieldID, stringName, signature)
|
||||||
|
|
||||||
#define DECLARE_JNI_CLASS_WITH_BYTECODE(CppClassName, javaPath, minSDK, byteCodeData) \
|
#define DECLARE_OPTIONAL_JNI_CLASS_WITH_BYTECODE(CppClassName, javaPath, minSDK, byteCodeData, allowFailure) \
|
||||||
static_assert (minSDK >= 24, "There's no need to supply a min SDK lower than JUCE's minimum requirement"); \
|
static_assert (minSDK >= 24, "There's no need to supply a min SDK lower than JUCE's minimum requirement"); \
|
||||||
class CppClassName ## _Class : public JNIClassBase \
|
class CppClassName ## _Class : public JNIClassBase \
|
||||||
{ \
|
{ \
|
||||||
|
|
@ -302,6 +303,19 @@ template <typename T, size_t N> constexpr auto numBytes (const T (&) [N]) { retu
|
||||||
\
|
\
|
||||||
void initialiseFields (JNIEnv* env) \
|
void initialiseFields (JNIEnv* env) \
|
||||||
{ \
|
{ \
|
||||||
|
if constexpr (allowFailure) \
|
||||||
|
{ \
|
||||||
|
if (getJclass() == nullptr) \
|
||||||
|
{ \
|
||||||
|
env->ExceptionClear(); \
|
||||||
|
return; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
{ \
|
||||||
|
jassert (getJclass() != nullptr); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
Array<JNINativeMethod> callbacks; \
|
Array<JNINativeMethod> callbacks; \
|
||||||
JNI_CLASS_MEMBERS (CREATE_JNI_METHOD, CREATE_JNI_STATICMETHOD, CREATE_JNI_FIELD, CREATE_JNI_STATICFIELD, CREATE_JNI_CALLBACK); \
|
JNI_CLASS_MEMBERS (CREATE_JNI_METHOD, CREATE_JNI_STATICMETHOD, CREATE_JNI_FIELD, CREATE_JNI_STATICFIELD, CREATE_JNI_CALLBACK); \
|
||||||
resolveCallbacks (env, callbacks); \
|
resolveCallbacks (env, callbacks); \
|
||||||
|
|
@ -311,6 +325,9 @@ template <typename T, size_t N> constexpr auto numBytes (const T (&) [N]) { retu
|
||||||
}; \
|
}; \
|
||||||
static inline const CppClassName ## _Class CppClassName;
|
static inline const CppClassName ## _Class CppClassName;
|
||||||
|
|
||||||
|
#define DECLARE_JNI_CLASS_WITH_BYTECODE(CppClassName, javaPath, minSDK, byteCodeData) \
|
||||||
|
DECLARE_OPTIONAL_JNI_CLASS_WITH_BYTECODE (CppClassName, javaPath, minSDK, byteCodeData, false) \
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
#define DECLARE_JNI_CLASS_WITH_MIN_SDK(CppClassName, javaPath, minSDK) \
|
#define DECLARE_JNI_CLASS_WITH_MIN_SDK(CppClassName, javaPath, minSDK) \
|
||||||
DECLARE_JNI_CLASS_WITH_BYTECODE (CppClassName, javaPath, minSDK, nullptr)
|
DECLARE_JNI_CLASS_WITH_BYTECODE (CppClassName, javaPath, minSDK, nullptr)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue