Encapsulating Functions into the JNI
Application Scenario
Encapsulate the six C++ APIs of the instruction stream engine client into the JNI.
Encapsulate the function of the communication module for setting the IP address and port number into the JNI.
Development Process
- Encapsulate the six C++ APIs of the instruction stream engine client.
- Encapsulate the function of the communication module for setting the IP address and port number into the JNI.
- Create a JNI callback object for the instruction stream engine.
Encoding Instance
// Encapsulate the six APIs of the instruction stream engine. #define INSTUCTION_JNI(func) Java_com_huawei_instructionstream_appui_engine_InstructionWrapper_##func // Instruction stream engine APIs corresponding to the function names. JNIEXPORT jint JNICALL INSTUCTION_JNI(initialize)(JNIEnv* env, jclass cls); JNIEXPORT jint JNICALL INSTUCTION_JNI(start)(JNIEnv* env, jclass cls, jobject surface, jint width, jint height, jfloat densityDpi); JNIEXPORT void JNICALL INSTUCTION_JNI(stop)(JNIEnv* env, jclass cls); JNIEXPORT jstring JNICALL INSTUCTION_JNI(getStat)(JNIEnv* env, jclass cls); JNIEXPORT jint JNICALL INSTUCTION_JNI(recvData)(JNIEnv* env, jclass cls, jbyte type, jbyteArray jData, jint length); // The following is the encapsulation API of the send functions. You can encapsulate APIs as required. JNIEXPORT jboolean JNICALL INSTUCTION_JNI(sendAudioDataArray)(JNIEnv* env, jclass cls, jbyteArray jData, jint length); JNIEXPORT jboolean JNICALL INSTUCTION_JNI(sendTouchEventArray)(JNIEnv* env, jclass cls, jbyteArray jData, jint length); JNIEXPORT jboolean JNICALL INSTUCTION_JNI(sendKeyEvent)(JNIEnv* env, jclass cls,jbyteArray jData, jint length); // Encapsulate the callback event of the instruction stream engine. #define CB_JNI(func) Java_com_huawei_instructionstream_appui_engine_JniCallBack_##func JNIEXPORT void JNICALL CB_JNI(setNativeCallback)(JNIEnv* env, jobject obj); // Encapsulate the communication module APIs. #define NET_CONFIG_JNI(func) Java_com_huawei_instructionstream_appui_maincontrol_NetConfig_##func JNIEXPORT jboolean JNICALL NET_CONFIG_JNI(initialize)(JNIEnv* env, jclass cls); // Set the IP address and port number of the communication module. JNIEXPORT jboolean JNICALL NET_CONFIG_JNI(setNetConfig)(JNIEnv* env, jclass cls, jstring ip, jint port, jint type);
Parent topic: API Development Process