blob: 8f3dbacd62d3e89c8c961d736080f7eaf773e3ce [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001#include "AudioParamParserPriv.h"
2#include <time.h>
3
4typedef struct StrPair {
5 char *key; /* key */
6 char *value;
7 UT_hash_handle hh; /* hash handle */
8} StrPair;
9
10StrPair *strPairCreate(const char *key, const char *value) {
11 StrPair *pair = malloc(sizeof(StrPair));
12 pair->key = strdup(key ? key : "");
13 pair->value = strdup(value ? value : "");
14 return pair;
15}
16
17void strPairRelease(StrPair *pair) {
18 if (pair) {
19 free(pair->key);
20 free(pair->value);
21 free(pair);
22 }
23}
24
25EXPORT void utilDumpAudioTypeLoadingList(const char *audioTypeLoadingList[]) {
26 int index = 0;
27 INFO_LOG("===AudioTypeLoadingList===\n");
28 if (audioTypeLoadingList != NULL) {
29 for (index = 0; audioTypeLoadingList[index] != NULL; index++) {
30 INFO_LOG("[%d] %s\n", index, audioTypeLoadingList[index]);
31 }
32 } else {
33 INFO_LOG("All audio type\n");
34 }
35}
36
37EXPORT char **appGetXmlDirFromProperty() {
38#if !defined(WIN32) && !defined(SYS_IMPL)&& !defined(MTK_YOCTO_AUDIO)
39 char **xmlDirList = NULL;
40 char *xmlDir = malloc(MAX_PROP_VALUE_LEN);
41
42 property_get(PROPERTY_KEY_XML_DEF_PATH, xmlDir, "");
43 if (strcmp(xmlDir, "")) {
44 MUST_LOG("%s = %s", PROPERTY_KEY_XML_DEF_PATH, xmlDir);
45 xmlDirList = malloc(sizeof(char*) * 2);
46 xmlDirList[0] = xmlDir;
47 xmlDirList[1] = NULL;
48 } else {
49 free(xmlDir);
50 }
51
52 return xmlDirList;
53#else
54 return NULL;
55#endif
56}
57
58EXPORT int appSetAudioTypeLoadingList(const char *audioTypeLoadingList[]) {
59 if (appAudioTypeLoadingList == NULL) {
60 appAudioTypeLoadingList = audioTypeLoadingList;
61 MUST_LOG("Set audioTypeLoadingList with %p\n", appAudioTypeLoadingList);
62 utilDumpAudioTypeLoadingList(appAudioTypeLoadingList);
63 return 1;
64 } else {
65 WARN_LOG("audioTypeLoadingList already been setup. (cur = %s, new = %s)\n", appAudioTypeLoadingList[0], audioTypeLoadingList[0]);
66 return 0;
67 }
68}
69
70EXPORT const char *appGetAudioTypeLoadingList(void) {
71 return (const char*)appAudioTypeLoadingList;
72}
73
74EXPORT void appSetDebugLevel(MSG_LEVEL level) {
75 INFO_LOG("appSetDebugLevel(), level = %d\n", level);
76#ifndef FORCE_DEBUG_LEVEL
77 appDebugLevel = level;
78#endif
79}
80
81EXPORT MSG_LEVEL appGetDebugLevel() {
82 INFO_LOG("appGetDebugLevel(), level = %d\n", appDebugLevel);
83 return appDebugLevel;
84}
85
86EXPORT xmlNode *findXmlNodeByElemName(xmlNode *node, const char *elemName) {
87 xmlNode *cur_node;
88
89 if (!node) {
90 DEBUG_LOG("xmlNode is NULL\n");
91 return NULL;
92 }
93
94 if (!elemName) {
95 DEBUG_LOG("elemName is NULL\n");
96 return NULL;
97 }
98
99 for (cur_node = node; cur_node; cur_node = cur_node->next) {
100 if (cur_node->type == XML_ELEMENT_NODE && !strncmp((const char *)cur_node->name, elemName, strlen(elemName) + 1)) {
101 return cur_node;
102 }
103 }
104 return NULL;
105}
106
107EXPORT int utilIsUIAudioType(const char *audioType) {
108 char* uiStr = strstr(audioType, "UI");
109 if (uiStr == NULL || strlen(uiStr) != 2) {
110 return 0;
111 }
112
113 return 1;
114}
115
116EXPORT int utilIsAudioTypeInLoadingList(const char *audioType) {
117
118 if (appAudioTypeLoadingList == NULL) {
119 /* If appAudioTypeLoadingList not specified, all audioType are allowed */
120 DEBUG_LOG("%s audio type is allow by default!\n", audioType);
121 return 1;
122 } else {
123 int index = 0;
124 for (index = 0; appAudioTypeLoadingList[index] != NULL; index++) {
125 if (!strcmp(audioType, appAudioTypeLoadingList[index])) {
126 DEBUG_LOG("%s audio type is in allow list!\n", audioType);
127 return 1;
128 }
129 }
130 DEBUG_LOG("%s audio type is not in allow list!\n", audioType);
131
132 return 0;
133 }
134}
135
136EXPORT xmlChar *xmlNodeGetProp(xmlNode *node, const char *prop) {
137 if (!node) {
138 ERR_LOG("xmlNode is NULL\n");
139 return NULL;
140 }
141
142 if (!prop) {
143 ERR_LOG("prop is NULL\n");
144 return NULL;
145 }
146
147 return xmlGetProp(node, (const xmlChar *)prop);
148}
149
150EXPORT xmlChar *xmlNodeGetWording(xmlNode *node) {
151 xmlChar *wording = xmlNodeGetProp(node, ATTRI_WORDING);
152 if (wording == NULL) {
153 wording = xmlNodeGetProp(node, ATTRI_NAME);
154 }
155 return wording;
156}
157
158void print_element_names(xmlNode *a_node) {
159 xmlNode *cur_node = NULL;
160
161 for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
162 if (cur_node->type == XML_ELEMENT_NODE) {
163 printf("node type: Element, name: %s\n", cur_node->name);
164 }
165
166 print_element_names(cur_node->children);
167 }
168}
169
170void appDumpXmlDoc(xmlDoc *doc) {
171 /*Get the root element node */
172 xmlNode *root_element = xmlDocGetRootElement(doc);
173
174 print_element_names(root_element);
175}
176
177#ifndef WIN32
178EXPORT void signalHandler(int sig, siginfo_t *info, void *ucontext) {
179 INFO_LOG("Got thread notify signal. sig = %d, info = %p, ucontext = %p\n", sig, info, ucontext);
180}
181#endif
182
183EXPORT APP_STATUS utilConvDataStringToNative(DATA_TYPE dataType, const char *str, void **data, size_t *arraySize) {
184 errno = 0;
185 switch (dataType) {
186 case TYPE_STR:
187 *data = strdup(str);
188 *arraySize = 0;
189 break;
190 case TYPE_INT: {
191 int *val = malloc(sizeof(int));
192 *val = strtol(str, NULL, 0);
193 if (errno == ERANGE) {
194 ERR_LOG("Cannot convert \"%s\" to int!\n", str);
195 free(val);
196 return APP_ERROR;
197 }
198
199 *data = val;
200 *arraySize = 0;
201 break;
202 }
203 case TYPE_UINT: {
204 unsigned int *val = malloc(sizeof(unsigned int));
205 *val = strtoul(str, NULL, 0);
206 if (errno == ERANGE) {
207 ERR_LOG("Cannot convert \"%s\" to uint!\n", str);
208 free(val);
209 return APP_ERROR;
210 }
211
212 *data = val;
213 *arraySize = 0;
214 break;
215 }
216 case TYPE_FLOAT: {
217 float *val = malloc(sizeof(float));
218 *val = (float)strtod(str, NULL);
219 if (errno == ERANGE) {
220 ERR_LOG("Cannot convert \"%s\" to float!\n", str);
221 free(val);
222 return APP_ERROR;
223 }
224
225 *data = val;
226 *arraySize = 0;
227 break;
228 }
229 case TYPE_BYTE_ARRAY: {
230 char *elemData;
231 unsigned int convVal;
232 int index = 0;
233 APP_STATUS result = APP_NO_ERROR;
234
235 int size = paramGetArraySizeFromString(str);
236 char *val = malloc(sizeof(char) * size);
237
238 if (size == 1) {
239 /* Convert str */
240 convVal = strtol(str, NULL, 0);
241 if (errno == ERANGE) {
242 ERR_LOG("Cannot convert \"%s\" to byte array!\n", str);
243 result = APP_ERROR;
244 } else {
245 val[0] = (char)convVal & 0xFF;
246 }
247 } else {
248 char *tmpStr = strdup(str);
249 char *restOfStr = NULL;
250 elemData = utilStrtok(tmpStr, ARRAY_SEPERATOR, &restOfStr);
251
252 /* Convert str */
253 if (elemData != NULL) {
254 convVal = strtol(elemData, NULL, 0);
255 } else {
256 errno = ERANGE;
257 }
258
259 if (errno == ERANGE) {
260 ERR_LOG("Cannot convert \"%s\" to byte array!\n", str);
261 result = APP_ERROR;
262 } else {
263 val[index++] = (char)convVal & 0xFF;
264
265 while ((elemData = utilStrtok(NULL, ARRAY_SEPERATOR, &restOfStr))) {
266 convVal = strtol(elemData, NULL, 0);
267 if (errno == ERANGE) {
268 ERR_LOG("Cannot convert \"%s\" to byte array!\n", str);
269 result = APP_ERROR;
270 break;
271 }
272 val[index++] = (char)convVal & 0xFF;
273 }
274 }
275
276 free(tmpStr);
277 }
278
279 if (result == APP_NO_ERROR) {
280 *data = val;
281 *arraySize = size;
282 } else {
283 free(val);
284 *data = NULL;
285 *arraySize = 0;
286 }
287 return result;
288 }
289 case TYPE_UBYTE_ARRAY: {
290 char *elemData;
291 unsigned int convVal;
292 int index = 0;
293 APP_STATUS result = APP_NO_ERROR;
294
295 int size = paramGetArraySizeFromString(str);
296 unsigned char *val = malloc(sizeof(unsigned char) * size);
297
298 if (size == 1) {
299 /* Convert str */
300 convVal = strtoul(str, NULL, 0);
301 if (errno == ERANGE) {
302 ERR_LOG("Cannot convert \"%s\" to ubyte array!\n", str);
303 result = APP_ERROR;
304 } else {
305 val[0] = (unsigned char)convVal & 0xFF;
306 }
307 } else {
308 char *tmpStr = strdup(str);
309 char *restOfStr = NULL;
310 elemData = utilStrtok(tmpStr, ARRAY_SEPERATOR, &restOfStr);
311
312 /* Convert str */
313 if (elemData != NULL) {
314 convVal = strtoul(elemData, NULL, 0);
315 } else {
316 errno = ERANGE;
317 }
318
319 if (errno == ERANGE) {
320 ERR_LOG("Cannot convert \"%s\" to ubyte array!\n", str);
321 result = APP_ERROR;
322 } else {
323 val[index++] = (unsigned char)convVal & 0xFF;
324
325 while ((elemData = utilStrtok(NULL, ARRAY_SEPERATOR, &restOfStr))) {
326 convVal = strtoul(elemData, NULL, 0);
327 if (errno == ERANGE) {
328 ERR_LOG("Cannot convert \"%s\" to ubyte array!\n", str);
329 result = APP_ERROR;
330 break;
331 }
332 val[index++] = (unsigned char)convVal & 0xFF;
333 }
334 }
335
336 free(tmpStr);
337 }
338
339 if (result == APP_NO_ERROR) {
340 *data = val;
341 *arraySize = size;
342 } else {
343 free(val);
344 *data = NULL;
345 *arraySize = 0;
346 }
347 return result;
348 }
349 case TYPE_SHORT_ARRAY: {
350 char *elemData;
351 unsigned int convVal;
352 int index = 0;
353 APP_STATUS result = APP_NO_ERROR;
354
355 int size = paramGetArraySizeFromString(str);
356 short *val = malloc(sizeof(short) * size);
357
358 if (size == 1) {
359 /* Convert str */
360 convVal = strtol(str, NULL, 0);
361 if (errno == ERANGE) {
362 ERR_LOG("Cannot convert \"%s\" to short array!\n", str);
363 result = APP_ERROR;
364 } else {
365 val[0] = (short)convVal & 0xFFFF;
366 }
367 } else {
368 char *tmpStr = strdup(str);
369 char *restOfStr = NULL;
370 elemData = utilStrtok(tmpStr, ARRAY_SEPERATOR, &restOfStr);
371
372 /* Convert str */
373 if (elemData != NULL) {
374 convVal = strtol(elemData, NULL, 0);
375 } else {
376 errno = ERANGE;
377 }
378
379 if (errno == ERANGE) {
380 ERR_LOG("Cannot convert \"%s\" to short array!\n", str);
381 result = APP_ERROR;
382 } else {
383 val[index++] = (short)convVal & 0xFFFF;
384
385 while ((elemData = utilStrtok(NULL, ARRAY_SEPERATOR, &restOfStr))) {
386 convVal = strtol(elemData, NULL, 0);
387 if (errno == ERANGE) {
388 ERR_LOG("Cannot convert \"%s\" to short array!\n", str);
389 result = APP_ERROR;
390 break;
391 }
392 val[index++] = (short)convVal & 0xFFFF;
393 }
394 }
395
396 free(tmpStr);
397 }
398
399 if (result == APP_NO_ERROR) {
400 *data = val;
401 *arraySize = size;
402 } else {
403 free(val);
404 *data = NULL;
405 *arraySize = 0;
406 }
407 return result;
408 }
409 case TYPE_USHORT_ARRAY: {
410 char *elemData;
411 unsigned int convVal;
412 int index = 0;
413 APP_STATUS result = APP_NO_ERROR;
414
415 int size = paramGetArraySizeFromString(str);
416 unsigned short *val = malloc(sizeof(unsigned short) * size);
417
418 if (size == 1) {
419 /* Convert str */
420 convVal = strtoul(str, NULL, 0);
421 if (errno == ERANGE) {
422 ERR_LOG("Cannot convert \"%s\" to ushort array!\n", str);
423 result = APP_ERROR;
424 } else {
425 val[0] = (unsigned short)convVal & 0xFFFF;
426 }
427 } else {
428 char *tmpStr = strdup(str);
429 char *restOfStr = NULL;
430 elemData = utilStrtok(tmpStr, ARRAY_SEPERATOR, &restOfStr);
431
432 /* Convert str */
433 if (elemData != NULL) {
434 convVal = strtoul(elemData, NULL, 0);
435 } else {
436 errno = ERANGE;
437 }
438
439 if (errno == ERANGE) {
440 ERR_LOG("Cannot convert \"%s\" to ushort array!\n", str);
441 result = APP_ERROR;
442 } else {
443 val[index++] = (unsigned short)convVal & 0xFFFF;
444
445 while ((elemData = utilStrtok(NULL, ARRAY_SEPERATOR, &restOfStr))) {
446 convVal = strtoul(elemData, NULL, 0);
447 if (errno == ERANGE) {
448 ERR_LOG("Cannot convert \"%s\" to ushort array!\n", str);
449 result = APP_ERROR;
450 break;
451 }
452 val[index++] = (unsigned short)convVal & 0xFFFF;
453 }
454 }
455
456 free(tmpStr);
457 }
458
459 if (result == APP_NO_ERROR) {
460 *data = val;
461 *arraySize = size;
462 } else {
463 free(val);
464 *data = NULL;
465 *arraySize = 0;
466 }
467 return result;
468 }
469 case TYPE_INT_ARRAY: {
470 char *elemData;
471 unsigned int convVal;
472 int index = 0;
473 APP_STATUS result = APP_NO_ERROR;
474
475 int size = paramGetArraySizeFromString(str);
476 int *val = malloc(sizeof(int) * size);
477
478 if (size == 1) {
479 /* Convert str */
480 convVal = strtol(str, NULL, 0);
481 if (errno == ERANGE) {
482 ERR_LOG("Cannot convert \"%s\" to int array!\n", str);
483 result = APP_ERROR;
484 } else {
485 val[0] = (int)convVal & 0xFFFFFFFF;
486 }
487 } else {
488 char *tmpStr = strdup(str);
489 char *restOfStr = NULL;
490 elemData = utilStrtok(tmpStr, ARRAY_SEPERATOR, &restOfStr);
491
492 /* Convert str */
493 if (elemData != NULL) {
494 convVal = strtol(elemData, NULL, 0);
495 } else {
496 errno = ERANGE;
497 }
498
499 if (errno == ERANGE) {
500 ERR_LOG("Cannot convert \"%s\" to int array!\n", str);
501 result = APP_ERROR;
502 } else {
503 val[index++] = (int)convVal & 0xFFFFFFFF;
504
505 while ((elemData = utilStrtok(NULL, ARRAY_SEPERATOR, &restOfStr))) {
506 convVal = strtoul(elemData, NULL, 0);
507 if (errno == ERANGE) {
508 ERR_LOG("Cannot convert \"%s\" to int array!\n", str);
509 result = APP_ERROR;
510 break;
511 }
512 val[index++] = (int)convVal & 0xFFFFFFFF;
513 }
514 }
515
516 free(tmpStr);
517 }
518
519 if (result == APP_NO_ERROR) {
520 *data = val;
521 *arraySize = size;
522 } else {
523 free(val);
524 *data = NULL;
525 *arraySize = 0;
526 }
527 return result;
528 }
529 case TYPE_UINT_ARRAY: {
530 char *elemData;
531 unsigned int convVal;
532 int index = 0;
533 APP_STATUS result = APP_NO_ERROR;
534
535 int size = paramGetArraySizeFromString(str);
536 unsigned int *val = malloc(sizeof(unsigned int) * size);
537
538 if (size == 1) {
539 /* Convert str */
540 convVal = strtoul(str, NULL, 0);
541 if (errno == ERANGE) {
542 ERR_LOG("Cannot convert \"%s\" to uint array!\n", str);
543 result = APP_ERROR;
544 } else {
545 val[0] = (unsigned int)convVal & 0xFFFFFFFF;
546 }
547 } else {
548 char *tmpStr = strdup(str);
549 char *restOfStr = NULL;
550 elemData = utilStrtok(tmpStr, ARRAY_SEPERATOR, &restOfStr);
551
552 /* Convert str */
553 if (elemData != NULL) {
554 convVal = strtoul(elemData, NULL, 0);
555 } else {
556 errno = ERANGE;
557 }
558
559 if (errno == ERANGE) {
560 ERR_LOG("Cannot convert \"%s\" to uint array!\n", str);
561 result = APP_ERROR;
562 } else {
563 val[index++] = (unsigned int)convVal & 0xFFFFFFFF;
564
565 while ((elemData = utilStrtok(NULL, ARRAY_SEPERATOR, &restOfStr))) {
566 convVal = strtoul(elemData, NULL, 0);
567 if (errno == ERANGE) {
568 ERR_LOG("Cannot convert \"%s\" to uint array!\n", str);
569 result = APP_ERROR;
570 break;
571 }
572 val[index++] = (unsigned int)convVal & 0xFFFFFFFF;
573 }
574 }
575
576 free(tmpStr);
577 }
578
579 if (result == APP_NO_ERROR) {
580 *data = val;
581 *arraySize = size;
582 } else {
583 free(val);
584 *data = NULL;
585 *arraySize = 0;
586 }
587 return result;
588 }
589 case TYPE_DOUBLE_ARRAY: {
590 char *elemData, *p;
591 double convVal;
592 int index = 0;
593 APP_STATUS result = APP_NO_ERROR;
594
595 int size = paramGetArraySizeFromString(str);
596 double *val = malloc(sizeof(double) * size);
597
598 if (size == 1) {
599 /* Convert str */
600 convVal = strtod(str, &p);
601 if (p != (str + strlen(str))) {
602 ERR_LOG("Cannot convert \"%s\" to double array!\n", str);
603 result = APP_ERROR;
604 } else {
605 val[0] = (double)convVal;
606 }
607 } else {
608 char *tmpStr = strdup(str);
609 char *restOfStr = NULL;
610 elemData = utilStrtok(tmpStr, ARRAY_SEPERATOR, &restOfStr);
611
612 if (elemData) {
613 /* Convert str */
614 convVal = strtod(elemData, &p);
615 if (p != (elemData + strlen(elemData))) {
616 ERR_LOG("Cannot convert \"%s\" to double array!\n", elemData);
617 result = APP_ERROR;
618 } else {
619 val[index++] = (double)convVal;
620
621 while ((elemData = utilStrtok(NULL, ARRAY_SEPERATOR, &restOfStr))) {
622 convVal = strtod(elemData, &p);
623 if (p != (elemData + strlen(elemData))) {
624 ERR_LOG("Cannot convert \"%s\" to double array!\n", elemData);
625 result = APP_ERROR;
626 break;
627 }
628 val[index++] = (double)convVal;
629 }
630 }
631 } else {
632 ERR_LOG("elemData is NULL");
633 result = APP_ERROR;
634 }
635
636 free(tmpStr);
637 }
638
639 if (result == APP_NO_ERROR) {
640 *data = val;
641 *arraySize = size;
642 } else {
643 free(val);
644 *data = NULL;
645 *arraySize = 0;
646 }
647 return result;
648 }
649 case TYPE_UNKNOWN:
650 *data = strdup(str);
651 *arraySize = 0;
652 break;
653 default:
654 *data = NULL;
655 *arraySize = 0;
656 break;
657 }
658
659 return APP_NO_ERROR;
660}
661
662EXPORT char *utilConvDataToString(DATA_TYPE dataType, void *data, int arraySize, int uArrayHexMode) {
663 char *str = NULL;
664 UT_string *dataStr = NULL;
665
666 switch (dataType) {
667 case TYPE_STR: {
668 str = strdup((char *)data);
669 return str;
670 }
671 case TYPE_INT: {
672 int value = *(int *) data;
673 utstring_new(dataStr);
674 utstring_printf(dataStr, "%d", value);
675 str = strdup(utstring_body(dataStr));
676 utstring_free(dataStr);
677 return str;
678 }
679 case TYPE_UINT: {
680 unsigned int value = *(unsigned int *) data;
681 utstring_new(dataStr);
682 utstring_printf(dataStr, "%u", value);
683 str = strdup(utstring_body(dataStr));
684 utstring_free(dataStr);
685 return str;
686 }
687 case TYPE_FLOAT: {
688 float value = *(float *) data;
689 utstring_new(dataStr);
690 utstring_printf(dataStr, "%f", value);
691 str = strdup(utstring_body(dataStr));
692 utstring_free(dataStr);
693 return str;
694 }
695 case TYPE_BYTE_ARRAY: {
696 char *byteArray = (char *)data;
697 int i = 0;
698 utstring_new(dataStr);
699 for (i = 0; i < arraySize; i++) {
700 if (i == arraySize - 1) {
701 utstring_printf(dataStr, "%d", byteArray[i]);
702 } else {
703 utstring_printf(dataStr, "%d,", byteArray[i]);
704 }
705 }
706 str = strdup(utstring_body(dataStr));
707 utstring_free(dataStr);
708 return str;
709 }
710 case TYPE_UBYTE_ARRAY: {
711 unsigned char *ubyteArray = (unsigned char *)data;
712 int i = 0;
713 utstring_new(dataStr);
714 for (i = 0; i < arraySize; i++) {
715 if (i == arraySize - 1) {
716 utstring_printf(dataStr, uArrayHexMode ? "0x%X" : "%d", ubyteArray[i]);
717 } else {
718 utstring_printf(dataStr, uArrayHexMode ? "0x%X," : "%d,", ubyteArray[i]);
719 }
720 }
721 str = strdup(utstring_body(dataStr));
722 utstring_free(dataStr);
723 return str;
724 }
725 case TYPE_SHORT_ARRAY: {
726 short *shortArray = (short *)data;
727 int i = 0;
728 utstring_new(dataStr);
729 for (i = 0; i < arraySize; i++) {
730 if (i == arraySize - 1) {
731 utstring_printf(dataStr, "%d", shortArray[i]);
732 } else {
733 utstring_printf(dataStr, "%d,", shortArray[i]);
734 }
735 }
736 str = strdup(utstring_body(dataStr));
737 utstring_free(dataStr);
738 return str;
739 }
740 case TYPE_USHORT_ARRAY: {
741 unsigned short *ushortArray = (unsigned short *)data;
742 int i = 0;
743 utstring_new(dataStr);
744 for (i = 0; i < arraySize; i++) {
745 if (i == arraySize - 1) {
746 utstring_printf(dataStr, uArrayHexMode ? "0x%X" : "%d", ushortArray[i]);
747 } else {
748 utstring_printf(dataStr, uArrayHexMode ? "0x%X," : "%d,", ushortArray[i]);
749 }
750 }
751 str = strdup(utstring_body(dataStr));
752 utstring_free(dataStr);
753 return str;
754 }
755 case TYPE_INT_ARRAY: {
756 int *intArray = (int *)data;
757 int i = 0;
758 utstring_new(dataStr);
759 for (i = 0; i < arraySize; i++) {
760 if (i == arraySize - 1) {
761 utstring_printf(dataStr, "%d", intArray[i]);
762 } else {
763 utstring_printf(dataStr, "%d,", intArray[i]);
764 }
765 }
766 str = strdup(utstring_body(dataStr));
767 utstring_free(dataStr);
768 return str;
769 }
770 case TYPE_UINT_ARRAY: {
771 unsigned int *uintArray = (unsigned int *)data;
772 int i = 0;
773 utstring_new(dataStr);
774 for (i = 0; i < arraySize; i++) {
775 if (i == arraySize - 1) {
776 utstring_printf(dataStr, uArrayHexMode ? "0x%X" : "%d", uintArray[i]);
777 } else {
778 utstring_printf(dataStr, uArrayHexMode ? "0x%X," : "%d,", uintArray[i]);
779 }
780 }
781 str = strdup(utstring_body(dataStr));
782 utstring_free(dataStr);
783 return str;
784 }
785 case TYPE_DOUBLE_ARRAY: {
786 double *doubleArray = (double *)data;
787 int i = 0;
788 utstring_new(dataStr);
789 for (i = 0; i < arraySize; i++) {
790 if (i == arraySize - 1) {
791 utstring_printf(dataStr, "%f", doubleArray[i]);
792 } else {
793 utstring_printf(dataStr, "%f,", doubleArray[i]);
794 }
795 }
796 str = strdup(utstring_body(dataStr));
797 utstring_free(dataStr);
798 return str;
799 }
800 case TYPE_UNKNOWN:
801 case TYPE_FIELD:
802 break;
803 }
804
805 return str;
806}
807
808/* Convert category path to category group path. eg: HAC -> Handset */
809EXPORT UT_string *utilNormalizeCategoryGroupPathForAudioType(const char *categoryPath, AudioType *audioType) {
810 UT_string *searchPath = NULL;
811 char *categoryType, *category, *tmpCategoryPath;
812 char *restOfStr = NULL;
813 StrPair *strPairHash = NULL, *pair = NULL;
814 size_t numOfCategoryType, i;
815 utstring_new(searchPath);
816
817 /* Split string with token to parse category path info */
818 tmpCategoryPath = strdup(categoryPath);
819 if ((categoryType = utilStrtok(tmpCategoryPath, ARRAY_SEPERATOR, &restOfStr)) == NULL) {
820 free(tmpCategoryPath);
821 return searchPath;
822 }
823
824 if ((category = utilStrtok(NULL, ARRAY_SEPERATOR, &restOfStr)) == NULL) {
825 free(tmpCategoryPath);
826 return searchPath;
827 }
828
829 pair = strPairCreate(categoryType, category);
830 HASH_ADD_KEYPTR(hh, strPairHash, pair->key, strlen(pair->key), pair);
831 while ((categoryType = utilStrtok(NULL, ARRAY_SEPERATOR, &restOfStr))) {
832 if ((category = utilStrtok(NULL, ARRAY_SEPERATOR, &restOfStr))) {
833 pair = strPairCreate(categoryType, category);
834 HASH_ADD_KEYPTR(hh, strPairHash, pair->key, strlen(pair->key), pair);
835 }
836 }
837 free(tmpCategoryPath);
838
839 /* Finding the audioType related Cateory*/
840 numOfCategoryType = audioTypeGetNumOfCategoryType(audioType);
841 for (i = 0; i < numOfCategoryType; i++) {
842 CategoryType *categoryType = audioTypeGetCategoryTypeByIndex(audioType, i);
843 HASH_FIND_STR(strPairHash, categoryType->name, pair);
844 if (pair) {
845 /* Checking if there is alias for the category name */
846 CategoryAlias *categoryAlias = categoryTypeGetCategoryByAlias(categoryType, pair->value);
847 if (categoryAlias) {
848 if (categoryAlias->category->parentType == PARENT_IS_CATEGORY_GROUP) {
849 utstring_printf(searchPath, "%s"ARRAY_SEPERATOR, ((CategoryGroup *)categoryAlias->category->parent.category)->name);
850 } else {
851 WARN_LOG("Cannot get the categroup name of %s category!\n", categoryAlias->category->name);
852 }
853 } else {
854 Category *category = categoryTypeGetCategoryByName(categoryType, pair->value);
855 if (category && category->parentType == PARENT_IS_CATEGORY_GROUP) {
856 utstring_printf(searchPath, "%s"ARRAY_SEPERATOR, ((CategoryGroup *)category->parent.category)->name);
857 } else {
858 /* If the category is not category group, checking the bypass list */
859 int arrayIndex = 0;
860 int bypassCategoryName = 0;
861
862 for (arrayIndex = 0; HARD_CATEGORY_GROUP[arrayIndex][0]; arrayIndex++) {
863 if (!strncmp(audioType->name, HARD_CATEGORY_GROUP[arrayIndex][0], strlen(audioType->name) + 1)
864 && !strncmp(pair->key, HARD_CATEGORY_GROUP[arrayIndex][1], strlen(pair->key) + 1)
865 && !strncmp(pair->value, HARD_CATEGORY_GROUP[arrayIndex][2], strlen(pair->value) + 1)) {
866 bypassCategoryName = 1;
867 break;
868 }
869 }
870
871 if (bypassCategoryName) {
872 utstring_printf(searchPath, "%s"ARRAY_SEPERATOR, HARD_CATEGORY_GROUP[arrayIndex][2]);
873 } else {
874 WARN_LOG("Cannot get the categroup name of %s category!\n", pair->value);
875 }
876 }
877 }
878 }
879 }
880
881 /* Remove the end of seperator char */
882 {
883 char *ch = strrchr(utstring_body(searchPath), ARRAY_SEPERATOR_CH);
884 if (ch) {
885 *ch = '\0';
886 }
887 }
888
889 /* Release strPair */
890 if (strPairHash) {
891 StrPair *tmp, *item;
892 HASH_ITER(hh, strPairHash, item, tmp) {
893 HASH_DEL(strPairHash, item);
894 strPairRelease(item);
895 }
896 }
897
898 return searchPath;
899}
900
901EXPORT UT_string *utilNormalizeCategoryPathForAudioType(const char *categoryPath, AudioType *audioType) {
902 UT_string *searchPath = NULL;
903 char *categoryType, *category, *tmpCategoryPath;
904 char *restOfStr = NULL;
905 StrPair *strPairHash = NULL, *pair = NULL;
906 size_t numOfCategoryType, i;
907 utstring_new(searchPath);
908
909 /* Split string with token to parse category path info */
910 tmpCategoryPath = strdup(categoryPath);
911 if ((categoryType = utilStrtok(tmpCategoryPath, ARRAY_SEPERATOR, &restOfStr)) == NULL) {
912 free(tmpCategoryPath);
913 return searchPath;
914 }
915
916 if ((category = utilStrtok(NULL, ARRAY_SEPERATOR, &restOfStr)) == NULL) {
917 free(tmpCategoryPath);
918 return searchPath;
919 }
920
921 pair = strPairCreate(categoryType, category);
922 HASH_ADD_KEYPTR(hh, strPairHash, pair->key, strlen(pair->key), pair);
923 while ((categoryType = utilStrtok(NULL, ARRAY_SEPERATOR, &restOfStr))) {
924 if ((category = utilStrtok(NULL, ARRAY_SEPERATOR, &restOfStr))) {
925 pair = strPairCreate(categoryType, category);
926 HASH_ADD_KEYPTR(hh, strPairHash, pair->key, strlen(pair->key), pair);
927 }
928 }
929 free(tmpCategoryPath);
930
931 /* Finding the audioType related Cateory*/
932 numOfCategoryType = audioTypeGetNumOfCategoryType(audioType);
933 for (i = 0; i < numOfCategoryType; i++) {
934 CategoryType *categoryType = audioTypeGetCategoryTypeByIndex(audioType, i);
935 HASH_FIND_STR(strPairHash, categoryType->name, pair);
936 if (pair) {
937 /* Checking if there is alias for the category name */
938 CategoryAlias *categoryAlias = categoryTypeGetCategoryByAlias(categoryType, pair->value);
939 if (categoryAlias) {
940 utstring_printf(searchPath, "%s"ARRAY_SEPERATOR, categoryAlias->category->name);
941 } else {
942 utstring_printf(searchPath, "%s"ARRAY_SEPERATOR, pair->value);
943 }
944 }
945 }
946
947 /* Remove the end of seperator char */
948 {
949 char *ch = strrchr(utstring_body(searchPath), ARRAY_SEPERATOR_CH);
950 if (ch) {
951 *ch = '\0';
952 }
953 }
954
955 /* Release strPair */
956 if (strPairHash) {
957 StrPair *tmp, *item;
958 HASH_ITER(hh, strPairHash, item, tmp) {
959 HASH_DEL(strPairHash, item);
960 strPairRelease(item);
961 }
962 }
963
964 return searchPath;
965}
966
967EXPORT int utilFindUnusedParamId(AudioType *audioType) {
968 ParamUnit *paramUnit;
969 while (1) {
970 HASH_FIND_INT(audioType->paramUnitHash, &audioType->unusedParamId, paramUnit);
971 if (paramUnit) {
972 audioType->unusedParamId++;
973 } else {
974 INFO_LOG("Unsed param ID found (id = %d)\n", audioType->unusedParamId);
975 return audioType->unusedParamId++;
976 }
977 }
978
979 return 0;
980}
981
982
983EXPORT void utilUsleep(unsigned int usec) {
984#ifndef WIN32
985 usleep(usec);
986#else
987 Sleep(usec);
988#endif
989}
990
991EXPORT char *utilGetStdin(char *buf, int bufSize) {
992 char *input;
993 input = fgets(buf, bufSize, stdin);
994 if ((input = strchr(input, '\n')) != NULL) {
995 *input = '\0';
996 }
997 return buf;
998}
999
1000EXPORT void utilLog(char *format, ...) {
1001 time_t timep;
1002 struct tm *p;
1003 va_list arglist;
1004
1005 /* Get time struct */
1006 time(&timep);
1007 p = localtime(&timep);
1008
1009 if (appLogFp == NULL) {
1010 /* Create file handle */
1011 UT_string *fileName = NULL;
1012 utstring_new(fileName);
1013 utstring_printf(fileName, "%04d%02d%02d_%02d%02d%02d_AppLogFile.txt", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);
1014 appLogFp = fopen(utstring_body(fileName), "a");
1015 utstring_free(fileName);
1016
1017 if (!appLogFp) {
1018 printf("Log file open failed!\n");
1019 exit(1);
1020 }
1021 }
1022
1023 /* Write to file */
1024 fprintf(appLogFp, "%02d-%02d %02d:%02d:%02d ", 1 + p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);
1025 va_start(arglist, format);
1026 vfprintf(appLogFp, format, arglist);
1027 va_end(arglist);
1028
1029 /* Show log to console */
1030 if (outputLogToStdout) {
1031 va_start(arglist, format);
1032 vfprintf(stdout, format, arglist);
1033 va_end(arglist);
1034 }
1035}
1036
1037EXPORT void utilLogClose() {
1038 if (appLogFp) {
1039 fflush(appLogFp);
1040 fclose(appLogFp);
1041 appLogFp = NULL;
1042 }
1043}
1044
1045EXPORT void utilShowParamValue(Param *param) {
1046 if (!param) {
1047 ERR_LOG("param is NULL\n");
1048 return;
1049 }
1050
1051 switch (param->paramInfo->dataType) {
1052 case TYPE_STR: {
1053 char *value = (char *)param->data;
1054 printf("param name = %s, value = %s (type = %s, bytes = "APP_SIZE_T_FT")\n", param->name, value, paramDataTypeToStr(param->paramInfo->dataType), paramGetNumOfBytes(param));
1055 break;
1056 }
1057 case TYPE_INT: {
1058 int value = *(int *) param->data;
1059 printf("param name = %s, value = %d (type = %s, bytes = "APP_SIZE_T_FT")\n", param->name, value, paramDataTypeToStr(param->paramInfo->dataType), paramGetNumOfBytes(param));
1060 break;
1061 }
1062 case TYPE_UINT: {
1063 unsigned int value = *(unsigned int *) param->data;
1064 printf("param name = %s, value = %d (type = %s, bytes = "APP_SIZE_T_FT")\n", param->name, value, paramDataTypeToStr(param->paramInfo->dataType), paramGetNumOfBytes(param));
1065 break;
1066 }
1067 case TYPE_FLOAT: {
1068 float value = *(float *) param->data;
1069 /* JH's platform cannot show the float type, wei chiu could show the value by %f*/
1070 printf("param name = %s, value = %d (type = %s, bytes = "APP_SIZE_T_FT")\n", param->name, (int)value, paramDataTypeToStr(param->paramInfo->dataType), paramGetNumOfBytes(param));
1071 break;
1072 }
1073 case TYPE_BYTE_ARRAY: {
1074 char *byteArray = (char *)param->data;
1075 int arraySize = param->arraySize;
1076 int i = 0;
1077 printf("param name = %s (type = %s, size = %d, bytes = "APP_SIZE_T_FT")\n", param->name, paramDataTypeToStr(param->paramInfo->dataType), arraySize, paramGetNumOfBytes(param));
1078 for (i = 0; i < arraySize; i++) {
1079 printf("\tarray[%d] 0x%x\n", i, byteArray[i]);
1080 }
1081 break;
1082 }
1083 case TYPE_UBYTE_ARRAY: {
1084 unsigned char *ubyteArray = (unsigned char *)param->data;
1085 int arraySize = param->arraySize;
1086 int i = 0;
1087 printf("param name = %s (type = %s, size = %d, bytes = "APP_SIZE_T_FT")\n", param->name, paramDataTypeToStr(param->paramInfo->dataType), arraySize, paramGetNumOfBytes(param));
1088 for (i = 0; i < arraySize; i++) {
1089 printf("\tarray[%d] 0x%x\n", i, ubyteArray[i]);
1090 }
1091 break;
1092 }
1093 case TYPE_SHORT_ARRAY: {
1094 short *shortArray = (short *)param->data;
1095 int arraySize = param->arraySize;
1096 int i = 0;
1097 printf("param name = %s (type = %s, size = %d, bytes = "APP_SIZE_T_FT")\n", param->name, paramDataTypeToStr(param->paramInfo->dataType), arraySize, paramGetNumOfBytes(param));
1098 for (i = 0; i < arraySize; i++) {
1099 printf("\tarray[%d] %d\n", i, shortArray[i]);
1100 }
1101 break;
1102 }
1103 case TYPE_USHORT_ARRAY: {
1104 unsigned short *ushortArray = (unsigned short *)param->data;
1105 int arraySize = param->arraySize;
1106 int i = 0;
1107 printf("param name = %s (type = %s, size = %d, bytes = "APP_SIZE_T_FT")\n", param->name, paramDataTypeToStr(param->paramInfo->dataType), arraySize, paramGetNumOfBytes(param));
1108 for (i = 0; i < arraySize; i++) {
1109 printf("\tarray[%d] 0x%x\n", i, ushortArray[i]);
1110 }
1111 break;
1112 }
1113 case TYPE_INT_ARRAY: {
1114 int *intArray = (int *)param->data;
1115 int arraySize = param->arraySize;
1116 int i = 0;
1117 printf("param name = %s (type = %s, size = %d, bytes = "APP_SIZE_T_FT")\n", param->name, paramDataTypeToStr(param->paramInfo->dataType), arraySize, paramGetNumOfBytes(param));
1118 for (i = 0; i < arraySize; i++) {
1119 printf("\tarray[%d] %d\n", i, intArray[i]);
1120 }
1121 break;
1122 }
1123 case TYPE_UINT_ARRAY: {
1124 unsigned int *uintArray = (unsigned int *)param->data;
1125 int arraySize = param->arraySize;
1126 int i = 0;
1127 printf("param name = %s (type = %s, size = %d, bytes = "APP_SIZE_T_FT")\n", param->name, paramDataTypeToStr(param->paramInfo->dataType), arraySize, paramGetNumOfBytes(param));
1128 for (i = 0; i < arraySize; i++) {
1129 printf("\tarray[%d] 0x%x\n", i, uintArray[i]);
1130 }
1131 break;
1132 }
1133 case TYPE_DOUBLE_ARRAY: {
1134 double *doubleArray = (double *)param->data;
1135 int arraySize = param->arraySize;
1136 int i = 0;
1137 printf("param name = %s (type = %s, size = %d, bytes = "APP_SIZE_T_FT")\n", param->name, paramDataTypeToStr(param->paramInfo->dataType), arraySize, paramGetNumOfBytes(param));
1138 for (i = 0; i < arraySize; i++) {
1139 printf("\tarray[%d] %f\n", i, doubleArray[i]);
1140 }
1141 break;
1142 }
1143 default:
1144 printf("param name = %s, value = 0x%p (type = %s, bytes = "APP_SIZE_T_FT")\n", param->name, param->data, paramDataTypeToStr(param->paramInfo->dataType), paramGetNumOfBytes(param));
1145 }
1146}
1147
1148EXPORT FieldInfo *utilXmlNodeGetFieldInfo(AppHandle *appHandle, xmlNode *node, const char *audioTypeAttrName, const char *paramAttrName, const char *fieldAttrName) {
1149 AudioType *audioType = NULL;
1150 ParamInfo *paramInfo = NULL;
1151 FieldInfo *fieldInfo = NULL;
1152
1153 xmlChar *audioTypeName = NULL;
1154 xmlChar *paramName = NULL;
1155 xmlChar *fieldName = NULL;
1156
1157 audioTypeName = xmlNodeGetProp(node, audioTypeAttrName);
1158 if (audioTypeName) {
1159 audioType = appHandleGetAudioTypeByName(appHandle, (const char *)audioTypeName);
1160 } else {
1161 return NULL;
1162 }
1163
1164 paramName = xmlNodeGetProp(node, paramAttrName);
1165 if (audioType && paramName) {
1166 paramInfo = audioTypeGetParamInfoByName(audioType, (const char *)paramName);
1167 } else {
1168 WARN_LOG("Cannot find FieldInfo (AudioType = %s, Param = %s, Field = %s)\n", audioTypeName, paramName, fieldName);
1169 return NULL;
1170 }
1171
1172 fieldName = xmlNodeGetProp(node, fieldAttrName);
1173 if (paramInfo && fieldName) {
1174 fieldInfo = paramInfoGetFieldInfoByName(paramInfo, (const char *)fieldName);
1175 } else {
1176 WARN_LOG("Cannot find FieldInfo (AudioType = %s, Param = %s, Field = %s)\n", audioTypeName, paramName, fieldName);
1177 return NULL;
1178 }
1179
1180 if (!fieldInfo) {
1181 WARN_LOG("Cannot find FieldInfo (AudioType = %s, Param = %s, Field = %s)\n", audioTypeName, paramName, fieldName);
1182 }
1183
1184 return fieldInfo;
1185}
1186
1187EXPORT char *utilGenCheckList(int bits) {
1188 UT_string *dataStr = NULL;
1189 double num = pow(2, bits);
1190 int i = 0;
1191 char *retStr = NULL;
1192
1193 utstring_new(dataStr);
1194 for (i = 0; i < num; i++) {
1195 if (i != num - 1) {
1196 utstring_printf(dataStr, "%d,%d,", i, i);
1197 } else {
1198 utstring_printf(dataStr, "%d,%d", i, i);
1199 }
1200 }
1201
1202 retStr = strdup(utstring_body(dataStr));
1203 utstring_free(dataStr);
1204 return retStr;
1205}
1206
1207EXPORT void showTreeRoot(xmlNode *treeRootNode, const char *categoryPath) {
1208}
1209
1210EXPORT void utilMkdir(const char *dir) {
1211#ifdef WIN32
1212 _mkdir(dir);
1213#else
1214 mkdir(dir, 0770);
1215#endif
1216}
1217
1218unsigned int utilNativeGetField(const char *audioTypeName, const char *categoryPath, const char *paramName, const char *fieldName) {
1219 INFO_LOG("audioTypeName = %s, categoryPath = %s, paramName = %s, fieldName = %s", audioTypeName, categoryPath, paramName, fieldName);
1220
1221 if (audioTypeName && categoryPath && paramName && fieldName) {
1222#if defined(SYS_IMPL)
1223 char *resultStr = NULL;
1224 unsigned int result = 0;
1225 UT_string *str = NULL;
1226
1227 utstring_new(str);
1228 utstring_printf(str, APP_GET_FIELD_KEY "#%s#%s#%s#%s", audioTypeName, categoryPath, paramName, fieldName);
1229 resultStr = audioSystemGetParameters(utstring_body(str));
1230 result = atoi(resultStr);
1231 free(resultStr);
1232 utstring_free(str);
1233
1234 return result;
1235#else
1236 AppHandle *appHandle = NULL;
1237 AudioType *audioType = NULL;
1238 ParamUnit *paramUnit = NULL;
1239 unsigned int fieldValue = 0;
1240
1241 appHandle = appHandleGetInstance();
1242 if (appHandle) {
1243 audioType = appHandleGetAudioTypeByName(appHandle, audioTypeName);
1244 } else {
1245 ERR_LOG("appHandle is NULL\n");
1246 }
1247
1248 audioTypeReadLock(audioType, __FUNCTION__);
1249
1250 if (audioType) {
1251 paramUnit = audioTypeGetParamUnit(audioType, categoryPath);
1252 } else {
1253 ERR_LOG("categoryType is NULL\n");
1254 }
1255
1256 if (paramUnitGetFieldVal(paramUnit, paramName, fieldName, &fieldValue) == APP_ERROR) {
1257 ERR_LOG("Query field value fail!\n");
1258 } else {
1259 audioTypeUnlock(audioType);
1260 return fieldValue;
1261 }
1262 audioTypeUnlock(audioType);
1263#endif
1264 } else {
1265 ERR_LOG("Invalid parameter: audioType = %s, category path = %s, param = %s, field = %s\n", audioTypeName, categoryPath, paramName, fieldName);
1266 }
1267
1268 return 0;
1269}
1270
1271char *utilNativeGetParam(const char *audioTypeName, const char *categoryPath, const char *paramName) {
1272 char *paramDataStr = NULL;
1273 if (audioTypeName && categoryPath && paramName) {
1274#if defined(SYS_IMPL)
1275 INFO_LOG("audioTypeName = %s, categoryPath = %s, paramName = %s", audioTypeName, categoryPath, paramName);
1276 UT_string *str = NULL;
1277
1278 utstring_new(str);
1279 utstring_printf(str, APP_GET_PARAM_KEY "#%s#%s#%s", audioTypeName, categoryPath, paramName);
1280 paramDataStr = audioSystemGetParameters(utstring_body(str));
1281 utstring_free(str);
1282#else
1283 AppHandle *appHandle = NULL;
1284 AudioType *audioType = NULL;
1285 ParamUnit *paramUnit = NULL;
1286 Param *param = NULL;
1287
1288 appHandle = appHandleGetInstance();
1289 if (appHandle) {
1290 audioType = appHandleGetAudioTypeByName(appHandle, audioTypeName);
1291 } else {
1292 ERR_LOG("appHandle is NULL\n");
1293 }
1294
1295 audioTypeReadLock(audioType, __FUNCTION__);
1296
1297 if (audioType) {
1298 paramUnit = audioTypeGetParamUnit(audioType, categoryPath);
1299 } else {
1300 ERR_LOG("categoryType is NULL\n");
1301 }
1302
1303 if (paramUnit) {
1304 param = paramUnitGetParamByName(paramUnit, paramName);
1305 } else {
1306 ERR_LOG("paramUnit is NULL\n");
1307 }
1308
1309 if (param) {
1310 paramDataStr = paramNewDataStr(param);
1311 }
1312
1313 audioTypeUnlock(audioType);
1314#endif
1315 } else {
1316 ERR_LOG("Invalid parameter: audioType = %s, category path = %s, param = %s\n", audioTypeName, categoryPath, paramName);
1317 }
1318
1319 return paramDataStr;
1320}
1321
1322EXPORT char *utilNativeGetCategory(const char *audioTypeName, const char *categoryTypeName) {
1323 INFO_LOG("audioTypeName = %s, categoryTypeName = %s", audioTypeName, categoryTypeName);
1324
1325 if (audioTypeName && categoryTypeName) {
1326#if defined(SYS_IMPL)
1327 char *result = NULL;
1328 UT_string *str = NULL;
1329
1330 utstring_new(str);
1331 utstring_printf(str, APP_GET_CATEGORY_KEY "#%s#%s", audioTypeName, categoryTypeName);
1332 result = audioSystemGetParameters(utstring_body(str));
1333 utstring_free(str);
1334
1335 return result;
1336#else
1337 UT_string *utString = NULL;
1338 char *result;
1339 int firstCategory = 1;
1340 int numOfCategory, numOfCategoryGroup = 0;
1341 int i, j, k;
1342 AppHandle *appHandle = NULL;
1343 AudioType *audioType = NULL;
1344 CategoryType *categoryType = NULL;
1345
1346 utstring_new(utString);
1347 appHandle = appHandleGetInstance();
1348 if (appHandle) {
1349 audioType = appHandleGetAudioTypeByName(appHandle, audioTypeName);
1350 } else {
1351 ERR_LOG("appHandle is NULL\n");
1352 }
1353
1354 if (audioType) {
1355 categoryType = audioTypeGetCategoryTypeByName(audioType, categoryTypeName);
1356 } else {
1357 ERR_LOG("audioType is NULL\n");
1358 }
1359
1360 if (!categoryType) {
1361 ERR_LOG("categoryType is NULL\n");
1362 }
1363
1364 numOfCategoryGroup = categoryTypeGetNumOfCategoryGroup(categoryType);
1365 for (i = 0; i < numOfCategoryGroup; i++) {
1366 CategoryGroup *categoryGroup = categoryTypeGetCategoryGroupByIndex(categoryType, i);
1367 numOfCategory = categoryGroupGetNumOfCategory(categoryGroup);
1368 for (j = 0; j < numOfCategory; j++) {
1369 Category *category = categoryGroupGetCategoryByIndex(categoryGroup, j);
1370 if (firstCategory) {
1371 utstring_printf(utString, "%s,%s", category->name, category->wording);
1372 firstCategory = 0;
1373 } else {
1374 utstring_printf(utString, ",%s,%s", category->name, category->wording);
1375 }
1376 }
1377 }
1378
1379 numOfCategory = categoryTypeGetNumOfCategory(categoryType);
1380 for (k = 0; k < numOfCategory; k++) {
1381 Category *category = categoryTypeGetCategoryByIndex(categoryType, k);
1382 if (firstCategory) {
1383 utstring_printf(utString, "%s,%s", category->name, category->wording);
1384 firstCategory = 0;
1385 } else {
1386 utstring_printf(utString, ",%s,%s", category->name, category->wording);
1387 }
1388 }
1389
1390 result = strdup(utstring_body(utString));
1391 utstring_free(utString);
1392 return result;
1393#endif
1394 }
1395
1396 return NULL;
1397}
1398
1399EXPORT APP_STATUS utilNativeSetParam(const char *audioTypeName, const char *categoryPath, const char *paramName, const char *paramDataStr) {
1400 INFO_LOG("audioTypeName = %s, categoryPath = %s, paramName = %s", audioTypeName, categoryPath, paramName);
1401
1402 if (audioTypeName && categoryPath && paramName && paramDataStr) {
1403#if defined(SYS_IMPL)
1404 UT_string *str = NULL;
1405
1406 utstring_new(str);
1407 utstring_printf(str, APP_SET_PARAM_KEY "=%s#%s#%s#%s", audioTypeName, categoryPath, paramName, paramDataStr);
1408 audioSystemSetParameters(utstring_body(str));
1409 utstring_free(str);
1410
1411 return APP_NO_ERROR;
1412#else
1413 AppHandle *appHandle = NULL;
1414 AudioType *audioType = NULL;
1415 ParamInfo *paramInfo = NULL;
1416
1417 appHandle = appHandleGetInstance();
1418 if (appHandle) {
1419 audioType = appHandleGetAudioTypeByName(appHandle, audioTypeName);
1420 } else {
1421 ERR_LOG("appHandle is NULL\n");
1422 }
1423
1424 if (audioType) {
1425 paramInfo = audioTypeGetParamInfoByName(audioType, paramName);
1426 } else {
1427 ERR_LOG("audioType is NULL\n");
1428 }
1429
1430 if (paramInfo) {
1431 void *paramData = NULL;
1432 size_t arraySize = 0;
1433
1434 if (utilConvDataStringToNative(paramInfo->dataType, paramDataStr, &paramData, &arraySize) == APP_NO_ERROR) {
1435 if (audioTypeSetParamData(audioType, categoryPath, paramInfo, paramData, arraySize) == APP_ERROR) {
1436 ERR_LOG("audioTypeSetParamData fail! audioType = %s, categoryPath = %s, paramInfo = %s\n", audioType->name, categoryPath, paramInfo->name);
1437 } else {
1438 if (paramData) {
1439 free(paramData);
1440 }
1441 return APP_NO_ERROR;
1442 }
1443 } else {
1444 ERR_LOG("Cannot convert param string to native type (param str = %s)\n", paramDataStr);
1445 }
1446
1447 if (paramData) {
1448 free(paramData);
1449 }
1450 } else {
1451 ERR_LOG("paramInfo is NULL\n");
1452 }
1453#endif
1454 } else {
1455 ERR_LOG("Invalid parameter\n");
1456 }
1457
1458 return APP_ERROR;
1459}
1460
1461EXPORT APP_STATUS utilNativeSetField(const char *audioTypeName, const char *categoryPath, const char *paramName, const char *fieldName, const char *fieldValueStr) {
1462 INFO_LOG("audioTypeName = %s, categoryPath = %s, paramName = %s, fieldName = %s", audioTypeName, categoryPath, paramName, fieldName);
1463
1464 if (audioTypeName && categoryPath && paramName && fieldName && fieldValueStr) {
1465#if defined(SYS_IMPL)
1466 UT_string *str = NULL;
1467
1468 utstring_new(str);
1469 utstring_printf(str, APP_SET_FIELD_KEY "=%s#%s#%s#%s#%s", audioTypeName, categoryPath, paramName, fieldName, fieldValueStr);
1470 audioSystemSetParameters(utstring_body(str));
1471 utstring_free(str);
1472
1473 return APP_NO_ERROR;
1474#else
1475 AppHandle *appHandle = NULL;
1476 AudioType *audioType = NULL;
1477 ParamInfo *paramInfo = NULL;
1478 FieldInfo *fieldInfo = NULL;
1479
1480 appHandle = appHandleGetInstance();
1481 if (appHandle) {
1482 audioType = appHandleGetAudioTypeByName(appHandle, audioTypeName);
1483 } else {
1484 ERR_LOG("appHandle is NULL\n");
1485 }
1486
1487 if (audioType) {
1488 paramInfo = audioTypeGetParamInfoByName(audioType, paramName);
1489 } else {
1490 ERR_LOG("audioType is NULL\n");
1491 }
1492
1493 if (paramInfo) {
1494 fieldInfo = paramInfoGetFieldInfoByName(paramInfo, fieldName);
1495 } else {
1496 ERR_LOG("paramInfo is NULL\n");
1497 }
1498
1499 if (fieldInfo) {
1500 if (audioTypeSetFieldData(audioType, categoryPath, fieldInfo, strtoul(fieldValueStr, NULL, 0)) == APP_ERROR) {
1501 ERR_LOG("audioTypeSetFieldData fail!. audioType = %s, categoryPath = %s, paramInfo = %s, fieldInfo = %s, value = %s\n", audioType->name, categoryPath, paramInfo->name, fieldInfo->name, fieldValueStr);
1502 } else {
1503 return APP_NO_ERROR;
1504 }
1505 } else {
1506 ERR_LOG("fieldInfo is NULL\n");
1507 }
1508#endif
1509 } else {
1510 ERR_LOG("Invalid parameter\n");
1511 }
1512
1513 return APP_ERROR;
1514}
1515
1516EXPORT APP_STATUS utilNativeSaveXml(const char *audioTypeName) {
1517
1518#if defined(SYS_IMPL)
1519 INFO_LOG("audioTypeName = %s", audioTypeName);
1520 UT_string *str = NULL;
1521
1522 utstring_new(str);
1523 utstring_printf(str, APP_SAVE_XML_KEY "=%s", audioTypeName);
1524 audioSystemSetParameters(utstring_body(str));
1525 utstring_free(str);
1526#else
1527 AppHandle *appHandle = appHandleGetInstance();
1528 AudioType *audioType = appHandleGetAudioTypeByName(appHandle, audioTypeName);
1529 if (audioType) {
1530 if (audioType->dirty) {
1531#ifdef WIN32
1532 return audioTypeSaveAudioParamXml(audioType, XML_CUS_FOLDER_ON_TUNING_TOOL, 1) ;
1533#else
1534 return audioTypeSaveAudioParamXml(audioType, XML_CUS_FOLDER_ON_DEVICE, 1);
1535#endif
1536 } else {
1537 INFO_LOG("%s AudioType's parameter not changed, don't save XML\n", audioType->name);
1538 }
1539 } else {
1540 ERR_LOG("audioType is NULL\n");
1541 return APP_ERROR;
1542 }
1543#endif
1544
1545 return APP_NO_ERROR;
1546}
1547
1548EXPORT const char *utilNativeGetChecklist(const char *audioTypeName, const char *paramName, const char *fieldName) {
1549#if defined(SYS_IMPL)
1550 INFO_LOG("audioTypeName = %s, paramName = %s, fieldName = %s", audioTypeName, paramName, fieldName);
1551
1552 char *result = NULL;
1553 UT_string *str = NULL;
1554
1555 utstring_new(str);
1556 utstring_printf(str, APP_GET_CHECKLIST_KEY "#%s#%s#%s", audioTypeName, paramName, fieldName);
1557 result = audioSystemGetParameters(utstring_body(str));
1558 utstring_free(str);
1559
1560 return result;
1561#else
1562 AppHandle *appHandle = appHandleGetInstance();
1563 AudioType *audioType = appHandleGetAudioTypeByName(appHandle, audioTypeName);
1564 ParamInfo *paramInfo = NULL;
1565 FieldInfo *fieldInfo = NULL;
1566
1567 if (!audioType) {
1568 ERR_LOG("Cannot find %s AudioType\n", audioTypeName);
1569 return NULL;
1570 }
1571
1572 paramInfo = audioTypeGetParamInfoByName(audioType, paramName);
1573 if (!paramInfo) {
1574 ERR_LOG("Cannot find %s paramInfo of %s AudioType\n", paramName, audioTypeName);
1575 return NULL;
1576 }
1577
1578 fieldInfo = paramInfoGetFieldInfoByName(paramInfo, fieldName);
1579 if (!fieldInfo) {
1580 ERR_LOG("Cannot find %s fieldInfo of %s paramInfo of %s AudioType\n", fieldName, paramName, audioTypeName);
1581 return NULL;
1582 }
1583
1584 return fieldInfo->checkListStr;
1585#endif
1586}
1587
1588EXPORT int utilCompNormalizeCategoryPath(AudioType *audioType, const char *srcCategoryPath, const char *dstCategoryPath) {
1589 UT_string *srcNormalizedPath;
1590 UT_string *dstNormalizedPath;
1591 int equal = 0;
1592
1593 if (!strncmp(srcCategoryPath, dstCategoryPath, strlen(dstCategoryPath) + 1)) {
1594 return 1;
1595 }
1596
1597 srcNormalizedPath = utilNormalizeCategoryPathForAudioType(srcCategoryPath, audioType);
1598 dstNormalizedPath = utilNormalizeCategoryPathForAudioType(dstCategoryPath, audioType);
1599
1600 if (!strncmp(utstring_body(srcNormalizedPath), utstring_body(dstNormalizedPath), strlen(utstring_body(dstNormalizedPath)) + 1)) {
1601 equal = 1;
1602 INFO_LOG("Src path %s and dst path %s are equal to %s\n", srcCategoryPath, dstCategoryPath, utstring_body(srcNormalizedPath));
1603 } else {
1604 equal = 0;
1605 }
1606
1607 utstring_free(srcNormalizedPath);
1608 utstring_free(dstNormalizedPath);
1609
1610 return equal;
1611}
1612
1613EXPORT char *utilStrtok(char *str, const char *delim, char **saveptr) {
1614#ifdef WIN32
1615 return strtok(str, delim);
1616#else
1617 return strtok_r(str, delim, saveptr);
1618#endif
1619}
1620
1621EXPORT void utilShellExecute(const char *prog, const char *params) {
1622#ifdef WIN32
1623 SHELLEXECUTEINFO ShExecInfo = {0};
1624 ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
1625 ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
1626 ShExecInfo.hwnd = NULL;
1627 ShExecInfo.lpVerb = NULL;
1628 ShExecInfo.lpFile = prog;
1629 ShExecInfo.lpParameters = params;
1630 ShExecInfo.lpDirectory = NULL;
1631 ShExecInfo.nShow = SW_HIDE;
1632 ShExecInfo.hInstApp = NULL;
1633 ShellExecuteEx(&ShExecInfo);
1634 WaitForSingleObject(ShExecInfo.hProcess, INFINITE);
1635#endif
1636}