Android HAL
2010-04-21 06:36:00 来源:WEB开发网LOGI("led_init");
if (hw_get_module(LED_HARDWARE_MODULE_ID, (const hw_module_t**)&module) == 0) {
LOGI("get Module OK");
sLedModule = (led_module_t *) module;
if (led_control_open(&module->common, &sLedDevice) != 0) {
LOGI("led_init error");
return -1;
}
}
LOGI("led_init success");
return 0;
}
/*
* Array of methods.
*
* Each entry has three fields: the name of the method, the method
* signature, and a pointer to the native implementation.
*/
static const JNINativeMethod gMethods[] = {
{"_init", "()Z",
(void*)led_init},
{ "_set_on", "()I",
(void*)led_setOn },
{ "_set_off", "()I",
(void*)led_setOff },
{ "_get_count", "()I",
(void*)get_count },
};
static int registerMethods(JNIEnv* env) {
static const char* const kClassName =
"com/hello/LedService/LedService";
jclass clazz;
/* look up the class */
clazz = env->FindClass(kClassName);
if (clazz == NULL) {
LOGE("Can't find class %s ", 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 ", kClassName);
return -1;
}
/* fill out the rest of the ID cache */
return 0;
}
/*
* This is called by the VM when the shared library is first loaded.
*/
jint JNI_OnLoad(JavaVM* vm, void* reserved) {
JNIEnv* env = NULL;
jint result = -1;
LOGI("JNI_OnLoad");
更多精彩
赞助商链接