Remove async APIs same as 2.4
[platform/core/pim/contacts-service.git] / client / ctsvc_client_group.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
22 #include "contacts.h"
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"
28
29 API int contacts_group_add_contact(int group_id, int contact_id)
30 {
31         int ret = CONTACTS_ERROR_NONE;
32
33         pims_ipc_data_h indata = NULL;
34         pims_ipc_data_h outdata = NULL;
35
36         RETVM_IF(group_id <= 0 || contact_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
37
38         // make indata
39         indata = pims_ipc_data_create(0);
40         if (indata == NULL)
41         {
42                 CTS_ERR("ipc data created fail!");
43                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
44                 return ret;
45         }
46
47         ret = ctsvc_ipc_marshal_int( group_id, indata);
48         if (ret != CONTACTS_ERROR_NONE)
49         {
50                 CTS_ERR("marshal fail");
51                 pims_ipc_data_destroy(indata);
52                 return ret;
53         }
54         ret = ctsvc_ipc_marshal_int( contact_id, indata);
55         if (ret != CONTACTS_ERROR_NONE)
56         {
57                 CTS_ERR("marshal fail");
58                 pims_ipc_data_destroy(indata);
59                 return ret;
60         }
61
62         // ipc call
63         if (ctsvc_ipc_call(CTSVC_IPC_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_ADD_CONTACT, indata, &outdata) != 0)
64         {
65                 CTS_ERR("ctsvc_ipc_call failed");
66                 pims_ipc_data_destroy(indata);
67                 return CONTACTS_ERROR_IPC;
68         }
69
70         pims_ipc_data_destroy(indata);
71
72         if (outdata)
73         {
74                 // check result
75                 unsigned int size = 0;
76                 ret = *(int*) pims_ipc_data_get(outdata, &size);
77
78                 if (CONTACTS_ERROR_NONE == ret) {
79                         int transaction_ver = 0;
80                         transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
81                         ctsvc_client_ipc_set_change_version(transaction_ver);
82                 }
83
84                 pims_ipc_data_destroy(outdata);
85         }
86
87         return ret;
88 }
89
90 API int contacts_group_remove_contact(int group_id, int contact_id)
91 {
92         int ret = CONTACTS_ERROR_NONE;
93
94         pims_ipc_data_h indata = NULL;
95         pims_ipc_data_h outdata = NULL;
96
97         RETVM_IF(group_id <= 0 || contact_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
98
99         // make indata
100         indata = pims_ipc_data_create(0);
101         if (indata == NULL)
102         {
103                 CTS_ERR("ipc data created fail!");
104                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
105                 return ret;
106         }
107
108         ret = ctsvc_ipc_marshal_int( group_id, indata);
109         if (ret != CONTACTS_ERROR_NONE)
110         {
111                 CTS_ERR("marshal fail");
112                 pims_ipc_data_destroy(indata);
113                 return ret;
114         }
115         ret = ctsvc_ipc_marshal_int( contact_id, indata);
116         if (ret != CONTACTS_ERROR_NONE)
117         {
118                 CTS_ERR("marshal fail");
119                 pims_ipc_data_destroy(indata);
120                 return ret;
121         }
122
123         // ipc call
124         if (ctsvc_ipc_call(CTSVC_IPC_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_REMOVE_CONTACT, indata, &outdata) != 0)
125         {
126                 CTS_ERR("ctsvc_ipc_call failed");
127                 pims_ipc_data_destroy(indata);
128                 return CONTACTS_ERROR_IPC;
129         }
130
131         pims_ipc_data_destroy(indata);
132
133         if (outdata)
134         {
135                 // check result
136                 unsigned int size = 0;
137                 ret = *(int*) pims_ipc_data_get(outdata, &size);
138
139                 if (CONTACTS_ERROR_NONE == ret) {
140                         int transaction_ver = 0;
141                         transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
142                         ctsvc_client_ipc_set_change_version(transaction_ver);
143                 }
144
145                 pims_ipc_data_destroy(outdata);
146         }
147
148         return ret;
149 }
150
151 API int contacts_group_set_group_order(int group_id, int previous_group_id, int next_group_id)
152 {
153         int ret = CONTACTS_ERROR_NONE;
154
155         pims_ipc_data_h indata = NULL;
156         pims_ipc_data_h outdata = NULL;
157
158         RETVM_IF(group_id <= 0 || previous_group_id < 0 || next_group_id < 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
159
160         // make indata
161         indata = pims_ipc_data_create(0);
162         if (indata == NULL)
163         {
164                 CTS_ERR("ipc data created fail!");
165                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
166                 return ret;
167         }
168
169         ret = ctsvc_ipc_marshal_int( group_id, indata);
170         if (ret != CONTACTS_ERROR_NONE)
171         {
172                 CTS_ERR("marshal fail");
173                 pims_ipc_data_destroy(indata);
174                 return ret;
175         }
176         ret = ctsvc_ipc_marshal_int( previous_group_id, indata);
177         if (ret != CONTACTS_ERROR_NONE)
178         {
179                 CTS_ERR("marshal fail");
180                 pims_ipc_data_destroy(indata);
181                 return ret;
182         }
183         ret = ctsvc_ipc_marshal_int( next_group_id, indata);
184         if (ret != CONTACTS_ERROR_NONE)
185         {
186                 CTS_ERR("marshal fail");
187                 pims_ipc_data_destroy(indata);
188                 return ret;
189         }
190
191         // ipc call
192         if (ctsvc_ipc_call(CTSVC_IPC_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_SET_GROUP_ORDER, indata, &outdata) != 0)
193         {
194                 CTS_ERR("ctsvc_ipc_call failed");
195                 pims_ipc_data_destroy(indata);
196                 return CONTACTS_ERROR_IPC;
197         }
198
199         pims_ipc_data_destroy(indata);
200
201         if (outdata)
202         {
203                 // check result
204                 unsigned int size = 0;
205                 ret = *(int*) pims_ipc_data_get(outdata, &size);
206
207                 if (CONTACTS_ERROR_NONE == ret) {
208                         int transaction_ver = 0;
209                         transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
210                         ctsvc_client_ipc_set_change_version(transaction_ver);
211                 }
212
213                 pims_ipc_data_destroy(outdata);
214         }
215
216         return ret;
217
218 }
219