310bc5024046cf7149cc010c12e079531ae6cf7b
[platform/core/appfw/vconf.git] / include / vconf-internals.h
1 /*
2  * libslp-setting
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Hakjoo Ko <hakjoo.ko@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 /*
23  * Internals of libslp-setting
24  *
25  * @file        setting-internals.h
26  * @author      Sangjung Woo (sangjung.woo@samsung.com)
27  * @version     0.2
28  * @brief       This file is the header file of internal functions.
29  */
30
31 #ifndef __VCONF_GCONF_H__
32 #define __VCONF_GCONF_H__
33
34 #include "vconf-log.h"
35 #include "vconf.h"
36
37 #define BACKEND_DB_PREFIX "db/"
38 #define BACKEND_FILE_PREFIX "file/"
39 #define BACKEND_MEMORY_PREFIX "memory/"
40
41 #define BACKEND_SYSTEM_DIR "/opt/var/kdb/"
42 #define BACKEND_MEMORY_DIR "/var/run/"
43
44 /* This value can be optimized according to the device characteristcs and file system configuration */
45 #define FILE_ATOMIC_GUARANTEE_SIZE      4096
46
47 #define VCONF_BACKUP_COMPLETE_MARK      0x64416548
48
49 #define VCONF_KEY_PATH_LEN      1024
50 #define BUF_LEN                 1024
51 #define ERR_LEN                 128
52
53 #define VCONF_TYPE_SIZE sizeof(int)
54 #define VCONF_BACKUP_COMP_MARK_SIZE     sizeof(int)
55
56 enum {
57         VCONF_BACKEND_NULL = 0,
58         VCONF_BACKEND_DB,
59         VCONF_BACKEND_FILE,
60         VCONF_BACKEND_MEMORY
61 };
62
63 #if 0
64 enum {
65         VCONF_TYPE_NONE = 0,
66         VCONF_TYPE_STRING = 40, /*KEY_TYPE_STRING of KDB is 40 */
67         VCONF_TYPE_INT = 41,
68         VCONF_TYPE_DOUBLE = 42,
69         VCONF_TYPE_BOOL = 43,
70         VCONF_TYPE_DIR
71 };
72
73 typedef int get_option_t;
74 enum {
75         VCONF_GET_KEY = 0,
76         VCONF_GET_ALL,
77         VCONF_GET_DIR,
78 };
79
80 /*This is a callback function pointer signature for value return*/
81 typedef void (*vconf_callback_fn) (keynode_t *node, void *user_data);
82
83 #endif
84
85
86
87 #define VCONF_OK                 0
88 #define VCONF_ERROR              -1
89
90 enum {
91         VCONF_ERROR_WRONG_PREFIX = 1,
92         VCONF_ERROR_WRONG_TYPE,
93         VCONF_ERROR_WRONG_VALUE,
94         VCONF_ERROR_NO_MEM,
95         VCONF_ERROR_NOT_INITIALIZED,
96         VCONF_ERROR_FILE_OPEN = 11,
97         VCONF_ERROR_FILE_FREAD,
98         VCONF_ERROR_FILE_FGETS,
99         VCONF_ERROR_FILE_WRITE,
100         VCONF_ERROR_FILE_SYNC,
101         VCONF_ERROR_FILE_CLOSE,
102         VCONF_ERROR_FILE_ACCESS,
103         VCONF_ERROR_FILE_CHMOD,
104         VCONF_ERROR_FILE_LOCK,
105         VCONF_ERROR_FILE_REMOVE,
106         VCONF_ERROR_FILE_SEEK,
107         VCONF_ERROR_FILE_TRUNCATE
108 };
109
110 #define return_err(err) return 0-err;
111
112 /* Error codes returned by the configuration manager */
113 #if 0
114 typedef enum {
115         /*Unknown Error */
116         VCONF_ERROR_UNKNOWN = -1,
117         VCONF_ERROR_SUCCESS = 0,
118         /* Something didn't work, don't know why, probably unrecoverable
119            so there's no point having a more specific errno */
120         VCONF_ERROR_FAILED = 1,
121         /* Server can't be launched/contacted */
122         VCONF_ERROR_NO_SERVER = 2,
123         /* don't have permission for that */
124         VCONF_ERROR_NO_PERMISSION = 3,
125         /* Address couldn't be resolved */
126         VCONF_ERROR_BAD_ADDRESS = 4,
127         /* directory or key isn't valid
128            (contains bad characters, or malformed slash arrangement) */
129         VCONF_ERROR_BAD_KEY = 5,
130         /* Syntax error when parsing */
131         VCONF_ERROR_PARSE_ERROR = 6,
132         /* Fatal error parsing/loading information inside the backend */
133         VCONF_ERROR_CORRUPT = 7,
134         /* Type requested doesn't match type found */
135         VCONF_ERROR_TYPE_MISMATCH = 8,
136         /* Requested key operation on a dir */
137         VCONF_ERROR_IS_DIR = 9,
138         /* Requested dir operation on a key */
139         VCONF_ERROR_IS_KEY = 10,
140         /* Read-only source at front of path has set the value */
141         VCONF_ERROR_OVERRIDDEN = 11,
142         /* liboaf error */
143         VCONF_ERROR_OAF_ERROR = 12,
144         /* Tried to use remote operations on a local engine */
145         VCONF_ERROR_LOCAL_ENGINE = 13,
146         /* Failed to get a lockfile */
147         VCONF_ERROR_LOCK_FAILED = 14,
148         /* nowhere to write a value */
149         VCONF_ERROR_NO_WRITABLE_DATABASE = 15,
150         /* server is shutting down */
151         VCONF_ERROR_IN_SHUTDOWN = 16,
152         /* no key */
153         VCONF_NO_KEY = 17,
154         /* connection failure */
155         VCONF_CONF_CONNECTION_FAIL = 18,
156         /* invalid parameter */
157         VCONF_CONF_INVALID_PARAMETER = 19,
158         /* unable to get kdb key new */
159         VCONF_CONF_ERROR_GET_KDB_KEY_NEW = 20,
160         /* kdb open failure */
161         VCONF_CONF_ERROR_KDB_OPEN = 21,
162         /* unable to set kdb key val */
163         VCONF_CONF_ERROR_KDB_KEY_SET = 22,
164         /* unable to get kdb key val */
165         VCONF_CONF_ERROR_KDB_KEY_GET = 23,
166         /* unable to register callback notification */
167         VCONF_ERROR_NOTI_ADD_FILE_CB = 24,
168         /* kdb remove failure */
169         VCONF_CONF_ERROR_KDB_REMOVE = 25,
170         /* unable to remove callback function registered */
171         VCONF_ERROR_NOTI_DEL_FILE_CB = 26,
172         /*Supplied keylist is empty/Non existing */
173         VCONF_ERROR_NO_KEYLIST = 27,
174         /*This functionality is not supported */
175         VCONF_ERROR_NOT_SUPPORTED = 28,
176         /*Callback could not be called/Failed */
177         VCONF_ERROR_CALLBACK_FAILED = 29
178 } SLP_Setting_Error;
179 #endif
180
181 int _vconf_kdb_add_notify
182         (const char *keyname, vconf_callback_fn cb, void *data);
183 int _vconf_kdb_del_notify
184         (const char *keyname, vconf_callback_fn cb);
185
186 int _vconf_get_key_path(const char *keyname, char *path);
187 int _vconf_get_key(keynode_t *keynode);
188
189 int _vconf_keynode_set_keyname(keynode_t *keynode, const char *keyname);
190 inline void _vconf_keynode_set_null(keynode_t *keynode);
191 inline keynode_t *_vconf_keynode_new(void);
192 inline void _vconf_keynode_free(keynode_t *keynode);
193
194 #endif