Skip to content

AUI_JNI_STATIC_METHOD#

Defines static method C++ -> Java.

Header:#include <AUI/JNI/AJni.h>
CMake:aui_link(my_target PUBLIC aui::core)

Definition#

#define AUI_JNI_STATIC_METHOD(ret_t, name, args) \
    static ret_t name (AUI_PP_FOR_EACH(AUI_JNI_INTERNAL_OMIT_BRACES, _, args)) { \
        static_assert(::aui::jni::convertible<ret_t>, "return type is required to be convertible"); \
        auto clazz = getClass();                 \
        auto e = ::aui::jni::env();              \
        const char* signature = ::aui::jni::signature_v<ret_t (AUI_PP_FOR_EACH(AUI_JNI_INTERNAL_OMIT_BRACES, _, args))>; \
        static auto methodId = e->GetStaticMethodID(clazz, #name, signature);    \
        if (methodId == 0) {                          \
            throw AException("no such static jni method: {} {}"_format(#name, signature)); \
        }                                         \
        return ::aui::jni::callStaticMethod<ret_t>(clazz, methodId AUI_PP_FOR_EACH(AUI_JNI_INTERNAL_OMIT_BRACES_CONTENTS, _, args)); \
    }

Detailed Description#

Usage:

namespace com::github::aui::android {
    AUI_JNI_CLASS(com/github/aui/android/Platform, Platform) {  // required for AUI_JNI_STATIC_METHOD
    public:
        AUI_JNI_STATIC_METHOD(float, getDpiRatio, ())
        AUI_JNI_STATIC_METHOD(void, openUrl, ((const AString&) url))
        AUI_JNI_STATIC_METHOD(void, test, ((int) x, (int) y))
    };
}
..
com::github::aui::android::Platform::getClassName() -> "com/github/aui/android/Platform"