正文

Android HAL 开发 (2)2012-08-24 10:12:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/liyutai/53737.html

分享到:

在上一篇文章中,我们看到了如何撰写HAL层的用户硬件驱动程序,我们每也知道,最终该代码会被编译成动态链接库提供给service(jni)使用,那么我们下面来看看service(jni)是如何与HAL通信的。 一般service的jni代码位于framework/base/service/jni/中,我们看看mokoid的ledservice是如何实现的:   framework/base/service/jni/com_mokoid_server_LedService.cpp static const JNINativeMethod gMethods[] = {     { "_init",      "()Z",  (void *)mokoid_init },      { "_set_on",        "(I)Z", (void *)mokoid_setOn },    { "_set_off",       "(I)Z", (void *)mokoid_setOff },  };   int register_mokoid_server_LedService(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;  }  上面的函数register_mokoid_server_LedService会把以C/C++实现的接口注册为java可调用的接口,比如mokoid_init为C/C++代码, 而_init则位java可以使用的接口。这个函数会在JNI_OnLoad里面被调用。 阅读更多下文请点击:http://www.hzlitai.com.cn/article/ARM11/SYSTEM/Android_HAL_kaifa2.html  

阅读(2692) | 评论(3)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

loading...
您需要登录后才能评论,请 登录 或者 注册