merge tizen 2.4
[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_FILE_OPEN.
61  */
62 #define PREFERENCE_ERROR_FILE_OPEN       -21
63
64 /**
65  * @brief Definition for PREFERENCE_ERROR_FILE_FREAD.
66  */
67 #define PREFERENCE_ERROR_FILE_FREAD      -22
68
69 /**
70  * @brief Definition for PREFERENCE_ERROR_FILE_FGETS.
71  */
72 #define PREFERENCE_ERROR_FILE_FGETS      -23
73
74 /**
75  * @brief Definition for PREFERENCE_ERROR_FILE_WRITE.
76  */
77 #define PREFERENCE_ERROR_FILE_WRITE      -24
78
79 /**
80  * @brief Definition for PREFERENCE_ERROR_FILE_SYNC.
81  */
82 #define PREFERENCE_ERROR_FILE_SYNC       -25
83
84 /**
85  * @brief Definition for PREFERENCE_ERROR_FILE_CHMOD.
86  */
87 #define PREFERENCE_ERROR_FILE_CHMOD      -28
88
89 /**
90  * @brief Definition for PREFERENCE_ERROR_FILE_LOCK.
91  */
92 #define PREFERENCE_ERROR_FILE_LOCK       -29
93
94 typedef enum
95 {
96         PREFERENCE_TYPE_NONE = 0,
97         PREFERENCE_TYPE_STRING,
98         PREFERENCE_TYPE_INT,
99         PREFERENCE_TYPE_DOUBLE,
100         PREFERENCE_TYPE_BOOLEAN,
101 } preference_type_e;
102
103 typedef struct _pref_changed_cb_node_t{
104         char *key;
105         preference_changed_cb cb;
106         void *user_data;
107         struct _pref_changed_cb_node_t *prev;
108         struct _pref_changed_cb_node_t *next;
109 } pref_changed_cb_node_t;
110
111 typedef struct _keynode_t {
112     char *keyname;           /**< Keyname for keynode */
113     int type;                /**< Keynode type */
114     union {
115         int i;               /**< Integer type */
116         int b;               /**< Bool type */
117         double d;            /**< Double type */
118         char *s;             /**< String type */
119     } value;                 /**< Value for keynode */
120     struct _keynode_t *next; /**< Next keynode */
121 } keynode_t;
122
123 /**
124  * @brief The structure type for opaque type. It must be used via accessor functions.
125  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
126  */
127 typedef struct _keylist_t {
128     int num;           /**< Number of list */
129     keynode_t *head;   /**< Head node */
130     keynode_t *cursor; /**< Cursor node */
131 } keylist_t;
132
133
134 int _preference_kdb_add_notify
135         (keynode_t *keynode, preference_changed_cb cb, void *data);
136 int _preference_kdb_del_notify
137         (keynode_t *keynode);
138
139 int _preference_get_key_path(keynode_t *keynode, char *path);
140 int _preference_get_key(keynode_t *keynode);
141
142 int _preference_keynode_set_keyname(keynode_t *keynode, const char *keyname);
143 inline void _preference_keynode_set_null(keynode_t *keynode);
144 inline keynode_t *_preference_keynode_new(void);
145 inline void _preference_keynode_free(keynode_t *keynode);
146
147
148 #ifdef __cplusplus
149 }
150 #endif
151
152 #endif /* __TIZEN_APPFW_PREFERENCE_INTERNAL_H__ */