Android应用程序访问linux驱动第五步:回顾hw_get_module

在《android应用程序访问Linux驱动第二步-实现并测试hardware层》文章中,我们实现了自己的HAL层module,并且写了一个应用程序测试module是否正常工作。在编译的时候,我说过这样一段话:
这里写图片描述
为什么这么说呢?这还得从hw_get_module函数寻找我们的模块的过程说起。
hw_get_module函数定义在hardware.c函数中:

int hw_get_module(const char *id, const struct hw_module_t **module)
{
    return hw_get_module_by_class(id, NULL, module);
}

以我们的自己编写hellotest模块为例,我们在这里传入的参数就是 hellotest 字符串和module的地址。之后,函数调用hw_get_module_by_class进一步处理:

一.hw_get_module_by_class

int hw_get_module_by_class(const char *class_id, const char *inst,
                           const struct hw_module_t **module)
{
    int i = 0;
    char prop[PATH_MAX] = {
  
  0};
    char path[PATH_MAX] = {
  
  0};
    char name[PATH_MAX] = {
  
  0};
    char prop_name[PATH_MAX] = {
  
  0};


    if (inst)
        snprintf(name, PATH_MAX, "%s.%s", class_id, inst);
    else
        strlcpy(name, class_id, PATH_MAX);

    /*
     * Here we rely on the fact that calling dlopen multiple times on
     * the same .so will simply increment a refcount (and not load
     * a new copy of the library).
     * We also assume that dlopen() is thread-safe.
     */

    /* First try a property specific to the class and possibly instance */
    snprintf(prop_name, sizeof(prop_name), "ro.hardware.%s", name);//ro.hardware.hellotest
    if (property_get(prop_name, prop, NULL) > 0) {
        if (hw_module_exists(path, 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值