4 * Copyright (c) 2010 - 2012 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.
23 #include "ctsvc_internal.h"
24 #include "ctsvc_ipc_define.h"
25 #include "ctsvc_client_ipc.h"
26 #include <pims-ipc-data.h>
27 #include "ctsvc_ipc_marshal.h"
29 API int contacts_person_link_person(int base_person_id, int person_id)
32 int ret = CONTACTS_ERROR_NONE;
34 pims_ipc_data_h indata = NULL;
35 pims_ipc_data_h outdata = NULL;
37 RETVM_IF(base_person_id <= 0 || person_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
38 RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");
41 indata = pims_ipc_data_create(0);
44 CTS_ERR("ipc data created fail!");
45 return CONTACTS_ERROR_OUT_OF_MEMORY;
50 if( ctsvc_ipc_marshal_int( base_person_id, indata) != CONTACTS_ERROR_NONE ) break;
51 if( ctsvc_ipc_marshal_int( person_id, indata) != CONTACTS_ERROR_NONE ) break;
56 if( success == false ) {
57 CTS_ERR("marshal fail");
58 pims_ipc_data_destroy(indata);
59 return CONTACTS_ERROR_IPC;
63 ret = ctsvc_ipc_marshal_int( base_person_id, indata);
64 if (ret != CONTACTS_ERROR_NONE)
66 CTS_ERR("marshal fail");
69 ret = ctsvc_ipc_marshal_int( person_id, indata);
70 if (ret != CONTACTS_ERROR_NONE)
72 CTS_ERR("marshal fail");
78 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_LINK_PERSON, indata, &outdata) != 0)
80 CTS_ERR("pims_ipc_call failed");
81 return CONTACTS_ERROR_IPC;
86 pims_ipc_data_destroy(indata);
92 unsigned int size = 0;
93 ret = *(int*) pims_ipc_data_get(outdata, &size);
95 pims_ipc_data_destroy(outdata);
101 API int contacts_person_unlink_contact(int person_id, int contact_id, int* unlinked_person_id)
103 int ret = CONTACTS_ERROR_NONE;
105 pims_ipc_data_h indata = NULL;
106 pims_ipc_data_h outdata = NULL;
108 RETVM_IF(person_id <= 0 || contact_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
109 RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");
111 if (unlinked_person_id)
112 *unlinked_person_id = 0;
115 indata = pims_ipc_data_create(0);
118 CTS_ERR("ipc data created fail!");
119 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
123 ret = ctsvc_ipc_marshal_int( person_id, indata);
124 if (ret != CONTACTS_ERROR_NONE)
126 CTS_ERR("marshal fail");
127 pims_ipc_data_destroy(indata);
130 ret = ctsvc_ipc_marshal_int( contact_id, indata);
131 if (ret != CONTACTS_ERROR_NONE)
133 CTS_ERR("marshal fail");
134 pims_ipc_data_destroy(indata);
139 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_UNLINK_CONTACT, indata, &outdata) != 0)
141 CTS_ERR("pims_ipc_call failed");
142 pims_ipc_data_destroy(indata);
143 return CONTACTS_ERROR_IPC;
148 pims_ipc_data_destroy(indata);
154 unsigned int size = 0;
155 ret = *(int*) pims_ipc_data_get(outdata, &size);
157 if (CONTACTS_ERROR_NONE == ret) {
158 if (unlinked_person_id)
159 *unlinked_person_id = *(int*)pims_ipc_data_get(outdata,&size);
162 pims_ipc_data_destroy(outdata);
168 API int contacts_person_reset_usage(int person_id, contacts_usage_type_e type)
170 int ret = CONTACTS_ERROR_NONE;
172 pims_ipc_data_h indata = NULL;
173 pims_ipc_data_h outdata = NULL;
175 RETVM_IF(person_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,"contact_id should be greater than 0");
176 RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");
179 indata = pims_ipc_data_create(0);
182 CTS_ERR("ipc data created fail!");
183 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
187 ret = ctsvc_ipc_marshal_int( person_id, indata);
188 if (ret != CONTACTS_ERROR_NONE)
190 CTS_ERR("marshal fail");
191 pims_ipc_data_destroy(indata);
194 ret = ctsvc_ipc_marshal_int( (int)type, indata);
195 if (ret != CONTACTS_ERROR_NONE)
197 CTS_ERR("marshal fail");
198 pims_ipc_data_destroy(indata);
203 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_RESET_USAGE, indata, &outdata) != 0)
205 CTS_ERR("pims_ipc_call failed");
206 pims_ipc_data_destroy(indata);
207 return CONTACTS_ERROR_IPC;
212 pims_ipc_data_destroy(indata);
218 unsigned int size = 0;
219 ret = *(int*) pims_ipc_data_get(outdata, &size);
221 pims_ipc_data_destroy(outdata);
227 API int contacts_person_set_favorite_order(int person_id, int previous_person_id, int next_person_id)
229 int ret = CONTACTS_ERROR_NONE;
231 pims_ipc_data_h indata = NULL;
232 pims_ipc_data_h outdata = NULL;
234 RETVM_IF(person_id <= 0 || previous_person_id < 0 || next_person_id < 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
235 RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");
238 indata = pims_ipc_data_create(0);
241 CTS_ERR("ipc data created fail!");
242 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
246 ret = ctsvc_ipc_marshal_int( person_id, indata);
247 if (ret != CONTACTS_ERROR_NONE)
249 CTS_ERR("marshal fail");
250 pims_ipc_data_destroy(indata);
253 ret = ctsvc_ipc_marshal_int( previous_person_id, indata);
254 if (ret != CONTACTS_ERROR_NONE)
256 CTS_ERR("marshal fail");
257 pims_ipc_data_destroy(indata);
260 ret = ctsvc_ipc_marshal_int( next_person_id, indata);
261 if (ret != CONTACTS_ERROR_NONE)
263 CTS_ERR("marshal fail");
264 pims_ipc_data_destroy(indata);
269 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_SET_FAVORITE_ORDER, indata, &outdata) != 0)
271 CTS_ERR("pims_ipc_call failed");
272 return CONTACTS_ERROR_IPC;
277 pims_ipc_data_destroy(indata);
283 unsigned int size = 0;
284 ret = *(int*) pims_ipc_data_get(outdata, &size);
286 pims_ipc_data_destroy(outdata);
293 API int contacts_person_set_default_property(contacts_person_property_e property,
294 int person_id, int id)
296 int ret = CONTACTS_ERROR_NONE;
298 pims_ipc_data_h indata = NULL;
299 pims_ipc_data_h outdata = NULL;
301 RETVM_IF(person_id <= 0 || id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
302 RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");
305 indata = pims_ipc_data_create(0);
308 CTS_ERR("ipc data created fail!");
309 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
313 ret = ctsvc_ipc_marshal_int( person_id, indata);
314 if (ret != CONTACTS_ERROR_NONE)
316 CTS_ERR("marshal fail");
317 pims_ipc_data_destroy(indata);
320 ret = ctsvc_ipc_marshal_unsigned_int( property, indata);
321 if (ret != CONTACTS_ERROR_NONE)
323 CTS_ERR("marshal fail");
324 pims_ipc_data_destroy(indata);
327 ret = ctsvc_ipc_marshal_int( id, indata);
328 if (ret != CONTACTS_ERROR_NONE)
330 CTS_ERR("marshal fail");
331 pims_ipc_data_destroy(indata);
336 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_SET_DEFAULT_PROPERTY, indata, &outdata) != 0)
338 CTS_ERR("pims_ipc_call failed");
339 pims_ipc_data_destroy(indata);
340 return CONTACTS_ERROR_IPC;
345 pims_ipc_data_destroy(indata);
351 unsigned int size = 0;
352 ret = *(int*) pims_ipc_data_get(outdata, &size);
354 pims_ipc_data_destroy(outdata);
360 API int contacts_person_get_default_property(contacts_person_property_e property,
361 int person_id, int *id)
363 int ret = CONTACTS_ERROR_NONE;
364 pims_ipc_data_h indata = NULL;
365 pims_ipc_data_h outdata = NULL;
367 RETVM_IF(person_id <= 0 || id == NULL, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
369 RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");
372 indata = pims_ipc_data_create(0);
373 if (indata == NULL) {
374 CTS_ERR("ipc data created fail!");
375 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
379 ret = ctsvc_ipc_marshal_int(person_id, indata);
380 if (ret != CONTACTS_ERROR_NONE) {
381 CTS_ERR("marshal fail");
382 pims_ipc_data_destroy(indata);
386 ret = ctsvc_ipc_marshal_unsigned_int(property, indata);
387 if (ret != CONTACTS_ERROR_NONE) {
388 CTS_ERR("marshal fail");
389 pims_ipc_data_destroy(indata);
394 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_GET_DEFAULT_PROPERTY,
395 indata, &outdata) != 0) {
396 CTS_ERR("pims_ipc_call failed");
397 pims_ipc_data_destroy(indata);
398 return CONTACTS_ERROR_IPC;
402 pims_ipc_data_destroy(indata);
407 unsigned int size = 0;
408 ret = *(int*) pims_ipc_data_get(outdata, &size);
409 if (ret == CONTACTS_ERROR_NONE) {
411 *id = *(int*)pims_ipc_data_get(outdata,&size);
413 pims_ipc_data_destroy(outdata);