android hal层与jni层,android HAL层架构分析(二)——jni调用.doc

android HAL层架构分析(二)——jni调用

android HAL层架构分析(二)——jni调用

android HAL层架构分析(二)——jni调用_蓝维的电子空间_百度空间

android HAL层架构分析(二)——jni调用2011-07-07

17:511>jni调用分为3个部分,java层调用接口,以native关键字声明 2>JNI映射表数组 JNINativeMethod;

3>本地函数实现

/***************************************************************************/

struct led_module_t {

struct hw_module_t common;

};

//HAL 规定不能直接使用hw_module_t结构,因此需要做这么一个继承。

struct led_control_device_t {

//自定义的一个针对Led控制的结构,包含hw_device_t和支持的API操作

struct hw_device_t common;

/* attributes */

int fd; //可用于具体的设备描述符

/* supporting control APIs go here */

int (*set_on)(struct led_control_device_t *dev, int32_t

led);

int (*set_off)(struct led_control_device_t *dev, int32_t

led);

};

#define LED_HARDWARE_MODULE_ID "led"

//定义一个MODULE_ID,HAL层可以根据这个ID找到我们这个HAL stub

struct led_control_device_t *sLedDevice = NULL; static jboolean

mokoid_setOn(JNIEnv* env, jobject thiz, jint led) //这就是本地函数的实现{

LOGI("LedService JNI: mokoid_setOn() is invoked."); if (sLedDevice

== NULL) { LOGI("LedService JNI: sLedDevice was not fetched

correctly."); return -1; } else { return

sLedDevice->set_on(sLedDevice, led);//调用hal层的注册的方法 } } static

jboolean mokoid_setOff(JNIEnv* env, jobject thiz, jint led) {

LOGI("LedService JNI: mokoid_setOff() is invoked."); if

(sLedDevice == NULL) { LOGI("LedService JNI: sLedDevice was not

fetched correctly."); return -1; } else { return

sLedDevice->set_off(sLedDevice, led); //调用hal层的注册的方法 } } /**

helper APIs */ static inline int led_control_open(const struct

hw_module_t* module,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值