4 * Copyright (c) 2010 - 2015 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.
26 #include <pims-ipc-data.h>
30 #include "ctsvc_internal.h"
31 #include "ctsvc_list.h"
32 #include "ctsvc_record.h"
33 #include "ctsvc_inotify.h"
34 #include "ctsvc_ipc_define.h"
35 #include "ctsvc_ipc_marshal.h"
36 #include "ctsvc_view.h"
37 #include "ctsvc_client_ipc.h"
38 #include "ctsvc_mutex.h"
39 #include "ctsvc_handle.h"
40 #include "ctsvc_client_db_helper.h"
42 int ctsvc_client_db_insert_record(contacts_h contact, contacts_record_h record, int *id)
44 int ret = CONTACTS_ERROR_NONE;
45 pims_ipc_data_h indata = NULL;
46 pims_ipc_data_h outdata = NULL;
51 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
52 RETVM_IF(record==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"record is NULL");
55 indata = pims_ipc_data_create(0);
57 CTS_ERR("ipc data created fail!");
58 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
61 ret = ctsvc_ipc_marshal_handle(contact, indata);
62 if (ret != CONTACTS_ERROR_NONE) {
63 CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
64 pims_ipc_data_destroy(indata);
68 ret = ctsvc_ipc_marshal_record(record,indata);
69 if (ret != CONTACTS_ERROR_NONE) {
70 CTS_ERR("marshal fail");
71 pims_ipc_data_destroy(indata);
76 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_INSERT_RECORD, indata, &outdata) != 0) {
77 CTS_ERR("ctsvc_ipc_call failed");
78 pims_ipc_data_destroy(indata);
79 return CONTACTS_ERROR_IPC;
82 pims_ipc_data_destroy(indata);
85 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
86 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
87 pims_ipc_data_destroy(outdata);
88 return CONTACTS_ERROR_IPC;
91 if (CONTACTS_ERROR_NONE == ret) {
92 int transaction_ver = 0;
93 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
94 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
95 pims_ipc_data_destroy(outdata);
96 return CONTACTS_ERROR_IPC;
98 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
101 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, id)) {
102 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
103 pims_ipc_data_destroy(outdata);
104 return CONTACTS_ERROR_IPC;
108 pims_ipc_data_destroy(outdata);
114 int ctsvc_client_db_get_record(contacts_h contact, const char* view_uri, int id, contacts_record_h* out_record)
116 int ret = CONTACTS_ERROR_NONE;
117 pims_ipc_data_h indata = NULL;
118 pims_ipc_data_h outdata = NULL;
120 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
121 RETVM_IF(view_uri==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"view_uri is NULL");
122 RETVM_IF(id<0,CONTACTS_ERROR_INVALID_PARAMETER,"id<0");
123 RETVM_IF(out_record==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"record is NULL");
127 indata = pims_ipc_data_create(0);
128 if (indata == NULL) {
129 CTS_ERR("ipc data created fail!");
130 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
134 ret = ctsvc_ipc_marshal_handle(contact, indata);
135 if (ret != CONTACTS_ERROR_NONE) {
136 CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
137 pims_ipc_data_destroy(indata);
141 ret = ctsvc_ipc_marshal_string(view_uri,indata);
142 if (ret != CONTACTS_ERROR_NONE) {
143 CTS_ERR("marshal fail");
144 pims_ipc_data_destroy(indata);
147 ret = ctsvc_ipc_marshal_int(id,indata);
148 if (ret != CONTACTS_ERROR_NONE) {
149 CTS_ERR("marshal fail");
150 pims_ipc_data_destroy(indata);
155 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_RECORD, indata, &outdata) != 0) {
156 CTS_ERR("ctsvc_ipc_call failed");
157 pims_ipc_data_destroy(indata);
158 return CONTACTS_ERROR_IPC;
161 pims_ipc_data_destroy(indata);
164 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
165 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
166 pims_ipc_data_destroy(outdata);
167 return CONTACTS_ERROR_IPC;
169 if (CONTACTS_ERROR_NONE == ret) {
170 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_record(outdata, out_record)) {
171 CTS_ERR("ctsvc_ipc_unmarshal_record() Fail");
172 pims_ipc_data_destroy(outdata);
173 return CONTACTS_ERROR_IPC;
176 pims_ipc_data_destroy(outdata);
181 int ctsvc_client_db_update_record(contacts_h contact, contacts_record_h record)
183 int ret = CONTACTS_ERROR_NONE;
184 pims_ipc_data_h indata = NULL;
185 pims_ipc_data_h outdata = NULL;
187 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
188 RETVM_IF(record==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"record is NULL");
191 indata = pims_ipc_data_create(0);
192 if (indata == NULL) {
193 CTS_ERR("ipc data created fail!");
194 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
198 ret = ctsvc_ipc_marshal_handle(contact, indata);
199 if (ret != CONTACTS_ERROR_NONE) {
200 CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
201 pims_ipc_data_destroy(indata);
205 ret = ctsvc_ipc_marshal_record(record,indata);
206 if (ret != CONTACTS_ERROR_NONE) {
207 CTS_ERR("marshal fail");
208 pims_ipc_data_destroy(indata);
213 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_UPDATE_RECORD, indata, &outdata) != 0) {
214 CTS_ERR("ctsvc_ipc_call failed");
215 pims_ipc_data_destroy(indata);
216 return CONTACTS_ERROR_IPC;
219 pims_ipc_data_destroy(indata);
222 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
223 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
224 pims_ipc_data_destroy(outdata);
225 return CONTACTS_ERROR_IPC;
227 if (CONTACTS_ERROR_NONE == ret) {
228 CTSVC_RECORD_RESET_PROPERTY_FLAGS((ctsvc_record_s *)record);
229 int transaction_ver = 0;
230 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
231 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
232 pims_ipc_data_destroy(outdata);
233 return CONTACTS_ERROR_IPC;
235 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
237 pims_ipc_data_destroy(outdata);
242 int ctsvc_client_db_delete_record(contacts_h contact, const char* view_uri, int id)
244 int ret = CONTACTS_ERROR_NONE;
245 pims_ipc_data_h indata = NULL;
246 pims_ipc_data_h outdata = NULL;
248 RETVM_IF(view_uri==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"view_uri is NULL");
249 RETVM_IF(id<=0,CONTACTS_ERROR_INVALID_PARAMETER,"id <= 0");
252 indata = pims_ipc_data_create(0);
253 if (indata == NULL) {
254 CTS_ERR("ipc data created fail!");
255 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
259 ret = ctsvc_ipc_marshal_handle(contact, indata);
260 if (CONTACTS_ERROR_NONE != ret) {
261 CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
262 pims_ipc_data_destroy(indata);
266 ret = ctsvc_ipc_marshal_string(view_uri,indata);
267 if (ret != CONTACTS_ERROR_NONE) {
268 CTS_ERR("marshal fail");
269 pims_ipc_data_destroy(indata);
272 ret = ctsvc_ipc_marshal_int(id,indata);
273 if (ret != CONTACTS_ERROR_NONE) {
274 CTS_ERR("marshal fail");
275 pims_ipc_data_destroy(indata);
280 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_DELETE_RECORD, indata, &outdata) != 0) {
281 CTS_ERR("ctsvc_ipc_call failed");
282 pims_ipc_data_destroy(indata);
283 return CONTACTS_ERROR_IPC;
286 pims_ipc_data_destroy(indata);
289 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
290 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
291 pims_ipc_data_destroy(outdata);
292 return CONTACTS_ERROR_IPC;
294 if (CONTACTS_ERROR_NONE == ret) {
295 int transaction_ver = 0;
296 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
297 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
298 pims_ipc_data_destroy(outdata);
299 return CONTACTS_ERROR_IPC;
301 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
304 pims_ipc_data_destroy(outdata);
310 int ctsvc_client_db_replace_record(contacts_h contact, contacts_record_h record, int id)
312 int ret = CONTACTS_ERROR_NONE;
313 pims_ipc_data_h indata = NULL;
314 pims_ipc_data_h outdata = NULL;
316 RETVM_IF(NULL == contact,CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
317 RETVM_IF(NULL == record, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : record is NULL");
320 indata = pims_ipc_data_create(0);
321 if (indata == NULL) {
322 CTS_ERR("ipc data created fail!");
323 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
327 ret = ctsvc_ipc_marshal_handle(contact, indata);
328 if (CONTACTS_ERROR_NONE != ret) {
329 CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
330 pims_ipc_data_destroy(indata);
334 ret = ctsvc_ipc_marshal_record(record, indata);
335 if (ret != CONTACTS_ERROR_NONE) {
336 CTS_ERR("marshal fail");
337 pims_ipc_data_destroy(indata);
340 ret = ctsvc_ipc_marshal_int(id, indata);
341 if (ret != CONTACTS_ERROR_NONE) {
342 CTS_ERR("marshal fail");
343 pims_ipc_data_destroy(indata);
348 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE,
349 CTSVC_IPC_SERVER_DB_REPLACE_RECORD, indata, &outdata) != 0) {
350 CTS_ERR("ctsvc_ipc_call failed");
351 pims_ipc_data_destroy(indata);
352 return CONTACTS_ERROR_IPC;
355 pims_ipc_data_destroy(indata);
358 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
359 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
360 pims_ipc_data_destroy(outdata);
361 return CONTACTS_ERROR_IPC;
363 if (CONTACTS_ERROR_NONE == ret) {
364 int transaction_ver = 0;
365 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
366 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
367 pims_ipc_data_destroy(outdata);
368 return CONTACTS_ERROR_IPC;
370 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
372 pims_ipc_data_destroy(outdata);
378 int ctsvc_client_db_get_all_records(contacts_h contact, const char* view_uri, int offset, int limit, contacts_list_h* out_list)
380 int ret = CONTACTS_ERROR_NONE;
381 pims_ipc_data_h indata = NULL;
382 pims_ipc_data_h outdata = NULL;
384 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
385 RETVM_IF(NULL == out_list,CONTACTS_ERROR_INVALID_PARAMETER,"list is NULL");
387 RETVM_IF(view_uri==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"view_uri is NULL");
390 indata = pims_ipc_data_create(0);
391 if (indata == NULL) {
392 CTS_ERR("ipc data created fail!");
393 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
397 ret = ctsvc_ipc_marshal_handle(contact, indata);
398 if (CONTACTS_ERROR_NONE != ret) {
399 CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
400 pims_ipc_data_destroy(indata);
404 ret = ctsvc_ipc_marshal_string(view_uri,indata);
405 if (ret != CONTACTS_ERROR_NONE) {
406 CTS_ERR("marshal fail");
407 pims_ipc_data_destroy(indata);
410 ret = ctsvc_ipc_marshal_int(offset,indata);
411 if (ret != CONTACTS_ERROR_NONE) {
412 CTS_ERR("marshal fail");
413 pims_ipc_data_destroy(indata);
416 ret = ctsvc_ipc_marshal_int(limit,indata);
417 if (ret != CONTACTS_ERROR_NONE) {
418 CTS_ERR("marshal fail");
419 pims_ipc_data_destroy(indata);
424 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_ALL_RECORDS, indata, &outdata) != 0) {
425 CTS_ERR("ctsvc_ipc_call failed");
426 pims_ipc_data_destroy(indata);
427 return CONTACTS_ERROR_IPC;
430 pims_ipc_data_destroy(indata);
433 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
434 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
435 pims_ipc_data_destroy(outdata);
436 return CONTACTS_ERROR_IPC;
439 if (ret == CONTACTS_ERROR_NONE) {
440 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_list(outdata, out_list)) {
441 CTS_ERR("ctsvc_ipc_unmarshal_list() Fail");
442 pims_ipc_data_destroy(outdata);
443 return CONTACTS_ERROR_IPC;
446 pims_ipc_data_destroy(outdata);
451 int ctsvc_client_db_get_records_with_query(contacts_h contact, contacts_query_h query, int offset, int limit, contacts_list_h* out_list)
453 int ret = CONTACTS_ERROR_NONE;
454 pims_ipc_data_h indata = NULL;
455 pims_ipc_data_h outdata = NULL;
457 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
458 RETVM_IF(NULL == out_list,CONTACTS_ERROR_INVALID_PARAMETER,"list is NULL");
460 RETVM_IF(NULL == query,CONTACTS_ERROR_INVALID_PARAMETER,"query is NULL");
463 indata = pims_ipc_data_create(0);
464 if (indata == NULL) {
465 CTS_ERR("ipc data created fail!");
466 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
470 ret = ctsvc_ipc_marshal_handle(contact, indata);
471 if (CONTACTS_ERROR_NONE != ret) {
472 CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
473 pims_ipc_data_destroy(indata);
477 ret = ctsvc_ipc_marshal_query(query,indata);
478 if (ret != CONTACTS_ERROR_NONE) {
479 CTS_ERR("marshal fail");
480 pims_ipc_data_destroy(indata);
484 ret = ctsvc_ipc_marshal_int(offset,indata);
485 if (ret != CONTACTS_ERROR_NONE) {
486 CTS_ERR("marshal fail");
487 pims_ipc_data_destroy(indata);
490 ret = ctsvc_ipc_marshal_int(limit,indata);
491 if (ret != CONTACTS_ERROR_NONE) {
492 CTS_ERR("marshal fail");
497 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_RECORDS_WITH_QUERY, indata, &outdata) != 0) {
498 CTS_ERR("ctsvc_ipc_call failed");
499 pims_ipc_data_destroy(indata);
500 return CONTACTS_ERROR_IPC;
503 pims_ipc_data_destroy(indata);
506 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
507 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
508 pims_ipc_data_destroy(outdata);
509 return CONTACTS_ERROR_IPC;
512 if (CONTACTS_ERROR_NONE == ret) {
513 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_list(outdata, out_list)) {
514 CTS_ERR("ctsvc_ipc_unmarshal_list() Fail");
515 pims_ipc_data_destroy(outdata);
516 return CONTACTS_ERROR_IPC;
520 pims_ipc_data_destroy(outdata);
527 int ctsvc_client_db_get_count(contacts_h contact, const char* view_uri, int *out_count)
529 int ret = CONTACTS_ERROR_NONE;
530 pims_ipc_data_h indata = NULL;
531 pims_ipc_data_h outdata = NULL;
533 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
534 RETVM_IF(view_uri==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"view_uri is NULL");
535 RETVM_IF(out_count==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"count pointer is NULL");
539 indata = pims_ipc_data_create(0);
540 if (indata == NULL) {
541 CTS_ERR("ipc data created fail!");
542 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
546 ret = ctsvc_ipc_marshal_handle(contact, indata);
547 if (CONTACTS_ERROR_NONE != ret) {
548 CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
549 pims_ipc_data_destroy(indata);
553 ret = ctsvc_ipc_marshal_string(view_uri,indata);
554 if (ret != CONTACTS_ERROR_NONE) {
555 CTS_ERR("marshal fail");
556 pims_ipc_data_destroy(indata);
561 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_COUNT, indata, &outdata) != 0) {
562 CTS_ERR("ctsvc_ipc_call failed");
563 pims_ipc_data_destroy(indata);
564 return CONTACTS_ERROR_IPC;
567 pims_ipc_data_destroy(indata);
570 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
571 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
572 pims_ipc_data_destroy(outdata);
573 return CONTACTS_ERROR_IPC;
576 if (CONTACTS_ERROR_NONE == ret) {
577 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, out_count)) {
578 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
579 pims_ipc_data_destroy(outdata);
580 return CONTACTS_ERROR_IPC;
584 pims_ipc_data_destroy(outdata);
590 int ctsvc_client_db_get_count_with_query(contacts_h contact, contacts_query_h query, int *out_count)
592 int ret = CONTACTS_ERROR_NONE;
593 pims_ipc_data_h indata = NULL;
594 pims_ipc_data_h outdata = NULL;
596 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
597 RETVM_IF(NULL == query,CONTACTS_ERROR_INVALID_PARAMETER,"record is NULL");
598 RETVM_IF(out_count==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"count pointer is NULL");
602 indata = pims_ipc_data_create(0);
603 if (indata == NULL) {
604 CTS_ERR("ipc data created fail!");
605 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
608 ret = ctsvc_ipc_marshal_handle(contact, indata);
609 if (CONTACTS_ERROR_NONE != ret) {
610 CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
611 pims_ipc_data_destroy(indata);
615 ret = ctsvc_ipc_marshal_query(query,indata);
616 if (ret != CONTACTS_ERROR_NONE) {
617 CTS_ERR("marshal fail");
618 pims_ipc_data_destroy(indata);
623 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_COUNT_WITH_QUERY, indata, &outdata) != 0) {
624 CTS_ERR("ctsvc_ipc_call failed");
625 pims_ipc_data_destroy(indata);
626 return CONTACTS_ERROR_IPC;
629 pims_ipc_data_destroy(indata);
632 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
633 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
634 pims_ipc_data_destroy(outdata);
635 return CONTACTS_ERROR_IPC;
638 if (CONTACTS_ERROR_NONE == ret) {
639 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, out_count)) {
640 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
641 pims_ipc_data_destroy(outdata);
642 return CONTACTS_ERROR_IPC;
645 pims_ipc_data_destroy(outdata);
651 int ctsvc_client_db_insert_records(contacts_h contact, contacts_list_h list, int **ids, int *count)
653 int ret = CONTACTS_ERROR_NONE;
654 pims_ipc_data_h indata = NULL;
655 pims_ipc_data_h outdata = NULL;
662 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
663 RETVM_IF(list==NULL,CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
665 indata = pims_ipc_data_create(0);
666 if (indata == NULL) {
667 CTS_ERR("ipc data created fail!");
668 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
671 ret = ctsvc_ipc_marshal_handle(contact, indata);
672 if (CONTACTS_ERROR_NONE != ret) {
673 CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
674 pims_ipc_data_destroy(indata);
678 ret = ctsvc_ipc_marshal_list(list,indata);
679 if (ret != CONTACTS_ERROR_NONE) {
680 CTS_ERR("marshal fail");
681 pims_ipc_data_destroy(indata);
685 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_INSERT_RECORDS,
686 indata, &outdata) != 0) {
687 CTS_ERR("ctsvc_ipc_call failed");
688 pims_ipc_data_destroy(indata);
689 return CONTACTS_ERROR_IPC;
692 pims_ipc_data_destroy(indata);
695 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
696 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
697 pims_ipc_data_destroy(outdata);
698 return CONTACTS_ERROR_IPC;
701 if (CONTACTS_ERROR_NONE == ret) {
702 int transaction_ver = 0;
703 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
704 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
705 pims_ipc_data_destroy(outdata);
706 return CONTACTS_ERROR_IPC;
708 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
715 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &c)) {
716 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
717 pims_ipc_data_destroy(outdata);
718 return CONTACTS_ERROR_IPC;
720 id = calloc(c, sizeof(int));
722 CTS_ERR("calloc() Fail");
723 pims_ipc_data_destroy(outdata);
724 return CONTACTS_ERROR_OUT_OF_MEMORY;
728 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &(id[i]))) {
729 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
730 pims_ipc_data_destroy(outdata);
732 return CONTACTS_ERROR_IPC;
739 pims_ipc_data_destroy(outdata);
745 int ctsvc_client_db_update_records(contacts_h contact, contacts_list_h list)
747 int ret = CONTACTS_ERROR_NONE;
748 pims_ipc_data_h indata = NULL;
749 pims_ipc_data_h outdata = NULL;
751 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contct is NULL");
752 RETVM_IF(NULL == list, CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
754 indata = pims_ipc_data_create(0);
755 if (indata == NULL) {
756 CTS_ERR("ipc data created fail!");
757 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
761 ret = ctsvc_ipc_marshal_handle(contact, indata);
762 if (CONTACTS_ERROR_NONE != ret) {
763 CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
764 pims_ipc_data_destroy(indata);
768 ret = ctsvc_ipc_marshal_list(list,indata);
769 if (ret != CONTACTS_ERROR_NONE) {
770 CTS_ERR("marshal fail");
771 pims_ipc_data_destroy(indata);
775 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_UPDATE_RECORDS,
776 indata, &outdata) != 0) {
777 CTS_ERR("ctsvc_ipc_call failed");
778 pims_ipc_data_destroy(indata);
779 return CONTACTS_ERROR_IPC;
782 pims_ipc_data_destroy(indata);
785 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
786 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
787 pims_ipc_data_destroy(outdata);
788 return CONTACTS_ERROR_IPC;
791 if (CONTACTS_ERROR_NONE == ret) {
792 int transaction_ver = 0;
793 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
794 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
795 pims_ipc_data_destroy(outdata);
796 return CONTACTS_ERROR_IPC;
798 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
801 pims_ipc_data_destroy(outdata);
807 int ctsvc_client_db_delete_records(contacts_h contact, const char* view_uri, int ids[], int count)
810 int ret = CONTACTS_ERROR_NONE;
811 pims_ipc_data_h indata = NULL;
812 pims_ipc_data_h outdata = NULL;
814 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
815 RETVM_IF(view_uri == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "view_uri is NULL");
817 indata = pims_ipc_data_create(0);
818 if (indata == NULL) {
819 CTS_ERR("ipc data created fail!");
820 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
824 ret = ctsvc_ipc_marshal_handle(contact, indata);
825 if (CONTACTS_ERROR_NONE != ret) {
826 CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
827 pims_ipc_data_destroy(indata);
831 ret = ctsvc_ipc_marshal_string(view_uri,indata);
832 if (ret != CONTACTS_ERROR_NONE) {
833 CTS_ERR("marshal fail");
834 pims_ipc_data_destroy(indata);
838 ret = ctsvc_ipc_marshal_int(count,indata);
839 if (ret != CONTACTS_ERROR_NONE) {
840 CTS_ERR("marshal fail");
841 pims_ipc_data_destroy(indata);
845 for (i=0;i<count;i++) {
846 ret = ctsvc_ipc_marshal_int(ids[i],indata);
847 if (ret != CONTACTS_ERROR_NONE) {
848 CTS_ERR("marshal fail");
849 pims_ipc_data_destroy(indata);
854 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_DELETE_RECORDS,
855 indata, &outdata) != 0) {
856 CTS_ERR("ctsvc_ipc_call failed");
857 pims_ipc_data_destroy(indata);
858 return CONTACTS_ERROR_IPC;
861 pims_ipc_data_destroy(indata);
864 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
865 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
866 pims_ipc_data_destroy(outdata);
867 return CONTACTS_ERROR_IPC;
870 if (CONTACTS_ERROR_NONE == ret) {
871 int transaction_ver = 0;
872 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
873 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
874 pims_ipc_data_destroy(outdata);
875 return CONTACTS_ERROR_IPC;
877 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
880 pims_ipc_data_destroy(outdata);
886 int ctsvc_client_db_replace_records(contacts_h contact, contacts_list_h list, int ids[], int count)
889 int ret = CONTACTS_ERROR_NONE;
890 pims_ipc_data_h indata = NULL;
891 pims_ipc_data_h outdata = NULL;
893 RETVM_IF(NULL == contact,CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
894 RETVM_IF(NULL == list,CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
895 RETVM_IF(NULL == ids, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
896 RETVM_IF(0 == count, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
899 indata = pims_ipc_data_create(0);
900 if (indata == NULL) {
901 CTS_ERR("ipc data created fail!");
902 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
906 ret = ctsvc_ipc_marshal_handle(contact, indata);
907 if (CONTACTS_ERROR_NONE != ret) {
908 CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
909 pims_ipc_data_destroy(indata);
913 ret = ctsvc_ipc_marshal_list(list, indata);
914 if (ret != CONTACTS_ERROR_NONE) {
915 CTS_ERR("marshal fail");
916 pims_ipc_data_destroy(indata);
920 ret = ctsvc_ipc_marshal_int(count, indata);
921 if (ret != CONTACTS_ERROR_NONE) {
922 CTS_ERR("marshal fail");
923 pims_ipc_data_destroy(indata);
927 for (i=0;i<count;i++) {
928 ret = ctsvc_ipc_marshal_int(ids[i], indata);
929 if (ret != CONTACTS_ERROR_NONE) {
930 CTS_ERR("marshal fail");
931 pims_ipc_data_destroy(indata);
936 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_REPLACE_RECORDS,
937 indata, &outdata) != 0) {
938 CTS_ERR("ctsvc_ipc_call failed");
939 pims_ipc_data_destroy(indata);
940 return CONTACTS_ERROR_IPC;
943 pims_ipc_data_destroy(indata);
946 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
947 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
948 pims_ipc_data_destroy(outdata);
949 return CONTACTS_ERROR_IPC;
951 if (CONTACTS_ERROR_NONE == ret) {
952 int transaction_ver = 0;
953 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
954 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
955 pims_ipc_data_destroy(outdata);
956 return CONTACTS_ERROR_IPC;
958 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
960 pims_ipc_data_destroy(outdata);
966 int ctsvc_client_db_get_changes_by_version(contacts_h contact, const char* view_uri, int addressbook_id, int contacts_db_version, contacts_list_h* record_list, int* current_contacts_db_version)
968 int ret = CONTACTS_ERROR_NONE;
969 pims_ipc_data_h indata = NULL;
970 pims_ipc_data_h outdata = NULL;
972 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
973 RETVM_IF(record_list==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"record_list is NULL");
975 RETVM_IF(view_uri==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"view_uri is NULL");
976 RETVM_IF(current_contacts_db_version==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"current_contacts_db_version is NULL");
979 indata = pims_ipc_data_create(0);
980 if (indata == NULL) {
981 CTS_ERR("ipc data created fail!");
982 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
986 ret = ctsvc_ipc_marshal_handle(contact, indata);
987 if (CONTACTS_ERROR_NONE != ret) {
988 CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
989 pims_ipc_data_destroy(indata);
993 ret = ctsvc_ipc_marshal_string(view_uri,indata);
994 if (ret != CONTACTS_ERROR_NONE) {
995 CTS_ERR("marshal fail");
996 pims_ipc_data_destroy(indata);
999 ret = ctsvc_ipc_marshal_int(addressbook_id,indata);
1000 if (ret != CONTACTS_ERROR_NONE) {
1001 CTS_ERR("marshal fail");
1002 pims_ipc_data_destroy(indata);
1005 ret = ctsvc_ipc_marshal_int(contacts_db_version,indata);
1006 if (ret != CONTACTS_ERROR_NONE) {
1007 CTS_ERR("marshal fail");
1008 pims_ipc_data_destroy(indata);
1013 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_CHANGES_BY_VERSION, indata, &outdata) != 0) {
1014 CTS_ERR("ctsvc_ipc_call failed");
1015 pims_ipc_data_destroy(indata);
1016 return CONTACTS_ERROR_IPC;
1019 pims_ipc_data_destroy(indata);
1022 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
1023 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
1024 pims_ipc_data_destroy(outdata);
1025 return CONTACTS_ERROR_IPC;
1028 if (ret == CONTACTS_ERROR_NONE) {
1029 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_list(outdata, record_list)) {
1030 CTS_ERR("ctsvc_ipc_unmarshal_list() Fail");
1031 pims_ipc_data_destroy(outdata);
1032 return CONTACTS_ERROR_IPC;
1034 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, current_contacts_db_version)) {
1035 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
1036 pims_ipc_data_destroy(outdata);
1037 return CONTACTS_ERROR_IPC;
1040 pims_ipc_data_destroy(outdata);
1046 int ctsvc_client_db_get_current_version(contacts_h contact, int* contacts_db_version)
1048 int ret = CONTACTS_ERROR_NONE;
1049 pims_ipc_data_h indata = NULL;
1050 pims_ipc_data_h outdata = NULL;
1052 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is null");
1053 RETVM_IF(contacts_db_version==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"contacts_db_version is null");
1054 *contacts_db_version = 0;
1057 indata = pims_ipc_data_create(0);
1058 if (indata == NULL) {
1059 CTS_ERR("ipc data created fail!");
1060 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1064 ret = ctsvc_ipc_marshal_handle(contact, indata);
1065 if (CONTACTS_ERROR_NONE != ret) {
1066 CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
1067 pims_ipc_data_destroy(indata);
1072 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_CURRENT_VERSION, indata, &outdata) != 0) {
1073 CTS_ERR("ctsvc_ipc_call failed");
1074 pims_ipc_data_destroy(indata);
1075 return CONTACTS_ERROR_IPC;
1078 pims_ipc_data_destroy(indata);
1081 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
1082 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
1083 pims_ipc_data_destroy(outdata);
1084 return CONTACTS_ERROR_IPC;
1087 if (CONTACTS_ERROR_NONE == ret) {
1088 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, contacts_db_version)) {
1089 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
1090 pims_ipc_data_destroy(outdata);
1091 return CONTACTS_ERROR_IPC;
1094 pims_ipc_data_destroy(outdata);
1100 int ctsvc_client_db_search_records(contacts_h contact, const char* view_uri, const char *keyword,
1101 int offset, int limit, contacts_list_h* out_list)
1103 int ret = CONTACTS_ERROR_NONE;
1104 pims_ipc_data_h indata = NULL;
1105 pims_ipc_data_h outdata = NULL;
1107 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
1108 RETVM_IF(out_list == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
1112 indata = pims_ipc_data_create(0);
1113 if (indata == NULL) {
1114 CTS_ERR("pims_ipc_data_create() Fail");
1115 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1118 ret = ctsvc_ipc_marshal_handle(contact, indata);
1119 if (CONTACTS_ERROR_NONE != ret) {
1120 CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
1121 pims_ipc_data_destroy(indata);
1124 ret = ctsvc_ipc_marshal_string(view_uri,indata);
1125 if (ret != CONTACTS_ERROR_NONE) {
1126 CTS_ERR("marshal fail");
1127 pims_ipc_data_destroy(indata);
1130 ret = ctsvc_ipc_marshal_string(keyword,indata);
1131 if (ret != CONTACTS_ERROR_NONE) {
1132 CTS_ERR("marshal fail");
1133 pims_ipc_data_destroy(indata);
1136 ret = ctsvc_ipc_marshal_int(offset,indata);
1137 if (ret != CONTACTS_ERROR_NONE) {
1138 CTS_ERR("marshal fail");
1139 pims_ipc_data_destroy(indata);
1142 ret = ctsvc_ipc_marshal_int(limit,indata);
1143 if (ret != CONTACTS_ERROR_NONE) {
1144 CTS_ERR("marshal fail");
1145 pims_ipc_data_destroy(indata);
1150 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_SEARCH_RECORDS, 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 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
1160 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
1161 pims_ipc_data_destroy(outdata);
1162 return CONTACTS_ERROR_IPC;
1165 if (CONTACTS_ERROR_NONE == ret) {
1166 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_list(outdata, out_list)) {
1167 CTS_ERR("ctsvc_ipc_unmarshal_list() Fail");
1168 pims_ipc_data_destroy(outdata);
1169 return CONTACTS_ERROR_IPC;
1173 pims_ipc_data_destroy(outdata);
1179 int ctsvc_client_db_search_records_with_range(contacts_h contact, const char* view_uri, const char *keyword,
1180 int offset, int limit, int range, contacts_list_h* out_list)
1182 int ret = CONTACTS_ERROR_NONE;
1183 pims_ipc_data_h indata = NULL;
1184 pims_ipc_data_h outdata = NULL;
1186 RETVM_IF(contact == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
1187 RETVM_IF(out_list == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
1188 RETVM_IF(range == 0, CONTACTS_ERROR_INVALID_PARAMETER, "range is 0");
1191 indata = pims_ipc_data_create(0);
1192 if (indata == NULL) {
1193 CTS_ERR("pims_ipc_data_create() Fail");
1194 return CONTACTS_ERROR_OUT_OF_MEMORY;
1196 ret = ctsvc_ipc_marshal_handle(contact, indata);
1197 if (CONTACTS_ERROR_NONE != ret) {
1198 CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
1199 pims_ipc_data_destroy(indata);
1203 ret = ctsvc_ipc_marshal_string(view_uri, indata);
1204 if (ret != CONTACTS_ERROR_NONE) {
1205 CTS_ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
1206 pims_ipc_data_destroy(indata);
1209 ret = ctsvc_ipc_marshal_string(keyword, indata);
1210 if (ret != CONTACTS_ERROR_NONE) {
1211 CTS_ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
1212 pims_ipc_data_destroy(indata);
1215 ret = ctsvc_ipc_marshal_int(offset, indata);
1216 if (ret != CONTACTS_ERROR_NONE) {
1217 CTS_ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
1218 pims_ipc_data_destroy(indata);
1221 ret = ctsvc_ipc_marshal_int(limit, indata);
1222 if (ret != CONTACTS_ERROR_NONE) {
1223 CTS_ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
1224 pims_ipc_data_destroy(indata);
1227 ret = ctsvc_ipc_marshal_int(range, indata);
1228 if (ret != CONTACTS_ERROR_NONE) {
1229 CTS_ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
1230 pims_ipc_data_destroy(indata);
1234 if (0 != ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_SEARCH_RECORDS_WITH_RANGE, indata, &outdata)) {
1235 CTS_ERR("ctsvc_ipc_call failed");
1236 pims_ipc_data_destroy(indata);
1237 return CONTACTS_ERROR_IPC;
1240 pims_ipc_data_destroy(indata);
1243 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
1244 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
1245 pims_ipc_data_destroy(outdata);
1246 return CONTACTS_ERROR_IPC;
1248 if (CONTACTS_ERROR_NONE == ret) {
1249 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_list(outdata, out_list)) {
1250 CTS_ERR("ctsvc_ipc_unmarshal_list() Fail");
1251 pims_ipc_data_destroy(outdata);
1252 return CONTACTS_ERROR_IPC;
1255 pims_ipc_data_destroy(outdata);
1261 int ctsvc_client_db_search_records_with_query(contacts_h contact, contacts_query_h query, const char *keyword,
1262 int offset, int limit, contacts_list_h* out_list)
1264 int ret = CONTACTS_ERROR_NONE;
1265 pims_ipc_data_h indata = NULL;
1266 pims_ipc_data_h outdata = NULL;
1268 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
1269 RETVM_IF(NULL == out_list, CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
1270 RETVM_IF(NULL == query, CONTACTS_ERROR_INVALID_PARAMETER, "query is NULL");
1274 indata = pims_ipc_data_create(0);
1275 if (indata == NULL) {
1276 CTS_ERR("pims_ipc_data_create() Fail");
1277 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1280 ret = ctsvc_ipc_marshal_handle(contact, indata);
1281 if (CONTACTS_ERROR_NONE != ret) {
1282 CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
1283 pims_ipc_data_destroy(indata);
1286 ret = ctsvc_ipc_marshal_query(query,indata);
1287 if (ret != CONTACTS_ERROR_NONE) {
1288 CTS_ERR("marshal fail");
1289 pims_ipc_data_destroy(indata);
1292 ret = ctsvc_ipc_marshal_string(keyword,indata);
1293 if (ret != CONTACTS_ERROR_NONE) {
1294 CTS_ERR("marshal fail");
1295 pims_ipc_data_destroy(indata);
1298 ret = ctsvc_ipc_marshal_int(offset,indata);
1299 if (ret != CONTACTS_ERROR_NONE) {
1300 CTS_ERR("marshal fail");
1303 ret = ctsvc_ipc_marshal_int(limit,indata);
1304 if (ret != CONTACTS_ERROR_NONE) {
1305 CTS_ERR("marshal fail");
1306 pims_ipc_data_destroy(indata);
1311 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_SEARCH_RECORDS_WITH_QUERY, indata, &outdata) != 0) {
1312 CTS_ERR("ctsvc_ipc_call failed");
1313 pims_ipc_data_destroy(indata);
1314 return CONTACTS_ERROR_IPC;
1317 pims_ipc_data_destroy(indata);
1320 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
1321 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
1322 pims_ipc_data_destroy(outdata);
1323 return CONTACTS_ERROR_IPC;
1326 if (CONTACTS_ERROR_NONE == ret) {
1327 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_list(outdata, out_list)) {
1328 CTS_ERR("ctsvc_ipc_unmarshal_list() Fail");
1329 pims_ipc_data_destroy(outdata);
1330 return CONTACTS_ERROR_IPC;
1334 pims_ipc_data_destroy(outdata);
1340 int ctsvc_client_db_get_last_change_version(contacts_h contact, int* last_version)
1342 int ret = CONTACTS_ERROR_NONE;
1343 bool result = false;
1345 RETVM_IF(NULL == last_version, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
1348 ret = ctsvc_ipc_client_check_permission(CTSVC_PERMISSION_CONTACT_READ, &result);
1349 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_ipc_client_check_permission fail (%d)", ret);
1350 if (result == false) {
1351 ret = ctsvc_ipc_client_check_permission(CTSVC_PERMISSION_PHONELOG_READ, &result);
1352 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_ipc_client_check_permission fail (%d)", ret);
1353 RETVM_IF(result == false, CONTACTS_ERROR_PERMISSION_DENIED, "Permission denied");
1356 *last_version = ctsvc_client_ipc_get_change_version(contact);
1362 contacts_db_status_changed_cb cb;
1364 }status_callback_info_s;
1366 static GSList *__status_change_subscribe_list = NULL;
1368 static void __ctsvc_client_db_free_cb_info(status_callback_info_s *cb_info)
1370 if (NULL == cb_info)
1375 static void __ctsvc_db_status_subscriber_callback(pims_ipc_h ipc, pims_ipc_data_h data, void *user_data)
1382 ret = ctsvc_ipc_unmarshal_int(data, &status);
1383 WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
1386 for (l = __status_change_subscribe_list;l;l=l->next) {
1387 status_callback_info_s *cb_info = l->data;
1388 /* TODO: Fixme - check zone_name */
1390 cb_info->cb(status, cb_info->user_data);
1394 int ctsvc_client_db_get_status(contacts_h contact, contacts_db_status_e *status)
1396 int ret = CONTACTS_ERROR_NONE;
1397 pims_ipc_data_h outdata = NULL;
1398 pims_ipc_data_h indata = NULL;
1400 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
1401 RETVM_IF(status == NULL, CONTACTS_ERROR_INVALID_PARAMETER,"The out param is NULL");
1405 indata = pims_ipc_data_create(0);
1406 if (indata == NULL) {
1407 CTS_ERR("pims_ipc_data_create() Fail");
1408 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1412 ret = ctsvc_ipc_marshal_handle(contact, indata);
1413 if (CONTACTS_ERROR_NONE != ret) {
1414 CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
1415 pims_ipc_data_destroy(indata);
1419 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_STATUS, indata, &outdata) != 0) {
1420 pims_ipc_data_destroy(indata);
1421 CTS_ERR("ctsvc_ipc_call failed");
1422 return CONTACTS_ERROR_IPC;
1424 pims_ipc_data_destroy(indata);
1427 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
1428 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
1429 pims_ipc_data_destroy(outdata);
1430 return CONTACTS_ERROR_IPC;
1432 if (CONTACTS_ERROR_NONE == ret) {
1433 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, (int *)status)) {
1434 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
1435 pims_ipc_data_destroy(outdata);
1436 return CONTACTS_ERROR_IPC;
1439 pims_ipc_data_destroy(outdata);
1445 int ctsvc_client_db_add_status_changed_cb(contacts_h contact,
1446 contacts_db_status_changed_cb cb, void* user_data)
1448 status_callback_info_s *cb_info = NULL;
1450 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
1451 RETVM_IF(NULL == cb, CONTACTS_ERROR_INVALID_PARAMETER,
1452 "Invalid parameter : callback is null");
1454 ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
1456 if (pims_ipc_subscribe(ctsvc_ipc_get_handle_for_change_subsciption(),
1457 CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_IPC_SERVER_DB_STATUS_CHANGED,
1458 __ctsvc_db_status_subscriber_callback, NULL) != 0) {
1459 CTS_ERR("pims_ipc_subscribe error\n");
1460 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
1461 return CONTACTS_ERROR_IPC;
1464 cb_info = calloc(1, sizeof(status_callback_info_s));
1465 if (NULL == cb_info) {
1466 CTS_ERR("calloc() Fail");
1467 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
1468 return CONTACTS_ERROR_OUT_OF_MEMORY;
1470 cb_info->user_data = user_data;
1472 __status_change_subscribe_list = g_slist_append(__status_change_subscribe_list, cb_info);
1474 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
1475 return CONTACTS_ERROR_NONE;
1478 int ctsvc_client_db_remove_status_changed_cb(contacts_h contact,
1479 contacts_db_status_changed_cb cb, void* user_data)
1483 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
1484 RETVM_IF(NULL == cb, CONTACTS_ERROR_INVALID_PARAMETER,
1485 "Invalid parameter : callback is null");
1487 ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
1488 for (l = __status_change_subscribe_list;l;l=l->next) {
1489 status_callback_info_s *cb_info = l->data;
1490 if (cb == cb_info->cb && user_data == cb_info->user_data) {
1491 __status_change_subscribe_list = g_slist_remove(__status_change_subscribe_list, cb_info);
1492 __ctsvc_client_db_free_cb_info(cb_info);
1497 if (g_slist_length(__status_change_subscribe_list) == 0) {
1498 pims_ipc_unsubscribe(ctsvc_ipc_get_handle_for_change_subsciption(),
1499 CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_IPC_SERVER_DB_STATUS_CHANGED);
1500 g_slist_free(__status_change_subscribe_list);
1501 __status_change_subscribe_list = NULL;
1504 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
1505 return CONTACTS_ERROR_NONE;