To use hash value for file name.
[platform/core/api/application.git] / include / app_preference_internal.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 #ifndef __TIZEN_APPFW_PREFERENCE_INTERNAL_H__
19 #define __TIZEN_APPFW_PREFERENCE_INTERNAL_H__
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 #include "app_preference_log.h"
26 #include "linux/limits.h"
27
28 #define BUF_LEN                 (4096)
29 #define PREF_DIR        ".pref/"
30
31 #define PREFERENCE_KEY_PATH_LEN         1024
32 #define ERR_LEN                 128
33
34 #define PREF_DB_NAME            ".pref.db"
35 #define PREF_TBL_NAME           "pref"
36 #define PREF_F_KEY_NAME         "pref_key"
37 #define PREF_F_TYPE_NAME        "pref_type"
38 #define PREF_F_DATA_NAME        "pref_data"
39
40 /* ASCII VALUE */
41 #define PREF_KEYNAME_C_PAD '='
42 #define PREF_KEYNAME_C_PLUS '+'
43 #define PREF_KEYNAME_C_SLASH '/'
44
45 #define PREF_KEYNAME_C_DOT '.'
46 #define PREF_KEYNAME_C_UNDERSCORE '_'
47 #define PREF_KEYNAME_C_HYPHEN '-'
48
49 /**
50  * @brief Definition for PREFERENCE_ERROR_WRONG_PREFIX.
51  */
52 #define PREFERENCE_ERROR_WRONG_PREFIX    -2
53
54 /**
55  * @brief Definition for PREFERENCE_ERROR_WRONG_TYPE.
56  */
57 #define PREFERENCE_ERROR_WRONG_TYPE      -3
58
59 /**
60  * @brief Definition for PREFERENCE_ERROR_OUT_OF_MEMORY.
61  */
62 #define PREFERENCE_ERROR_OUT_OF_MEMORY      -12
63
64 /**
65  * @brief Definition for PREFERENCE_ERROR_FILE_OPEN.
66  */
67 #define PREFERENCE_ERROR_FILE_OPEN       -21
68
69 /**
70  * @brief Definition for PREFERENCE_ERROR_FILE_FREAD.
71  */
72 #define PREFERENCE_ERROR_FILE_FREAD      -22
73
74 /**
75  * @brief Definition for PREFERENCE_ERROR_FILE_FGETS.
76  */
77 #define PREFERENCE_ERROR_FILE_FGETS      -23
78
79 /**
80  * @brief Definition for PREFERENCE_ERROR_FILE_WRITE.
81  */
82 #define PREFERENCE_ERROR_FILE_WRITE      -24
83
84 /**
85  * @brief Definition for PREFERENCE_ERROR_FILE_SYNC.
86  */
87 #define PREFERENCE_ERROR_FILE_SYNC       -25
88
89 /**
90  * @brief Definition for PREFERENCE_ERROR_FILE_CHMOD.
91  */
92 #define PREFERENCE_ERROR_FILE_CHMOD      -28
93
94 /**
95  * @brief Definition for PREFERENCE_ERROR_FILE_LOCK.
96  */
97 #define PREFERENCE_ERROR_FILE_LOCK       -29
98
99 typedef enum
100 {
101         PREFERENCE_TYPE_NONE = 0,
102         PREFERENCE_TYPE_STRING,
103         PREFERENCE_TYPE_INT,
104         PREFERENCE_TYPE_DOUBLE,
105         PREFERENCE_TYPE_BOOLEAN,
106 } preference_type_e;
107
108 typedef struct _pref_changed_cb_node_t{
109         char *key;
110         preference_changed_cb cb;
111         void *user_data;
112         struct _pref_changed_cb_node_t *prev;
113         struct _pref_changed_cb_node_t *next;
114 } pref_changed_cb_node_t;
115
116 typedef struct _keynode_t {
117     char *keyname;           /**< Keyname for keynode */
118     int type;                /**< Keynode type */
119     union {
120         int i;               /**< Integer type */
121         int b;               /**< Bool type */
122         double d;            /**< Double type */
123         char *s;             /**< String type */
124     } value;                 /**< Value for keynode */
125     struct _keynode_t *next; /**< Next keynode */
126 } keynode_t;
127
128 /**
129  * @brief The structure type for opaque type. It must be used via accessor functions.
130  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
131  */
132 typedef struct _keylist_t {
133     int num;           /**< Number of list */
134     keynode_t *head;   /**< Head node */
135     keynode_t *cursor; /**< Cursor node */
136 } keylist_t;
137
138
139 int _preference_kdb_add_notify
140         (keynode_t *keynode, preference_changed_cb cb, void *data);
141 int _preference_kdb_del_notify
142         (keynode_t *keynode);
143
144 int _preference_get_key_path(keynode_t *keynode, char *path);
145 int _preference_get_key(keynode_t *keynode);
146
147 int _preference_keynode_set_keyname(keynode_t *keynode, const char *keyname);
148 inline void _preference_keynode_set_null(keynode_t *keynode);
149 inline keynode_t *_preference_keynode_new(void);
150 inline void _preference_keynode_free(keynode_t *keynode);
151
152
153 #ifdef __cplusplus
154 }
155 #endif
156
157 #endif /* __TIZEN_APPFW_PREFERENCE_INTERNAL_H__ */