Tizen 2.1 base
[platform/core/system/sync-agent.git] / include / data-adapter / common.h
1 /*
2  * sync-agent
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #ifndef DATA_ADAPTER_COMMON_H_
19 #define DATA_ADAPTER_COMMON_H_
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <stdbool.h>
25 #include <malloc.h>
26 #include <glib.h>
27 #include <unistd.h>
28 #include <pthread.h>
29 #include <sys/stat.h>
30 #include <sqlite3.h>
31
32 #include "error.h"
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif                          /* __cplusplus */
37
38 /**
39  * @file                common.h
40  * @brief       Common factor of Framework common database
41  */
42
43 /** @addtogroup data_adapter
44  *      @{
45  */
46
47 /**
48  * @brief       MO handler
49  */
50 #define SYNC_AGENT_DA_MO_HANDLER                                                                                                sqlite3
51
52 /**
53  * @brief       Data Adapter handler
54  */
55 #define SYNC_AGENT_DA_HANDLER                                                                                           sqlite3
56
57 /**
58  * @brief       Database retry count
59  */
60 #define SYNC_AGENT_DA_RETRY_COUNT                                                                               10
61
62 /**
63  * @brief       Max DB query length
64  */
65 #define SYNC_AGENT_DA_MAX_QUERY_LENGTH                                                  2048
66
67 /**
68  * @brief       Max number account that sync-agent framework supports
69  */
70 #define SYNC_AGENT_DA_MAX_ACCOUNT                                                                               10
71
72 /**
73  * @brief       Redefined memset()
74  */
75 #define SYNC_AGENT_DA_MEMORY_SET(ptr)                                                                   memset(ptr, 0x00, sizeof(ptr));
76
77 /**
78  * @brief       Redefined malloc()
79  */
80 #define SYNC_AGENT_DA_MEMORY_MALLOC(type, size, count)          (type)malloc(size*count)
81
82 /**
83  * @brief       Redefined calloc()
84  */
85 #define SYNC_AGENT_DA_MEMORY_CALLOC(type, size, count)          (type)calloc(count, size)
86
87 /**
88  * @brief       Redefined free()
89  */
90 #define SYNC_AGENT_DA_MEMORY_FREE(src)  \
91         if (src != NULL) {\
92                 free(src);\
93                 src = NULL;\
94         }\
95
96 /**
97  * @brief       Redefined strdup()
98  */
99 #define SYNC_AGENT_DA_STRDUP(src)                                                                       (src == NULL) ?  NULL : strdup(src);
100
101 /**
102  * @brief       Redefined atoi()
103  */
104 #define SYNC_AGENT_DA_ATOI(src)                                                                         (src == NULL) ? 0 : atoi(src);
105
106 /**
107  * @brief       Macro for fetching self thread id
108  */
109 #define SYNC_AGENT_DA_GET_THREAD_ID                                                     pthread_self()
110
111 /**
112  * @brief       Redefined sqlite3 connection
113  */
114         typedef sqlite3_stmt *daci_stmt;
115
116 /**
117  * @brief       Enumerations of database peak type
118  */
119         typedef enum {
120                 SYNC_AGENT_DA_PEAK_TYPE_ON = 601,
121                                                 /**< peak type on */
122                 SYNC_AGENT_DA_PEAK_TYPE_ON_N_OFF,
123                                                 /**< peak type N off */
124                 SYNC_AGENT_DA_PEAK_TYPE_OFF
125                                         /**< peak type off */
126         } sync_agent_da_peak_type_e;
127
128 /**
129  * @brief       Enumerations of database transaction
130  */
131         typedef enum {
132                 SYNC_AGENT_DA_TRANSACTION_COMMIT,
133                                                 /**< means commit */
134                 SYNC_AGENT_DA_TRANSACTION_ROLLBACK
135                                                 /**< means rollback */
136         } sync_agent_da_transaction_e;
137
138 /**
139  * @brief       Enumerations of common db's table list
140  */
141         typedef enum {
142                 SYNC_AGENT_DA_TABLE_NAME_ACCOUNT,
143                                                 /**< means account_tbl */
144                 SYNC_AGENT_DA_TABLE_NAME_FOLDER,/**< means folder_tbl */
145                 SYNC_AGENT_DA_TABLE_NAME_ITEM,
146                                         /**< means item_tbl */
147                 SYNC_AGENT_DA_TABLE_NAME_CONFIG,/**< means config_tbl */
148                 SYNC_AGENT_DA_TABLE_NAME_ACCOUNT_ITEM_CHANGELOG,/**< means account_item_changelog_tbl */
149                 SYNC_AGENT_DA_TABLE_NAME_LAST_ANCHOR,
150                                                 /**< means last_anchor_tbl */
151                 SYNC_AGENT_DA_TABLE_NAME_MAPPING,
152                                                 /**< means mapping_tbl */
153                 SYNC_AGENT_DA_TABLE_NAME_ID_PROVIDER,
154                                                 /**< means id_provider_tbl */
155                 SYNC_AGENT_DA_TABLE_NAME_ID_PAGE,
156                                                 /**< means id_page_tbl */
157
158                 SYNC_AGENT_DA_TABLE_NAME_MAX
159                                         /**< count of common database's tables */
160         } sync_agent_da_table_name_e;
161
162 /**
163  * @brief       Structure of Item information
164  */
165         typedef struct {
166                 char *itemId;
167                         /**< F/W item id */
168                 int itemTypeId;
169                         /**< service data connector pluIn's ID described in F/W config file  */
170                 char *serviceId;/**< service item id */
171                 int operationId;/**< operation type - add, delete, update */
172                 char *syncStatus;
173                                 /**< user defined status of item */
174         } sync_agent_da_item_info_s;
175
176 /**
177  * @brief       Structure of Item id's container
178  */
179         typedef struct {
180                 int count;
181                         /**< count of id */
182                 char **id;
183                         /**< real id list */
184         } sync_agent_da_id_list_s;
185
186 /**
187  * @brief       Structure of framework id provider instance
188  */
189         typedef struct {
190                 unsigned int id_provider_code;
191                                         /**< ID of id provider - this described in F/W configuration file */
192                 unsigned int id_capacity;       /**< max ID count possible id provider generate - this described in F/W configuration file */
193                 unsigned int bit_per_page;      /**< most number of bit per one page */
194                 unsigned int last_id;
195                                 /**< current last provided ID */
196                 unsigned int free_bit_cnt;      /**< the number of IDs that can be issued */
197         } sync_agent_da_id_provider_s;
198
199 /**
200  * @brief       Structure of framework id page instance
201  */
202         typedef struct {
203                 unsigned int page_index;
204                                 /**< index of page */
205                 unsigned int id_provider_code;
206                                         /**< ID of id provider - this described in F/W configuration file */
207                 char *page_bit;
208                         /**< real construction of ID issued */
209         } sync_agent_da_id_page_s;
210
211 /**
212  *      @}
213  */
214
215 #ifdef __cplusplus
216 }
217 #endif                          /* __cplusplus */
218 #endif                          /* SYNC_AGENT_DA_COMMON_H_ */