static jboolean mokoid_setOn(JNIEnv* env, jobject thiz, jint led) {………}
static jboolean mokoid_setOff(JNIEnv* env, jobject thiz, jint led) {………}
static inline int led_control_open(const struct hw_module_t* module, struct led_control_device_t** device) {………..}
static jbooleanmokoid_init(JNIEnv *env, jclass clazz){…………..}
static const JNINativeMethod gMethods[] = {
{"_init", "()Z", (void*)mokoid_init},
{ "_set_on", "(I)Z", (void*)mokoid_setOn },
{ "_set_off", "(I)Z", (void*)mokoid_setOff },
};
static int registerMethods(JNIEnv* env) {
static const char* const kClassName = "com/mokoid/server/LedService";
jclass clazz;
/* look up the class */
clazz = env->FindClass(kClassName);
if (clazz == NULL) {
LOGE("Can't find class %s\n", kClassName);
return -1;
}
/* register all the methods */
if (env->RegisterNatives(clazz, gMethods,
sizeof(gMethods) / sizeof(gMethods[0])) != JNI_OK)
{
LOGE("Failed registering methods for %s\n", kClassName);
return -1;
}
/* fill out the rest of the ID cache */
return 0;
}
jint JNI_OnLoad(JavaVM* vm, void* reserved) {
JNIEnv* env = NULL;
jint result = -1;
if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
LOGE("ERROR: GetEnv failed\n");
goto bail;
}
assert(env != NULL);
if (registerMethods(env) != 0) {
LOGE("ERROR: PlatformLibrary native registration failed\n");
goto bail;
}
/* success -- return valid version number */
result = JNI_VERSION_1_4;
bail:
return result;
}
|