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.
21 #include "ctsvc_internal.h"
22 #include "ctsvc_ipc_define.h"
23 #include "ctsvc_client_ipc.h"
24 #include <pims-ipc-data.h>
25 #include "ctsvc_ipc_marshal.h"
28 int ctsvc_client_group_add_contact(contacts_h contact, int group_id, int contact_id)
30 int ret = CONTACTS_ERROR_NONE;
32 pims_ipc_data_h indata = NULL;
33 pims_ipc_data_h outdata = NULL;
35 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
36 RETVM_IF(group_id <= 0 || contact_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER, "id should be greater than 0");
39 indata = pims_ipc_data_create(0);
42 ERR("pims_ipc_data_create() Fail");
43 return CONTACTS_ERROR_OUT_OF_MEMORY;
47 ret = ctsvc_ipc_marshal_handle(contact, indata);
48 if (CONTACTS_ERROR_NONE != ret) {
50 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
51 pims_ipc_data_destroy(indata);
56 ret = ctsvc_ipc_marshal_int(group_id, indata);
57 if (ret != CONTACTS_ERROR_NONE) {
59 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
60 pims_ipc_data_destroy(indata);
64 ret = ctsvc_ipc_marshal_int(contact_id, indata);
65 if (ret != CONTACTS_ERROR_NONE) {
67 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
68 pims_ipc_data_destroy(indata);
74 if (ctsvc_ipc_call(CTSVC_IPC_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_ADD_CONTACT, indata, &outdata) != 0) {
76 ERR("ctsvc_ipc_call() Fail");
77 pims_ipc_data_destroy(indata);
78 return CONTACTS_ERROR_IPC;
82 pims_ipc_data_destroy(indata);
85 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
87 ERR("ctsvc_ipc_unmarshal_int() Fail");
88 pims_ipc_data_destroy(outdata);
89 return CONTACTS_ERROR_IPC;
93 if (CONTACTS_ERROR_NONE == ret) {
94 int transaction_ver = 0;
95 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
97 ERR("ctsvc_ipc_unmarshal_int() Fail");
98 pims_ipc_data_destroy(outdata);
99 return CONTACTS_ERROR_IPC;
102 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
105 pims_ipc_data_destroy(outdata);
111 int ctsvc_client_group_remove_contact(contacts_h contact, int group_id, int contact_id)
113 int ret = CONTACTS_ERROR_NONE;
115 pims_ipc_data_h indata = NULL;
116 pims_ipc_data_h outdata = NULL;
118 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
119 RETVM_IF(group_id <= 0 || contact_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER, "id should be greater than 0");
122 indata = pims_ipc_data_create(0);
123 if (indata == NULL) {
124 /* LCOV_EXCL_START */
125 ERR("pims_ipc_data_create() Fail");
126 return CONTACTS_ERROR_OUT_OF_MEMORY;
130 ret = ctsvc_ipc_marshal_handle(contact, indata);
131 if (CONTACTS_ERROR_NONE != ret) {
132 /* LCOV_EXCL_START */
133 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
134 pims_ipc_data_destroy(indata);
140 ret = ctsvc_ipc_marshal_int(group_id, indata);
141 if (ret != CONTACTS_ERROR_NONE) {
142 /* LCOV_EXCL_START */
143 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
144 pims_ipc_data_destroy(indata);
148 ret = ctsvc_ipc_marshal_int(contact_id, indata);
149 if (ret != CONTACTS_ERROR_NONE) {
150 /* LCOV_EXCL_START */
151 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
152 pims_ipc_data_destroy(indata);
158 if (ctsvc_ipc_call(CTSVC_IPC_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_REMOVE_CONTACT, indata, &outdata) != 0) {
159 /* LCOV_EXCL_START */
160 ERR("ctsvc_ipc_call() Fail");
161 pims_ipc_data_destroy(indata);
162 return CONTACTS_ERROR_IPC;
166 pims_ipc_data_destroy(indata);
169 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
170 /* LCOV_EXCL_START */
171 ERR("ctsvc_ipc_unmarshal_int() Fail");
172 pims_ipc_data_destroy(outdata);
173 return CONTACTS_ERROR_IPC;
177 if (CONTACTS_ERROR_NONE == ret) {
178 int transaction_ver = 0;
179 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
180 /* LCOV_EXCL_START */
181 ERR("ctsvc_ipc_unmarshal_int() Fail");
182 pims_ipc_data_destroy(outdata);
183 return CONTACTS_ERROR_IPC;
186 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
189 pims_ipc_data_destroy(outdata);
195 int ctsvc_client_group_set_group_order(contacts_h contact, int group_id, int previous_group_id, int next_group_id)
197 int ret = CONTACTS_ERROR_NONE;
199 pims_ipc_data_h indata = NULL;
200 pims_ipc_data_h outdata = NULL;
202 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
203 RETVM_IF(group_id <= 0 || previous_group_id < 0 || next_group_id < 0, CONTACTS_ERROR_INVALID_PARAMETER, "id should be greater than 0");
206 indata = pims_ipc_data_create(0);
207 if (indata == NULL) {
208 /* LCOV_EXCL_START */
209 ERR("pims_ipc_data_create() Fail");
210 return CONTACTS_ERROR_OUT_OF_MEMORY;
214 ret = ctsvc_ipc_marshal_handle(contact, indata);
215 if (CONTACTS_ERROR_NONE != ret) {
216 /* LCOV_EXCL_START */
217 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
218 pims_ipc_data_destroy(indata);
223 ret = ctsvc_ipc_marshal_int(group_id, indata);
224 if (ret != CONTACTS_ERROR_NONE) {
225 /* LCOV_EXCL_START */
226 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
227 pims_ipc_data_destroy(indata);
231 ret = ctsvc_ipc_marshal_int(previous_group_id, indata);
232 if (ret != CONTACTS_ERROR_NONE) {
233 /* LCOV_EXCL_START */
234 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
235 pims_ipc_data_destroy(indata);
239 ret = ctsvc_ipc_marshal_int(next_group_id, indata);
240 if (ret != CONTACTS_ERROR_NONE) {
241 /* LCOV_EXCL_START */
242 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
243 pims_ipc_data_destroy(indata);
249 if (ctsvc_ipc_call(CTSVC_IPC_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_SET_GROUP_ORDER, indata, &outdata) != 0) {
250 /* LCOV_EXCL_START */
251 ERR("ctsvc_ipc_call() Fail");
252 pims_ipc_data_destroy(indata);
253 return CONTACTS_ERROR_IPC;
257 pims_ipc_data_destroy(indata);
260 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
261 /* LCOV_EXCL_START */
262 ERR("ctsvc_ipc_unmarshal_int() Fail");
263 pims_ipc_data_destroy(outdata);
264 return CONTACTS_ERROR_IPC;
268 if (CONTACTS_ERROR_NONE == ret) {
269 int transaction_ver = 0;
270 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
271 /* LCOV_EXCL_START */
272 ERR("ctsvc_ipc_unmarshal_int() Fail");
273 pims_ipc_data_destroy(outdata);
274 return CONTACTS_ERROR_IPC;
277 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
280 pims_ipc_data_destroy(outdata);