1 /*
2 * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "audio_dl_adp.h"
16 #include <stdio.h>
17
18 #if (!defined(__HuaweiLite__)) || defined(__OHOS__)
19 #include <dlfcn.h>
20 #else
21 #include <los_ld_elflib.h>
22 #endif
23
Audio_Dlpath(HI_CHAR * pChLibPath)24 HI_S32 Audio_Dlpath(HI_CHAR *pChLibPath)
25 {
26 #if (!defined(__HuaweiLite__)) || defined(__OHOS__)
27 (hi_void)pChLibPath;
28 #else
29 if (LOS_PathAdd(pChLibPath) != HI_SUCCESS) {
30 printf("add path %s failed!\n", pChLibPath);
31 return HI_FAILURE;
32 }
33 #endif
34
35 return HI_SUCCESS;
36 }
37
Audio_Dlopen(HI_VOID ** pLibhandle,HI_CHAR * pChLibName)38 HI_S32 Audio_Dlopen(HI_VOID **pLibhandle, HI_CHAR *pChLibName)
39 {
40 if (pLibhandle == HI_NULL || pChLibName == HI_NULL) {
41 return HI_FAILURE;
42 }
43
44 *pLibhandle = HI_NULL;
45 #if (!defined(__HuaweiLite__)) || defined(__OHOS__)
46 *pLibhandle = dlopen(pChLibName, RTLD_LAZY | RTLD_LOCAL);
47 #else
48 *pLibhandle = LOS_SoLoad(pChLibName);
49 #endif
50 if (*pLibhandle == HI_NULL) {
51 printf("dlopen %s failed!\n", pChLibName);
52 return HI_FAILURE;
53 }
54
55 return HI_SUCCESS;
56 }
57
Audio_Dlsym(HI_VOID ** pFunchandle,HI_VOID * Libhandle,HI_CHAR * pChFuncName)58 HI_S32 Audio_Dlsym(HI_VOID **pFunchandle, HI_VOID *Libhandle, HI_CHAR *pChFuncName)
59 {
60 if (pFunchandle == HI_NULL || Libhandle == HI_NULL || pChFuncName == HI_NULL) {
61 printf("LibHandle or FuncName is empty!");
62 return HI_FAILURE;
63 }
64
65 *pFunchandle = HI_NULL;
66 #if (!defined(__HuaweiLite__)) || defined(__OHOS__)
67 *pFunchandle = dlsym(Libhandle, pChFuncName);
68 #else
69 *pFunchandle = LOS_FindSymByName(Libhandle, pChFuncName);
70 #endif
71
72 if (*pFunchandle == HI_NULL) {
73 #if (!defined(__HuaweiLite__)) || defined(__OHOS__)
74 printf("dlsym %s fail,error msg is %s!\n", pChFuncName, dlerror());
75 #else
76 printf("dlsym %s fail!\n", pChFuncName);
77 #endif
78 return HI_FAILURE;
79 }
80
81 return HI_SUCCESS;
82 }
83
Audio_Dlclose(HI_VOID * Libhandle)84 HI_S32 Audio_Dlclose(HI_VOID *Libhandle)
85 {
86 if (Libhandle == HI_NULL) {
87 printf("LibHandle is empty!");
88 return HI_FAILURE;
89 }
90
91 #if (!defined(__HuaweiLite__)) || defined(__OHOS__)
92 dlclose(Libhandle);
93 #else
94 LOS_ModuleUnload(Libhandle);
95 #endif
96
97 return HI_SUCCESS;
98 }
99