upload tizen1.0 source
[framework/system/sync-agent.git] / framework / include / agent-framework / DACI / DACI_Common.h
1 /*
2  * sync-agent-framework
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: JuHak Park <juhaki.park@samsung.com>,
7  *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
8  *          SunBong Ha <sunbong.ha@samsung.com>
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */
23
24
25
26
27 /*
28  * For any sort of issue you concern as to this software,
29  * you may use following point of contact.
30  * All resources contributed on this software
31  * are orinigally written by S-Core Inc., a member of Samsung Group.
32  *
33  * JungWook Ryu <jungwook.ryu@samsung.com>,
34  * Heeyoung Hwang <heeyoung1008.hwang@samsung.com>
35  */
36
37 #ifndef DACI_COMMON_H_
38 #define DACI_COMMON_H_
39
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <string.h>
43 #include <stdbool.h>
44 #include <malloc.h>
45 #include <glib.h>
46 #include <unistd.h>
47 #include <pthread.h>
48 #include <sys/stat.h>
49 #include <sqlite3.h>
50
51 #include "EXT_DACI_Errors.h"
52
53 #ifdef __cplusplus
54 extern "C" {
55 #endif                          /* __cplusplus */
56
57 /**
58  * @file                DACI_Common.h
59  * @brief       Common factor of Framework common database
60  */
61
62 #define MO_HANDLER                                                                                              sqlite3
63
64 #define DACI_HANDLER                                                                                            sqlite3
65
66 #define DACI_RETRY_COUNT                                                                                10
67
68 #define DACI_MAX_QUERY_LENGTH                                                   2048
69
70 #define DACI_MAX_ACCOUNT                                                                                10
71
72 #define DACI_FOLDER_TYPE_COUNT                                                  19
73
74 #define DACI_ITEM_TYPE_COUNT                                                            6
75
76 #define DACI_OPERATION_TYPE_COUNT                                               3
77
78 #define DACI_MEMORY_SET(ptr)                                                                    memset(ptr, 0x00, sizeof(ptr));
79
80 #define DACI_MEMORY_MALLOC(type, size, count)           (type)malloc(size*count)
81
82 #define DACI_MEMORY_CALLOC(type, size, count)           (type)calloc(count, size)
83
84 #define DACI_MEMORY_FREE(src) \
85         if (src != NULL) {                                                                              \
86                 free(src);                                                                                              \
87                 src = NULL;                                                                                     \
88         }                                                                                                                               \
89
90 #define DACI_STRDUP(src)                                                                        (src == NULL) ?  NULL : strdup(src);
91
92 #define DACI_ATOI(src)                                                                          (src == NULL) ? 0 : atoi(src);
93
94 #define DACI_GET_THREAD_ID                                                      pthread_self()
95
96 /**
97  * @brief       rename sqlite3 connection
98  */
99         typedef sqlite3_stmt *daci_stmt;
100
101 /**
102  * @brief       Enumerations of database peak type
103  */
104         typedef enum {
105                 PEAK_TYPE_ON = 601,     /**< peak type on */
106                 PEAK_TYPE_ON_N_OFF,     /**< peak type N off */
107                 PEAK_TYPE_OFF   /**< peak type off */
108         } DACI_PEAK_TYPE;
109
110 /**
111  * @brief       Enumerations of database transaction
112  */
113         typedef enum {
114                 TRANSACTION_COMMIT,     /**< means commit */
115                 TRANSACTION_ROLLBACK
116                                 /**< means rollback */
117         } DACI_TRANSACTION;
118
119 /**
120  * @brief       Enumerations of common db's table list
121  */
122         typedef enum {
123                 TABLE_NAME_ACCOUNT,     /**< means account_tbl */
124                 TABLE_NAME_FOLDER,      /**< means folder_tbl */
125                 TABLE_NAME_ITEM,        /**< means item_tbl */
126                 TABLE_NAME_CONFIG,      /**< means config_tbl */
127                 TABLE_NAME_ACCOUNT_ITEM_CHANGELOG,      /**< means account_item_changelog_tbl */
128                 TABLE_NAME_LAST_ANCHOR, /**< means last_anchor_tbl */
129                 TABLE_NAME_MAPPING,     /**< means mapping_tbl */
130                 TABLE_NAME_ID_PROVIDER, /**< means id_provider_tbl */
131                 TABLE_NAME_ID_PAGE,     /**< means id_page_tbl */
132
133                 TABLE_NAME_MAX  /**< count of common database's tables */
134         } DACI_TABLE_NAME;
135
136 /**
137  * @brief       Enumerations of common column
138  */
139         typedef enum {
140                 COLUMN_NAME_ACCOUNT_ID, /**< means column, account_id */
141                 COLUMN_NAME_ITEM_ID,    /**< means column, item_id */
142                 COLUMN_NAME_SERVICE_ID, /**< means column, service_id */
143                 COLUMN_NAME_ACCESS_NAME,        /**< means column, access_name */
144
145                 COLUMN_NAME_MAX /**< count of common columns */
146         } DACI_COLUMN_NAME;
147
148 /**
149  * @brief       Enumerations of structure type concern of DACI
150  */
151         typedef enum {
152                 STRUCT_TYPE_ACCOUNT,    /**< means structure, daci_account */
153                 STRUCT_TYPE_FOLDER,     /**< means structure, daci_folder */
154                 STRUCT_TYPE_ITEM,       /**< means structure, daci_item */
155                 STRUCT_TYPE_CONFIG,     /**< means structure, daci_config */
156                 STRUCT_TYPE_ITEM_CHANGELOG,     /**< means structure, daci_item_changelog */
157                 STRUCT_TYPE_LAST_ANCHOR,        /**< means structure, daci_last_anchor */
158                 STRUCT_TYPE_MAPPING,    /**< means structure, daci_mapping */
159                 STRUCT_TYPE_ITEM_INFO,  /**< means structure, daci_item_info */
160                 STRUCT_TYPE_ID_LIST,    /**< means structure, daci_id_list */
161
162                 STRUCT_TYPE_MAX /**< count of enumeration */
163         } DACI_STRUCT_TYPE;
164
165 /**
166  * @brief       Structure of table - mapped column of account_tbl
167  */
168         typedef struct {
169                 int account_id; /**<  account_id */
170                 char *email_address;    /**<  email_address */
171                 char *password; /**<  password */
172                 bool enable;    /**<  enable */
173                 char *accessName;
174                                 /**<  name of accessor */
175         } daci_account;
176
177 /**
178  * @brief       Structure of table - mapped column of folder_tbl
179  */
180         typedef struct {
181                 char *folder_id;        /**< F/W folder id */
182                 int data_store_id;
183                                 /**< service data connector pluIn's ID described in F/W config file  */
184                 int account_id; /**< F/W account id */
185                 int folder_type_id;
186                                 /**< data connector plugIn has this folder type id */
187                 char *service_id;
188                                 /**< service folder id */
189                 char *parent_folder_id;
190                                 /**< parent folder id if exist hierarchy */
191                 char *access_name;
192                                 /**< name of accessor */
193         } daci_folder;
194
195 /**
196  * @brief       Structure of table - mapped column of item_tbl
197  */
198         typedef struct {
199                 char *item_id;  /**< F/W item id */
200                 int data_store_id;
201                                 /**< service data connector pluIn's ID described in F/W config file  */
202                 int account_id; /**< F/W account id */
203                 char *folder_id;        /**< F/W folder id */
204                 char *service_id;
205                                 /**< service item id */
206                 char *access_name;      /**< name of accessor */
207         } daci_item;
208
209 /**
210  * @brief       Structure of table - mapped column of config_tbl
211  */
212         typedef struct {
213                 int config_id;  /**< configuration id, this means account id */
214                 char *key;      /**< configuration key */
215                 char *value;    /**< configuration value */
216                 char *type;     /**< configuration type */
217                 char *access_name;      /**< name of accessor */
218         } daci_config;
219
220 /**
221  * @brief       Structure of table - mapped column of account_item_changelog_tbl
222  */
223         typedef struct {
224                 char *item_id;  /**< F/W item id */
225                 int operation_id;       /**< operation id - add, delete, update */
226                 char *status;   /**< user defined status of item */
227                 char *access_name;      /**< name of accessor */
228         } daci_item_changelog;
229
230 /**
231  * @brief       Structure of table - mapped column of last_anchor_tbl
232  */
233         typedef struct {
234                 int account_id; /**< F/W account id */
235                 int data_store_id;      /**< service data connector pluIn's ID described in F/W config file  */
236                 char *last_anchor_server;       /**< last anchor that server has */
237                 char *last_anchor_client;       /**< last anchor that client has */
238                 char *access_name;      /**< name of accessor */
239         } daci_last_anchor;
240
241 /**
242  * @brief       Structure of table - mapped column of mapping_tbl
243  */
244         typedef struct {
245                 int account_id; /**< F/W account id */
246                 int data_store_id;      /**< service data connector pluIn's ID described in F/W config file  */
247                 char *luid;     /**< Locally unique identifier */
248                 char *guid;
249                         /**< Globally unique identifier */
250                 char *access_name;      /**< name of accessor */
251         } daci_mapping;
252
253 /**
254  * @brief       Structure of Item information
255  */
256         typedef struct {
257                 char *itemId;   /**< F/W item id */
258                 int itemTypeId; /**< service data connector pluIn's ID described in F/W config file  */
259                 char *serviceId;        /**< service item id */
260                 int operationId;        /**< operation type - add, delete, update */
261                 char *syncStatus;       /**< user defined status of item */
262         } daci_item_info;
263
264 /**
265  * @brief       Structure of Item id's container
266  */
267         typedef struct {
268                 int count;      /**< count of id */
269                 char **id;      /**< real id list */
270         } daci_id_list;
271
272 /**
273  * @brief       Structure of table - mapped column of id_provider_tbl
274  */
275         typedef struct {
276                 unsigned int id_provider_code;  /**< ID of id provider - this described in F/W configuration file */
277                 unsigned int id_capacity;       /**< max ID count possible id provider generate - this described in F/W configuration file */
278                 unsigned int bit_per_page;
279                                         /**< most number of bit per one page */
280                 unsigned int last_id;   /**< current last provided ID */
281                 unsigned int free_bit_cnt;
282                                         /**< the number of IDs that can be issued */
283         } daci_id_provider;
284
285 /**
286  * @brief       Structure of table - mapped column of id_page_tbl
287  */
288         typedef struct {
289                 unsigned int page_index;/**< index of page */
290                 unsigned int id_provider_code;  /**< ID of id provider - this described in F/W configuration file */
291                 char *page_bit; /**< real construction of ID issued */
292         } daci_id_page;
293
294 /*
295  * @brief               free memory daci_account structure
296  * @param[in]   account                                 daci_account structure
297  * @param[in]   count                                           structure count
298  */
299         void DACI_Free_Memory_Account(daci_account *account, int count);
300
301 /*
302  * @brief               free memory daci_folder structure
303  * @param[in]   folder                                  daci_folder structure
304  * @param[in]   count                                           structure count
305  */
306         void DACI_Free_Memory_Folder(daci_folder *folder, int count);
307
308 /*
309  * @brief               free memory daci_item structure
310  * @param[in]   item                                            daci_item structure
311  * @param[in]   count                                           structure count
312  */
313         void DACI_Free_Memory_Item(daci_item *item, int count);
314
315 /*
316  * @brief               free memory daci_config structure
317  * @param[in]   config                                  daci_config structure
318  * @param[in]   count                                           structure count
319  */
320         void DACI_Free_Memory_Config(daci_config *config, int count);
321
322 /*
323  * @brief               free memory daci_item_changelog structure
324  * @param[in]   itemChangelog           daci_item_changelog structure
325  * @param[in]   count                                           structure count
326  */
327         void DACI_Free_Memory_Item_Changelog(daci_item_changelog *itemChangelog, int count);
328
329 /*
330  * @brief               free memory daci_last_anchor structure
331  * @param[in]   lastAnchor                              daci_last_anchor structure
332  * @param[in]   count                                           structure count
333  */
334         void DACI_Free_Memory_Last_Anchor(daci_last_anchor *lastAnchor, int count);
335
336 /*
337  * @brief               free memory daci_mapping structure
338  * @param[in]   mapping                         daci_mapping structure
339  * @param[in]   count                                           structure count
340  */
341         void DACI_Free_Memory_Mapping(daci_mapping *mapping, int count);
342
343 /*
344  * @brief               free memory daci_item_info structure
345  * @param[in]   itemInfo                                        daci_item_info structure
346  * @param[in]   count                                           structure count
347  */
348         void DACI_Free_Memory_Item_Info(daci_item_info *itemInfo, int count);
349
350 /*
351  * @brief               free memory daci_id_list structure
352  * @param[in]   idList                                          daci_id_list structure
353  */
354         void DACI_Free_Memory_Id_List(daci_id_list *idList);
355
356 #ifdef __cplusplus
357 }
358 #endif                          /* __cplusplus */
359 #endif                          /* DACI_COMMON_H_ */