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.
20 #include <pims-ipc-data.h>
23 #include "ctsvc_internal.h"
24 #include "ctsvc_ipc_define.h"
25 #include "ctsvc_client_ipc.h"
26 #include "ctsvc_ipc_marshal.h"
28 static const char CONTACTS_READ_PRIVILEGE_ID[] = "http://tizen.org/privilege/contact.read";
29 static const char CONTACTS_WRITE_PRIVILEGE_ID[] = "http://tizen.org/privilege/contact.write";
30 static const char PHONELOG_READ_PRIVILEGE_ID[] = "http://tizen.org/privilege/callhistory.read";
31 static const char PHONELOG_WRITE_PRIVILEGE_ID[] = "http://tizen.org/privilege/callhistory.write";
33 int ctsvc_client_person_link_person(contacts_h contact, int base_person_id, int person_id)
35 int ret = CONTACTS_ERROR_NONE;
37 pims_ipc_data_h indata = NULL;
38 pims_ipc_data_h outdata = NULL;
40 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
41 RETVM_IF(base_person_id <= 0 || person_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
45 indata = pims_ipc_data_create(0);
47 CTS_ERR("ipc data created fail!");
48 return CONTACTS_ERROR_OUT_OF_MEMORY;
50 ret = ctsvc_ipc_marshal_handle(contact, indata);
51 if (ret != CONTACTS_ERROR_NONE) {
52 CTS_ERR("ctsvc_ipc_marshal_handle Fail(%d)", ret);
53 pims_ipc_data_destroy(indata);
59 if (ctsvc_ipc_marshal_int(base_person_id, indata) != CONTACTS_ERROR_NONE) break;
60 if (ctsvc_ipc_marshal_int(person_id, indata) != CONTACTS_ERROR_NONE) break;
65 if (success == false) {
66 CTS_ERR("marshal fail");
67 pims_ipc_data_destroy(indata);
68 return CONTACTS_ERROR_IPC;
72 ret = ctsvc_ipc_marshal_int(base_person_id, indata);
73 if (ret != CONTACTS_ERROR_NONE) {
74 CTS_ERR("marshal fail");
77 ret = ctsvc_ipc_marshal_int(person_id, indata);
78 if (ret != CONTACTS_ERROR_NONE) {
79 CTS_ERR("marshal fail");
85 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_LINK_PERSON, indata, &outdata) != 0) {
86 CTS_ERR("ctsvc_ipc_call failed");
87 pims_ipc_data_destroy(indata);
88 return CONTACTS_ERROR_IPC;
91 pims_ipc_data_destroy(indata);
94 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
95 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
96 pims_ipc_data_destroy(outdata);
97 return CONTACTS_ERROR_IPC;
100 if (CONTACTS_ERROR_NONE == ret) {
101 int transaction_ver = 0;
102 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
103 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
104 pims_ipc_data_destroy(outdata);
105 return CONTACTS_ERROR_IPC;
107 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
110 pims_ipc_data_destroy(outdata);
116 int ctsvc_client_person_unlink_contact(contacts_h contact, int person_id, int contact_id, int* unlinked_person_id)
118 int ret = CONTACTS_ERROR_NONE;
120 pims_ipc_data_h indata = NULL;
121 pims_ipc_data_h outdata = NULL;
123 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
124 RETVM_IF(person_id <= 0 || contact_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
126 if (unlinked_person_id)
127 *unlinked_person_id = 0;
130 indata = pims_ipc_data_create(0);
131 if (indata == NULL) {
132 CTS_ERR("ipc data created fail!");
133 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
136 ret = ctsvc_ipc_marshal_handle(contact, indata);
137 if (ret != CONTACTS_ERROR_NONE) {
138 CTS_ERR("ctsvc_ipc_marshal_handle Fail(%d)", ret);
139 pims_ipc_data_destroy(indata);
143 ret = ctsvc_ipc_marshal_int(person_id, indata);
144 if (ret != CONTACTS_ERROR_NONE) {
145 CTS_ERR("marshal fail");
146 pims_ipc_data_destroy(indata);
149 ret = ctsvc_ipc_marshal_int(contact_id, indata);
150 if (ret != CONTACTS_ERROR_NONE) {
151 CTS_ERR("marshal fail");
152 pims_ipc_data_destroy(indata);
157 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_UNLINK_CONTACT, indata, &outdata) != 0) {
158 CTS_ERR("ctsvc_ipc_call failed");
159 pims_ipc_data_destroy(indata);
160 return CONTACTS_ERROR_IPC;
163 pims_ipc_data_destroy(indata);
166 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
167 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
168 pims_ipc_data_destroy(outdata);
169 return CONTACTS_ERROR_IPC;
172 if (CONTACTS_ERROR_NONE == ret) {
173 int transaction_ver = 0;
174 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
175 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
176 pims_ipc_data_destroy(outdata);
177 return CONTACTS_ERROR_IPC;
179 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
181 if (unlinked_person_id) {
182 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, unlinked_person_id)) {
183 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
184 pims_ipc_data_destroy(outdata);
185 return CONTACTS_ERROR_IPC;
189 pims_ipc_data_destroy(outdata);
195 int ctsvc_client_person_reset_usage(contacts_h contact, int person_id, contacts_usage_type_e type)
197 int ret = CONTACTS_ERROR_NONE;
199 pims_ipc_data_h indata = NULL;
200 pims_ipc_data_h outdata = NULL;
202 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
203 RETVM_IF(person_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,"contact_id should be greater than 0");
206 indata = pims_ipc_data_create(0);
207 if (indata == NULL) {
208 CTS_ERR("ipc data created fail!");
209 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
212 ret = ctsvc_ipc_marshal_handle(contact, indata);
213 if (ret != CONTACTS_ERROR_NONE) {
214 CTS_ERR("ctsvc_ipc_marshal_handle Fail(%d)", ret);
215 pims_ipc_data_destroy(indata);
220 ret = ctsvc_ipc_marshal_int(person_id, indata);
221 if (ret != CONTACTS_ERROR_NONE) {
222 CTS_ERR("marshal fail");
223 pims_ipc_data_destroy(indata);
226 ret = ctsvc_ipc_marshal_int((int)type, indata);
227 if (ret != CONTACTS_ERROR_NONE) {
228 CTS_ERR("marshal fail");
229 pims_ipc_data_destroy(indata);
234 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_RESET_USAGE, indata, &outdata) != 0) {
235 CTS_ERR("ctsvc_ipc_call failed");
236 pims_ipc_data_destroy(indata);
237 return CONTACTS_ERROR_IPC;
240 pims_ipc_data_destroy(indata);
243 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
244 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
245 pims_ipc_data_destroy(outdata);
246 return CONTACTS_ERROR_IPC;
249 if (CONTACTS_ERROR_NONE == ret) {
250 int transaction_ver = 0;
251 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
252 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
253 pims_ipc_data_destroy(outdata);
254 return CONTACTS_ERROR_IPC;
256 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
259 pims_ipc_data_destroy(outdata);
265 int ctsvc_client_person_set_favorite_order(contacts_h contact, int person_id, int previous_person_id, int next_person_id)
267 int ret = CONTACTS_ERROR_NONE;
269 pims_ipc_data_h indata = NULL;
270 pims_ipc_data_h outdata = NULL;
272 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
273 RETVM_IF(person_id <= 0 || previous_person_id < 0 || next_person_id < 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
276 indata = pims_ipc_data_create(0);
277 if (indata == NULL) {
278 CTS_ERR("ipc data created fail!");
279 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
282 ret = ctsvc_ipc_marshal_handle(contact, indata);
283 if (ret != CONTACTS_ERROR_NONE) {
284 CTS_ERR("ctsvc_ipc_marshal_handle Fail(%d)", ret);
285 pims_ipc_data_destroy(indata);
289 ret = ctsvc_ipc_marshal_int(person_id, indata);
290 if (ret != CONTACTS_ERROR_NONE) {
291 CTS_ERR("marshal fail");
292 pims_ipc_data_destroy(indata);
295 ret = ctsvc_ipc_marshal_int(previous_person_id, indata);
296 if (ret != CONTACTS_ERROR_NONE) {
297 CTS_ERR("marshal fail");
298 pims_ipc_data_destroy(indata);
301 ret = ctsvc_ipc_marshal_int(next_person_id, indata);
302 if (ret != CONTACTS_ERROR_NONE) {
303 CTS_ERR("marshal fail");
304 pims_ipc_data_destroy(indata);
309 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_SET_FAVORITE_ORDER, indata, &outdata) != 0) {
310 CTS_ERR("ctsvc_ipc_call failed");
311 pims_ipc_data_destroy(indata);
312 return CONTACTS_ERROR_IPC;
315 pims_ipc_data_destroy(indata);
318 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
319 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
320 pims_ipc_data_destroy(outdata);
321 return CONTACTS_ERROR_IPC;
324 if (CONTACTS_ERROR_NONE == ret) {
325 int transaction_ver = 0;
326 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
327 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
328 pims_ipc_data_destroy(outdata);
329 return CONTACTS_ERROR_IPC;
331 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
334 pims_ipc_data_destroy(outdata);
341 int ctsvc_client_person_set_default_property(contacts_h contact, contacts_person_property_e property,
342 int person_id, int id)
344 int ret = CONTACTS_ERROR_NONE;
346 pims_ipc_data_h indata = NULL;
347 pims_ipc_data_h outdata = NULL;
349 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
350 RETVM_IF(person_id <= 0 || id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
353 indata = pims_ipc_data_create(0);
354 if (indata == NULL) {
355 CTS_ERR("ipc data created fail!");
356 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
360 ret = ctsvc_ipc_marshal_handle(contact, indata);
361 if (ret != CONTACTS_ERROR_NONE) {
362 CTS_ERR("ctsvc_ipc_marshal_handle Fail(%d)", ret);
363 pims_ipc_data_destroy(indata);
367 ret = ctsvc_ipc_marshal_int(person_id, indata);
368 if (ret != CONTACTS_ERROR_NONE) {
369 CTS_ERR("marshal fail");
370 pims_ipc_data_destroy(indata);
373 ret = ctsvc_ipc_marshal_unsigned_int(property, indata);
374 if (ret != CONTACTS_ERROR_NONE) {
375 CTS_ERR("marshal fail");
376 pims_ipc_data_destroy(indata);
379 ret = ctsvc_ipc_marshal_int(id, indata);
380 if (ret != CONTACTS_ERROR_NONE) {
381 CTS_ERR("marshal fail");
382 pims_ipc_data_destroy(indata);
387 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_SET_DEFAULT_PROPERTY, indata, &outdata) != 0) {
388 CTS_ERR("ctsvc_ipc_call failed");
389 pims_ipc_data_destroy(indata);
390 return CONTACTS_ERROR_IPC;
393 pims_ipc_data_destroy(indata);
396 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
397 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
398 pims_ipc_data_destroy(outdata);
399 return CONTACTS_ERROR_IPC;
401 if (CONTACTS_ERROR_NONE == ret) {
402 int transaction_ver = 0;
403 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
404 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
405 pims_ipc_data_destroy(outdata);
406 return CONTACTS_ERROR_IPC;
408 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
411 pims_ipc_data_destroy(outdata);
417 int ctsvc_client_person_get_default_property(contacts_h contact, contacts_person_property_e property,
418 int person_id, int *id)
420 int ret = CONTACTS_ERROR_NONE;
421 pims_ipc_data_h indata = NULL;
422 pims_ipc_data_h outdata = NULL;
424 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
425 RETVM_IF(person_id <= 0 || id == NULL, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
429 indata = pims_ipc_data_create(0);
430 if (indata == NULL) {
431 CTS_ERR("ipc data created fail!");
432 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
436 ret = ctsvc_ipc_marshal_handle(contact, indata);
437 if (ret != CONTACTS_ERROR_NONE) {
438 CTS_ERR("ctsvc_ipc_marshal_handle Fail(%d)", ret);
439 pims_ipc_data_destroy(indata);
443 ret = ctsvc_ipc_marshal_int(person_id, indata);
444 if (ret != CONTACTS_ERROR_NONE) {
445 CTS_ERR("marshal fail");
446 pims_ipc_data_destroy(indata);
450 ret = ctsvc_ipc_marshal_unsigned_int(property, indata);
451 if (ret != CONTACTS_ERROR_NONE) {
452 CTS_ERR("marshal fail");
453 pims_ipc_data_destroy(indata);
458 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_GET_DEFAULT_PROPERTY,
459 indata, &outdata) != 0) {
460 CTS_ERR("ctsvc_ipc_call failed");
461 pims_ipc_data_destroy(indata);
462 return CONTACTS_ERROR_IPC;
465 pims_ipc_data_destroy(indata);
468 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
469 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
470 pims_ipc_data_destroy(outdata);
471 return CONTACTS_ERROR_IPC;
473 if (ret == CONTACTS_ERROR_NONE && id) {
474 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, id)) {
475 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
476 pims_ipc_data_destroy(outdata);
477 return CONTACTS_ERROR_IPC;
480 pims_ipc_data_destroy(outdata);