blob: eef274e0ccfba106cc6963f4d65937f283ecee07 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/* MediaTek Inc. (C) 2016. All rights reserved.
2 *
3 * Copyright Statement:
4 * This software/firmware and related documentation ("MediaTek Software") are
5 * protected under relevant copyright laws. The information contained herein is
6 * confidential and proprietary to MediaTek Inc. and/or its licensors. Without
7 * the prior written permission of MediaTek inc. and/or its licensors, any
8 * reproduction, modification, use or disclosure of MediaTek Software, and
9 * information contained herein, in whole or in part, shall be strictly
10 * prohibited.
11 */
12
13/*
14 * Description:
15 * Explor all public AudioParamParser APIs
16 */
17
18#ifndef AUDIO_PARAM_PARSER_H
19#define AUDIO_PARAM_PARSER_H
20
21#include <libxml/parser.h>
22#include <libxml/xmlreader.h>
23#include <libxml/tree.h>
24
25#ifdef WIN32
26#pragma warning( disable : 4996 )
27#ifdef __cplusplus
28#define EXPORT extern "C" __declspec(dllexport)
29#else
30#define EXPORT __declspec(dllexport)
31#endif
32#else /* WIN32*/
33#define EXPORT
34#ifdef __cplusplus
35extern "C" {
36#endif
37#endif
38
39#include "utstring.h"
40#include "uthash.h"
41#include "utlist.h"
42
43#ifndef WIN32
44#include <dlfcn.h>
45#include <pthread.h>
46#if defined(MTK_YOCTO_AUDIO)
47#include <logger/utils/Log.h>
48#else
49#include <utils/Log.h>
50#endif
51
52#endif
53
54/* Enable cus xml support */
55#define APP_FORCE_ENABLE_CUS_XML
56
57/* Debugging Macro Definition */
58//#define FORCE_DEBUG_LEVEL
59
60static const char *XML_FOLDER_LIST_ON_TUNING_TOOL[] = {
61 ".\\preload_xml\\",
62 NULL
63};
64#define XML_CUS_FOLDER_ON_TUNING_TOOL ".\\cus_xml\\"
65
66static const char *XML_FOLDER_LIST_ON_DEVICE[] = {
67 "/odm/etc/audio_param/",
68 "/vendor/etc/audio_param/",
69 "/system/etc/audio_param/",
70 NULL
71};
72
73/* For AudioParamParser on EM, No valid audio type list */
74static const char *EM_AUDIO_TYPE_LOADING_LIST[] = {
75 NULL
76};
77
78static const char *ATCMDHANDLER_AUDIO_TYPE_LOADING_LIST[] = {
79 "PlaybackACF",
80 "PlaybackDRC",
81 "PlaybackHCF",
82 "PlaybackVolDigi",
83 "SpeechVol",
84 "VoIPVol",
85 "Volume",
86 "VolumeGainMap",
87 NULL
88};
89
90#if defined(SYS_IMPL)
91#define APP_LIB_NAME "libaudio_param_parser-sys.so"
92#else
93#if defined(MTK_YOCTO_AUDIO)
94#define APP_LIB_NAME "libaudioparamparser.so.1.0.0"
95#else
96#define APP_LIB_NAME "libaudio_param_parser-vnd.so"
97#endif
98#endif
99
100#ifndef XML_CUS_FOLDER_ON_DEVICE
101#if defined(MTK_YOCTO_AUDIO)
102#define XML_CUS_FOLDER_ON_DEVICE "/home/root/.audio_param/"
103#else
104#define XML_CUS_FOLDER_ON_DEVICE "/data/vendor/audiohal/audio_param/"
105#endif
106#endif
107
108#define MAX_AUDIO_TYPE_LEN 50
109#define INOTIFY_BUF_SIZE 512
110
111#define AUDIO_PARAM_XML_POSFIX "_AudioParam.xml"
112#define PARAM_UNIT_DESC_XML_POSFIX "_ParamUnitDesc.xml"
113#define PARAM_TREE_VIEW_XML_POSFIX "_ParamTreeView.xml"
114#define FEATURE_OPTIONS_XML "AudioParamOptions.xml"
115
116/* XML element definition */
117#define ELEM_AUDIO_FEATURE_OPTIONS "AudioParamOptions"
118#define ELEM_PARAM "Param"
119#define ELEM_PARAM_UNIT_DESC "ParamUnitDesc"
120#define ELEM_CATEGORY_TYPE_LIST "CategoryTypeList"
121#define ELEM_CATEGORY_TYPE "CategoryType"
122#define ELEM_CATEGORY_GROUP "CategoryGroup"
123#define ELEM_CATEGORY "Category"
124
125#define ELEM_AUDIO_PARAM "AudioParam"
126#define ELEM_PARAM_TREE "ParamTree"
127#define ELEM_PARAM_UNIT_POOL "ParamUnitPool"
128#define ELEM_PARAM_UNIT "ParamUnit"
129#define ELEM_PARAM "Param"
130#define ELEM_FIELD "Field"
131
132#define ELEM_PARAM_TREE_VIEW "ParamTreeView"
133#define ELEM_TREE_ROOT "TreeRoot"
134#define ELEM_SHEET "Sheet"
135#define ELEM_FEATURE "Feature"
136#define ELEM_FIELD_LIST "FieldList"
137#define ELEM_CATEGORY_PATH_LIST "CategoryPathList"
138
139/* XML attribute definition */
140#define ATTRI_NAME "name"
141#define ATTRI_TAB_NAME "tab_name"
142#define ATTRI_VERSION "version"
143#define ATTRI_WORDING "wording"
144#define ATTRI_PARAM_ID "param_id"
145#define ATTRI_PATH "path"
146#define ATTRI_VALUE "value"
147#define ATTRI_TYPE "type"
148#define ATTRI_ARRAY_INDEX "array_index"
149#define ATTRI_BIT "bit"
150#define ATTRI_CHECK_LIST "check_list"
151#define ATTRI_ALIAS "alias"
152#define ATTRI_FEATURE_OPTION "feature_option"
153#define ATTRI_SWITCH_AUDIO_TYPE "switch_audio_type"
154#define ATTRI_SWITCH_PARAM "switch_param"
155#define ATTRI_SWITCH_FIELD "switch_field"
156#define ATTRI_AUDIO_TYPE "audio_type"
157#define ATTRI_PARAM "param"
158#define ATTRI_VISIBLE "visible"
159#define ATTRI_PATH_DESC "path_desc"
160
161/* DATA_TYPE string */
162#define DATA_TYPE_UNKNOWN_STRING "unknown"
163#define DATA_TYPE_STR_STRING "string"
164#define DATA_TYPE_INT_STRING "int"
165#define DATA_TYPE_UINT_STRING "uint"
166#define DATA_TYPE_FLOAT_STRING "float"
167#define DATA_TYPE_BYTE_ARRAY_STRING "byte_array"
168#define DATA_TYPE_UBYTE_ARRAY_STRING "ubyte_array"
169#define DATA_TYPE_SHORT_ARRAY_STRING "short_array"
170#define DATA_TYPE_USHORT_ARRAY_STRING "ushort_array"
171#define DATA_TYPE_INT_ARRAY_STRING "int_array"
172#define DATA_TYPE_UINT_ARRAY_STRING "uint_array"
173#define DATA_TYPE_DOUBLE_ARRAY_STRING "double_array"
174#define DATA_TYPE_FIELD_STRING "Field"
175
176#define ARRAY_SEPERATOR ","
177#define ARRAY_SEPERATOR_CH ','
178#define PARAM_FIELD_NAME_SEPERATOR "/"
179
180#define AUDIO_TYPE_FMT_STR(STR_LEN) AUDIO_TYPE_FMT(STR_LEN)
181#define AUDIO_TYPE_FMT(STR_LEN) "%"#STR_LEN"[^_]"
182
183#define APP_GET_FIELD_KEY "APP_GET_FIELD"
184#define APP_GET_FO_KEY "APP_GET_FO"
185#define APP_GET_PARAM_KEY "APP_GET_PARAM"
186#define APP_GET_CATEGORY_KEY "APP_GET_CATEGORY"
187#define APP_SET_PARAM_KEY "APP_SET_PARAM"
188#define APP_SET_FIELD_KEY "APP_SET_FIELD"
189#define APP_SAVE_XML_KEY "APP_SAVE_XML"
190#define APP_GET_CHECKLIST_KEY "APP_GET_CHECKLIST"
191
192typedef struct _AppHandle AppHandle;
193typedef struct _AudioType AudioType;
194typedef struct _FieldInfo FieldInfo;
195typedef struct _Category Category;
196typedef struct _CategoryAlias CategoryAlias;
197typedef struct _CategoryGroup CategoryGroup;
198typedef struct _CategoryNameAlias CategoryNameAlias;
199typedef struct _CategoryPath CategoryPath;
200typedef struct _CategoryType CategoryType;
201typedef struct _Feature Feature;
202typedef struct _FeatureField FeatureField;
203typedef struct _FeatureOption FeatureOption;
204typedef struct _Param Param;
205typedef struct _ParamInfo ParamInfo;
206typedef struct _ParamTreeView ParamTreeView;
207typedef struct _ParamUnit ParamUnit;
208typedef struct _TreeRoot TreeRoot;
209typedef struct _NotifyCb NotifyCb;
210
211typedef void(*NOTIFY_CB_FUN)(AppHandle *appHandle, const char *audioType);
212
213typedef enum {
214 DEBUG_LEVEL = 0,
215 INFO_LEVEL,
216 WARN_LEVEL,
217 ERR_LEVEL,
218} MSG_LEVEL;
219
220typedef enum {
221 APP_ERROR = 0,
222 APP_NO_ERROR = 1,
223} APP_STATUS;
224
225typedef enum {
226 PARENT_IS_CATEGORY_GROUP = 0,
227 PARENT_IS_CATEGORY_TYPE = 1,
228} CATEGORY_PARENT_TYPE;
229
230/*
231 Due to the system/media/camera/include/system/camera_metadata.h declare the same TYPE_FLOAT enum name,
232 If module include the camera_metadata.h and AudioParamParser.h, AudioParamParser change the DATA_TYPE
233 enum decleration to avoid conflict.
234 User could using the APP_TYPE_FLOAT enum instead the TYPE_FLOAT.
235*/
236#ifndef SYSTEM_MEDIA_INCLUDE_ANDROID_CAMERA_METADATA_H
237typedef enum {
238 TYPE_UNKNOWN = -1,
239 TYPE_STR,
240 TYPE_INT,
241 TYPE_UINT,
242 TYPE_FLOAT,
243 TYPE_BYTE_ARRAY,
244 TYPE_UBYTE_ARRAY,
245 TYPE_SHORT_ARRAY,
246 TYPE_USHORT_ARRAY,
247 TYPE_INT_ARRAY,
248 TYPE_UINT_ARRAY,
249 TYPE_DOUBLE_ARRAY,
250 TYPE_FIELD,
251} DATA_TYPE;
252#else
253typedef enum {
254 APP_TYPE_UNKNOWN = -1,
255 APP_TYPE_STR,
256 APP_TYPE_INT,
257 APP_TYPE_UINT,
258 APP_TYPE_FLOAT,
259 APP_TYPE_BYTE_ARRAY,
260 APP_TYPE_UBYTE_ARRAY,
261 APP_TYPE_SHORT_ARRAY,
262 APP_TYPE_USHORT_ARRAY,
263 APP_TYPE_INT_ARRAY,
264 APP_TYPE_UINT_ARRAY,
265 APP_TYPE_DOUBLE_ARRAY,
266 APP_TYPE_FIELD,
267} DATA_TYPE;
268#endif
269
270typedef union CategoryParent {
271 Category *category; /* Link to parent Category if it's not CategoryGroup */
272 CategoryType *categoryType; /* Link to parent CategoryType if it's CategoryGroup */
273} CategoryParent;
274
275/* UHash the parameter tree info from ParamTreeView.xml */
276struct _CategoryPath {
277 char *path;
278 Feature *feature;
279 UT_hash_handle hh;
280};
281
282struct _FeatureField {
283 FieldInfo *fieldInfo;
284 UT_hash_handle hh;
285};
286
287struct _Feature {
288 char *name;
289 char *featureOption;
290 FieldInfo *switchFieldInfo;
291 CategoryPath *categoryPathHash;
292 FeatureField *featureFieldHash;
293 AudioType *audioType;
294 UT_hash_handle hh;
295};
296
297struct _TreeRoot {
298 char *name; /* Key */
299 FieldInfo *switchFieldInfo;
300 xmlNode *treeRootNode; /* Used to traversal tree */
301 Feature *featureHash; /* Used to opt feature information */
302 ParamTreeView *paramTreeView; /* Belong to which paramTreeView */
303 UT_hash_handle hh;
304};
305
306struct _ParamTreeView {
307 int verMaj;
308 int verMin;
309 AudioType *audioType;
310 TreeRoot *treeRootHash;
311};
312
313/* Hash the Param & Field info from ParamUnitDesc.xml */
314struct _FieldInfo {
315 char *name; /* key */
316 size_t arrayIndex;
317 int startBit;
318 int endBit;
319 char *checkListStr; /* check list string array */
320 struct _ParamInfo *paramInfo; /* Link to parent ParamInfo */
321 UT_hash_handle hh; /* hash handle */
322};
323
324struct _ParamInfo {
325 char *name; /* key */
326 DATA_TYPE dataType;
327 struct _FieldInfo *fieldInfoHash;
328 AudioType *audioType; /* Link to parent AudioType */
329 UT_hash_handle hh; /* hash handle */
330};
331
332/* Hash the param name with value from AudioParam.xml */
333struct _Param {
334 char *name; /* key */
335 void *data; /* raw data */
336 size_t arraySize; /* Array size if the data is the array pointer */
337 ParamInfo *paramInfo;
338 struct _ParamUnit *paramUnit; /* Link to it's ParamUnit */
339 UT_hash_handle hh; /* hash handle */
340};
341
342/* Hash the id with ParamUnit from AudioParam.xml */
343struct _ParamUnit {
344 int paramId; /* key */
345 int refCount;
346 AudioType *audioType; /* Link to it's AudioType */
347 struct _Param *paramHash; /* ParamUnit's params */
348 UT_hash_handle hh;
349};
350
351/* Hash ParamTree info from AudioParam.xml */
352typedef struct {
353 char *categoryPath; /* key */
354 int paramId; /* Param id */
355 UT_hash_handle hh;
356} ParamTree;
357
358struct _Category {
359 char *wording; /* key */
360 char *name;
361 int visible;
362 CategoryParent parent;
363 CATEGORY_PARENT_TYPE parentType;
364 UT_hash_handle hh; /* Used to handle CategoryType->categoryHash */
365 UT_hash_handle hh2; /* Used to handle CategoryType->allCategoryHash */
366};
367
368struct _CategoryAlias {
369 char *alias; /* key */
370 Category *category;
371 UT_hash_handle hh;
372};
373
374struct _CategoryGroup {
375 char *wording; /* key */
376 char *name;
377 int visible;
378 Category *categoryHash; /* Link to children */
379 CategoryType *categoryType; /* Link to parent */
380 UT_hash_handle hh;
381};
382
383struct _CategoryType {
384 char *wording; /* key */
385 char *name;
386 int visible;
387 CategoryGroup *categoryGroupHash; /* Link to children */
388 Category *categoryHash; /* Link to children (not include these category under CategoryGroup) */
389 Category *allCategoryHash; /* Link to children (include these category under CategoryGroup) */
390 CategoryAlias *categoryAliasHash; /* Save category alias information */
391 AudioType *audioType; /* Link to parent */
392 UT_hash_handle hh;
393};
394
395struct _AudioType {
396 char *name;
397 char *tabName;
398 int paramUnitDescVerMaj; /* ParamUniDesc version */
399 int paramUnitDescVerMin;
400 int audioParamVerMaj; /* AudioParam version */
401 int audioParamVerMin;
402 xmlDocPtr audioParamDoc;
403 xmlDocPtr paramUnitDescDoc;
404 xmlDocPtr paramTreeViewDoc;
405 ParamTree *paramTreeHash;
406 ParamUnit *paramUnitHash;
407 ParamInfo *paramInfoHash;
408 ParamTreeView *paramTreeView;
409 int unusedParamId;
410 int dirty; /* Indicate if the audio type modified without saveing*/
411 int allowReload; /* Indicate the audio type can be reload since xml updated */
412 CategoryType *categoryTypeHash;
413#ifndef WIN32
414 pthread_rwlock_t lock;
415 const char *lockCallerFun; /* Used to cache the lock holder */
416#endif
417 AppHandle *appHandle; /* Link to it's appHandle parent */
418 UT_hash_handle hh;
419};
420
421struct _FeatureOption {
422 char *name;
423 char *value;
424 UT_hash_handle hh;
425};
426
427struct _NotifyCb {
428 NOTIFY_CB_FUN cb;
429 struct _NotifyCb *next, *pre;
430};
431
432struct _AppHandle {
433 const char **xmlDir;
434 char *xmlCusDir;
435 AudioType *audioTypeHash;
436 FeatureOption *featureOptionsHash;
437 xmlDocPtr featureOptionsDoc;
438 int xmlCusDirReady;
439 int xmlChangedNotifyEnabled; /* Used to identify notify enabled */
440#ifndef WIN32
441 pthread_t appThread;
442 int appThreadExit; /* Used to identify thread exit */
443 int inotifyFd;
444 pthread_rwlock_t lock;
445 pthread_rwlock_t notifyLock;
446 const char *lockCallerFun; /* Used to cache the lock holder */
447#endif
448 NotifyCb *noficyCbList;
449 int saveXmlWithHexMode;
450 int normalizeXmlContent; /* Breakdown all parameter tree element & add category path */
451};
452
453typedef struct AudioTypeVerInfo {
454 const char *audioTypeName;
455 int paramUnitDescVerMaj;
456 int paramUnitDescVerMin;
457 int audioParamVerMaj;
458 int audioParamVerMin;
459} AudioTypeVerInfo;
460
461/*
462 AudioParamParser will built-in ParamUnitDesc/AudioParam's maj number checking,
463 The ParamUnitDesc/AudioParam's min number is checking by client.
464*/
465static const AudioTypeVerInfo audioTypeSupportVerInfo [] = {
466 /* AudioType name, ParamUnitDescVer (maj, min), AudioParamVer (maj, min) */
467 {"AudioCommonSetting", 1, 0, 1, 0},
468 {"PlaybackACF", 1, 0, 1, 0},
469 {"Playback", 1, 0, 1, 0},
470 {"PlaybackDRC", 1, 0, 1, 0},
471 {"PlaybackHCF", 1, 0, 1, 0},
472 {"PlaybackVolAna", 1, 0, 1, 0},
473 {"PlaybackVolDigi", 1, 0, 1, 0},
474 {"PlaybackVolUI", 1, 0, 1, 0},
475 {"Record", 1, 0, 1, 0},
476 {"RecordDMNR", 1, 0, 1, 0},
477 {"RecordFIR", 1, 0, 1, 0},
478 {"RecordUI", 1, 0, 1, 0},
479 {"RecordVol", 1, 0, 1, 0},
480 {"RecordVolUI", 1, 0, 1, 0},
481 {"Speech", 1, 0, 1, 0},
482 {"SpeechDMNR", 1, 0, 1, 0},
483 {"SpeechGeneral", 1, 0, 1, 0},
484 {"SpeechMagiClarity", 1, 0, 1, 0},
485 {"SpeechUI", 1, 0, 1, 0},
486 {"SpeechVol", 1, 0, 1, 0},
487 {"SpeechVolUI", 1, 0, 1, 0},
488 {"VoIP", 1, 0, 1, 0},
489 {"VoIPDMNR", 1, 0, 1, 0},
490 {"VoIPGeneral", 1, 0, 1, 0},
491 {"VoIPUI", 1, 0, 1, 0},
492 {"VoIPVol", 1, 0, 1, 0},
493 {"VoIPVolUI", 1, 0, 1, 0},
494 {"Volume", 1, 0, 1, 0},
495 {"VolumeGainMap", 1, 0, 1, 0},
496 {"SpeechDeReverb", 1, 0, 1, 0},
497 {NULL, 0, 0, 0, 0}
498};
499
500typedef struct AppOps {
501 void *handle;
502 AppHandle *(*appHandleGetInstance)(void);
503
504 int (*appSetAudioTypeLoadingList)(const char *audioTypeLoadingList[]);
505 const char *(*appGetAudioTypeLoadingList)(void);
506
507 void (*appSetDebugLevel)(MSG_LEVEL level);
508 MSG_LEVEL (*appGetDebugLevel)(void);
509
510 APP_STATUS (*appHandleInit)(AppHandle *appHandle);
511 APP_STATUS (*appHandleUninit)(AppHandle *appHandle);
512 void (*appHandleRedirectIOToConsole)(void);
513 size_t (*appHandleGetNumOfAudioType)(AppHandle *appHandle);
514 AudioType *(*appHandleGetAudioTypeByIndex)(AppHandle *appHandle, size_t index);
515 AudioType *(*appHandleGetAudioTypeByName)(AppHandle *appHandle, const char *name);
516 const char *(*appHandleGetFeatureOptionValue)(AppHandle *appHandle, const char *featureOptionName);
517 int (*appHandleIsFeatureOptionEnabled)(AppHandle *appHandle, const char *featureOptionName);
518 size_t (*appHandleGetNumOfFeatureOption)(AppHandle *appHandle);
519 FeatureOption *(*appHandleGetFeatureOptionByIndex)(AppHandle *appHandle, size_t index);
520 const char *(*appHandleGetBuildTimeStamp)(void);
521 APP_STATUS (*appHandleCompressFiles)(const char *srcDir, const char *destFile);
522 APP_STATUS (*appHandleUncompressFile)(const char *srcFile, const char *destDir);
523
524 /* Following 2 APIs will acquire app handle write lock automatically */
525 APP_STATUS (*appHandleParseXml)(AppHandle *appHandle, const char *dir[], const char *cusDir);
526 APP_STATUS (*appHandleReloadAudioType)(AppHandle *appHandle, const char *audioTypeName);
527
528 /* AudioType API */
529 APP_STATUS (*audioTypeIsTuningToolSupportedXmlVer)(AudioType *audioType);
530 APP_STATUS (*audioTypeIsDeviceSupportedXmlVer)(AudioType *audioType);
531 size_t (*audioTypeGetNumOfCategoryType)(AudioType *audioType);
532 CategoryType *(*audioTypeGetCategoryTypeByIndex)(AudioType *audioType, size_t idnex);
533 CategoryType *(*audioTypeGetCategoryTypeByName)(AudioType *audioType, const char *categoryTypeName);
534 CategoryType *(*audioTypeGetCategoryTypeByWording)(AudioType *audioType, const char *categoryTypeWording);
535 xmlNode *(*audioTypeGetCategoryTypeListNode)(AudioType *audioType);
536 xmlNode *(*audioTypeGetParamUnitNode)(AudioType *audioType);
537 ParamUnit *(*audioTypeGetParamUnit)(AudioType *audioType, const char *categoryPath);
538 size_t (*audioTypeGetNumOfParamInfo)(AudioType *audioType);
539 ParamInfo *(*audioTypeGetParamInfoByIndex)(AudioType *audioType, size_t index);
540 ParamInfo *(*audioTypeGetParamInfoByName)(AudioType *audioType, const char *paramName);
541 APP_STATUS (*audioTypeSaveAudioParamXml)(AudioType *audioType, const char *saveDir, int clearDirtyBit);
542 int (*audioTypeReadLock)(AudioType *audioType, const char *callerFun);
543 int (*audioTypeWriteLock)(AudioType *audioType, const char *callerFun);
544 int (*audioTypeUnlock)(AudioType *audioType);
545 TreeRoot *(*audioTypeGetTreeRoot)(AudioType *audioType, const char *treeRootName);
546
547 /* Following 3 write APIs will acquire write lock automatically */
548 APP_STATUS (*audioTypeSetParamData)(AudioType *audioType, const char *categoryPath, ParamInfo *paramName, void *dataPtr, int arraySize);
549 APP_STATUS (*audioTypeSetFieldData)(AudioType *audioType, const char *categoryPath, FieldInfo *fieldInfo, unsigned int val);
550 APP_STATUS (*audioTypeParamUnitCopy)(AudioType *audioType, const char *srcCategoryPath, const char *dstCategoryPath);
551
552 /* CategoryType API */
553 size_t (*categoryTypeGetNumOfCategoryGroup)(CategoryType *categoryType);
554 CategoryGroup *(*categoryTypeGetCategoryGroupByIndex)(CategoryType *categoryType, size_t index);
555 CategoryGroup *(*categoryTypeGetCategoryGroupByWording)(CategoryType *categoryType, const char *wording);
556 size_t (*categoryTypeGetNumOfCategory)(CategoryType *categoryType);
557 Category *(*categoryTypeGetCategoryByIndex)(CategoryType *categoryType, size_t index);
558 Category *(*categoryTypeGetCategoryByWording)(CategoryType *categoryType, const char *wording);
559 Category *(*categoryTypeGetCategoryByName)(CategoryType *categoryType, const char *name);
560
561 /* CategoryGroup API */
562 size_t (*categoryGroupGetNumOfCategory)(CategoryGroup *categoryGroup);
563 Category *(*categoryGroupGetCategoryByIndex)(CategoryGroup *categoryGroup, size_t index);
564 Category *(*categoryGroupGetCategoryByWording)(CategoryGroup *categoryGroup, const char *index);
565
566 /* CategoryAlias API */
567 CategoryAlias *(*categoryAliasCreate)(const char *alias, Category *category);
568 void (*categoryAliasRelease)(CategoryAlias *categoryAlias);
569
570 /* ParamInfo API */
571 size_t (*paramInfoGetNumOfFieldInfo)(ParamInfo *paramInfo);
572 FieldInfo *(*paramInfoGetFieldInfoByIndex)(ParamInfo *paramInfo, size_t index);
573 FieldInfo *(*paramInfoGetFieldInfoByName)(ParamInfo *paramInfo, const char *fieldName);
574 char *(*paramNewDataStr)(Param *param);
575 char *(*paramNewDataStrWithMode)(Param *param, int uArrayHexMode);
576
577 /* ParamUnit API */
578 size_t (*paramUnitGetNumOfParam)(ParamUnit *paramUnit);
579 Param *(*paramUnitGetParamByIndex)(ParamUnit *paramUnit, size_t index);
580 Param *(*paramUnitGetParamByName)(ParamUnit *paramUnit, const char *paramName);
581 ParamInfo *(*paramUnitGetParamInfo)(ParamUnit *paramUnit, const char *paramInfoName);
582 FieldInfo *(*paramUnitGetFieldInfo)(ParamUnit *paramUnit, const char *paramName, const char *fieldName);
583 APP_STATUS (*paramUnitGetFieldVal)(ParamUnit *paramUnit, const char *paramName, const char *fieldName, unsigned int *val);
584
585 /* Param API */
586 size_t (*paramGetArraySizeFromString)(const char *str);
587 size_t (*paramGetNumOfBytes)(Param *param);
588 APP_STATUS (*paramGetFieldVal)(Param *param, FieldInfo *fieldInfo, unsigned int *val);
589 APP_STATUS (*paramSetFieldVal)(Param *param, FieldInfo *fieldInfo, unsigned int val);
590 DATA_TYPE (*paramDataTypeToEnum)(const char *dataType);
591 const char *(*paramDataTypeToStr)(DATA_TYPE dataType);
592
593 /* Field API */
594 APP_STATUS (*fieldInfoGetCheckListValue)(FieldInfo *fieldInfo, const char *checkName, unsigned int *checkVal);
595
596 /* TreeRoot API */
597 Feature *(*treeRootGetFeatureByName)(TreeRoot *treeRoot, const char *featureName);
598 int (*featureIsCategoryPathSupport)(Feature *feature, const char *categoryPath);
599
600 /* Xml Node related APIs */
601 xmlNode *(*findXmlNodeByElemName)(xmlNode *node, const char *elemName);
602 xmlChar *(*xmlNodeGetProp)(xmlNode *node, const char *prop);
603 xmlChar *(*xmlNodeGetWording)(xmlNode *node);
604
605 /* Control cust XML enabl API */
606 void (*appHandleCustXmlEnableChanged)(AppHandle* appHandle, int enable);
607
608 /* XML changed callback APIs */
609 void (*appHandleRegXmlChangedCb)(AppHandle *appHandle, NOTIFY_CB_FUN nofiyCallback);
610 void (*appHandleUnregXmlChangedCb)(AppHandle *appHandle, NOTIFY_CB_FUN nofiyCallback);
611
612 /* Utils APIs */
613 APP_STATUS (*utilConvDataStringToNative)(DATA_TYPE dataType, const char *paramDataStr, void **paramData, size_t *arraySize);
614
615 /* Unit test */
616 APP_STATUS (*unitTest)(AppHandle *appHandle);
617 char *(*utilGetStdin)(char *buf, int bufSize);
618
619 /* Following APIs is designed for EM tool integration */
620 APP_STATUS (*utilNativeSetField)(const char *audioTypeName, const char *categoryPath, const char *paramName, const char *fieldName, const char *fieldValueStr);
621 APP_STATUS (*utilNativeSetParam)(const char *audioTypeName, const char *categoryPath, const char *paramName, const char *paramDataStr);
622 char *(*utilNativeGetCategory)(const char *audioTypeName, const char *categoryTypeName);
623 char *(*utilNativeGetParam)(const char *audioTypeName, const char *categoryPath, const char *paramName);
624 unsigned int (*utilNativeGetField)(const char *audioTypeName, const char *categoryPath, const char *paramName, const char *fieldName);
625 APP_STATUS (*utilNativeSaveXml)(const char *audioTypeName);
626 const char *(*utilNativeGetChecklist)(const char *audioTypeName, const char *paramName, const char *fieldName);
627} AppOps;
628
629extern const char **appAudioTypeLoadingList;
630extern int appDebugLevel;
631static AppOps appOps;
632static short appOpsInited = 0;
633
634#ifndef WIN32
635EXPORT static AppOps *appOpsGetInstance(void) {
636const char *error;
637const char *funName = NULL;
638
639if (appOpsInited == 0) {
640 ALOGD("%s(), init AppOps struct, lib is %s", __FUNCTION__, APP_LIB_NAME);
641
642 /* dlopen */
643 appOps.handle = dlopen(APP_LIB_NAME, RTLD_LAZY);
644 if (!appOps.handle) {
645 ALOGE("%s(), dlopen fail! (%s)\n", __FUNCTION__, dlerror());
646 return NULL;
647 }
648 dlerror(); /* Clear any existing error */
649
650 funName = "appHandleGetInstance";
651 appOps.appHandleGetInstance = (AppHandle * ( *)(void)) dlsym(appOps.handle, funName);
652 error = dlerror();
653 if (error != NULL) {
654 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
655 return NULL;
656 }
657
658 /* dlsym */
659 funName = "appSetAudioTypeLoadingList";
660 appOps.appSetAudioTypeLoadingList = (int ( *)(const char *audioTypeLoadingList[])) dlsym(appOps.handle, funName);
661 error = dlerror();
662 if (error != NULL) {
663 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
664 return NULL;
665 }
666
667 funName = "appGetAudioTypeLoadingList";
668 appOps.appGetAudioTypeLoadingList = (const char*( *)(void)) dlsym(appOps.handle, funName);
669 error = dlerror();
670 if (error != NULL) {
671 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
672 return NULL;
673 }
674
675 funName = "appSetDebugLevel";
676 appOps.appSetDebugLevel = (void ( *)(MSG_LEVEL level)) dlsym(appOps.handle, funName);
677 error = dlerror();
678 if (error != NULL) {
679 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
680 return NULL;
681 }
682
683 funName = "appGetDebugLevel";
684 appOps.appGetDebugLevel = (MSG_LEVEL( *)(void)) dlsym(appOps.handle, funName);
685 error = dlerror();
686 if (error != NULL) {
687 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
688 return NULL;
689 }
690
691 /* appHandle API */
692 funName = "appHandleInit";
693 appOps.appHandleInit = (APP_STATUS( *)(AppHandle * appHandle)) dlsym(appOps.handle, funName);
694 error = dlerror();
695 if (error != NULL) {
696 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
697 return NULL;
698 }
699
700 funName = "appHandleUninit";
701 appOps.appHandleUninit = (APP_STATUS( *)(AppHandle * appHandle)) dlsym(appOps.handle, funName);
702 error = dlerror();
703 if (error != NULL) {
704 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
705 return NULL;
706 }
707
708 funName = "appHandleRedirectIOToConsole";
709 appOps.appHandleRedirectIOToConsole = (void ( *)(void)) dlsym(appOps.handle, funName);
710 error = dlerror();
711 if (error != NULL) {
712 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
713 return NULL;
714 }
715
716 funName = "appHandleGetNumOfAudioType";
717 appOps.appHandleGetNumOfAudioType = (size_t ( *)(AppHandle * appHandle)) dlsym(appOps.handle, funName);
718 error = dlerror();
719 if (error != NULL) {
720 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
721 return NULL;
722 }
723
724 funName = "appHandleGetAudioTypeByIndex";
725 appOps.appHandleGetAudioTypeByIndex = (AudioType * ( *)(AppHandle * appHandle, size_t index)) dlsym(appOps.handle, funName);
726 error = dlerror();
727 if (error != NULL) {
728 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
729 return NULL;
730 }
731
732 funName = "appHandleGetAudioTypeByName";
733 appOps.appHandleGetAudioTypeByName = (AudioType * ( *)(AppHandle * appHandle, const char * name)) dlsym(appOps.handle, funName);
734 error = dlerror();
735 if (error != NULL) {
736 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
737 return NULL;
738 }
739
740 funName = "appHandleGetFeatureOptionValue";
741 appOps.appHandleGetFeatureOptionValue = (const char * ( *)(AppHandle * appHandle, const char * featureOptionName)) dlsym(appOps.handle, funName);
742 error = dlerror();
743 if (error != NULL) {
744 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
745 return NULL;
746 }
747
748 funName = "appHandleIsFeatureOptionEnabled";
749 appOps.appHandleIsFeatureOptionEnabled = (int ( *)(AppHandle * appHandle, const char * featureOptionName)) dlsym(appOps.handle, funName);
750 error = dlerror();
751 if (error != NULL) {
752 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
753 return NULL;
754 }
755
756 funName = "appHandleGetNumOfFeatureOption";
757 appOps.appHandleGetNumOfFeatureOption = (size_t ( *)(AppHandle * appHandle)) dlsym(appOps.handle, funName);
758 error = dlerror();
759 if (error != NULL) {
760 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
761 return NULL;
762 }
763
764 funName = "appHandleGetFeatureOptionByIndex";
765 appOps.appHandleGetFeatureOptionByIndex = (FeatureOption * ( *)(AppHandle * appHandle, size_t index)) dlsym(appOps.handle, funName);
766 error = dlerror();
767 if (error != NULL) {
768 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
769 return NULL;
770 }
771
772 funName = "appHandleGetBuildTimeStamp";
773 appOps.appHandleGetBuildTimeStamp = (const char * ( *)(void)) dlsym(appOps.handle, funName);
774 error = dlerror();
775 if (error != NULL) {
776 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
777 return NULL;
778 }
779
780 funName = "appHandleCompressFiles";
781 appOps.appHandleCompressFiles = (APP_STATUS( *)(const char * srcDir, const char * destFile)) dlsym(appOps.handle, funName);
782 error = dlerror();
783 if (error != NULL) {
784 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
785 return NULL;
786 }
787
788 funName = "appHandleUncompressFile";
789 appOps.appHandleUncompressFile = (APP_STATUS( *)(const char * srcFile, const char * destDir)) dlsym(appOps.handle, funName);
790 error = dlerror();
791 if (error != NULL) {
792 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
793 return NULL;
794 }
795
796 /* Following 2 APIs will acquire app handle write lock automatically */
797 funName = "appHandleParseXml";
798 appOps.appHandleParseXml = (APP_STATUS( *)(AppHandle * appHandle, const char * dir[], const char * cusDir)) dlsym(appOps.handle, funName);
799 error = dlerror();
800 if (error != NULL) {
801 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
802 return NULL;
803 }
804
805 funName = "appHandleReloadAudioType";
806 appOps.appHandleReloadAudioType = (APP_STATUS( *)(AppHandle * appHandle, const char * audioTypeName)) dlsym(appOps.handle, funName);
807 error = dlerror();
808 if (error != NULL) {
809 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
810 return NULL;
811 }
812
813 /* AudioType API */
814 funName = "audioTypeIsTuningToolSupportedXmlVer";
815 appOps.audioTypeIsTuningToolSupportedXmlVer = (APP_STATUS( *)(AudioType * audioType)) dlsym(appOps.handle, funName);
816 error = dlerror();
817 if (error != NULL) {
818 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
819 return NULL;
820 }
821
822 funName = "audioTypeIsDeviceSupportedXmlVer";
823 appOps.audioTypeIsDeviceSupportedXmlVer = (APP_STATUS( *)(AudioType * audioType)) dlsym(appOps.handle, funName);
824 error = dlerror();
825 if (error != NULL) {
826 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
827 return NULL;
828 }
829
830 funName = "audioTypeGetNumOfCategoryType";
831 appOps.audioTypeGetNumOfCategoryType = (size_t ( *)(AudioType * audioType)) dlsym(appOps.handle, funName);
832 error = dlerror();
833 if (error != NULL) {
834 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
835 return NULL;
836 }
837
838 funName = "audioTypeGetCategoryTypeByIndex";
839 appOps.audioTypeGetCategoryTypeByIndex = (CategoryType * ( *)(AudioType * audioType, size_t idnex)) dlsym(appOps.handle, funName);
840 error = dlerror();
841 if (error != NULL) {
842 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
843 return NULL;
844 }
845
846 funName = "audioTypeGetCategoryTypeByName";
847 appOps.audioTypeGetCategoryTypeByName = (CategoryType * ( *)(AudioType * audioType, const char * categoryTypeName)) dlsym(appOps.handle, funName);
848 error = dlerror();
849 if (error != NULL) {
850 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
851 return NULL;
852 }
853
854 funName = "audioTypeGetCategoryTypeByWording";
855 appOps.audioTypeGetCategoryTypeByWording = (CategoryType * ( *)(AudioType * audioType, const char * categoryTypeWording)) dlsym(appOps.handle, funName);
856 error = dlerror();
857 if (error != NULL) {
858 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
859 return NULL;
860 }
861
862 funName = "audioTypeGetCategoryTypeListNode";
863 appOps.audioTypeGetCategoryTypeListNode = (xmlNode * ( *)(AudioType * audioType)) dlsym(appOps.handle, funName);
864 error = dlerror();
865 if (error != NULL) {
866 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
867 return NULL;
868 }
869
870 funName = "audioTypeGetParamUnitNode";
871 appOps.audioTypeGetParamUnitNode = (xmlNode * ( *)(AudioType * audioType)) dlsym(appOps.handle, funName);
872 error = dlerror();
873 if (error != NULL) {
874 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
875 return NULL;
876 }
877
878 funName = "audioTypeGetParamUnit";
879 appOps.audioTypeGetParamUnit = (ParamUnit * ( *)(AudioType * audioType, const char * categoryPath)) dlsym(appOps.handle, funName);
880 error = dlerror();
881 if (error != NULL) {
882 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
883 return NULL;
884 }
885
886 funName = "audioTypeGetNumOfParamInfo";
887 appOps.audioTypeGetNumOfParamInfo = (size_t ( *)(AudioType * audioType)) dlsym(appOps.handle, funName);
888 error = dlerror();
889 if (error != NULL) {
890 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
891 return NULL;
892 }
893
894 funName = "audioTypeGetParamInfoByIndex";
895 appOps.audioTypeGetParamInfoByIndex = (ParamInfo * ( *)(AudioType * audioType, size_t index)) dlsym(appOps.handle, funName);
896 error = dlerror();
897 if (error != NULL) {
898 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
899 return NULL;
900 }
901
902 funName = "audioTypeGetParamInfoByName";
903 appOps.audioTypeGetParamInfoByName = (ParamInfo * ( *)(AudioType * audioType, const char * paramName)) dlsym(appOps.handle, funName);
904 error = dlerror();
905 if (error != NULL) {
906 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
907 return NULL;
908 }
909
910 funName = "audioTypeSaveAudioParamXml";
911 appOps.audioTypeSaveAudioParamXml = (APP_STATUS( *)(AudioType * audioType, const char * saveDir, int clearDirtyBit)) dlsym(appOps.handle, funName);
912 error = dlerror();
913 if (error != NULL) {
914 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
915 return NULL;
916 }
917
918 funName = "audioTypeReadLock";
919 appOps.audioTypeReadLock = (int ( *)(AudioType * audioType, const char * callerFun)) dlsym(appOps.handle, funName);
920 error = dlerror();
921 if (error != NULL) {
922 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
923 return NULL;
924 }
925
926 funName = "audioTypeWriteLock";
927 appOps.audioTypeWriteLock = (int ( *)(AudioType * audioType, const char * callerFun)) dlsym(appOps.handle, funName);
928 error = dlerror();
929 if (error != NULL) {
930 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
931 return NULL;
932 }
933
934 funName = "audioTypeUnlock";
935 appOps.audioTypeUnlock = (int ( *)(AudioType * audioType)) dlsym(appOps.handle, funName);
936 error = dlerror();
937 if (error != NULL) {
938 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
939 return NULL;
940 }
941
942 funName = "audioTypeGetTreeRoot";
943 appOps.audioTypeGetTreeRoot = (TreeRoot * ( *)(AudioType * audioType, const char * treeRootName)) dlsym(appOps.handle, funName);
944 error = dlerror();
945 if (error != NULL) {
946 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
947 return NULL;
948 }
949
950 /* Following 3 write APIs will acquire write lock automatically */
951 funName = "audioTypeSetParamData";
952 appOps.audioTypeSetParamData = (APP_STATUS( *)(AudioType * audioType, const char * categoryPath, ParamInfo * paramName, void * dataPtr, int arraySize)) dlsym(appOps.handle, funName);
953 error = dlerror();
954 if (error != NULL) {
955 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
956 return NULL;
957 }
958
959 funName = "audioTypeSetFieldData";
960 appOps.audioTypeSetFieldData = (APP_STATUS( *)(AudioType * audioType, const char * categoryPath, FieldInfo * fieldInfo, unsigned int val)) dlsym(appOps.handle, funName);
961 error = dlerror();
962 if (error != NULL) {
963 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
964 return NULL;
965 }
966
967 funName = "audioTypeParamUnitCopy";
968 appOps.audioTypeParamUnitCopy = (APP_STATUS( *)(AudioType * audioType, const char * srcCategoryPath, const char * dstCategoryPath)) dlsym(appOps.handle, funName);
969 error = dlerror();
970 if (error != NULL) {
971 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
972 return NULL;
973 }
974
975 /* CategoryType API */
976 funName = "categoryTypeGetNumOfCategoryGroup";
977 appOps.categoryTypeGetNumOfCategoryGroup = (size_t ( *)(CategoryType * categoryType)) dlsym(appOps.handle, funName);
978 error = dlerror();
979 if (error != NULL) {
980 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
981 return NULL;
982 }
983
984 funName = "categoryTypeGetCategoryGroupByIndex";
985 appOps.categoryTypeGetCategoryGroupByIndex = (CategoryGroup * ( *)(CategoryType * categoryType, size_t index)) dlsym(appOps.handle, funName);
986 error = dlerror();
987 if (error != NULL) {
988 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
989 return NULL;
990 }
991
992 funName = "categoryTypeGetCategoryGroupByWording";
993 appOps.categoryTypeGetCategoryGroupByWording = (CategoryGroup * ( *)(CategoryType * categoryType, const char * wording)) dlsym(appOps.handle, funName);
994 error = dlerror();
995 if (error != NULL) {
996 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
997 return NULL;
998 }
999
1000 funName = "categoryTypeGetNumOfCategory";
1001 appOps.categoryTypeGetNumOfCategory = (size_t ( *)(CategoryType * categoryType)) dlsym(appOps.handle, funName);
1002 error = dlerror();
1003 if (error != NULL) {
1004 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1005 return NULL;
1006 }
1007
1008 funName = "categoryTypeGetCategoryByIndex";
1009 appOps.categoryTypeGetCategoryByIndex = (Category * ( *)(CategoryType * categoryType, size_t index)) dlsym(appOps.handle, funName);
1010 error = dlerror();
1011 if (error != NULL) {
1012 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1013 return NULL;
1014 }
1015
1016 funName = "categoryTypeGetCategoryByWording";
1017 appOps.categoryTypeGetCategoryByWording = (Category * ( *)(CategoryType * categoryType, const char * wording)) dlsym(appOps.handle, funName);
1018 error = dlerror();
1019 if (error != NULL) {
1020 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1021 return NULL;
1022 }
1023
1024 funName = "categoryTypeGetCategoryByName";
1025 appOps.categoryTypeGetCategoryByName = (Category * ( *)(CategoryType * categoryType, const char * name)) dlsym(appOps.handle, funName);
1026 error = dlerror();
1027 if (error != NULL) {
1028 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1029 return NULL;
1030 }
1031
1032 /* CategoryGroup API */
1033 funName = "categoryGroupGetNumOfCategory";
1034 appOps.categoryGroupGetNumOfCategory = (size_t ( *)(CategoryGroup * categoryGroup)) dlsym(appOps.handle, funName);
1035 error = dlerror();
1036 if (error != NULL) {
1037 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1038 return NULL;
1039 }
1040
1041 funName = "categoryGroupGetCategoryByIndex";
1042 appOps.categoryGroupGetCategoryByIndex = (Category * ( *)(CategoryGroup * categoryGroup, size_t index)) dlsym(appOps.handle, funName);
1043 error = dlerror();
1044 if (error != NULL) {
1045 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1046 return NULL;
1047 }
1048
1049 funName = "categoryGroupGetCategoryByWording";
1050 appOps.categoryGroupGetCategoryByWording = (Category * ( *)(CategoryGroup * categoryGroup, const char * index)) dlsym(appOps.handle, funName);
1051 error = dlerror();
1052 if (error != NULL) {
1053 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1054 return NULL;
1055 }
1056
1057 /* CategoryAlias API */
1058 funName = "categoryAliasCreate";
1059 appOps.categoryAliasCreate = (CategoryAlias * ( *)(const char * alias, Category * category)) dlsym(appOps.handle, funName);
1060 error = dlerror();
1061 if (error != NULL) {
1062 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1063 return NULL;
1064 }
1065
1066 funName = "categoryAliasRelease";
1067 appOps.categoryAliasRelease = (void ( *)(CategoryAlias * categoryAlias)) dlsym(appOps.handle, funName);
1068 error = dlerror();
1069 if (error != NULL) {
1070 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1071 return NULL;
1072 }
1073
1074 /* ParamInfo API */
1075 funName = "paramInfoGetNumOfFieldInfo";
1076 appOps.paramInfoGetNumOfFieldInfo = (size_t ( *)(ParamInfo * paramInfo)) dlsym(appOps.handle, funName);
1077 error = dlerror();
1078 if (error != NULL) {
1079 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1080 return NULL;
1081 }
1082
1083 funName = "paramInfoGetFieldInfoByIndex";
1084 appOps.paramInfoGetFieldInfoByIndex = (FieldInfo * ( *)(ParamInfo * paramInfo, size_t index)) dlsym(appOps.handle, funName);
1085 error = dlerror();
1086 if (error != NULL) {
1087 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1088 return NULL;
1089 }
1090
1091 funName = "paramInfoGetFieldInfoByName";
1092 appOps.paramInfoGetFieldInfoByName = (FieldInfo * ( *)(ParamInfo * paramInfo, const char * fieldName)) dlsym(appOps.handle, funName);
1093 error = dlerror();
1094 if (error != NULL) {
1095 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1096 return NULL;
1097 }
1098
1099 funName = "paramNewDataStr";
1100 appOps.paramNewDataStr = (char * ( *)(Param * param)) dlsym(appOps.handle, funName);
1101 error = dlerror();
1102 if (error != NULL) {
1103 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1104 return NULL;
1105 }
1106
1107 funName = "paramNewDataStrWithMode";
1108 appOps.paramNewDataStrWithMode = (char * ( *)(Param * param, int uArrayHexMode)) dlsym(appOps.handle, funName);
1109 error = dlerror();
1110 if (error != NULL) {
1111 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1112 return NULL;
1113 }
1114
1115 /* ParamUnit API */
1116 funName = "paramUnitGetNumOfParam";
1117 appOps.paramUnitGetNumOfParam = (size_t ( *)(ParamUnit * paramUnit)) dlsym(appOps.handle, funName);
1118 error = dlerror();
1119 if (error != NULL) {
1120 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1121 return NULL;
1122 }
1123
1124 funName = "paramUnitGetParamByIndex";
1125 appOps.paramUnitGetParamByIndex = (Param * ( *)(ParamUnit * paramUnit, size_t index)) dlsym(appOps.handle, funName);
1126 error = dlerror();
1127 if (error != NULL) {
1128 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1129 return NULL;
1130 }
1131
1132 funName = "paramUnitGetParamByName";
1133 appOps.paramUnitGetParamByName = (Param * ( *)(ParamUnit * paramUnit, const char * paramName)) dlsym(appOps.handle, funName);
1134 error = dlerror();
1135 if (error != NULL) {
1136 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1137 return NULL;
1138 }
1139
1140 funName = "paramUnitGetParamInfo";
1141 appOps.paramUnitGetParamInfo = (ParamInfo * ( *)(ParamUnit * paramUnit, const char * paramInfoName)) dlsym(appOps.handle, funName);
1142 error = dlerror();
1143 if (error != NULL) {
1144 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1145 return NULL;
1146 }
1147
1148 funName = "paramUnitGetFieldInfo";
1149 appOps.paramUnitGetFieldInfo = (FieldInfo * ( *)(ParamUnit * paramUnit, const char * paramName, const char * fieldName)) dlsym(appOps.handle, funName);
1150 error = dlerror();
1151 if (error != NULL) {
1152 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1153 return NULL;
1154 }
1155
1156 funName = "paramUnitGetFieldVal";
1157 appOps.paramUnitGetFieldVal = (APP_STATUS( *)(ParamUnit * paramUnit, const char * paramName, const char * fieldName, unsigned int * val)) dlsym(appOps.handle, funName);
1158 error = dlerror();
1159 if (error != NULL) {
1160 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1161 return NULL;
1162 }
1163
1164 /* Param API */
1165 funName = "paramGetArraySizeFromString";
1166 appOps.paramGetArraySizeFromString = (size_t ( *)(const char * str)) dlsym(appOps.handle, funName);
1167 error = dlerror();
1168 if (error != NULL) {
1169 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1170 return NULL;
1171 }
1172
1173 funName = "paramGetNumOfBytes";
1174 appOps.paramGetNumOfBytes = (size_t ( *)(Param * param)) dlsym(appOps.handle, funName);
1175 error = dlerror();
1176 if (error != NULL) {
1177 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1178 return NULL;
1179 }
1180
1181 funName = "paramGetFieldVal";
1182 appOps.paramGetFieldVal = (APP_STATUS( *)(Param * param, FieldInfo * fieldInfo, unsigned int * val)) dlsym(appOps.handle, funName);
1183 error = dlerror();
1184 if (error != NULL) {
1185 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1186 return NULL;
1187 }
1188
1189 funName = "paramSetFieldVal";
1190 appOps.paramSetFieldVal = (APP_STATUS( *)(Param * param, FieldInfo * fieldInfo, unsigned int val)) dlsym(appOps.handle, funName);
1191 error = dlerror();
1192 if (error != NULL) {
1193 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1194 return NULL;
1195 }
1196
1197 funName = "paramDataTypeToEnum";
1198 appOps.paramDataTypeToEnum = (DATA_TYPE( *)(const char * dataType)) dlsym(appOps.handle, funName);
1199 error = dlerror();
1200 if (error != NULL) {
1201 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1202 return NULL;
1203 }
1204
1205 funName = "paramDataTypeToStr";
1206 appOps.paramDataTypeToStr = (const char * ( *)(DATA_TYPE dataType)) dlsym(appOps.handle, funName);
1207 error = dlerror();
1208 if (error != NULL) {
1209 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1210 return NULL;
1211 }
1212
1213 /* Field API */
1214 funName = "fieldInfoGetCheckListValue";
1215 appOps.fieldInfoGetCheckListValue = (APP_STATUS( *)(FieldInfo * fieldInfo, const char * checkName, unsigned int * checkVal)) dlsym(appOps.handle, funName);
1216 error = dlerror();
1217 if (error != NULL) {
1218 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1219 return NULL;
1220 }
1221
1222 /* TreeRoot API */
1223 funName = "treeRootGetFeatureByName";
1224 appOps.treeRootGetFeatureByName = (Feature * ( *)(TreeRoot * treeRoot, const char * featureName)) dlsym(appOps.handle, funName);
1225 error = dlerror();
1226 if (error != NULL) {
1227 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1228 return NULL;
1229 }
1230
1231 funName = "featureIsCategoryPathSupport";
1232 appOps.featureIsCategoryPathSupport = (int ( *)(Feature * feature, const char * categoryPath)) dlsym(appOps.handle, funName);
1233 error = dlerror();
1234 if (error != NULL) {
1235 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1236 return NULL;
1237 }
1238
1239 /* Xml Node related APIs */
1240 funName = "findXmlNodeByElemName";
1241 appOps.findXmlNodeByElemName = (xmlNode * ( *)(xmlNode * node, const char * elemName)) dlsym(appOps.handle, funName);
1242 error = dlerror();
1243 if (error != NULL) {
1244 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1245 return NULL;
1246 }
1247
1248 funName = "xmlNodeGetProp";
1249 appOps.xmlNodeGetProp = (xmlChar * ( *)(xmlNode * node, const char * prop)) dlsym(appOps.handle, funName);
1250 error = dlerror();
1251 if (error != NULL) {
1252 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1253 return NULL;
1254 }
1255
1256 funName = "xmlNodeGetWording";
1257 appOps.xmlNodeGetWording = (xmlChar * ( *)(xmlNode * node)) dlsym(appOps.handle, funName);
1258 error = dlerror();
1259 if (error != NULL) {
1260 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1261 return NULL;
1262 }
1263
1264 funName = "appHandleCustXmlEnableChanged";
1265 appOps.appHandleCustXmlEnableChanged = (void ( *)(AppHandle * appHandle, int enable)) dlsym(appOps.handle, funName);
1266 error = dlerror();
1267 if (error != NULL) {
1268 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1269 return NULL;
1270 }
1271
1272 /* XML changed callback APIs */
1273 funName = "appHandleRegXmlChangedCb";
1274 appOps.appHandleRegXmlChangedCb = (void ( *)(AppHandle * appHandle, NOTIFY_CB_FUN nofiyCallback)) dlsym(appOps.handle, funName);
1275 error = dlerror();
1276 if (error != NULL) {
1277 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1278 return NULL;
1279 }
1280
1281 funName = "appHandleUnregXmlChangedCb";
1282 appOps.appHandleUnregXmlChangedCb = (void ( *)(AppHandle * appHandle, NOTIFY_CB_FUN nofiyCallback)) dlsym(appOps.handle, funName);
1283 error = dlerror();
1284 if (error != NULL) {
1285 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1286 return NULL;
1287 }
1288
1289 /* Utils APIs */
1290 funName = "utilConvDataStringToNative";
1291 appOps.utilConvDataStringToNative = (APP_STATUS( *)(DATA_TYPE dataType, const char * paramDataStr, void **paramData, size_t * arraySize)) dlsym(appOps.handle, funName);
1292 error = dlerror();
1293 if (error != NULL) {
1294 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1295 return NULL;
1296 }
1297
1298 /* Unit test */
1299 funName = "unitTest";
1300 appOps.unitTest = (APP_STATUS( *)(AppHandle * appHandle)) dlsym(appOps.handle, funName);
1301 error = dlerror();
1302 if (error != NULL) {
1303 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1304 return NULL;
1305 }
1306
1307 funName = "utilGetStdin";
1308 appOps.utilGetStdin = (char * ( *)(char * buf, int bufSize)) dlsym(appOps.handle, funName);
1309 error = dlerror();
1310 if (error != NULL) {
1311 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1312 return NULL;
1313 }
1314
1315 /* Following APIs is designed for EM tool integration */
1316 funName = "utilNativeSetField";
1317 appOps.utilNativeSetField = (APP_STATUS( *)(const char * audioTypeName, const char * categoryPath, const char * paramName, const char * fieldName, const char * fieldValueStr)) dlsym(appOps.handle, funName);
1318 error = dlerror();
1319 if (error != NULL) {
1320 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1321 return NULL;
1322 }
1323
1324 funName = "utilNativeSetParam";
1325 appOps.utilNativeSetParam = (APP_STATUS( *)(const char * audioTypeName, const char * categoryPath, const char * paramName, const char * paramDataStr)) dlsym(appOps.handle, funName);
1326 error = dlerror();
1327 if (error != NULL) {
1328 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1329 return NULL;
1330 }
1331
1332 funName = "utilNativeGetCategory";
1333 appOps.utilNativeGetCategory = (char * ( *)(const char * audioTypeName, const char * categoryTypeName)) dlsym(appOps.handle, funName);
1334 error = dlerror();
1335 if (error != NULL) {
1336 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1337 return NULL;
1338 }
1339
1340 funName = "utilNativeGetParam";
1341 appOps.utilNativeGetParam = (char * ( *)(const char * audioTypeName, const char * categoryPath, const char * paramName)) dlsym(appOps.handle, funName);
1342 error = dlerror();
1343 if (error != NULL) {
1344 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1345 return NULL;
1346 }
1347
1348 funName = "utilNativeGetField";
1349 appOps.utilNativeGetField = (unsigned int ( *)(const char * audioTypeName, const char * categoryPath, const char * paramName, const char * fieldName)) dlsym(appOps.handle, funName);
1350 error = dlerror();
1351 if (error != NULL) {
1352 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1353 return NULL;
1354 }
1355
1356 funName = "utilNativeSaveXml";
1357 appOps.utilNativeSaveXml = (APP_STATUS( *)(const char * audioTypeName)) dlsym(appOps.handle, funName);
1358 error = dlerror();
1359 if (error != NULL) {
1360 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1361 return NULL;
1362 }
1363
1364 funName = "utilNativeGetChecklist";
1365 appOps.utilNativeGetChecklist = (const char * ( *)(const char * audioTypeName, const char * paramName, const char * fieldName)) dlsym(appOps.handle, funName);
1366 error = dlerror();
1367 if (error != NULL) {
1368 ALOGE("%s(), dlsym %s fail. (%s)\n", __FUNCTION__, funName, error);
1369 return NULL;
1370 }
1371
1372 appOpsInited = 1;
1373}
1374
1375return &appOps;
1376}
1377
1378EXPORT static __attribute__((unused)) int appIsFeatureOptionEnabled(const char* fo) {
1379 AppOps* appOps = appOpsGetInstance();
1380 if (appOps == NULL) {
1381 ALOGE("%s(), AppOps is NULL!\n", __FUNCTION__);
1382 return -1;
1383 }
1384
1385 AppHandle *appHandle = appOps->appHandleGetInstance();
1386 if (appHandle == NULL) {
1387 ALOGE("%s(), AppHandle is NULL!\n", __FUNCTION__);
1388 return -1;
1389 }
1390
1391 return appOps->appHandleIsFeatureOptionEnabled(appHandle, fo);
1392}
1393
1394EXPORT static __attribute__((unused)) const char* appGetFeatureOptionValue(const char* fo) {
1395 AppOps* appOps = appOpsGetInstance();
1396 if (appOps == NULL) {
1397 ALOGE("%s(), AppOps is NULL!\n", __FUNCTION__);
1398 return NULL;
1399 }
1400
1401 AppHandle *appHandle = appOps->appHandleGetInstance();
1402 if (appHandle == NULL) {
1403 ALOGE("%s(), AppHandle is NULL!\n", __FUNCTION__);
1404 return NULL;
1405 }
1406
1407 return appOps->appHandleGetFeatureOptionValue(appHandle, fo);
1408}
1409
1410static __attribute__((unused)) void appOpsDelInstance() {
1411if (appOpsInited == 1) {
1412 dlclose(appOps.handle);
1413 appOps.handle = NULL;
1414 appOpsInited = 0;
1415}
1416}
1417#endif
1418
1419#ifndef WIN32
1420#ifdef __cplusplus
1421}
1422#endif
1423#endif
1424
1425#endif