blob: d7d362539825baf8975adf7e072f9275124e97a4 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001#include "AudioParamParserPriv.h"
2
3EXPORT size_t paramInfoGetNumOfFieldInfo(ParamInfo *paramInfo)
4{
5 if (!paramInfo)
6 {
7 ERR_LOG("paramInfo is NULL!\n");
8 return 0;
9 }
10
11 return HASH_COUNT(paramInfo->fieldInfoHash);
12}
13
14EXPORT FieldInfo *paramInfoGetFieldInfoByIndex(ParamInfo *paramInfo, size_t index)
15{
16 FieldInfo *fieldInfo = NULL;
17 size_t i = 0;
18
19 if (!paramInfo)
20 {
21 ERR_LOG("paramInfo is NULL!\n");
22 return NULL;
23 }
24
25 for (fieldInfo = paramInfo->fieldInfoHash; fieldInfo ; fieldInfo = fieldInfo->hh.next)
26 {
27 if (index == i++)
28 {
29 return fieldInfo;
30 }
31 }
32
33 return NULL;
34}
35
36EXPORT FieldInfo *paramInfoGetFieldInfoByName(ParamInfo *paramInfo, const char *fieldName)
37{
38 FieldInfo *fieldInfo;
39
40 if (!paramInfo)
41 {
42 ERR_LOG("paramInfo is NULL!\n");
43 return NULL;
44 }
45
46 /* Query Param name */
47 HASH_FIND_STR(paramInfo->fieldInfoHash, fieldName, fieldInfo);
48
49 return fieldInfo;
50}
51
52EXPORT ParamInfo *paramInfoCreate(const char *name, DATA_TYPE dataType, AudioType *audioType)
53{
54 ParamInfo *paramInfo = (ParamInfo *)malloc(sizeof(ParamInfo));
55 paramInfo->audioType = audioType;
56 paramInfo->name = strdup(name);
57 paramInfo->dataType = dataType;
58 paramInfo->fieldInfoHash = NULL;
59 return paramInfo;
60}
61
62EXPORT FieldInfo *fieldInfoCreate(const char *fieldName, unsigned int arrayIndex, int startBit, int endBit, const char *checkList, ParamInfo *paramInfo)
63{
64 FieldInfo *fieldInfo = (FieldInfo *)malloc(sizeof(FieldInfo));
65
66 /* Setup members */
67 fieldInfo->name = strdup(fieldName);
68 fieldInfo->arrayIndex = arrayIndex;
69 fieldInfo->startBit = startBit;
70 fieldInfo->endBit = endBit;
71 fieldInfo->paramInfo = paramInfo;
72
73 if (checkList)
74 {
75 fieldInfo->checkListStr = strdup(checkList);
76 }
77 else
78 {
79 fieldInfo->checkListStr = utilGenCheckList(endBit - startBit + 1);
80 }
81
82 return fieldInfo;
83}
84
85EXPORT void paramInfoRelease(ParamInfo *paramInfo)
86{
87 if (paramInfo == NULL)
88 {
89 return;
90 }
91
92 if (paramInfo->fieldInfoHash)
93 {
94 FieldInfo *tmp, *item;
95 HASH_ITER(hh, paramInfo->fieldInfoHash, item, tmp)
96 {
97 HASH_DEL(paramInfo->fieldInfoHash, item);
98 fieldInfoRelease(item);
99 }
100 }
101
102 free(paramInfo->name);
103 free(paramInfo);
104}
105
106EXPORT void fieldInfoRelease(FieldInfo *fieldInfo)
107{
108 if (fieldInfo == NULL)
109 {
110 return;
111 }
112
113 if (fieldInfo->checkListStr)
114 {
115 free(fieldInfo->checkListStr);
116 }
117
118 free(fieldInfo->name);
119 free(fieldInfo);
120}
121
122EXPORT APP_STATUS fieldInfoGetCheckListValue(FieldInfo *fieldInfo, const char *checkName, unsigned int *checkVal)
123{
124 char *checkList;
125 char *valStr;
126 char *nameStr;
127 if (!fieldInfo)
128 {
129 ERR_LOG("fieldInfo is NULL\n");
130 return APP_ERROR;
131 }
132
133 if (!checkName)
134 {
135 ERR_LOG("checkName is NULL\n");
136 return APP_ERROR;
137 }
138
139 if (!checkVal)
140 {
141 ERR_LOG("checkVal is NULL\n");
142 return APP_ERROR;
143 }
144
145 checkList = strdup(fieldInfo->checkListStr);
146 valStr = strtok(checkList, ARRAY_SEPERATOR);
147 if (!valStr)
148 {
149 ERR_LOG("Cannot parse valStr\n");
150 free(checkList);
151 return APP_ERROR;
152 }
153
154 while ((nameStr = strtok(NULL, ARRAY_SEPERATOR)) != NULL)
155 {
156 if (!strcmp(nameStr, checkName))
157 {
158 *checkVal = strtoul(valStr, NULL, 0);
159 free(checkList);
160 return APP_NO_ERROR;
161 }
162
163 valStr = strtok(NULL, ARRAY_SEPERATOR);
164 if (!valStr)
165 {
166 ERR_LOG("Cannot parse valStr\n");
167 free(checkList);
168 return APP_ERROR;
169 }
170 }
171
172 free(checkList);
173 return APP_ERROR;
174}