merge with master
[platform/core/system/sync-agent.git] / include / data-adapter / interface_item.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 INTERFACE_ITEM_H_
19 #define INTERFACE_ITEM_H_
20
21 #include "error.h"
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif                          /* __cplusplus */
26
27 /**
28  * @file                interface_item.h
29  * @brief
30  */
31
32 /** @addtogroup data_adapter
33  *      @{
34  */
35
36 /**
37  * @brief       Structure of framework item instance
38  */
39         typedef struct {
40                 char *item_id;
41                         /**< F/W item id */
42                 int data_store_id;
43                                 /**< service data connector pluIn's ID described in F/W config file  */
44                 int account_id;
45                         /**< F/W account id */
46                 char *folder_id;/**< F/W folder id */
47                 char *service_id;
48                                 /**< service item id */
49                 char *access_name;
50                                 /**< name of accessor */
51         } sync_agent_da_item_s;
52
53 /**
54  * @brief       Enumerations of option used to delete framework item
55  */
56         typedef enum {
57                 SYNC_AGENT_DA_DELETE_ITEM_OPTION_ITEM_TYPE_ID,
58                                                         /**< delete item by item type */
59         } sync_agent_da_delete_item_option_e;
60
61 /**
62  * @brief       Structure of query used to delete framework item
63  */
64         typedef struct {
65                 sync_agent_da_delete_item_option_e option;
66                 int account_id;
67                         /**< F/W account id - SYNC_AGENT_DA_DELETE_ITEM_OPTION_ITEM_TYPE_ID */
68                 int item_type_id;
69                                 /**< F/W item type id - SYNC_AGENT_DA_DELETE_ITEM_OPTION_ITEM_TYPE_ID */
70         } sync_agent_da_delete_item_query_s;
71
72 /**
73  * @brief       Enumerations of option used to fetch framework item list
74  */
75         typedef enum {
76                 SYNC_AGENT_DA_GET_ITEM_LIST_OPTION_ACCOUNT_ID,          /**< get item by account id */
77                 SYNC_AGENT_DA_GET_ITEM_LIST_OPTION_SERVICE_ID_MAPPING,
78                                                                 /**< get item by service id */
79         } sync_agent_da_get_item_list_option_e;
80
81 /**
82  * @brief       Structure of query used to fetch framework item list
83  */
84         typedef struct {
85                 sync_agent_da_get_item_list_option_e option;
86                 int item_type_id;
87                                 /**< F/W item type id - SYNC_AGENT_DA_ITEM_GET_LIST_OPTION_ACCOUNT_ID */
88                 char *item_id;
89                         /**< F/W item id - SYNC_AGENT_DA_ITEM_GET_LIST_OPTION_SERVICE_ID_MAPPING */
90         } sync_agent_da_get_item_list_query_s;
91
92 /**
93  * @brief       Structure of query used to fetch framework item id
94  */
95         typedef struct {
96                 int account_id; /**< account id */
97                 char *service_id;       /**< service id */
98                 int item_type_id;       /**< item type */
99         } sync_agent_da_get_item_id_query_s;
100
101 /**
102  * @brief       Enumerations of option used to fetch framework item id list
103  */
104         typedef enum {
105                 SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_COLUMN_NAME,                                      /**< get item by column name */
106                 SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_OPERATION_ID,                                     /**< get item by operation id */
107                 SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_OPERATION_ID_N_FOLDER_ID,         /**< get item by operation id and folder id */
108                 SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_OPERATION_ID_N_ITEM_TYPE_ID,      /**< get item by operation id and item type */
109                 SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_ITEM_TYPE_ID,                                     /**< get item by item type */
110                 SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_ITEM_TYPE_ID_N_ACCOUNT_ID,        /**< get item by item type and account id */
111                 SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_FOLDER_ID_N_ACCOUNT_ID            /**< get item by folder id and account id */
112         } sync_agent_da_get_item_id_list_option_e;
113
114 /**
115  * @brief       Enumerations of common column related to framework item
116  */
117         typedef enum {
118                 SYNC_AGENT_DA_COLUMN_NAME_ACCOUNT_ID,
119                                                 /**< means column, account_id */
120                 SYNC_AGENT_DA_COLUMN_NAME_ITEM_ID,
121                                                 /**< means column, item_id */
122                 SYNC_AGENT_DA_COLUMN_NAME_SERVICE_ID,
123                                                 /**< means column, service_id */
124                 SYNC_AGENT_DA_COLUMN_NAME_ACCESS_NAME,
125                                                 /**< means column, access_name */
126
127                 SYNC_AGENT_DA_COLUMN_NAME_MAX
128                                         /**< count of common columns */
129         } sync_agent_da_column_name_e;
130
131 /**
132  * @brief       Structure of query used to fetch framework item id list
133  */
134         typedef struct {
135                 sync_agent_da_get_item_id_list_option_e option;
136                 sync_agent_da_column_name_e column_name;/**< Column name - SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_COLUMN_NAME */
137                 int operation_id;       /**< F/W operation id - SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_OPERATION_ID, SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_OPERATION_ID_N_FOLDER_ID, SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_OPERATION_ID_N_ITEM_TYPE_ID*/
138                 char *folder_id;/**< F/W folder id - SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_COLUMN_NAME, SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_OPERATION_ID_N_FOLDER_ID */
139                 int account_id;
140                         /**< F/W account id - SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_OPERATION_ID, SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_OPERATION_ID_N_FOLDER_ID, SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_OPERATION_ID_N_ITEM_TYPE_ID, SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_ITEM_TYPE_ID_N_ACCOUNT_ID */
141                 int item_type_id;
142                                 /**< F/W item type id - SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_OPERATION_ID_N_FOLDER_ID, SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_OPERATION_ID_N_ITEM_TYPE_ID, SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_ITEM_TYPE_ID, SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_ITEM_TYPE_ID_N_ACCOUNT_ID */
143         } sync_agent_da_get_item_id_list_query_s;
144
145 /**
146  * @brief                       Create initialized framework item instance
147  * @par Usage:
148  * @code
149  
150  sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
151  sync_agent_da_item_s *item;
152  
153  ret = sync_agent_create_item(&item);
154  if (ret != SYNC_AGENT_DA_SUCCESS) {
155         ...
156  }
157  
158  * @endcode
159  * @remarks             item in FW corresponds to entity in service layer such as conatct in Contact-service and event in Calendar-service
160  * @param[out]  sync_agent_item                         framework item instance initialized new
161  * @return              operation result
162  * @retval              SYNC_AGENT_DA_SUCCESS           success
163  * @retval              error_value                                     fail
164  */
165         sync_agent_da_return_e sync_agent_create_item(sync_agent_da_item_s ** sync_agent_item);
166
167 /**
168  * @brief                       Add framework item instance into frameowrk db
169  * @par Usage:
170  * @code
171  
172  sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
173  sync_agent_da_item_s *item = NULL;
174  char *item_id = NULL;
175
176  ret = sync_agent_create_item(&item);
177  if (ret != SYNC_AGENT_DA_SUCCESS) {
178         ...
179  }
180
181  ...
182  
183  ret = sync_agent_add_item(item, &item_id, true);
184  if (ret != SYNC_AGENT_DA_SUCCESS) {
185         ...
186  }
187  
188  * @endcode
189  * @param[in]           sync_agent_item                         framework item instance to add
190  * @param[out]  item_id                                         id of framework item instance added new
191  * @param[in]           use_changelog                           option specifying whether use of changelog for sync history
192  * @return              operation result
193  * @retval              SYNC_AGENT_DA_SUCCESS           success
194  * @retval              error_value                                     fail
195  */
196         sync_agent_da_return_e sync_agent_add_item(sync_agent_da_item_s * sync_agent_item, char **item_id, int use_changelog);
197
198 /**
199  * @brief                       Update framework item
200  * @par Usage:
201  * @code
202  
203  sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
204  sync_agent_da_item_s *item = NULL;
205
206  ret = sync_agent_get_item(item_id, &item);
207  if (ret != SYNC_AGENT_DA_SUCCESS) {
208         ...
209  }
210
211  ...
212
213  ret = sync_agent_update_item(item_id, true);
214  if (ret != SYNC_AGENT_DA_SUCCESS) {
215         ...
216  }
217
218  * @endcode
219  * @remarks             Framework item is just mapped to service item so just has mapping information. Means it doesn't have real service data, and mapping information which framework item has just need to be updated
220  * @param[in]           item_id                                         id of framework item instance desired to update
221  * @param[in]           use_changelog                           option specifying whether use of changelog for sync history
222  * @return              operation result
223  * @retval              SYNC_AGENT_DA_SUCCESS           success
224  * @retval              error_value                                     fail
225  */
226         sync_agent_da_return_e sync_agent_update_item(char *item_id, int use_changelog);
227
228 /**
229  * @brief                       Delete framework item
230  * @par Usage:
231  * @code
232  
233  sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
234
235  ret = sync_agent_delete_item(item_id, true);
236  if (ret != SYNC_AGENT_DA_SUCCESS) {
237         ...
238  }
239
240  * @endcode
241  * @param[in]           item_id                                         id of framework item instance desired to delete
242  * @param[in]           use_changelog                           option specifying whether use of changelog for sync history
243  * @return              operation result
244  * @retval              SYNC_AGENT_DA_SUCCESS           success
245  * @retval              error_value                                     fail
246  */
247         sync_agent_da_return_e sync_agent_delete_item(char *item_id, int use_changelog);
248
249 /**
250  * @brief                       Delete framework items according to given query in GList form
251  * @par Usage:
252  * @code
253  
254  sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
255  sync_agent_da_delete_item_query_s query;
256
257  query_item.option = SYNC_AGENT_DA_DELETE_ITEM_OPTION_ITEM_TYPE_ID;
258  query_item.item_type_id = FW_CONTACT;
259  query_item.account_id = account_id;
260
261  ret = sync_agent_query_delete_item(&query);
262  if (ret != SYNC_AGENT_DA_SUCCESS) {
263         ...
264  }
265
266  * @endcode
267  * @param[in]           query                                           sync_agent_da_delete_item_query_s type of query for delete operation
268  * @return              operation result
269  * @retval              SYNC_AGENT_DA_SUCCESS           success
270  * @retval              error_value                                     fail
271  */
272         sync_agent_da_return_e sync_agent_query_delete_item(sync_agent_da_delete_item_query_s * query);
273
274 /**
275  * @brief                       Fetch framework item instance
276  * @par Usage:
277  * @code
278  
279  sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
280  sync_agent_da_item_s *item = NULL;
281
282  ret = sync_agent_get_item(item_id, &item);
283  if (ret != SYNC_AGENT_DA_SUCCESS) {
284         ...
285  }
286
287  * @endcode
288  * @param[in]           item_id                                         id of framework folder item instance desired to get
289  * @param[out]  sync_agent_item                         framework item instance fetched
290  * @return              operation result
291  * @retval              SYNC_AGENT_DA_SUCCESS           success
292  * @retval              error_value                                     fail
293  */
294         sync_agent_da_return_e sync_agent_get_item(char *item_id, sync_agent_da_item_s ** sync_agent_item);
295
296 /**
297  * @brief                       Get data store item id
298  * @par Usage:
299  * @code
300
301  sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
302  sync_agent_da_item_s *item = NULL;
303
304  ret = sync_agent_get_item_data_store_id(item_id, &item);
305  if (ret != SYNC_AGENT_DA_SUCCESS) {
306         ...
307  }
308
309  * @endcode
310  * @param[in]           item_id                                         id of framework folder item instance desired to get
311  * @param[out]  sync_agent_item                         framework item instance fetched
312  * @return              operation result
313  * @retval              SYNC_AGENT_DA_SUCCESS           success
314  * @retval              error_value                                     fail
315  */
316         sync_agent_da_return_e sync_agent_get_item_data_store_id(char *item_id, sync_agent_da_item_s ** sync_agent_item);
317
318 /**
319  * @brief                       Get account item id
320  * @par Usage:
321  * @code
322
323  sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
324  sync_agent_da_item_s *item = NULL;
325
326  ret = sync_agent_get_item_account_id(item_id, &item);
327  if (ret != SYNC_AGENT_DA_SUCCESS) {
328         ...
329  }
330
331  * @endcode
332  * @param[in]           item_id                                         id of framework folder item instance desired to get
333  * @param[out]  sync_agent_item                         framework item instance fetched
334  * @return              operation result
335  * @retval              SYNC_AGENT_DA_SUCCESS           success
336  * @retval              error_value                                     fail
337  */
338         sync_agent_da_return_e sync_agent_get_item_account_id(char *item_id, sync_agent_da_item_s ** sync_agent_item);
339
340 /**
341  * @brief                       Fetch framework items according to given query in GList form
342  * @par Usage:
343  * @code
344  
345  sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
346  sync_agent_da_get_item_list_query_s query;
347  GList *item_list = NULL;
348
349  query.option = SYNC_AGENT_DA_GET_ITEM_LIST_OPTION_ACCOUNT_ID;
350  query.item_type_id = FW_CONTACT;
351
352  ret = sync_agent_get_item_list(accoutn_id, &query, &item_list);
353  if (ret != SYNC_AGENT_DA_SUCCESS) {
354         ...
355  }
356
357  * @endcode
358  * @param[in]           account_id                                      account id of items desired to get
359  * @param[in]           query                                           sync_agent_da_get_item_list_query_s type of query for fetch operation
360  * @param[out]  list                                                    list of framework item instance fetched
361  * @return              operation result
362  * @retval              SYNC_AGENT_DA_SUCCESS           success
363  * @retval              error_value                                     fail
364  */
365         sync_agent_da_return_e sync_agent_get_item_list(int account_id, sync_agent_da_get_item_list_query_s * query, GList ** list);
366
367 /**
368  * @brief                       Get framework item id according to given query
369  * @par Usage:
370  * @code
371  
372  sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
373  sync_agent_da_get_item_id_query_s query;
374  char *item_id = NULL;
375
376  query.service_id = service_item_id;
377  query.account_id = account_id;
378  query.item_type_id = FW_CONTACT;
379
380  da_err = sync_agent_get_item_id(&query, &item_id);
381  if (ret != SYNC_AGENT_DA_SUCCESS) {
382         ...
383  }
384
385  * @endcode
386  * @param[in]           query                                           sync_agent_da_get_item_id_query_s type of query for fetch operation
387  * @param[out]  item_id                                         id of framework item instance requested
388  * @return              operation result
389  * @retval              SYNC_AGENT_DA_SUCCESS           success
390  * @retval              error_value                                     fail
391  */
392         sync_agent_da_return_e sync_agent_get_item_id(sync_agent_da_get_item_id_query_s * query, char **item_id);
393
394 /**
395  * @brief                       Get framework item ids according to given query in GList form
396  * @par Usage:
397  * @code
398  
399  sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
400  sync_agent_da_get_item_id_list_query_s query;
401  GList *item_id_list = NULL;
402
403  query.option = SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_OPERATION_ID_N_ITEM_TYPE_ID;
404  query.account_id = account_id;
405  query.item_type_id = FW_CONTACT;
406  query.operation_id = SYNC_AGENT_DA_CHANGE_OPERATION_DELETE;
407  
408
409  da_err = sync_agent_get_item_id_list(&query, &item_id_list);
410  if (ret != SYNC_AGENT_DA_SUCCESS) {
411         ...
412  }
413
414  * @endcode
415  * @param[in]           query                                           sync_agent_da_get_item_id_list_query_s type of query for fetch operation
416  * @param[out]  list                                                    list of framework item id fetched
417  * @return              operation result
418  * @retval              SYNC_AGENT_DA_SUCCESS           success
419  * @retval              error_value                                     fail
420  */
421         sync_agent_da_return_e sync_agent_get_item_id_list(sync_agent_da_get_item_id_list_query_s * query, GList ** list);
422
423 /**
424  * @brief                       Free framework item instance provided
425  * @par Usage:
426  * @code
427  
428  sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
429  sync_agent_da_item_s *item = NULL;
430
431  ret = sync_agent_get_item(item_id, &item);
432  if (ret != SYNC_AGENT_DA_SUCCESS) {
433         ...
434  }
435
436  ...
437
438  ret = sync_agent_free_item(item);
439  
440  if (ret != SYNC_AGENT_DA_SUCCESS) {
441         ...
442  }
443
444  * @endcode
445  * @param[in]           sync_agent_item                         framework item instance to free
446  * @return              operation result
447  * @retval              SYNC_AGENT_DA_SUCCESS           success
448  * @retval              error_value                                     fail
449  */
450         sync_agent_da_return_e sync_agent_free_item(sync_agent_da_item_s * sync_agent_item);
451
452 /**
453  * @brief                       Free framework items provided in GList form
454  * @par Usage:
455  * @code
456  
457  sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
458  sync_agent_da_get_item_list_query_s query;
459  GList *item_list = NULL;
460
461  query.option = SYNC_AGENT_DA_GET_ITEM_LIST_OPTION_ACCOUNT_ID;
462  query.item_type_id = FW_CONTACT;
463
464  ret = sync_agent_get_item_list(accoutn_id, &query, &item_list);
465  if (ret != SYNC_AGENT_DA_SUCCESS) {
466         ...
467  }
468
469  ...
470
471  ret = sync_agent_free_item_list(item_list);
472  if (ret != SYNC_AGENT_DA_SUCCESS) {
473         ...
474  }
475
476  * @endcode
477  * @param[in]           list                                                    framework item instance list to free
478  * @return              operation result
479  * @retval              SYNC_AGENT_DA_SUCCESS           success
480  * @retval              error_value                                     fail
481  */
482         sync_agent_da_return_e sync_agent_free_item_list(GList * list);
483
484 /**
485  * @brief                       Free framework item id provided
486  * @par Usage:
487  * @code
488  
489  sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
490  sync_agent_da_get_item_id_query_s query;
491  char *item_id = NULL;
492
493  query.service_id = service_item_id;
494  query.account_id = account_id;
495  query.item_type_id = FW_CONTACT;
496
497  da_err = sync_agent_get_item_id(&query, &item_id);
498  if (ret != SYNC_AGENT_DA_SUCCESS) {
499         ...
500  }
501
502  ...
503
504  ret = sync_agent_free_item_id(item_id);
505  if (ret != SYNC_AGENT_DA_SUCCESS) {
506         ...
507  }
508
509  * @endcode
510  * @param[in]           item_id                                         framework item id to free
511  * @return              operation result
512  * @retval              SYNC_AGENT_DA_SUCCESS           success
513  * @retval              error_value                                     fail
514  */
515         sync_agent_da_return_e sync_agent_free_item_id(char *item_id);
516
517 /**
518  * @brief                       Free framework item id list provided in GList form
519  * @par Usage:
520  * @code
521  
522  sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
523  sync_agent_da_get_item_id_list_query_s query;
524  GList *item_id_list = NULL;
525
526  query.option = SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_OPERATION_ID_N_ITEM_TYPE_ID;
527  query.account_id = account_id;
528  query.item_type_id = FW_CONTACT;
529  query.operation_id = SYNC_AGENT_DA_CHANGE_OPERATION_DELETE;
530  
531
532  da_err = sync_agent_get_item_id_list(&query, &item_id_list);
533  if (ret != SYNC_AGENT_DA_SUCCESS) {
534         ...
535  }
536
537  ...
538
539  ret = sync_agent_free_item_id_list(item_id_list);
540  if (ret != SYNC_AGENT_DA_SUCCESS) {
541         ...
542  }
543
544  * @endcode
545  * @param[in]           list                                                    framework item id list to free
546  * @return              operation result
547  * @retval              SYNC_AGENT_DA_SUCCESS           success
548  * @retval              error_value                                     fail
549  */
550         sync_agent_da_return_e sync_agent_free_item_id_list(GList * list);
551
552 /**
553  * @brief               get item count in item table where service type
554  * @param[in]   data_store_id                           item's service type
555  * @param[out]  item_count                                      item count for service id
556  * @return              operation result
557  * @retval              SYNC_AGENT_DA_SUCCESS           success
558  * @retval              error_value                                     fail
559  */
560         sync_agent_da_return_e sync_agent_get_item_count(int data_store_id, int *item_count);
561
562 /**
563  *      @}
564  */
565
566 #ifdef __cplusplus
567 }
568 #endif                          /* __cplusplus */
569 #endif                          /* INTERFACE_ITEM_H_ */