• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * linux-5.4/drivers/media/platform/sunxi-vin/utility/cfg_op.h
3  *
4  * Copyright (c) 2007-2017 Allwinnertech Co., Ltd.
5  *
6  * This software is licensed under the terms of the GNU General Public
7  * License version 2, as published by the Free Software Foundation, and
8  * may be copied, distributed, and modified under those terms.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  */
16 
17 #ifndef __CFG__OP__H__
18 #define __CFG__OP__H__
19 #include <linux/vmalloc.h>
20 
21 #define LINE_MAX_CHAR_NUM 512
22 #define MAX_LINE_NUM      1024
23 #define MAX_NAME_LEN      32
24 #define MAX_VALUE_LEN     128
25 #define MAX_MAINKEY_NUM   16
26 #define MAX_SUBKEY_NUM    512
27 #define INI_MAX_CHAR_NUM (LINE_MAX_CHAR_NUM * MAX_LINE_NUM)
28 #define BIN_MAX_SIZE (4096*4)
29 
30 enum cfg_item_type {
31 	CFG_ITEM_VALUE_TYPE_INVALID = 0,
32 	CFG_ITEM_VALUE_TYPE_INT,
33 	CFG_ITEM_VALUE_TYPE_STR,
34 };
35 
36 enum cfg_key_flag {
37 	CFG_KEY_RELEASE,
38 	CFG_KEY_INIT,
39 };
40 
41 struct cfg_item {
42 	int val;
43 	char str[MAX_VALUE_LEN];
44 };
45 
46 struct cfg_subkey {
47 	char name[MAX_NAME_LEN];
48 	struct cfg_item value;
49 	enum cfg_item_type type;
50 	enum cfg_key_flag cfg_flag;
51 };
52 
53 struct cfg_mainkey {
54 	char name[MAX_NAME_LEN];
55 	struct cfg_subkey subkey[MAX_SUBKEY_NUM];
56 	char *subkey_name[MAX_SUBKEY_NUM];
57 	char *subkey_value[MAX_SUBKEY_NUM];
58 	int subkey_cnt;
59 	enum cfg_key_flag cfg_flag;
60 };
61 
62 struct cfg_section {
63 	struct cfg_mainkey *mainkey[MAX_MAINKEY_NUM];
64 	char *mainkey_name[MAX_MAINKEY_NUM];
65 	int mainkey_cnt;
66 	enum cfg_key_flag cfg_flag;
67 };
68 
69 int cfg_get_sections(char *buffer, char *sections[]);
70 int cfg_get_one_key_value(char *buffer, struct cfg_mainkey *scts,
71 			  struct cfg_subkey *subkey);
72 int cfg_get_all_keys_value(char *buffer, struct cfg_mainkey *scts);
73 void cfg_subkey_init(struct cfg_subkey **subkey);
74 void cfg_subkey_release(struct cfg_subkey **subkey);
75 void cfg_mainkey_init(struct cfg_mainkey **mainkey, char **mainkey_name);
76 void cfg_mainkey_release(struct cfg_mainkey **mainkey, char **mainkey_name);
77 void cfg_section_init(struct cfg_section **cfg_sct);
78 void cfg_section_release(struct cfg_section **cfg_sct);
79 int cfg_read_ini(char *file_path, struct cfg_section **cfg_section);
80 int cfg_read_file(char *file_path, char *buf, size_t len);
81 
82 int cfg_get_one_subkey(struct cfg_section *cfg_section, char *main, char *sub,
83 		       struct cfg_subkey *subkey);
84 
85 struct file *cfg_open_file(char *file_path);
86 int cfg_close_file(struct file *fp);
87 int cfg_write_file(struct file *fp, char *buf, size_t len);
88 #endif /*__CFG__OP__H__*/
89