-
Notifications
You must be signed in to change notification settings - Fork 0
/
shared_preferences.h
284 lines (233 loc) · 8.16 KB
/
shared_preferences.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#ifndef __TG_SHARED_PREFERENCES_H__
#define __TG_SHARED_PREFERENCES_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <common.h>
struct _SharedPreferences;
typedef struct _SharedPreferences SharedPreferences;
typedef enum
{
SharedPreferences_SUCC,
SharedPreferences_ERROR=-1,
SharedPreferences_KEY_NOT_EXIST=-2,
SharedPreferences_OCCUPIED=-3,
SharedPreferences_PATH_ERROR=-4,
SharedPreferences_OPEN_FILE_ERROR=-5,
SharedPreferences_LACK_MEMORY=-6,
}SharedPreferences_ERROR_CODE;
typedef enum
{
SharedPreferences_Read_Mode,
SharedPreferences_ReadWrite_Mode,
}SharedPreferences_Open_Mode;
typedef enum
{
SharedPreferences_Delete_Mode,
SharedPreferences_Add_Mode,
SharedPreferences_Modify_Mode,
}SharedPreferences_WRITE_TYPE;
typedef INT32 (*SharedPreferences_Notification_Callback ) ( );
/**
initilizate preferences manager, it only needs to be called when power on
*/
extern void tg_shared_preferences_manager_init();
/**
open one preference
@param [in] path SharedPreferences path
@param [in] mode open mode
@return SharedPreferences handle
*/
extern SharedPreferences* tg_shared_preferences_open(const CHAR* path,SharedPreferences_Open_Mode mode);
/**
close one preference
@param [in] thiz SharedPreferences handle
@return error code
*/
extern INT32 tg_shared_preferences_close(SharedPreferences* thiz);
/**
commit the modify on one preference,after modify or delete, need to commit to save the changes
@param [in] thiz SharedPreferences handle
@return error code
*/
extern INT32 tg_shared_preferences_commit(SharedPreferences* thiz);
/**
delete sharepreference file
@param [in] path SharedPreferences path
@return error code
*/
extern INT32 tg_shared_preferences_delete(const CHAR* path);
/**
check whether or not the sharepreference file is exist
@param [in] path SharedPreferences path
@return error code
*/
extern BOOL tg_shared_preferences_is_ready(const CHAR* path);
/**
create/reset a sharepreference file using json string
@param [in] path SharedPreferences path
@param [in] json_str json string
@return error code
*/
extern INT32 tg_shared_preferences_init_from_string(const CHAR* path,const CHAR* json_str);
/**
create/reset a sharepreference file using default file
@param [in] path SharedPreferences path
@param [in] default_path json file path
@return error code
*/
extern INT32 tg_shared_preferences_init_from_file(const CHAR* path,const CHAR* default_path);
/**
register for notification, there is a limitation,only first level key can be reigstered
@param [in] path SharedPreferences path
@param [in] keys item path
@param [in] cb notify callback
@param [in] type type
@return error code
*/
extern INT32 tg_shared_preferences_register(const CHAR* path,const CHAR* keys,SharedPreferences_Notification_Callback cb,SharedPreferences_WRITE_TYPE type);
/**
unregister one data notification
@param [in] path SharedPreferences path
@param [in] keys item path
@param [in] cb notify callback
@param [in] type type
@return error code
*/
extern INT32 tg_shared_preferences_unregister(const CHAR* path,const CHAR* keys,SharedPreferences_Notification_Callback cb,SharedPreferences_WRITE_TYPE type);
/**
unregister all data notification
@return error code
*/
extern INT32 tg_shared_preferences_unregister_all();
/**
Retrieve a wstring value from the preferences.
@param [in] thiz SharedPreferences handle
@param [in] key_path key path string
@return wstring
*/
extern INT32 tg_shared_preferences_get_serialization(SharedPreferences* thiz,const CHAR* key_path,void** ret);
/**
Retrieve a wstring value from the preferences.
@param [in] thiz SharedPreferences handle
@param [in] key_path key path string
@param [out] ret save wstring value
@return error code
*/
extern INT32 tg_shared_preferences_get_string_16(SharedPreferences* thiz,const CHAR* key_path,WCHAR** ret);
/**
Retrieve a string value from the preferences.
@param [in] thiz SharedPreferences handle
@param [in] key_path key path string
@param [out] ret save string value
@return error code
*/
extern INT32 tg_shared_preferences_get_string(SharedPreferences* thiz,const CHAR* key_path,CHAR** ret);
/**
Retrieve a string value from the preferences.
@param [in] thiz SharedPreferences handle
@param [in] key_path key path string
@return string value
*/
extern const CHAR* tg_shared_preferences_get_string_v2(SharedPreferences* thiz,const CHAR* key_path);
/**
Retrieve a int value from the preferences.
@param [in] thiz SharedPreferences handle
@param [in] key_path key path string
@param [out] ret save int value
@return error code
*/
extern INT32 tg_shared_preferences_get_int(SharedPreferences* thiz,const CHAR* key_path,INT32* ret);
/**
Retrieve a double value from the preferences.
@param [in] thiz SharedPreferences handle
@param [in] key_path key path string
@param [out] ret save double value
@return error code
*/
extern INT32 tg_shared_preferences_get_double(SharedPreferences* thiz,const CHAR* key_path,double* ret);
/**
Retrieve a boolean value from the preferences.
@param [in] thiz SharedPreferences handle
@param [in] key_path key path string
@param [out] ret save bool value
@return error code
*/
extern INT32 tg_shared_preferences_get_bool(SharedPreferences* thiz,const CHAR* key_path,BOOL* ret);
/**
delete one item, if the item has sub item, the sub item also will be deleted
@param [in] thiz SharedPreferences handle
@param [in] key_path key path string
@return error code
*/
extern INT32 tg_shared_preferences_delete_key(SharedPreferences* thiz,const CHAR* key_path);
/**
put a serialization value into the preferences.
@param [in] thiz SharedPreferences handle
@param [in] key_path key path string
@param [int] value serialization value
@param [int] len serialization value length
@return error code
*/
extern INT32 tg_shared_preferences_put_serialization(SharedPreferences* thiz,const CHAR* key_path,const void* value,INT32 len);
/**
put a wstring value into the preferences.
@param [in] thiz SharedPreferences handle
@param [in] key_path key path string
@param [int] value wstring value
@return error code
*/
extern INT32 tg_shared_preferences_put_string_16(SharedPreferences* thiz,const CHAR* key_path,const WCHAR* value);
/**
put a string value into the preferences.
@param [in] thiz SharedPreferences handle
@param [in] key_path key path string
@param [int] value string value
@return error code
*/
extern INT32 tg_shared_preferences_put_string(SharedPreferences* thiz,const CHAR* key_path,const CHAR* value);
/**
put a int value into the preferences.
@param [in] thiz SharedPreferences handle
@param [in] key_path key path string
@param [int] value int value
@return error code
*/
extern INT32 tg_shared_preferences_put_int(SharedPreferences* thiz,const CHAR* key_path,INT32 value);
/**
put a double value into the preferences.
@param [in] thiz SharedPreferences handle
@param [in] key_path key path string
@param [int] value double value
@return error code
*/
extern INT32 tg_shared_preferences_put_double(SharedPreferences* thiz,const CHAR* key_path,double value);
/**
put a bool value into the preferences.
@param [in] thiz SharedPreferences handle
@param [in] key_path key path string
@param [int] value bool value
@return error code
*/
extern INT32 tg_shared_preferences_put_bool(SharedPreferences* thiz,const CHAR* key_path,BOOL value);
/**
get child item count of one item
@param [in] thiz SharedPreferences handle
@param [in] key_path key path string
@param [out] count save the sub item number
@return error code
*/
extern INT32 tg_shared_preferences_get_child_count(SharedPreferences* thiz,const CHAR* key_path,INT32* count);
/**
get child item full path
@param [in] thiz SharedPreferences handle
@param [in] key_path key path string
@param [in] index index
@param [out] ret save the sub item full path
@return error code
*/
extern INT32 tg_shared_preferences_produce_child_path_by_idx(SharedPreferences* thiz,const CHAR* key_path,INT32 index,CHAR** ret);
#ifdef __cplusplus
}
#endif
#endif