4 * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Dohyung Jin <dh.jin@samsung.com>
7 * Jongwon Lee <gogosing.lee@samsung.com>
8 * Donghee Ye <donghee.ye@samsung.com>
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
14 * http://www.apache.org/licenses/LICENSE-2.0
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.
27 #include "ctsvc_internal.h"
28 #include "ctsvc_list.h"
29 #include "ctsvc_record.h"
30 #include "ctsvc_query.h"
31 #include "ctsvc_inotify.h"
33 #include "ctsvc_internal.h"
34 #include "ctsvc_ipc_define.h"
35 #include "ctsvc_ipc_marshal.h"
36 #include "ctsvc_view.h"
38 #include "ctsvc_client_ipc.h"
39 #include <pims-ipc-data.h>
41 #include "ctsvc_inotify.h"
46 }ctsvc_ipc_async_userdata_s;
48 static void __ctsvc_ipc_client_insert_records_cb(pims_ipc_h ipc, pims_ipc_data_h data_out, void *userdata);
49 static void __ctsvc_ipc_client_update_records_cb(pims_ipc_h ipc, pims_ipc_data_h data_out, void *userdata);
50 static void __ctsvc_ipc_client_delete_records_cb(pims_ipc_h ipc, pims_ipc_data_h data_out, void *userdata);
52 void __ctsvc_ipc_client_insert_records_cb(pims_ipc_h ipc, pims_ipc_data_h data_out, void *userdata)
54 ctsvc_ipc_async_userdata_s *sync_data = (ctsvc_ipc_async_userdata_s *)userdata;
55 int ret = CONTACTS_ERROR_NONE;
57 unsigned int count = 0;
62 unsigned int size = 0;
63 ret = *(int*) pims_ipc_data_get(data_out,&size);
65 if (ret == CONTACTS_ERROR_NONE) {
67 unsigned int size = 0;
68 int transaction_ver = 0;
69 transaction_ver = *(int*)pims_ipc_data_get(data_out, &size);
70 ctsvc_client_ipc_set_change_version(transaction_ver);
72 count = *(unsigned int*) pims_ipc_data_get(data_out,&size);
73 ids = calloc(count, sizeof(int));
76 ids[i] = *(int*) pims_ipc_data_get(data_out,&size);
81 if (sync_data->callback)
83 contacts_db_insert_result_cb callback = sync_data->callback;
84 callback(ret, ids, count, sync_data->user_data);
88 ctsvc_inotify_call_blocked_callback();
90 CONTACTS_FREE(sync_data);
95 void __ctsvc_ipc_client_update_records_cb(pims_ipc_h ipc, pims_ipc_data_h data_out, void *userdata)
97 ctsvc_ipc_async_userdata_s *sync_data = (ctsvc_ipc_async_userdata_s *)userdata;
98 int ret = CONTACTS_ERROR_NONE;
103 unsigned int size = 0;
104 ret = *(int*) pims_ipc_data_get(data_out,&size);
106 if (CONTACTS_ERROR_NONE == ret) {
107 int transaction_ver = 0;
108 transaction_ver = *(int*)pims_ipc_data_get(data_out, &size);
109 ctsvc_client_ipc_set_change_version(transaction_ver);
113 if (sync_data->callback)
115 contacts_db_result_cb callback = sync_data->callback;
116 callback(ret, sync_data->user_data);
119 ctsvc_inotify_call_blocked_callback();
121 CONTACTS_FREE(sync_data);
125 void __ctsvc_ipc_client_delete_records_cb(pims_ipc_h ipc, pims_ipc_data_h data_out, void *userdata)
127 ctsvc_ipc_async_userdata_s *sync_data = (ctsvc_ipc_async_userdata_s *)userdata;
128 int ret = CONTACTS_ERROR_NONE;
133 unsigned int size = 0;
134 ret = *(int*) pims_ipc_data_get(data_out,&size);
135 if (CONTACTS_ERROR_NONE == ret) {
136 int transaction_ver = 0;
137 transaction_ver = *(int*)pims_ipc_data_get(data_out, &size);
138 ctsvc_client_ipc_set_change_version(transaction_ver);
142 if (sync_data->callback)
144 contacts_db_result_cb callback = sync_data->callback;
145 callback(ret, sync_data->user_data);
148 ctsvc_inotify_call_blocked_callback();
150 CONTACTS_FREE(sync_data);
155 API int contacts_db_insert_record( contacts_record_h record, int *id )
157 int ret = CONTACTS_ERROR_NONE;
158 pims_ipc_data_h indata = NULL;
159 pims_ipc_data_h outdata = NULL;
164 RETVM_IF(record==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"record is NULL");
167 indata = pims_ipc_data_create(0);
170 CTS_ERR("ipc data created fail!");
171 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
174 ret = ctsvc_ipc_marshal_record(record,indata);
175 if (ret != CONTACTS_ERROR_NONE)
177 CTS_ERR("marshal fail");
182 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_INSERT_RECORD, indata, &outdata) != 0)
184 CTS_ERR("ctsvc_ipc_call failed");
185 pims_ipc_data_destroy(indata);
186 return CONTACTS_ERROR_IPC;
191 pims_ipc_data_destroy(indata);
197 unsigned int size = 0;
198 ret = *(int*) pims_ipc_data_get(outdata,&size);
200 if (ret == CONTACTS_ERROR_NONE) {
201 int transaction_ver = 0;
202 transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
203 ctsvc_client_ipc_set_change_version(transaction_ver);
206 *id = *(int*)pims_ipc_data_get(outdata,&size);
209 pims_ipc_data_destroy(outdata);
215 API int contacts_db_get_record( const char* view_uri, int id, contacts_record_h* out_record )
217 int ret = CONTACTS_ERROR_NONE;
218 pims_ipc_data_h indata = NULL;
219 pims_ipc_data_h outdata = NULL;
221 RETVM_IF(view_uri==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"view_uri is NULL");
222 RETVM_IF(id<0,CONTACTS_ERROR_INVALID_PARAMETER,"id<0");
223 RETVM_IF(out_record==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"record is NULL");
227 indata = pims_ipc_data_create(0);
230 CTS_ERR("ipc data created fail!");
231 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
234 ret = ctsvc_ipc_marshal_string(view_uri,indata);
235 if (ret != CONTACTS_ERROR_NONE)
237 CTS_ERR("marshal fail");
240 ret = ctsvc_ipc_marshal_int(id,indata);
241 if (ret != CONTACTS_ERROR_NONE)
243 CTS_ERR("marshal fail");
248 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_RECORD, indata, &outdata) != 0)
250 CTS_ERR("ctsvc_ipc_call failed");
251 pims_ipc_data_destroy(indata);
252 return CONTACTS_ERROR_IPC;
257 pims_ipc_data_destroy(indata);
263 unsigned int size = 0;
264 ret = *(int*) pims_ipc_data_get(outdata,&size);
266 if (ret == CONTACTS_ERROR_NONE)
268 ret = ctsvc_ipc_unmarshal_record(outdata,out_record);
271 pims_ipc_data_destroy(outdata);
277 API int contacts_db_update_record( contacts_record_h record )
279 int ret = CONTACTS_ERROR_NONE;
280 pims_ipc_data_h indata = NULL;
281 pims_ipc_data_h outdata = NULL;
283 RETVM_IF(record==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"record is NULL");
287 indata = pims_ipc_data_create(0);
290 CTS_ERR("ipc data created fail!");
291 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
294 ret = ctsvc_ipc_marshal_record(record,indata);
295 if (ret != CONTACTS_ERROR_NONE)
297 CTS_ERR("marshal fail");
302 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_UPDATE_RECORD, indata, &outdata) != 0)
304 CTS_ERR("ctsvc_ipc_call failed");
305 pims_ipc_data_destroy(indata);
306 return CONTACTS_ERROR_IPC;
311 pims_ipc_data_destroy(indata);
317 unsigned int size = 0;
318 ret = *(int*) pims_ipc_data_get(outdata,&size);
319 if (CONTACTS_ERROR_NONE == ret) {
320 CTSVC_RECORD_RESET_PROPERTY_FLAGS((ctsvc_record_s *)record);
321 int transaction_ver = 0;
322 transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
323 ctsvc_client_ipc_set_change_version(transaction_ver);
326 pims_ipc_data_destroy(outdata);
332 API int contacts_db_delete_record( const char* view_uri, int id )
334 int ret = CONTACTS_ERROR_NONE;
335 pims_ipc_data_h indata = NULL;
336 pims_ipc_data_h outdata = NULL;
338 RETVM_IF(view_uri==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"view_uri is NULL");
339 RETVM_IF(id<=0,CONTACTS_ERROR_INVALID_PARAMETER,"id <= 0");
343 indata = pims_ipc_data_create(0);
346 CTS_ERR("ipc data created fail!");
347 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
350 ret = ctsvc_ipc_marshal_string(view_uri,indata);
351 if (ret != CONTACTS_ERROR_NONE)
353 CTS_ERR("marshal fail");
356 ret = ctsvc_ipc_marshal_int(id,indata);
357 if (ret != CONTACTS_ERROR_NONE)
359 CTS_ERR("marshal fail");
364 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_DELETE_RECORD, indata, &outdata) != 0)
366 CTS_ERR("ctsvc_ipc_call failed");
367 pims_ipc_data_destroy(indata);
368 return CONTACTS_ERROR_IPC;
373 pims_ipc_data_destroy(indata);
379 unsigned int size = 0;
380 ret = *(int*) pims_ipc_data_get(outdata,&size);
381 if (CONTACTS_ERROR_NONE == ret) {
382 int transaction_ver = 0;
383 transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
384 ctsvc_client_ipc_set_change_version(transaction_ver);
387 pims_ipc_data_destroy(outdata);
393 API int contacts_db_replace_record( contacts_record_h record, int id )
395 int ret = CONTACTS_ERROR_NONE;
396 pims_ipc_data_h indata = NULL;
397 pims_ipc_data_h outdata = NULL;
399 RETVM_IF(NULL == record, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : record is NULL");
402 indata = pims_ipc_data_create(0);
403 if (indata == NULL) {
404 CTS_ERR("ipc data created fail!");
405 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
409 ret = ctsvc_ipc_marshal_record(record, indata);
410 if (ret != CONTACTS_ERROR_NONE) {
411 CTS_ERR("marshal fail");
414 ret = ctsvc_ipc_marshal_int(id, indata);
415 if (ret != CONTACTS_ERROR_NONE) {
416 CTS_ERR("marshal fail");
421 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE,
422 CTSVC_IPC_SERVER_DB_REPLACE_RECORD, indata, &outdata) != 0) {
423 CTS_ERR("ctsvc_ipc_call failed");
424 pims_ipc_data_destroy(indata);
425 return CONTACTS_ERROR_IPC;
428 pims_ipc_data_destroy(indata);
432 unsigned int size = 0;
433 ret = *(int*) pims_ipc_data_get(outdata,&size);
434 if (CONTACTS_ERROR_NONE == ret) {
435 int transaction_ver = 0;
436 transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
437 ctsvc_client_ipc_set_change_version(transaction_ver);
439 pims_ipc_data_destroy(outdata);
445 API int contacts_db_get_all_records( const char* view_uri, int offset, int limit, contacts_list_h* out_list )
447 int ret = CONTACTS_ERROR_NONE;
448 pims_ipc_data_h indata = NULL;
449 pims_ipc_data_h outdata = NULL;
451 RETVM_IF(out_list==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"list is NULL");
452 RETVM_IF(view_uri==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"view_uri is NULL");
456 indata = pims_ipc_data_create(0);
459 CTS_ERR("ipc data created fail!");
460 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
464 ret = ctsvc_ipc_marshal_string(view_uri,indata);
465 if (ret != CONTACTS_ERROR_NONE)
467 CTS_ERR("marshal fail");
470 ret = ctsvc_ipc_marshal_int(offset,indata);
471 if (ret != CONTACTS_ERROR_NONE)
473 CTS_ERR("marshal fail");
476 ret = ctsvc_ipc_marshal_int(limit,indata);
477 if (ret != CONTACTS_ERROR_NONE)
479 CTS_ERR("marshal fail");
484 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_ALL_RECORDS, indata, &outdata) != 0)
486 CTS_ERR("ctsvc_ipc_call failed");
487 pims_ipc_data_destroy(indata);
488 return CONTACTS_ERROR_IPC;
493 pims_ipc_data_destroy(indata);
499 unsigned int size = 0;
500 ret = *(int*) pims_ipc_data_get(outdata,&size);
502 if (ret == CONTACTS_ERROR_NONE)
504 ret = ctsvc_ipc_unmarshal_list(outdata,out_list);
506 pims_ipc_data_destroy(outdata);
512 API int contacts_db_get_records_with_query( contacts_query_h query, int offset, int limit, contacts_list_h* out_list )
514 int ret = CONTACTS_ERROR_NONE;
515 pims_ipc_data_h indata = NULL;
516 pims_ipc_data_h outdata = NULL;
518 RETVM_IF(query==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"query is NULL");
519 RETVM_IF(out_list==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"list is NULL");
523 indata = pims_ipc_data_create(0);
526 CTS_ERR("ipc data created fail!");
527 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
530 ret = ctsvc_ipc_marshal_query(query,indata);
531 if (ret != CONTACTS_ERROR_NONE)
533 CTS_ERR("marshal fail");
536 ret = ctsvc_ipc_marshal_int(offset,indata);
537 if (ret != CONTACTS_ERROR_NONE)
539 CTS_ERR("marshal fail");
542 ret = ctsvc_ipc_marshal_int(limit,indata);
543 if (ret != CONTACTS_ERROR_NONE)
545 CTS_ERR("marshal fail");
550 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_RECORDS_WITH_QUERY, indata, &outdata) != 0)
552 CTS_ERR("ctsvc_ipc_call failed");
553 pims_ipc_data_destroy(indata);
554 return CONTACTS_ERROR_IPC;
559 pims_ipc_data_destroy(indata);
565 unsigned int size = 0;
566 ret = *(int*) pims_ipc_data_get(outdata,&size);
568 if (ret == CONTACTS_ERROR_NONE)
570 ret = ctsvc_ipc_unmarshal_list(outdata,out_list);
573 pims_ipc_data_destroy(outdata);
580 API int contacts_db_get_count( const char* view_uri, int *out_count )
582 int ret = CONTACTS_ERROR_NONE;
583 pims_ipc_data_h indata = NULL;
584 pims_ipc_data_h outdata = NULL;
586 RETVM_IF(view_uri==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"view_uri is NULL");
587 RETVM_IF(out_count==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"count pointer is NULL");
591 indata = pims_ipc_data_create(0);
594 CTS_ERR("ipc data created fail!");
595 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
598 ret = ctsvc_ipc_marshal_string(view_uri,indata);
599 if (ret != CONTACTS_ERROR_NONE)
601 CTS_ERR("marshal fail");
606 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_COUNT, indata, &outdata) != 0)
608 CTS_ERR("ctsvc_ipc_call failed");
609 pims_ipc_data_destroy(indata);
610 return CONTACTS_ERROR_IPC;
615 pims_ipc_data_destroy(indata);
621 unsigned int size = 0;
622 ret = *(int*) pims_ipc_data_get(outdata,&size);
624 if (ret == CONTACTS_ERROR_NONE)
626 ret = ctsvc_ipc_unmarshal_int(outdata,out_count);
629 pims_ipc_data_destroy(outdata);
635 API int contacts_db_get_count_with_query( contacts_query_h query, int *out_count )
637 int ret = CONTACTS_ERROR_NONE;
638 pims_ipc_data_h indata = NULL;
639 pims_ipc_data_h outdata = NULL;
641 RETVM_IF(query==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"record is NULL");
642 RETVM_IF(out_count==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"count pointer is NULL");
646 indata = pims_ipc_data_create(0);
649 CTS_ERR("ipc data created fail!");
650 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
653 ret = ctsvc_ipc_marshal_query(query,indata);
654 if (ret != CONTACTS_ERROR_NONE)
656 CTS_ERR("marshal fail");
661 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_COUNT_WITH_QUERY, indata, &outdata) != 0)
663 CTS_ERR("ctsvc_ipc_call failed");
664 pims_ipc_data_destroy(indata);
665 return CONTACTS_ERROR_IPC;
670 pims_ipc_data_destroy(indata);
676 unsigned int size = 0;
677 ret = *(int*) pims_ipc_data_get(outdata,&size);
679 if (ret == CONTACTS_ERROR_NONE)
681 ret = ctsvc_ipc_unmarshal_int(outdata,out_count);
684 pims_ipc_data_destroy(outdata);
690 API int contacts_db_insert_records_async(const contacts_list_h list, contacts_db_insert_result_cb callback, void *user_data)
692 int ret = CONTACTS_ERROR_NONE;
693 pims_ipc_data_h indata = NULL;
694 ctsvc_ipc_async_userdata_s *async_data = NULL;
696 RETVM_IF(list==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"list is NULL");
698 indata = pims_ipc_data_create(0);
701 CTS_ERR("ipc data created fail!");
702 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
705 ret = ctsvc_ipc_marshal_list(list,indata);
706 if (ret != CONTACTS_ERROR_NONE)
708 CTS_ERR("marshal fail");
712 async_data = (ctsvc_ipc_async_userdata_s*)malloc(sizeof(ctsvc_ipc_async_userdata_s));
713 if (async_data == NULL)
715 CTS_ERR("malloc fail!");
716 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
717 pims_ipc_data_destroy(indata);
720 async_data->callback = callback;
721 async_data->user_data = user_data;
723 if (ctsvc_ipc_call_async(CTSVC_IPC_DB_MODULE,CTSVC_IPC_SERVER_DB_INSERT_RECORDS,
724 indata,__ctsvc_ipc_client_insert_records_cb,async_data) != 0)
726 CONTACTS_FREE(async_data);
727 CTS_ERR("ctsvc_ipc_call_async failed");
728 return CONTACTS_ERROR_IPC;
731 pims_ipc_data_destroy(indata);
736 API int contacts_db_update_records_async(const contacts_list_h list, contacts_db_result_cb callback, void *user_data)
738 int ret = CONTACTS_ERROR_NONE;
739 pims_ipc_data_h indata = NULL;
740 ctsvc_ipc_async_userdata_s *async_data = NULL;
742 RETVM_IF(list==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"record is NULL");
745 indata = pims_ipc_data_create(0);
748 CTS_ERR("ipc data created fail!");
749 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
752 ret = ctsvc_ipc_marshal_list(list,indata);
753 if (ret != CONTACTS_ERROR_NONE)
755 CTS_ERR("marshal fail");
759 async_data = (ctsvc_ipc_async_userdata_s*)malloc(sizeof(ctsvc_ipc_async_userdata_s));
760 if (async_data == NULL)
762 CTS_ERR("malloc fail!");
763 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
764 pims_ipc_data_destroy(indata);
767 async_data->callback = callback;
768 async_data->user_data = user_data;
770 if (ctsvc_ipc_call_async(CTSVC_IPC_DB_MODULE,CTSVC_IPC_SERVER_DB_UPDATE_RECORDS,
771 indata,__ctsvc_ipc_client_update_records_cb,async_data) != 0)
773 CONTACTS_FREE(async_data);
774 CTS_ERR("ctsvc_ipc_call_async failed");
775 return CONTACTS_ERROR_IPC;
780 pims_ipc_data_destroy(indata);
786 API int contacts_db_delete_records_async(const char* view_uri, int ids[], int count, contacts_db_result_cb callback, void *user_data)
788 int ret = CONTACTS_ERROR_NONE;
789 pims_ipc_data_h indata = NULL;
791 ctsvc_ipc_async_userdata_s *async_data = NULL;
793 RETVM_IF(view_uri==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"view_uri is NULL");
794 RETVM_IF(NULL == ids, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
795 RETVM_IF(0 == count, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
798 indata = pims_ipc_data_create(0);
801 CTS_ERR("ipc data created fail!");
802 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
805 ret = ctsvc_ipc_marshal_string(view_uri,indata);
806 if (ret != CONTACTS_ERROR_NONE)
808 CTS_ERR("marshal fail");
811 ret = ctsvc_ipc_marshal_int(count,indata);
812 if (ret != CONTACTS_ERROR_NONE)
814 CTS_ERR("marshal fail");
817 for (i=0;i<count;i++)
819 ret = ctsvc_ipc_marshal_int(ids[i],indata);
820 if (ret != CONTACTS_ERROR_NONE)
822 CTS_ERR("marshal fail");
827 async_data = (ctsvc_ipc_async_userdata_s*)malloc(sizeof(ctsvc_ipc_async_userdata_s));
828 if (async_data == NULL)
830 CTS_ERR("malloc fail!");
831 pims_ipc_data_destroy(indata);
832 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
835 async_data->callback = callback;
836 async_data->user_data = user_data;
837 if (ctsvc_ipc_call_async(CTSVC_IPC_DB_MODULE,CTSVC_IPC_SERVER_DB_DELETE_RECORDS,
838 indata,__ctsvc_ipc_client_delete_records_cb,async_data) != 0)
840 CONTACTS_FREE(async_data);
841 CTS_ERR("ctsvc_ipc_call_async failed");
842 return CONTACTS_ERROR_IPC;
845 pims_ipc_data_destroy(indata);
850 void __ctsvc_ipc_client_replace_records_cb(pims_ipc_h ipc, pims_ipc_data_h data_out, void *userdata)
852 ctsvc_ipc_async_userdata_s *async_data = (ctsvc_ipc_async_userdata_s *)userdata;
853 int ret = CONTACTS_ERROR_NONE;
856 unsigned int size = 0;
857 ret = *(int*) pims_ipc_data_get(data_out,&size);
859 if (CONTACTS_ERROR_NONE == ret) {
860 int transaction_ver = 0;
861 transaction_ver = *(int*)pims_ipc_data_get(data_out, &size);
862 ctsvc_client_ipc_set_change_version(transaction_ver);
866 if (async_data->callback) {
867 contacts_db_result_cb callback = async_data->callback;
868 callback(ret, async_data->user_data);
871 ctsvc_inotify_call_blocked_callback();
878 API int contacts_db_replace_records_async( contacts_list_h list, int ids[], unsigned int count,
879 contacts_db_result_cb callback, void *user_data )
882 int ret = CONTACTS_ERROR_NONE;
883 pims_ipc_data_h indata = NULL;
884 ctsvc_ipc_async_userdata_s *async_data = NULL;
886 RETVM_IF(NULL == list,CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
887 RETVM_IF(NULL == ids, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
888 RETVM_IF(0 == count, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
891 indata = pims_ipc_data_create(0);
892 if (indata == NULL) {
893 CTS_ERR("ipc data created fail!");
894 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
898 ret = ctsvc_ipc_marshal_list(list, indata);
899 if (ret != CONTACTS_ERROR_NONE) {
900 CTS_ERR("marshal fail");
904 ret = ctsvc_ipc_marshal_unsigned_int(count, indata);
905 if (ret != CONTACTS_ERROR_NONE) {
906 CTS_ERR("marshal fail");
910 for (i=0;i<count;i++) {
911 ret = ctsvc_ipc_marshal_int(ids[i],indata);
912 if (ret != CONTACTS_ERROR_NONE) {
913 CTS_ERR("marshal fail");
918 async_data = (ctsvc_ipc_async_userdata_s*)malloc(sizeof(ctsvc_ipc_async_userdata_s));
919 async_data->callback = callback;
920 async_data->user_data = user_data;
922 if (ctsvc_ipc_call_async(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_REPLACE_RECORDS,
923 indata, __ctsvc_ipc_client_replace_records_cb, async_data) != 0) {
924 CONTACTS_FREE(async_data);
925 CTS_ERR("ctsvc_ipc_call_async failed");
926 return CONTACTS_ERROR_IPC;
929 pims_ipc_data_destroy(indata);
934 API int contacts_db_insert_records( contacts_list_h list, int **ids, unsigned int *count)
936 int ret = CONTACTS_ERROR_NONE;
937 pims_ipc_data_h indata = NULL;
938 pims_ipc_data_h outdata = NULL;
945 RETVM_IF(list==NULL,CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
946 RETVM_IF(ctsvc_get_ipc_handle()==NULL,CONTACTS_ERROR_IPC, "contacts not connected");
948 indata = pims_ipc_data_create(0);
949 if (indata == NULL) {
950 CTS_ERR("ipc data created fail!");
951 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
955 ret = ctsvc_ipc_marshal_list(list,indata);
956 if (ret != CONTACTS_ERROR_NONE) {
957 CTS_ERR("marshal fail");
958 pims_ipc_data_destroy(indata);
962 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_INSERT_RECORDS,
963 indata, &outdata) != 0) {
964 CTS_ERR("ctsvc_ipc_call_async failed");
965 pims_ipc_data_destroy(indata);
966 return CONTACTS_ERROR_IPC;
969 pims_ipc_data_destroy(indata);
972 unsigned int size = 0;
973 ret = *(int*) pims_ipc_data_get(outdata,&size);
975 if (ret == CONTACTS_ERROR_NONE) {
976 int transaction_ver = 0;
977 transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
978 ctsvc_client_ipc_set_change_version(transaction_ver);
984 c = *(unsigned int*)pims_ipc_data_get(outdata, &size);
985 id = calloc(c, sizeof(int));
987 id[i] = *(int*) pims_ipc_data_get(outdata, &size);
992 pims_ipc_data_destroy(outdata);
998 API int contacts_db_update_records( contacts_list_h list)
1000 int ret = CONTACTS_ERROR_NONE;
1001 pims_ipc_data_h indata = NULL;
1002 pims_ipc_data_h outdata = NULL;
1004 RETVM_IF(NULL == list, CONTACTS_ERROR_INVALID_PARAMETER, "record is NULL");
1005 RETVM_IF(ctsvc_get_ipc_handle() == NULL, CONTACTS_ERROR_IPC, "contacts not connected");
1007 indata = pims_ipc_data_create(0);
1008 if (indata == NULL) {
1009 CTS_ERR("ipc data created fail!");
1010 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1014 ret = ctsvc_ipc_marshal_list(list,indata);
1015 if (ret != CONTACTS_ERROR_NONE) {
1016 CTS_ERR("marshal fail");
1017 pims_ipc_data_destroy(indata);
1021 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_UPDATE_RECORDS,
1022 indata, &outdata) != 0) {
1023 CTS_ERR("ctsvc_ipc_call failed");
1024 pims_ipc_data_destroy(indata);
1025 return CONTACTS_ERROR_IPC;
1028 pims_ipc_data_destroy(indata);
1031 unsigned int size = 0;
1032 ret = *(int*) pims_ipc_data_get(outdata,&size);
1033 if (CONTACTS_ERROR_NONE == ret) {
1034 int transaction_ver = 0;
1035 transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
1036 ctsvc_client_ipc_set_change_version(transaction_ver);
1039 pims_ipc_data_destroy(outdata);
1045 API int contacts_db_delete_records(const char* view_uri, int ids[], int count)
1048 int ret = CONTACTS_ERROR_NONE;
1049 pims_ipc_data_h indata = NULL;
1050 pims_ipc_data_h outdata = NULL;
1052 RETVM_IF(view_uri == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "view_uri is NULL");
1053 RETVM_IF(ctsvc_get_ipc_handle() == NULL, CONTACTS_ERROR_IPC, "contacts not connected");
1055 indata = pims_ipc_data_create(0);
1056 if (indata == NULL) {
1057 CTS_ERR("ipc data created fail!");
1058 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1062 ret = ctsvc_ipc_marshal_string(view_uri,indata);
1063 if (ret != CONTACTS_ERROR_NONE) {
1064 CTS_ERR("marshal fail");
1065 pims_ipc_data_destroy(indata);
1069 ret = ctsvc_ipc_marshal_int(count,indata);
1070 if (ret != CONTACTS_ERROR_NONE) {
1071 CTS_ERR("marshal fail");
1072 pims_ipc_data_destroy(indata);
1076 for (i=0;i<count;i++) {
1077 ret = ctsvc_ipc_marshal_int(ids[i],indata);
1078 if (ret != CONTACTS_ERROR_NONE) {
1079 CTS_ERR("marshal fail");
1080 pims_ipc_data_destroy(indata);
1085 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_DELETE_RECORDS,
1086 indata, &outdata) != 0) {
1087 CTS_ERR("ctsvc_ipc_call failed");
1088 pims_ipc_data_destroy(indata);
1089 return CONTACTS_ERROR_IPC;
1092 pims_ipc_data_destroy(indata);
1095 unsigned int size = 0;
1096 ret = *(int*) pims_ipc_data_get(outdata,&size);
1098 if (CONTACTS_ERROR_NONE == ret) {
1099 int transaction_ver = 0;
1100 transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
1101 ctsvc_client_ipc_set_change_version(transaction_ver);
1104 pims_ipc_data_destroy(outdata);
1110 API int contacts_db_replace_records( contacts_list_h list, int ids[], unsigned int count )
1113 int ret = CONTACTS_ERROR_NONE;
1114 pims_ipc_data_h indata = NULL;
1115 pims_ipc_data_h outdata = NULL;
1117 RETVM_IF(NULL == list,CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
1118 RETVM_IF(NULL == ids, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
1119 RETVM_IF(0 == count, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
1122 indata = pims_ipc_data_create(0);
1123 if (indata == NULL) {
1124 CTS_ERR("ipc data created fail!");
1125 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1129 ret = ctsvc_ipc_marshal_list(list, indata);
1130 if (ret != CONTACTS_ERROR_NONE) {
1131 CTS_ERR("marshal fail");
1135 ret = ctsvc_ipc_marshal_unsigned_int(count, indata);
1136 if (ret != CONTACTS_ERROR_NONE) {
1137 CTS_ERR("marshal fail");
1141 for (i=0;i<count;i++) {
1142 ret = ctsvc_ipc_marshal_int(ids[i], indata);
1143 if (ret != CONTACTS_ERROR_NONE) {
1144 CTS_ERR("marshal fail");
1149 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_REPLACE_RECORDS,
1150 indata, &outdata) != 0) {
1151 CTS_ERR("ctsvc_ipc_call failed");
1152 pims_ipc_data_destroy(indata);
1153 return CONTACTS_ERROR_IPC;
1156 pims_ipc_data_destroy(indata);
1159 unsigned int size = 0;
1160 ret = *(int*) pims_ipc_data_get(outdata,&size);
1161 if (CONTACTS_ERROR_NONE == ret) {
1162 int transaction_ver = 0;
1163 transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
1164 ctsvc_client_ipc_set_change_version(transaction_ver);
1166 pims_ipc_data_destroy(outdata);
1172 API int contacts_db_get_changes_by_version(const char* view_uri, int addressbook_id, int contacts_db_version, contacts_list_h* record_list, int* current_contacts_db_version )
1174 int ret = CONTACTS_ERROR_NONE;
1175 pims_ipc_data_h indata = NULL;
1176 pims_ipc_data_h outdata = NULL;
1178 RETVM_IF(view_uri==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"view_uri is NULL");
1179 RETVM_IF(record_list==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"record_list is NULL");
1180 RETVM_IF(current_contacts_db_version==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"current_contacts_db_version is NULL");
1181 *record_list = NULL;
1184 indata = pims_ipc_data_create(0);
1187 CTS_ERR("ipc data created fail!");
1188 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1191 ret = ctsvc_ipc_marshal_string(view_uri,indata);
1192 if (ret != CONTACTS_ERROR_NONE)
1194 CTS_ERR("marshal fail");
1197 ret = ctsvc_ipc_marshal_int(addressbook_id,indata);
1198 if (ret != CONTACTS_ERROR_NONE)
1200 CTS_ERR("marshal fail");
1203 ret = ctsvc_ipc_marshal_int(contacts_db_version,indata);
1204 if (ret != CONTACTS_ERROR_NONE)
1206 CTS_ERR("marshal fail");
1211 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_CHANGES_BY_VERSION, indata, &outdata) != 0)
1213 CTS_ERR("ctsvc_ipc_call failed");
1214 pims_ipc_data_destroy(indata);
1215 return CONTACTS_ERROR_IPC;
1220 pims_ipc_data_destroy(indata);
1226 unsigned int size = 0;
1227 ret = *(int*) pims_ipc_data_get(outdata,&size);
1229 if (ret == CONTACTS_ERROR_NONE)
1231 ret = ctsvc_ipc_unmarshal_list(outdata,record_list);
1233 if (ret == CONTACTS_ERROR_NONE)
1235 ret = ctsvc_ipc_unmarshal_int(outdata,current_contacts_db_version);
1239 pims_ipc_data_destroy(outdata);
1245 API int contacts_db_get_current_version(int* contacts_db_version)
1247 int ret = CONTACTS_ERROR_NONE;
1248 pims_ipc_data_h outdata = NULL;
1250 RETVM_IF(contacts_db_version==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"contacts_db_version is null");
1251 *contacts_db_version = 0;
1254 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_CURRENT_VERSION, NULL, &outdata) != 0)
1256 CTS_ERR("ctsvc_ipc_call failed");
1257 return CONTACTS_ERROR_IPC;
1263 unsigned int size = 0;
1264 ret = *(int*) pims_ipc_data_get(outdata,&size);
1265 if (ret == CONTACTS_ERROR_NONE)
1267 ret = ctsvc_ipc_unmarshal_int(outdata,contacts_db_version);
1269 pims_ipc_data_destroy(outdata);
1275 API int contacts_db_search_records(const char* view_uri, const char *keyword,
1276 int offset, int limit, contacts_list_h* out_list)
1278 int ret = CONTACTS_ERROR_NONE;
1279 pims_ipc_data_h indata = NULL;
1280 pims_ipc_data_h outdata = NULL;
1282 RETVM_IF(out_list == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
1283 RETVM_IF(ctsvc_get_ipc_handle() == NULL, CONTACTS_ERROR_IPC, "contacts not connected");
1287 indata = pims_ipc_data_create(0);
1290 CTS_ERR("ipc data created fail !");
1291 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1294 ret = ctsvc_ipc_marshal_string(view_uri,indata);
1295 if (ret != CONTACTS_ERROR_NONE)
1297 CTS_ERR("marshal fail");
1300 ret = ctsvc_ipc_marshal_string(keyword,indata);
1301 if (ret != CONTACTS_ERROR_NONE)
1303 CTS_ERR("marshal fail");
1306 ret = ctsvc_ipc_marshal_int(offset,indata);
1307 if (ret != CONTACTS_ERROR_NONE)
1309 CTS_ERR("marshal fail");
1312 ret = ctsvc_ipc_marshal_int(limit,indata);
1313 if (ret != CONTACTS_ERROR_NONE)
1315 CTS_ERR("marshal fail");
1320 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_SEARCH_RECORDS, indata, &outdata) != 0)
1322 CTS_ERR("ctsvc_ipc_call failed");
1323 pims_ipc_data_destroy(indata);
1324 return CONTACTS_ERROR_IPC;
1329 pims_ipc_data_destroy(indata);
1335 unsigned int size = 0;
1336 ret = *(int*) pims_ipc_data_get(outdata,&size);
1338 if (ret == CONTACTS_ERROR_NONE)
1340 ret = ctsvc_ipc_unmarshal_list(outdata,out_list);
1343 pims_ipc_data_destroy(outdata);
1349 API int contacts_db_search_records_with_range(const char* view_uri, const char *keyword,
1350 int offset, int limit, int range, contacts_list_h* out_list)
1352 int ret = CONTACTS_ERROR_NONE;
1353 pims_ipc_data_h indata = NULL;
1354 pims_ipc_data_h outdata = NULL;
1356 RETVM_IF(out_list == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
1358 RETVM_IF(range == 0, CONTACTS_ERROR_INVALID_PARAMETER, "range is 0");
1359 RETVM_IF(ctsvc_get_ipc_handle() == NULL, CONTACTS_ERROR_IPC, "contacts not connected");
1361 indata = pims_ipc_data_create(0);
1362 if (indata == NULL) {
1363 CTS_ERR("ipc data created fail !");
1364 return CONTACTS_ERROR_OUT_OF_MEMORY;
1367 ret = ctsvc_ipc_marshal_string(view_uri, indata);
1368 if (ret != CONTACTS_ERROR_NONE) {
1369 CTS_ERR("marshal fail");
1372 ret = ctsvc_ipc_marshal_string(keyword, indata);
1373 if (ret != CONTACTS_ERROR_NONE) {
1374 CTS_ERR("marshal fail");
1377 ret = ctsvc_ipc_marshal_int(offset, indata);
1378 if (ret != CONTACTS_ERROR_NONE) {
1379 CTS_ERR("marshal fail");
1382 ret = ctsvc_ipc_marshal_int(limit, indata);
1383 if (ret != CONTACTS_ERROR_NONE) {
1384 CTS_ERR("marshal fail");
1387 ret = ctsvc_ipc_marshal_int(range, indata);
1388 if (ret != CONTACTS_ERROR_NONE) {
1389 CTS_ERR("marshal fail");
1393 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_SEARCH_RECORDS_WITH_RANGE, indata, &outdata) != 0) {
1394 CTS_ERR("ctsvc_ipc_call failed");
1395 pims_ipc_data_destroy(indata);
1396 return CONTACTS_ERROR_IPC;
1399 pims_ipc_data_destroy(indata);
1402 unsigned int size = 0;
1403 ret = *(int*) pims_ipc_data_get(outdata,&size);
1405 if (ret == CONTACTS_ERROR_NONE)
1406 ret = ctsvc_ipc_unmarshal_list(outdata,out_list);
1407 pims_ipc_data_destroy(outdata);
1417 API int contacts_db_search_records_with_query(contacts_query_h query, const char *keyword,
1418 int offset, int limit, contacts_list_h* out_list)
1420 int ret = CONTACTS_ERROR_NONE;
1421 pims_ipc_data_h indata = NULL;
1422 pims_ipc_data_h outdata = NULL;
1424 RETVM_IF(query==NULL, CONTACTS_ERROR_INVALID_PARAMETER, "query is NULL");
1425 RETVM_IF(out_list==NULL, CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
1426 RETVM_IF(ctsvc_get_ipc_handle() == NULL, CONTACTS_ERROR_IPC, "contacts not connected");
1430 indata = pims_ipc_data_create(0);
1433 CTS_ERR("ipc data created fail !");
1434 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1437 ret = ctsvc_ipc_marshal_query(query,indata);
1438 if (ret != CONTACTS_ERROR_NONE)
1440 CTS_ERR("marshal fail");
1443 ret = ctsvc_ipc_marshal_string(keyword,indata);
1444 if (ret != CONTACTS_ERROR_NONE)
1446 CTS_ERR("marshal fail");
1449 ret = ctsvc_ipc_marshal_int(offset,indata);
1450 if (ret != CONTACTS_ERROR_NONE)
1452 CTS_ERR("marshal fail");
1455 ret = ctsvc_ipc_marshal_int(limit,indata);
1456 if (ret != CONTACTS_ERROR_NONE)
1458 CTS_ERR("marshal fail");
1463 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_SEARCH_RECORDS_WITH_QUERY, indata, &outdata) != 0)
1465 CTS_ERR("ctsvc_ipc_call failed");
1466 pims_ipc_data_destroy(indata);
1467 return CONTACTS_ERROR_IPC;
1472 pims_ipc_data_destroy(indata);
1478 unsigned int size = 0;
1479 ret = *(int*) pims_ipc_data_get(outdata,&size);
1481 if (ret == CONTACTS_ERROR_NONE)
1483 ret = ctsvc_ipc_unmarshal_list(outdata,out_list);
1486 pims_ipc_data_destroy(outdata);
1492 API int contacts_db_get_last_change_version(int* last_version)
1494 int ret = CONTACTS_ERROR_NONE;
1496 RETVM_IF(NULL == last_version, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
1497 *last_version = ctsvc_client_ipc_get_change_version();