AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
aui::jni

C++/Java bridge. More...

Detailed Description#

Used to make AUI work on Android.

Classes#

class  aui::jni::ArrayView< T >
 Java array view. More...
 
class  aui::jni::GlobalRef
 Global ref. More...
 

Macros#

#define AUI_JNI_CLASS(path, name)
 Defines getClassName and other useful methods required for Java class definition.
 
#define AUI_JNI_STATIC_METHOD(ret_t, name, args)
 Defines static method C++ -> Java.
 
#define AUI_JNI_METHOD(ret_t, name, args)
 Defines nonstatic method C++ -> Java.
 

Macro Definition Documentation#

◆ AUI_JNI_CLASS#

#define AUI_JNI_CLASS ( path,
name )
Value:
class name ## _info: public ::aui::jni::GlobalRef { \
public:                           \
    static constexpr auto JAVA_CLASS_NAME = #path ## _asl;                        \
    [[nodiscard]] static constexpr auto getClassName() noexcept { return #path; } \
    [[nodiscard]] static auto getClass() noexcept { static ::aui::jni::GlobalRef t = ::aui::jni::env()->FindClass(getClassName()); AUI_ASSERTX(t.asClass() != nullptr, "no such class: " #path); return t.asClass(); } \
                                      \
};                                \
struct name: public name ## _info
Global ref.
Definition GlobalRef.h:23
JNIEnv * env()
Definition Globals.h:38
AString name(T *v)
Runtime reflection based on typeid.
Definition AReflect.h:29
#define AUI_ASSERTX(condition, what)
Asserts that the passed condition evaluates to true. Adds extra message string.
Definition Assert.h:74
Parameters
namename of cpp class
pathslash-style path to Java class (including name)

Usage:

namespace com::github::aui::android {
    AUI_JNI_CLASS(com/github/aui/android/Platform, AUI) {
    public:
        // class definition
        AUI_JNI_STATIC_METHOD(void, callStaticMethod, ())
        AUI_JNI_METHOD(void, CallNonStaticMethod, ())
    };
}
..
com::github::aui::android::Platform::getClassName() -> "com/github/aui/android/Platform"
#define AUI_JNI_METHOD(ret_t, name, args)
Defines nonstatic method C++ -> Java.
Definition AJni.h:117
#define AUI_JNI_STATIC_METHOD(ret_t, name, args)
Defines static method C++ -> Java.
Definition AJni.h:83
#define AUI_JNI_CLASS(path, name)
Defines getClassName and other useful methods required for Java class definition.
Definition AJni.h:52

◆ AUI_JNI_METHOD#

#define AUI_JNI_METHOD ( ret_t,
name,
args )
Value:
    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->GetMethodID(clazz, #name, signature);    \
        if (methodId == 0) {                          \
            throw AException("no such jni method: {} {}"_format(#name, signature)); \
        }                                         \
        return ::aui::jni::callMethod<ret_t>(this->asObject(), methodId AUI_PP_FOR_EACH(AUI_JNI_INTERNAL_OMIT_BRACES_CONTENTS, _, args)); \
    }
Abstract AUI exception.
Definition AException.h:28
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179
#define AUI_PP_FOR_EACH(_Macro, _Data, _Tuple)
Expands to _Macro(0, _Data, e1) _Macro(1, _Data, e2) ... _Macro(K -1, _Data, eK) as many of AUI_INTER...
Definition APreprocessor.h:203
Parameters
ret_treturn type.
namestatic method's name.
argsarguments wrapped with braces. Types should be also wrapped in braces (see example).

Usage:

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

◆ AUI_JNI_STATIC_METHOD#

#define AUI_JNI_STATIC_METHOD ( ret_t,
name,
args )
Value:
    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)); \
    }
Parameters
ret_treturn type.
namestatic method's name.
argsarguments wrapped with braces. Types should be also wrapped in braces (see example).

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"

Function Documentation#

◆ env()#

JNIEnv * aui::jni::env ( )
Returns
JNI Env pointer for the current thread.

◆ javaVM()#

API_AUI_CORE JavaVM * aui::jni::javaVM ( )
Returns
Java VM pointer.