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