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("ctsvc_ipc_call failed");
81 pims_ipc_data_destroy(indata);
82 return CONTACTS_ERROR_IPC;
87 pims_ipc_data_destroy(indata);
93 unsigned int size = 0;
94 ret = *(int*) pims_ipc_data_get(outdata, &size);
96 if (CONTACTS_ERROR_NONE == ret) {
97 int transaction_ver = 0;
98 transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
99 ctsvc_client_ipc_set_change_version(transaction_ver);
102 pims_ipc_data_destroy(outdata);
108 API int contacts_person_unlink_contact(int person_id, int contact_id, int* unlinked_person_id)
110 int ret = CONTACTS_ERROR_NONE;
112 pims_ipc_data_h indata = NULL;
113 pims_ipc_data_h outdata = NULL;
115 RETVM_IF(person_id <= 0 || contact_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
116 RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");
118 if (unlinked_person_id)
119 *unlinked_person_id = 0;
122 indata = pims_ipc_data_create(0);
125 CTS_ERR("ipc data created fail!");
126 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
130 ret = ctsvc_ipc_marshal_int( person_id, indata);
131 if (ret != CONTACTS_ERROR_NONE)
133 CTS_ERR("marshal fail");
134 pims_ipc_data_destroy(indata);
137 ret = ctsvc_ipc_marshal_int( contact_id, indata);
138 if (ret != CONTACTS_ERROR_NONE)
140 CTS_ERR("marshal fail");
141 pims_ipc_data_destroy(indata);
146 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_UNLINK_CONTACT, indata, &outdata) != 0)
148 CTS_ERR("ctsvc_ipc_call failed");
149 pims_ipc_data_destroy(indata);
150 return CONTACTS_ERROR_IPC;
155 pims_ipc_data_destroy(indata);
161 unsigned int size = 0;
162 ret = *(int*) pims_ipc_data_get(outdata, &size);
164 if (CONTACTS_ERROR_NONE == ret) {
165 int transaction_ver = 0;
166 transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
167 ctsvc_client_ipc_set_change_version(transaction_ver);
169 if (unlinked_person_id)
170 *unlinked_person_id = *(int*)pims_ipc_data_get(outdata,&size);
173 pims_ipc_data_destroy(outdata);
179 API int contacts_person_reset_usage(int person_id, contacts_usage_type_e type)
181 int ret = CONTACTS_ERROR_NONE;
183 pims_ipc_data_h indata = NULL;
184 pims_ipc_data_h outdata = NULL;
186 RETVM_IF(person_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,"contact_id should be greater than 0");
187 RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");
190 indata = pims_ipc_data_create(0);
193 CTS_ERR("ipc data created fail!");
194 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
198 ret = ctsvc_ipc_marshal_int( person_id, indata);
199 if (ret != CONTACTS_ERROR_NONE)
201 CTS_ERR("marshal fail");
202 pims_ipc_data_destroy(indata);
205 ret = ctsvc_ipc_marshal_int( (int)type, indata);
206 if (ret != CONTACTS_ERROR_NONE)
208 CTS_ERR("marshal fail");
209 pims_ipc_data_destroy(indata);
214 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_RESET_USAGE, indata, &outdata) != 0)
216 CTS_ERR("ctsvc_ipc_call failed");
217 pims_ipc_data_destroy(indata);
218 return CONTACTS_ERROR_IPC;
223 pims_ipc_data_destroy(indata);
229 unsigned int size = 0;
230 ret = *(int*) pims_ipc_data_get(outdata, &size);
232 if (CONTACTS_ERROR_NONE == ret) {
233 int transaction_ver = 0;
234 transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
235 ctsvc_client_ipc_set_change_version(transaction_ver);
238 pims_ipc_data_destroy(outdata);
244 API int contacts_person_set_favorite_order(int person_id, int previous_person_id, int next_person_id)
246 int ret = CONTACTS_ERROR_NONE;
248 pims_ipc_data_h indata = NULL;
249 pims_ipc_data_h outdata = NULL;
251 RETVM_IF(person_id <= 0 || previous_person_id < 0 || next_person_id < 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
252 RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");
255 indata = pims_ipc_data_create(0);
258 CTS_ERR("ipc data created fail!");
259 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
263 ret = ctsvc_ipc_marshal_int( person_id, indata);
264 if (ret != CONTACTS_ERROR_NONE)
266 CTS_ERR("marshal fail");
267 pims_ipc_data_destroy(indata);
270 ret = ctsvc_ipc_marshal_int( previous_person_id, indata);
271 if (ret != CONTACTS_ERROR_NONE)
273 CTS_ERR("marshal fail");
274 pims_ipc_data_destroy(indata);
277 ret = ctsvc_ipc_marshal_int( next_person_id, indata);
278 if (ret != CONTACTS_ERROR_NONE)
280 CTS_ERR("marshal fail");
281 pims_ipc_data_destroy(indata);
286 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_SET_FAVORITE_ORDER, indata, &outdata) != 0)
288 CTS_ERR("ctsvc_ipc_call failed");
289 pims_ipc_data_destroy(indata);
290 return CONTACTS_ERROR_IPC;
295 pims_ipc_data_destroy(indata);
301 unsigned int size = 0;
302 ret = *(int*) pims_ipc_data_get(outdata, &size);
304 if (CONTACTS_ERROR_NONE == ret) {
305 int transaction_ver = 0;
306 transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
307 ctsvc_client_ipc_set_change_version(transaction_ver);
310 pims_ipc_data_destroy(outdata);
317 API int contacts_person_set_default_property(contacts_person_property_e property,
318 int person_id, int id)
320 int ret = CONTACTS_ERROR_NONE;
322 pims_ipc_data_h indata = NULL;
323 pims_ipc_data_h outdata = NULL;
325 RETVM_IF(person_id <= 0 || id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
326 RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");
329 indata = pims_ipc_data_create(0);
332 CTS_ERR("ipc data created fail!");
333 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
337 ret = ctsvc_ipc_marshal_int( person_id, indata);
338 if (ret != CONTACTS_ERROR_NONE)
340 CTS_ERR("marshal fail");
341 pims_ipc_data_destroy(indata);
344 ret = ctsvc_ipc_marshal_unsigned_int( property, indata);
345 if (ret != CONTACTS_ERROR_NONE)
347 CTS_ERR("marshal fail");
348 pims_ipc_data_destroy(indata);
351 ret = ctsvc_ipc_marshal_int( id, indata);
352 if (ret != CONTACTS_ERROR_NONE)
354 CTS_ERR("marshal fail");
355 pims_ipc_data_destroy(indata);
360 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_SET_DEFAULT_PROPERTY, indata, &outdata) != 0)
362 CTS_ERR("ctsvc_ipc_call failed");
363 pims_ipc_data_destroy(indata);
364 return CONTACTS_ERROR_IPC;
369 pims_ipc_data_destroy(indata);
375 unsigned int size = 0;
376 ret = *(int*) pims_ipc_data_get(outdata, &size);
377 if (CONTACTS_ERROR_NONE == ret) {
378 int transaction_ver = 0;
379 transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
380 ctsvc_client_ipc_set_change_version(transaction_ver);
383 pims_ipc_data_destroy(outdata);
389 API int contacts_person_get_default_property(contacts_person_property_e property,
390 int person_id, int *id)
392 int ret = CONTACTS_ERROR_NONE;
393 pims_ipc_data_h indata = NULL;
394 pims_ipc_data_h outdata = NULL;
396 RETVM_IF(person_id <= 0 || id == NULL, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
398 RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");
401 indata = pims_ipc_data_create(0);
402 if (indata == NULL) {
403 CTS_ERR("ipc data created fail!");
404 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
408 ret = ctsvc_ipc_marshal_int(person_id, indata);
409 if (ret != CONTACTS_ERROR_NONE) {
410 CTS_ERR("marshal fail");
411 pims_ipc_data_destroy(indata);
415 ret = ctsvc_ipc_marshal_unsigned_int(property, indata);
416 if (ret != CONTACTS_ERROR_NONE) {
417 CTS_ERR("marshal fail");
418 pims_ipc_data_destroy(indata);
423 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_GET_DEFAULT_PROPERTY,
424 indata, &outdata) != 0) {
425 CTS_ERR("ctsvc_ipc_call failed");
426 pims_ipc_data_destroy(indata);
427 return CONTACTS_ERROR_IPC;
431 pims_ipc_data_destroy(indata);
436 unsigned int size = 0;
437 ret = *(int*) pims_ipc_data_get(outdata, &size);
438 if (ret == CONTACTS_ERROR_NONE) {
440 *id = *(int*)pims_ipc_data_get(outdata,&size);
442 pims_ipc_data_destroy(outdata);