1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
/**
* File generated by Jenny -- https://github.com/LanderlYoung/Jenny
*
* DO NOT EDIT THIS FILE.
*
* For bug report, please refer to github issue tracker https://github.com/LanderlYoung/Jenny/issues.
*/
/* C++ header file for class io/github/landerlyoung/jennysampleapp/NativeDrawable */
#pragma once
#include <jni.h>
namespace NativeDrawable {
// DO NOT modify
static constexpr auto FULL_CLASS_NAME = u8"io/github/landerlyoung/jennysampleapp/NativeDrawable";
/*
* Class: io.github.landerlyoung.jennysampleapp.NativeDrawable
* Method: private final long nativeInit()
* Signature: ()J
*/
jlong JNICALL nativeInit(JNIEnv* env, jobject thiz);
/*
* Class: io.github.landerlyoung.jennysampleapp.NativeDrawable
* Method: public final void onClick()
* Signature: ()V
*/
void JNICALL onClick(JNIEnv* env, jobject thiz);
/*
* Class: io.github.landerlyoung.jennysampleapp.NativeDrawable
* Method: public void draw(android.graphics.Canvas canvas)
* Signature: (Landroid/graphics/Canvas;)V
*/
void JNICALL draw(JNIEnv* env, jobject thiz, jobject canvas);
/*
* Class: io.github.landerlyoung.jennysampleapp.NativeDrawable
* Method: public final void release()
* Signature: ()V
*/
void JNICALL release(JNIEnv* env, jobject thiz);
/**
* register Native functions
* @returns success or not
*/
inline bool registerNativeFunctions(JNIEnv* env) {
// 1. C++20 has u8"" string as char8_t type, we should cast them.
// 2. jni.h has JNINativeMethod::name as char* type not const char*. (while Android does)
#define jenny_u8cast(u8) const_cast<char *>(reinterpret_cast<const char *>(u8))
const JNINativeMethod gsNativeMethods[] = {
{
/* method name */ jenny_u8cast(u8"nativeInit"),
/* method signature */ jenny_u8cast(u8"()J"),
/* function pointer */ reinterpret_cast<void *>(nativeInit)
},
{
/* method name */ jenny_u8cast(u8"onClick"),
/* method signature */ jenny_u8cast(u8"()V"),
/* function pointer */ reinterpret_cast<void *>(onClick)
},
{
/* method name */ jenny_u8cast(u8"draw"),
/* method signature */ jenny_u8cast(u8"(Landroid/graphics/Canvas;)V"),
/* function pointer */ reinterpret_cast<void *>(draw)
},
{
/* method name */ jenny_u8cast(u8"release"),
/* method signature */ jenny_u8cast(u8"()V"),
/* function pointer */ reinterpret_cast<void *>(release)
}
};
const int gsMethodCount = sizeof(gsNativeMethods) / sizeof(JNINativeMethod);
bool success = false;
jclass clazz = env->FindClass(jenny_u8cast(FULL_CLASS_NAME));
if (clazz != nullptr) {
success = !env->RegisterNatives(clazz, gsNativeMethods, gsMethodCount);
env->DeleteLocalRef(clazz);
}
return success;
#undef jenny_u8cast
}
} // endof namespace NativeDrawable
|