Init Chiaki Lib on Android

This commit is contained in:
Florian Märkl 2019-09-14 16:21:59 +02:00
commit 103df69d29
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
2 changed files with 47 additions and 2 deletions

View file

@ -2,4 +2,7 @@
cmake_minimum_required(VERSION 3.2)
add_library(chiaki-jni SHARED src/main/cpp/chiaki-jni.c)
target_link_libraries(chiaki-jni chiaki-lib)
target_link_libraries(chiaki-jni chiaki-lib)
find_library(ANDROID_LIB_LOG log)
target_link_libraries(chiaki-jni "${ANDROID_LIB_LOG}")

View file

@ -1,9 +1,51 @@
#include <jni.h>
#include <android/log.h>
#include <chiaki/common.h>
#include <chiaki/log.h>
JNIEXPORT jstring JNICALL Java_com_metallic_chiaki_lib_Chiaki_stringFromJNI(JNIEnv* env, jobject thiz)
#define LOG_TAG "Chiaki"
static void log_cb_android(ChiakiLogLevel level, const char *msg, void *user)
{
int prio;
switch(level)
{
case CHIAKI_LOG_DEBUG:
prio = ANDROID_LOG_DEBUG;
break;
case CHIAKI_LOG_VERBOSE:
prio = ANDROID_LOG_VERBOSE;
break;
case CHIAKI_LOG_INFO:
prio = ANDROID_LOG_INFO;
break;
case CHIAKI_LOG_WARNING:
prio = ANDROID_LOG_ERROR;
break;
case CHIAKI_LOG_ERROR:
prio = ANDROID_LOG_ERROR;
break;
default:
prio = ANDROID_LOG_INFO;
break;
}
__android_log_print(prio, LOG_TAG, "%s", msg);
}
ChiakiLog log_ctx;
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)
{
chiaki_log_init(&log_ctx, CHIAKI_LOG_ALL & ~CHIAKI_LOG_VERBOSE, log_cb_android, NULL);
CHIAKI_LOGI(&log_ctx, "Loading Chiaki Library");
ChiakiErrorCode err = chiaki_lib_init();
CHIAKI_LOGI(&log_ctx, "Chiaki Library Init Result: %s\n", chiaki_error_string(err));
return JNI_VERSION_1_2;
}
JNIEXPORT jstring JNICALL Java_com_metallic_chiaki_lib_Chiaki_stringFromJNI(JNIEnv *env, jobject thiz)
{
return (*env)->NewStringUTF(env, chiaki_error_string(CHIAKI_ERR_SUCCESS));
}