国产成人精品三级麻豆,色综合天天综合高清网,亚洲精品夜夜夜,国产成人综合在线女婷五月99播放,色婷婷色综合激情国产日韩

當(dāng)前位置:首頁 > 嵌入式培訓(xùn) > 嵌入式學(xué)習(xí) > 講師博文 > Android硬件抽象層(HAL)深入剖析(三)

Android硬件抽象層(HAL)深入剖析(三) 時(shí)間:2018-09-26      來源:未知

前面分析了android HAL層是如何搜索硬件模塊的動(dòng)態(tài)共享庫的,其實(shí)就是在"system/lib/hw/"或者"/vendor/lib/hw/"這兩個(gè)路徑下找到共享庫modueid.variant.so后,通過調(diào)用load函數(shù)加載庫。

下面我們進(jìn)入load函數(shù),看看具體是如何實(shí)現(xiàn)加載共享庫的。

以下為load函數(shù)定義,同樣在/hardware/libhardware/hardware.c中實(shí)現(xiàn)的。

1 /**

2 * Load the file defined by the variant and if successful

3 * return the dlopen handle and the hmi.

4 * @return 0 = success, !0 = failure.

5 */

6 static int load(const char *id,

7 const char *path,

8 const struct hw_module_t **pHmi)

9 {//傳入硬件模塊id和庫所在路徑,獲取到硬件模塊結(jié)構(gòu)體

10 int status;

11 void *handle;

12 struct hw_module_t *hmi;

13

14 /*

15 * load the symbols resolving undefined symbols before

16 * dlopen returns. Since RTLD_GLOBAL is not or'd in with

17 * RTLD_NOW the external symbols will not be global

18 */

19 handle = dlopen(path, RTLD_NOW);//打開共享庫

20 if (handle == NULL) {

21 char const *err_str = dlerror();

22 LOGE("load: module=%s\n%s", path, err_str?err_str:"unknown");

23 status = -EINVAL;

24 goto done;

25 }

26

27 /* Get the address of the struct hal_module_info. */

28 const char *sym = HAL_MODULE_INFO_SYM_AS_STR;

29 hmi = (struct hw_module_t *)dlsym(handle, sym);//解析共享庫

30 if (hmi == NULL) {

31 LOGE("load: couldn't find symbol %s", sym);

32 status = -EINVAL;

33 goto done;

34 }

35

36 /* Check that the id matches */

37 if (strcmp(id, hmi->id) != 0) {//匹配解析出硬件模塊的id和傳入我們實(shí)際想要得到的模塊id是否一致

38 LOGE("load: id=%s != hmi->id=%s", id, hmi->id);

39 status = -EINVAL;

40 goto done;

41 }

42

43 hmi->dso = handle; //將打開庫得到句柄傳給硬件模塊的dso

44

45 /* success */

46 status = 0;

47

48 done:

49 if (status != 0) {

50 hmi = NULL;

51 if (handle != NULL) {

52 dlclose(handle);

53 handle = NULL;

54 }

55 } else {

56 LOGV("loaded HAL id=%s path=%s hmi=%p handle=%p",

57 id, path, *pHmi, handle);

58 }

59

60 *pHmi = hmi;//將得到的module的結(jié)果通過第三個(gè)參數(shù)傳給hw_module_t

61

62 return status;

63 }

可以看到load函數(shù)傳入的幾個(gè)參數(shù),第一個(gè)參數(shù)就是需要加載的硬件模塊對應(yīng)動(dòng)態(tài)庫的硬件模塊的id;

第二個(gè)參數(shù)就是動(dòng)態(tài)庫存放的路徑,就是在hw_get_module函數(shù)前部分搜索庫得到的path;

第三個(gè)參數(shù)就是我們需要得到的硬件模塊結(jié)構(gòu)體,通過它傳給hw_get_module,hw_get_module函數(shù)在通過參數(shù)傳給jni。

第19行,首先調(diào)用dlopen打開共享庫,該函數(shù)通過傳入的庫的路徑找到庫,并且打開它,傳回一個(gè)操作句柄handle,然后再調(diào)用dlsym函數(shù)解析這個(gè)打開的庫,下面第29行,得到庫中包含的硬件模塊結(jié)構(gòu)體,并將它返回回來。所以硬件廠商或者硬件移植者都必須根據(jù)hal的這個(gè)架構(gòu)去實(shí)現(xiàn)填充這個(gè)和自己硬件相關(guān)的硬件模塊結(jié)構(gòu)體hw_module_t,供使用。

通過dlsym解析之后就得到了hw_module_t,隨后第37行,將從庫中解析得到的結(jié)構(gòu)體中的id和傳入的id做比較,看是否一致。

如果一致則證明就是得到正確的硬件模塊了。

后第60行,將hw_module_t結(jié)構(gòu)體指針傳給第三個(gè)參數(shù),傳給hw_get_module函數(shù)。

到此,hw_get_module函數(shù)就得到了硬件模塊結(jié)構(gòu)體hw_module_t.

有了hw_module_t,那么通過其內(nèi)部的method open就能打開硬件模塊對應(yīng)的設(shè)備了,通過結(jié)構(gòu)體中的一些方法就能操作硬件設(shè)備了。

上一篇:大學(xué)生就業(yè)市場現(xiàn)狀分析 如何能更好實(shí)現(xiàn)就業(yè)

下一篇:Android屏幕適配

熱點(diǎn)文章推薦
華清學(xué)員就業(yè)榜單
高薪學(xué)員經(jīng)驗(yàn)分享
熱點(diǎn)新聞推薦
前臺(tái)專線:010-82525158 企業(yè)培訓(xùn)洽談專線:010-82525379 院校合作洽談專線:010-82525379 Copyright © 2004-2022 北京華清遠(yuǎn)見科技集團(tuán)有限公司 版權(quán)所有 ,京ICP備16055225號-5,京公海網(wǎng)安備11010802025203號

回到頂部