Remove async APIs same as 2.4
[platform/core/pim/contacts-service.git] / client / ctsvc_client_person.c
1 /*
2  * Contacts Service
3  *
4  * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19
20 #include <glib.h>
21 #include <pims-ipc-data.h>
22
23 #include "contacts.h"
24 #include "ctsvc_internal.h"
25 #include "ctsvc_ipc_define.h"
26 #include "ctsvc_client_ipc.h"
27 #include "ctsvc_ipc_marshal.h"
28
29 API int contacts_person_link_person(int base_person_id, int person_id)
30 {
31
32         int ret = CONTACTS_ERROR_NONE;
33
34         pims_ipc_data_h indata = NULL;
35         pims_ipc_data_h outdata = NULL;
36
37         RETVM_IF(base_person_id <= 0 || person_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
38
39         // make indata
40         indata = pims_ipc_data_create(0);
41         if (indata == NULL)
42         {
43                 CTS_ERR("ipc data created fail!");
44                 return CONTACTS_ERROR_OUT_OF_MEMORY;
45         }
46
47         bool success = false;
48         do {
49                 if( ctsvc_ipc_marshal_int( base_person_id, indata) != CONTACTS_ERROR_NONE ) break;
50                 if( ctsvc_ipc_marshal_int( person_id, indata) != CONTACTS_ERROR_NONE ) break;
51
52                 success = true;
53         } while(0);
54
55         if( success == false ) {
56                 CTS_ERR("marshal fail");
57                 pims_ipc_data_destroy(indata);
58                 return CONTACTS_ERROR_IPC;
59         }
60
61 /*
62         ret = ctsvc_ipc_marshal_int( base_person_id, indata);
63         if (ret != CONTACTS_ERROR_NONE)
64         {
65                 CTS_ERR("marshal fail");
66                 return ret;
67         }
68         ret = ctsvc_ipc_marshal_int( person_id, indata);
69         if (ret != CONTACTS_ERROR_NONE)
70         {
71                 CTS_ERR("marshal fail");
72                 return ret;
73         }
74 */
75
76         // ipc call
77         if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_LINK_PERSON, indata, &outdata) != 0)
78         {
79                 CTS_ERR("ctsvc_ipc_call failed");
80                 pims_ipc_data_destroy(indata);
81                 return CONTACTS_ERROR_IPC;
82         }
83
84         pims_ipc_data_destroy(indata);
85
86         if (outdata)
87         {
88                 // check result
89                 unsigned int size = 0;
90                 ret = *(int*) pims_ipc_data_get(outdata, &size);
91
92                 if (CONTACTS_ERROR_NONE == ret) {
93                         int transaction_ver = 0;
94                         transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
95                         ctsvc_client_ipc_set_change_version(transaction_ver);
96                 }
97
98                 pims_ipc_data_destroy(outdata);
99         }
100
101         return ret;
102 }
103
104 API int contacts_person_unlink_contact(int person_id, int contact_id, int* unlinked_person_id)
105 {
106         int ret = CONTACTS_ERROR_NONE;
107
108         pims_ipc_data_h indata = NULL;
109         pims_ipc_data_h outdata = NULL;
110
111         RETVM_IF(person_id <= 0 || contact_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
112
113         if (unlinked_person_id)
114                 *unlinked_person_id = 0;
115
116         // make indata
117         indata = pims_ipc_data_create(0);
118         if (indata == NULL)
119         {
120                 CTS_ERR("ipc data created fail!");
121                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
122                 return ret;
123         }
124
125         ret = ctsvc_ipc_marshal_int( person_id, indata);
126         if (ret != CONTACTS_ERROR_NONE)
127         {
128                 CTS_ERR("marshal fail");
129                 pims_ipc_data_destroy(indata);
130                 return ret;
131         }
132         ret = ctsvc_ipc_marshal_int( contact_id, indata);
133         if (ret != CONTACTS_ERROR_NONE)
134         {
135                 CTS_ERR("marshal fail");
136                 pims_ipc_data_destroy(indata);
137                 return ret;
138         }
139
140         // ipc call
141         if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_UNLINK_CONTACT, indata, &outdata) != 0)
142         {
143                 CTS_ERR("ctsvc_ipc_call failed");
144                 pims_ipc_data_destroy(indata);
145                 return CONTACTS_ERROR_IPC;
146         }
147
148         pims_ipc_data_destroy(indata);
149
150         if (outdata)
151         {
152                 // check result
153                 unsigned int size = 0;
154                 ret = *(int*) pims_ipc_data_get(outdata, &size);
155
156                 if (CONTACTS_ERROR_NONE == ret) {
157                         int transaction_ver = 0;
158                         transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
159                         ctsvc_client_ipc_set_change_version(transaction_ver);
160
161                         if (unlinked_person_id)
162                                 *unlinked_person_id = *(int*)pims_ipc_data_get(outdata,&size);
163                 }
164
165                 pims_ipc_data_destroy(outdata);
166         }
167
168         return ret;
169 }
170
171 API int contacts_person_reset_usage(int person_id, contacts_usage_type_e type)
172 {
173         int ret = CONTACTS_ERROR_NONE;
174
175         pims_ipc_data_h indata = NULL;
176         pims_ipc_data_h outdata = NULL;
177
178         RETVM_IF(person_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,"contact_id should be greater than 0");
179
180         // make indata
181         indata = pims_ipc_data_create(0);
182         if (indata == NULL)
183         {
184                 CTS_ERR("ipc data created fail!");
185                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
186                 return ret;
187         }
188
189         ret = ctsvc_ipc_marshal_int( person_id, indata);
190         if (ret != CONTACTS_ERROR_NONE)
191         {
192                 CTS_ERR("marshal fail");
193                 pims_ipc_data_destroy(indata);
194                 return ret;
195         }
196         ret = ctsvc_ipc_marshal_int( (int)type, indata);
197         if (ret != CONTACTS_ERROR_NONE)
198         {
199                 CTS_ERR("marshal fail");
200                 pims_ipc_data_destroy(indata);
201                 return ret;
202         }
203
204         // ipc call
205         if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_RESET_USAGE, indata, &outdata) != 0)
206         {
207                 CTS_ERR("ctsvc_ipc_call failed");
208                 pims_ipc_data_destroy(indata);
209                 return CONTACTS_ERROR_IPC;
210         }
211
212         pims_ipc_data_destroy(indata);
213
214         if (outdata)
215         {
216                 // check result
217                 unsigned int size = 0;
218                 ret = *(int*) pims_ipc_data_get(outdata, &size);
219
220                 if (CONTACTS_ERROR_NONE == ret) {
221                         int transaction_ver = 0;
222                         transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
223                         ctsvc_client_ipc_set_change_version(transaction_ver);
224                 }
225
226                 pims_ipc_data_destroy(outdata);
227         }
228
229         return ret;
230 }
231
232 API int contacts_person_set_favorite_order(int person_id, int previous_person_id, int next_person_id)
233 {
234         int ret = CONTACTS_ERROR_NONE;
235
236         pims_ipc_data_h indata = NULL;
237         pims_ipc_data_h outdata = NULL;
238
239         RETVM_IF(person_id <= 0 || previous_person_id < 0 || next_person_id < 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
240
241         // make indata
242         indata = pims_ipc_data_create(0);
243         if (indata == NULL)
244         {
245                 CTS_ERR("ipc data created fail!");
246                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
247                 return ret;
248         }
249
250         ret = ctsvc_ipc_marshal_int( person_id, indata);
251         if (ret != CONTACTS_ERROR_NONE)
252         {
253                 CTS_ERR("marshal fail");
254                 pims_ipc_data_destroy(indata);
255                 return ret;
256         }
257         ret = ctsvc_ipc_marshal_int( previous_person_id, indata);
258         if (ret != CONTACTS_ERROR_NONE)
259         {
260                 CTS_ERR("marshal fail");
261                 pims_ipc_data_destroy(indata);
262                 return ret;
263         }
264         ret = ctsvc_ipc_marshal_int( next_person_id, indata);
265         if (ret != CONTACTS_ERROR_NONE)
266         {
267                 CTS_ERR("marshal fail");
268                 pims_ipc_data_destroy(indata);
269                 return ret;
270         }
271
272         // ipc call
273         if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_SET_FAVORITE_ORDER, indata, &outdata) != 0)
274         {
275                 CTS_ERR("ctsvc_ipc_call failed");
276                 pims_ipc_data_destroy(indata);
277                 return CONTACTS_ERROR_IPC;
278         }
279
280         pims_ipc_data_destroy(indata);
281
282         if (outdata)
283         {
284                 // check result
285                 unsigned int size = 0;
286                 ret = *(int*) pims_ipc_data_get(outdata, &size);
287
288                 if (CONTACTS_ERROR_NONE == ret) {
289                         int transaction_ver = 0;
290                         transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
291                         ctsvc_client_ipc_set_change_version(transaction_ver);
292                 }
293
294                 pims_ipc_data_destroy(outdata);
295         }
296
297         return ret;
298
299 }
300
301 API int contacts_person_set_default_property(contacts_person_property_e property,
302                 int person_id, int id)
303 {
304         int ret = CONTACTS_ERROR_NONE;
305
306         pims_ipc_data_h indata = NULL;
307         pims_ipc_data_h outdata = NULL;
308
309         RETVM_IF(person_id <= 0 || id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
310
311         // make indata
312         indata = pims_ipc_data_create(0);
313         if (indata == NULL)
314         {
315                 CTS_ERR("ipc data created fail!");
316                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
317                 return ret;
318         }
319
320         ret = ctsvc_ipc_marshal_int( person_id, indata);
321         if (ret != CONTACTS_ERROR_NONE)
322         {
323                 CTS_ERR("marshal fail");
324                 pims_ipc_data_destroy(indata);
325                 return ret;
326         }
327         ret = ctsvc_ipc_marshal_unsigned_int( property, indata);
328         if (ret != CONTACTS_ERROR_NONE)
329         {
330                 CTS_ERR("marshal fail");
331                 pims_ipc_data_destroy(indata);
332                 return ret;
333         }
334         ret = ctsvc_ipc_marshal_int( id, indata);
335         if (ret != CONTACTS_ERROR_NONE)
336         {
337                 CTS_ERR("marshal fail");
338                 pims_ipc_data_destroy(indata);
339                 return ret;
340         }
341
342         // ipc call
343         if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_SET_DEFAULT_PROPERTY, indata, &outdata) != 0)
344         {
345                 CTS_ERR("ctsvc_ipc_call failed");
346                 pims_ipc_data_destroy(indata);
347                 return CONTACTS_ERROR_IPC;
348         }
349
350         pims_ipc_data_destroy(indata);
351
352         if (outdata)
353         {
354                 // check result
355                 unsigned int size = 0;
356                 ret = *(int*) pims_ipc_data_get(outdata, &size);
357                 if (CONTACTS_ERROR_NONE == ret) {
358                         int transaction_ver = 0;
359                         transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
360                         ctsvc_client_ipc_set_change_version(transaction_ver);
361                 }
362
363                 pims_ipc_data_destroy(outdata);
364         }
365
366         return ret;
367 }
368
369 API int contacts_person_get_default_property(contacts_person_property_e property,
370                 int person_id, int *id)
371 {
372         int ret = CONTACTS_ERROR_NONE;
373         pims_ipc_data_h indata = NULL;
374         pims_ipc_data_h outdata = NULL;
375
376         RETVM_IF(person_id <= 0 || id == NULL, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
377         *id = 0;
378
379         // make indata
380         indata = pims_ipc_data_create(0);
381         if (indata == NULL) {
382                 CTS_ERR("ipc data created fail!");
383                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
384                 return ret;
385         }
386
387         ret = ctsvc_ipc_marshal_int(person_id, indata);
388         if (ret != CONTACTS_ERROR_NONE) {
389                 CTS_ERR("marshal fail");
390                 pims_ipc_data_destroy(indata);
391                 return ret;
392         }
393
394         ret = ctsvc_ipc_marshal_unsigned_int(property, indata);
395         if (ret != CONTACTS_ERROR_NONE) {
396                 CTS_ERR("marshal fail");
397                 pims_ipc_data_destroy(indata);
398                 return ret;
399         }
400
401         // ipc call
402         if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_GET_DEFAULT_PROPERTY,
403                                 indata, &outdata) != 0) {
404                 CTS_ERR("ctsvc_ipc_call failed");
405                 pims_ipc_data_destroy(indata);
406                 return CONTACTS_ERROR_IPC;
407         }
408
409         pims_ipc_data_destroy(indata);
410
411         if (outdata) {
412                 // check result
413                 unsigned int size = 0;
414                 ret = *(int*) pims_ipc_data_get(outdata, &size);
415                 if (ret == CONTACTS_ERROR_NONE) {
416                         if (id)
417                                 *id = *(int*)pims_ipc_data_get(outdata,&size);
418                 }
419                 pims_ipc_data_destroy(outdata);
420         }
421
422         return ret;
423 }
424