xref: /rockchip-linux_mpp/mpp/base/inc/mpp_cfg_io.h (revision 437bfbeb9567cca9cd9080e3f6954aa9d6a94f18)
1 /* SPDX-License-Identifier: Apache-2.0 OR MIT */
2 /*
3  * Copyright (c) 2025 Rockchip Electronics Co., Ltd.
4  */
5 
6 #ifndef __MPP_CFG_IO__
7 #define __MPP_CFG_IO__
8 
9 #include "rk_mpp_cfg.h"
10 
11 #include "mpp_internal.h"
12 
13 typedef enum MppCfgType_e {
14     MPP_CFG_TYPE_INVALID = 0,
15 
16     /* invalid or empty value type */
17     MPP_CFG_TYPE_NULL,
18 
19     /* leaf type must with name */
20     MPP_CFG_TYPE_BOOL,
21     MPP_CFG_TYPE_s32,
22     MPP_CFG_TYPE_u32,
23     MPP_CFG_TYPE_s64,
24     MPP_CFG_TYPE_u64,
25     MPP_CFG_TYPE_f32,
26     MPP_CFG_TYPE_f64,
27     MPP_CFG_TYPE_STRING,
28     MPP_CFG_TYPE_RAW,
29 
30     /* branch type */
31     MPP_CFG_TYPE_OBJECT,
32     MPP_CFG_TYPE_ARRAY,
33 
34     MPP_CFG_TYPE_BUTT,
35 } MppCfgType;
36 
37 typedef union MppCfgVal_u {
38     rk_bool     b1;
39     rk_s32      s32;
40     rk_u32      u32;
41     rk_s64      s64;
42     rk_u64      u64;
43     rk_float    f32;
44     rk_double   f64;
45     void        *str;
46     void        *ptr;
47 } MppCfgVal;
48 
49 typedef void* MppCfgObj;
50 typedef rk_s32 (*MppCfgObjCond)(MppCfgObj obj);
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 rk_s32 mpp_cfg_get_object(MppCfgObj *obj, const char *name, MppCfgType type, MppCfgVal *val);
57 rk_s32 mpp_cfg_get_array(MppCfgObj *obj, const char *name, rk_s32 count);
58 rk_s32 mpp_cfg_put(MppCfgObj obj);
59 rk_s32 mpp_cfg_put_all(MppCfgObj obj);
60 
61 /* object tree build */
62 rk_s32 mpp_cfg_add(MppCfgObj root, MppCfgObj leaf);
63 /* object tree release */
64 rk_s32 mpp_cfg_del(MppCfgObj obj);
65 /* find by name string */
66 rk_s32 mpp_cfg_find(MppCfgObj *obj, MppCfgObj root, char *name, rk_s32 type);
67 
68 /* attach MppCfgInfo for access location */
69 rk_s32 mpp_cfg_set_info(MppCfgObj obj, MppCfgInfo *info);
70 /* attach KmppEntry for access location */
71 rk_s32 mpp_cfg_set_entry(MppCfgObj obj, KmppEntry *entry);
72 /* add cfg obj condition for input / output option */
73 rk_s32 mpp_cfg_set_cond(MppCfgObj obj, MppCfgObjCond cond);
74 
75 void mpp_cfg_dump(MppCfgObj obj, const char *func);
76 #define mpp_cfg_dump_f(obj) mpp_cfg_dump(obj, __FUNCTION__)
77 
78 /* mark all MppCfgObject ready and build trie for string access */
79 MppTrie mpp_cfg_to_trie(MppCfgObj obj);
80 
81 /* mpp_cfg output to string and input from string */
82 rk_s32 mpp_cfg_to_string(MppCfgObj obj, MppCfgStrFmt fmt, char **buf);
83 rk_s32 mpp_cfg_from_string(MppCfgObj *obj, MppCfgStrFmt fmt, const char *buf);
84 
85 /*
86  * obj  - read from file or string and get an object as source
87  * type - struct type object root for location table indexing and access
88  * st   - struct body to write obj values to
89  */
90 rk_s32 mpp_cfg_to_struct(MppCfgObj obj, MppCfgObj type, void *st);
91 /*
92  * obj  - output object root for the struct values
93  * type - struct type object root for location table access
94  * st   - struct body to write obj values
95  */
96 rk_s32 mpp_cfg_from_struct(MppCfgObj *obj, MppCfgObj type, void *st);
97 
98 rk_s32 mpp_cfg_print_string(char *buf);
99 
100 #ifdef __cplusplus
101 }
102 #endif
103 
104 #endif /* __MPP_CFG_IO__ */
105