4 * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 #include <pims-ipc-data.h>
22 #include "ctsvc_internal.h"
23 #include "ctsvc_ipc_define.h"
24 #include "ctsvc_client_ipc.h"
25 #include "ctsvc_ipc_marshal.h"
28 int ctsvc_client_person_link_person(contacts_h contact, int base_person_id, int person_id)
30 int ret = CONTACTS_ERROR_NONE;
32 pims_ipc_data_h indata = NULL;
33 pims_ipc_data_h outdata = NULL;
35 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
36 RETVM_IF(base_person_id <= 0 || person_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,
37 "id should be greater than 0");
40 indata = pims_ipc_data_create(0);
43 ERR("pims_ipc_data_create() Fail");
44 return CONTACTS_ERROR_OUT_OF_MEMORY;
47 ret = ctsvc_ipc_marshal_handle(contact, indata);
48 if (CONTACTS_ERROR_NONE != ret) {
50 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
51 pims_ipc_data_destroy(indata);
58 if (ctsvc_ipc_marshal_int(base_person_id, indata) != CONTACTS_ERROR_NONE)
60 if (ctsvc_ipc_marshal_int(person_id, indata) != CONTACTS_ERROR_NONE)
66 if (success == false) {
68 ERR("ctsvc_ipc_marshal_int() Fail");
69 pims_ipc_data_destroy(indata);
70 return CONTACTS_ERROR_IPC;
75 ret = ctsvc_ipc_marshal_int(base_person_id, indata);
76 if (CONTACTS_ERROR_NONE != ret) {
80 ret = ctsvc_ipc_marshal_int(person_id, indata);
81 if (CONTACTS_ERROR_NONE != ret) {
88 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_LINK_PERSON,
89 indata, &outdata) != 0) {
91 ERR("ctsvc_ipc_call() Fail");
92 pims_ipc_data_destroy(indata);
93 return CONTACTS_ERROR_IPC;
97 pims_ipc_data_destroy(indata);
100 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
101 /* LCOV_EXCL_START */
102 ERR("ctsvc_ipc_unmarshal_int() Fail");
103 pims_ipc_data_destroy(outdata);
104 return CONTACTS_ERROR_IPC;
108 if (CONTACTS_ERROR_NONE == ret) {
109 int transaction_ver = 0;
110 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
111 /* LCOV_EXCL_START */
112 ERR("ctsvc_ipc_unmarshal_int() Fail");
113 pims_ipc_data_destroy(outdata);
114 return CONTACTS_ERROR_IPC;
117 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
120 pims_ipc_data_destroy(outdata);
126 int ctsvc_client_person_unlink_contact(contacts_h contact, int person_id, int contact_id,
127 int *unlinked_person_id)
129 int ret = CONTACTS_ERROR_NONE;
131 pims_ipc_data_h indata = NULL;
132 pims_ipc_data_h outdata = NULL;
134 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
135 RETVM_IF(person_id <= 0 || contact_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,
136 "id should be greater than 0");
138 if (unlinked_person_id)
139 *unlinked_person_id = 0;
142 indata = pims_ipc_data_create(0);
143 if (NULL == indata) {
144 /* LCOV_EXCL_START */
145 ERR("pims_ipc_data_create() Fail");
146 return CONTACTS_ERROR_OUT_OF_MEMORY;
150 ret = ctsvc_ipc_marshal_handle(contact, indata);
151 if (CONTACTS_ERROR_NONE != ret) {
152 /* LCOV_EXCL_START */
153 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
154 pims_ipc_data_destroy(indata);
159 ret = ctsvc_ipc_marshal_int(person_id, indata);
160 if (CONTACTS_ERROR_NONE != ret) {
161 /* LCOV_EXCL_START */
162 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
163 pims_ipc_data_destroy(indata);
167 ret = ctsvc_ipc_marshal_int(contact_id, indata);
168 if (CONTACTS_ERROR_NONE != ret) {
169 /* LCOV_EXCL_START */
170 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
171 pims_ipc_data_destroy(indata);
177 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_UNLINK_CONTACT,
178 indata, &outdata) != 0) {
179 /* LCOV_EXCL_START */
180 ERR("ctsvc_ipc_call() Fail");
181 pims_ipc_data_destroy(indata);
182 return CONTACTS_ERROR_IPC;
186 pims_ipc_data_destroy(indata);
189 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
190 /* LCOV_EXCL_START */
191 ERR("ctsvc_ipc_unmarshal_int() Fail");
192 pims_ipc_data_destroy(outdata);
193 return CONTACTS_ERROR_IPC;
197 if (CONTACTS_ERROR_NONE == ret) {
198 int transaction_ver = 0;
199 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
200 /* LCOV_EXCL_START */
201 ERR("ctsvc_ipc_unmarshal_int() Fail");
202 pims_ipc_data_destroy(outdata);
203 return CONTACTS_ERROR_IPC;
206 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
208 if (unlinked_person_id) {
209 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata,
210 unlinked_person_id)) {
211 /* LCOV_EXCL_START */
212 ERR("ctsvc_ipc_unmarshal_int() Fail");
213 pims_ipc_data_destroy(outdata);
214 return CONTACTS_ERROR_IPC;
219 pims_ipc_data_destroy(outdata);
225 int ctsvc_client_person_reset_usage(contacts_h contact, int person_id,
226 contacts_usage_type_e type)
228 int ret = CONTACTS_ERROR_NONE;
230 pims_ipc_data_h indata = NULL;
231 pims_ipc_data_h outdata = NULL;
233 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
234 RETVM_IF(person_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,
235 "contact_id should be greater than 0");
238 indata = pims_ipc_data_create(0);
239 if (NULL == indata) {
240 /* LCOV_EXCL_START */
241 ERR("pims_ipc_data_create() Fail");
242 return CONTACTS_ERROR_OUT_OF_MEMORY;
246 ret = ctsvc_ipc_marshal_handle(contact, indata);
247 if (CONTACTS_ERROR_NONE != ret) {
248 /* LCOV_EXCL_START */
249 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
250 pims_ipc_data_destroy(indata);
256 ret = ctsvc_ipc_marshal_int(person_id, indata);
257 if (CONTACTS_ERROR_NONE != ret) {
258 /* LCOV_EXCL_START */
259 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
260 pims_ipc_data_destroy(indata);
264 ret = ctsvc_ipc_marshal_int((int)type, indata);
265 if (CONTACTS_ERROR_NONE != ret) {
266 /* LCOV_EXCL_START */
267 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
268 pims_ipc_data_destroy(indata);
274 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_RESET_USAGE,
275 indata, &outdata) != 0) {
276 /* LCOV_EXCL_START */
277 ERR("ctsvc_ipc_call() Fail");
278 pims_ipc_data_destroy(indata);
279 return CONTACTS_ERROR_IPC;
283 pims_ipc_data_destroy(indata);
286 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
287 /* LCOV_EXCL_START */
288 ERR("ctsvc_ipc_unmarshal_int() Fail");
289 pims_ipc_data_destroy(outdata);
290 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 /* LCOV_EXCL_START */
298 ERR("ctsvc_ipc_unmarshal_int() Fail");
299 pims_ipc_data_destroy(outdata);
300 return CONTACTS_ERROR_IPC;
303 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
306 pims_ipc_data_destroy(outdata);
312 int ctsvc_client_person_set_favorite_order(contacts_h contact, int person_id,
313 int previous_person_id, int next_person_id)
315 int ret = CONTACTS_ERROR_NONE;
317 pims_ipc_data_h indata = NULL;
318 pims_ipc_data_h outdata = NULL;
320 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
321 RETVM_IF(person_id <= 0 || previous_person_id < 0 || next_person_id < 0,
322 CONTACTS_ERROR_INVALID_PARAMETER, "id should be greater than 0");
325 indata = pims_ipc_data_create(0);
326 if (NULL == indata) {
327 /* LCOV_EXCL_START */
328 ERR("pims_ipc_data_create() Fail");
329 return CONTACTS_ERROR_OUT_OF_MEMORY;
333 ret = ctsvc_ipc_marshal_handle(contact, indata);
334 if (CONTACTS_ERROR_NONE != ret) {
335 /* LCOV_EXCL_START */
336 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
337 pims_ipc_data_destroy(indata);
342 ret = ctsvc_ipc_marshal_int(person_id, indata);
343 if (CONTACTS_ERROR_NONE != ret) {
344 /* LCOV_EXCL_START */
345 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
346 pims_ipc_data_destroy(indata);
350 ret = ctsvc_ipc_marshal_int(previous_person_id, indata);
351 if (CONTACTS_ERROR_NONE != ret) {
352 /* LCOV_EXCL_START */
353 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
354 pims_ipc_data_destroy(indata);
358 ret = ctsvc_ipc_marshal_int(next_person_id, indata);
359 if (CONTACTS_ERROR_NONE != ret) {
360 /* LCOV_EXCL_START */
361 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
362 pims_ipc_data_destroy(indata);
368 ret = ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE,
369 CTSVC_IPC_SERVER_PERSON_SET_FAVORITE_ORDER, indata, &outdata);
371 /* LCOV_EXCL_START */
372 ERR("ctsvc_ipc_call() Fail");
373 pims_ipc_data_destroy(indata);
374 return CONTACTS_ERROR_IPC;
378 pims_ipc_data_destroy(indata);
381 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
382 /* LCOV_EXCL_START */
383 ERR("ctsvc_ipc_unmarshal_int() Fail");
384 pims_ipc_data_destroy(outdata);
385 return CONTACTS_ERROR_IPC;
389 if (CONTACTS_ERROR_NONE == ret) {
390 int transaction_ver = 0;
391 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
392 /* LCOV_EXCL_START */
393 ERR("ctsvc_ipc_unmarshal_int() Fail");
394 pims_ipc_data_destroy(outdata);
395 return CONTACTS_ERROR_IPC;
398 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
401 pims_ipc_data_destroy(outdata);
408 int ctsvc_client_person_set_default_property(contacts_h contact,
409 contacts_person_property_e property, int person_id, int id)
411 int ret = CONTACTS_ERROR_NONE;
413 pims_ipc_data_h indata = NULL;
414 pims_ipc_data_h outdata = NULL;
416 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
417 RETVM_IF(person_id <= 0 || id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,
418 "id should be greater than 0");
421 indata = pims_ipc_data_create(0);
422 if (NULL == indata) {
423 /* LCOV_EXCL_START */
424 ERR("pims_ipc_data_create() Fail");
425 return CONTACTS_ERROR_OUT_OF_MEMORY;
429 ret = ctsvc_ipc_marshal_handle(contact, indata);
430 if (CONTACTS_ERROR_NONE != ret) {
431 /* LCOV_EXCL_START */
432 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
433 pims_ipc_data_destroy(indata);
438 ret = ctsvc_ipc_marshal_int(person_id, indata);
439 if (CONTACTS_ERROR_NONE != ret) {
440 /* LCOV_EXCL_START */
441 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
442 pims_ipc_data_destroy(indata);
446 ret = ctsvc_ipc_marshal_unsigned_int(property, indata);
447 if (CONTACTS_ERROR_NONE != ret) {
448 /* LCOV_EXCL_START */
449 ERR("ctsvc_ipc_marshal_unsigned_int() Fail(%d)", ret);
450 pims_ipc_data_destroy(indata);
454 ret = ctsvc_ipc_marshal_int(id, indata);
455 if (CONTACTS_ERROR_NONE != ret) {
456 /* LCOV_EXCL_START */
457 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
458 pims_ipc_data_destroy(indata);
464 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_SET_DEFAULT_PROPERTY,
465 indata, &outdata) != 0) {
466 /* LCOV_EXCL_START */
467 ERR("ctsvc_ipc_call() Fail");
468 pims_ipc_data_destroy(indata);
469 return CONTACTS_ERROR_IPC;
473 pims_ipc_data_destroy(indata);
476 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
477 /* LCOV_EXCL_START */
478 ERR("ctsvc_ipc_unmarshal_int() Fail");
479 pims_ipc_data_destroy(outdata);
480 return CONTACTS_ERROR_IPC;
483 if (CONTACTS_ERROR_NONE == ret) {
484 int transaction_ver = 0;
485 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
486 /* LCOV_EXCL_START */
487 ERR("ctsvc_ipc_unmarshal_int() Fail");
488 pims_ipc_data_destroy(outdata);
489 return CONTACTS_ERROR_IPC;
492 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
495 pims_ipc_data_destroy(outdata);
501 int ctsvc_client_person_get_default_property(contacts_h contact,
502 contacts_person_property_e property, int person_id, int *id)
504 int ret = CONTACTS_ERROR_NONE;
505 pims_ipc_data_h indata = NULL;
506 pims_ipc_data_h outdata = NULL;
508 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
509 RETVM_IF(person_id <= 0 || id == NULL, CONTACTS_ERROR_INVALID_PARAMETER,
510 "id should be greater than 0");
514 indata = pims_ipc_data_create(0);
515 if (NULL == indata) {
516 /* LCOV_EXCL_START */
517 ERR("pims_ipc_data_create() Fail");
518 return CONTACTS_ERROR_OUT_OF_MEMORY;
522 ret = ctsvc_ipc_marshal_handle(contact, indata);
523 if (CONTACTS_ERROR_NONE != ret) {
524 /* LCOV_EXCL_START */
525 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
526 pims_ipc_data_destroy(indata);
531 ret = ctsvc_ipc_marshal_int(person_id, indata);
532 if (CONTACTS_ERROR_NONE != ret) {
533 /* LCOV_EXCL_START */
534 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
535 pims_ipc_data_destroy(indata);
540 ret = ctsvc_ipc_marshal_unsigned_int(property, indata);
541 if (CONTACTS_ERROR_NONE != ret) {
542 /* LCOV_EXCL_START */
543 ERR("ctsvc_ipc_marshal_unsigned_int() Fail(%d)", ret);
544 pims_ipc_data_destroy(indata);
550 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_GET_DEFAULT_PROPERTY,
551 indata, &outdata) != 0) {
552 /* LCOV_EXCL_START */
553 ERR("ctsvc_ipc_call() Fail");
554 pims_ipc_data_destroy(indata);
555 return CONTACTS_ERROR_IPC;
559 pims_ipc_data_destroy(indata);
562 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
563 /* LCOV_EXCL_START */
564 ERR("ctsvc_ipc_unmarshal_int() Fail");
565 pims_ipc_data_destroy(outdata);
566 return CONTACTS_ERROR_IPC;
569 if (ret == CONTACTS_ERROR_NONE && id) {
570 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, id)) {
571 /* LCOV_EXCL_START */
572 ERR("ctsvc_ipc_unmarshal_int() Fail");
573 pims_ipc_data_destroy(outdata);
574 return CONTACTS_ERROR_IPC;
578 pims_ipc_data_destroy(outdata);
584 int ctsvc_client_person_get_aggregation_suggestions(contacts_h contact,
585 int person_id, int limit, contacts_list_h *out_list)
587 int ret = CONTACTS_ERROR_NONE;
588 int ret_val = CONTACTS_ERROR_NONE;
590 pims_ipc_data_h indata = NULL;
591 pims_ipc_data_h outdata = NULL;
593 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
594 RETV_IF(person_id <= 0 || NULL == out_list, CONTACTS_ERROR_INVALID_PARAMETER);
597 indata = pims_ipc_data_create(0);
598 if (NULL == indata) {
599 /* LCOV_EXCL_START */
600 ERR("pims_ipc_data_create() Fail");
601 return CONTACTS_ERROR_OUT_OF_MEMORY;
605 ret = ctsvc_ipc_marshal_handle(contact, indata);
606 if (CONTACTS_ERROR_NONE != ret) {
607 /* LCOV_EXCL_START */
608 ERR("ctsvc_ipc_marshal_handle Fail(%d)", ret);
609 pims_ipc_data_destroy(indata);
614 ret = ctsvc_ipc_marshal_int(person_id, indata);
615 if (CONTACTS_ERROR_NONE != ret) {
616 /* LCOV_EXCL_START */
617 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
618 pims_ipc_data_destroy(indata);
623 ret = ctsvc_ipc_marshal_int(limit, indata);
624 if (CONTACTS_ERROR_NONE != ret) {
625 /* LCOV_EXCL_START */
626 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
627 pims_ipc_data_destroy(indata);
633 ret = ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_GET_AGGREGATION_SUGGESTIONS,
635 pims_ipc_data_destroy(indata);
636 if (CONTACTS_ERROR_NONE != ret) {
637 /* LCOV_EXCL_START */
638 ERR("ctsvc_ipc_call() Fail(%d)", ret);
639 return CONTACTS_ERROR_IPC;
644 ret = ctsvc_ipc_unmarshal_int(outdata, &ret_val);
645 if (CONTACTS_ERROR_NONE != ret) {
646 /* LCOV_EXCL_START */
647 ERR("ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
648 pims_ipc_data_destroy(outdata);
649 return CONTACTS_ERROR_IPC;
653 if (CONTACTS_ERROR_NONE == ret_val) {
654 ret = ctsvc_ipc_unmarshal_list(outdata, out_list);
655 if (CONTACTS_ERROR_NONE != ret) {
656 /* LCOV_EXCL_START */
657 ERR("ctsvc_ipc_unmarshal_list() Fail(%d)");
658 pims_ipc_data_destroy(outdata);
659 return CONTACTS_ERROR_IPC;
663 pims_ipc_data_destroy(outdata);