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,