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 static const char CONTACTS_READ_PRIVILEGE_ID[] = "http://tizen.org/privilege/contact.read";
29 static const char CONTACTS_WRITE_PRIVILEGE_ID[] = "http://tizen.org/privilege/contact.write";
30 static const char PHONELOG_READ_PRIVILEGE_ID[] = "http://tizen.org/privilege/callhistory.read";
31 static const char PHONELOG_WRITE_PRIVILEGE_ID[] = "http://tizen.org/privilege/callhistory.write";
33 int ctsvc_client_group_add_contact(contacts_h contact, int group_id, int contact_id)
35 int ret = CONTACTS_ERROR_NONE;
37 pims_ipc_data_h indata = NULL;
38 pims_ipc_data_h outdata = NULL;
40 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
41 RETVM_IF(group_id <= 0 || contact_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER, "id should be greater than 0");
44 indata = pims_ipc_data_create(0);
47 ERR("pims_ipc_data_create() Fail");
48 return CONTACTS_ERROR_OUT_OF_MEMORY;
52 ret = ctsvc_ipc_marshal_handle(contact, indata);
53 if (CONTACTS_ERROR_NONE != ret) {
55 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
56 pims_ipc_data_destroy(indata);
61 ret = ctsvc_ipc_marshal_int(group_id, indata);
62 if (ret != CONTACTS_ERROR_NONE) {
64 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
65 pims_ipc_data_destroy(indata);
69 ret = ctsvc_ipc_marshal_int(contact_id, indata);
70 if (ret != CONTACTS_ERROR_NONE) {
72 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
73 pims_ipc_data_destroy(indata);
79 if (ctsvc_ipc_call(CTSVC_IPC_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_ADD_CONTACT, indata, &outdata) != 0) {
81 ERR("ctsvc_ipc_call() Fail");
82 pims_ipc_data_destroy(indata);
83 return CONTACTS_ERROR_IPC;
87 pims_ipc_data_destroy(indata);
90 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
92 ERR("ctsvc_ipc_unmarshal_int() Fail");
93 pims_ipc_data_destroy(outdata);
94 return CONTACTS_ERROR_IPC;
98 if (CONTACTS_ERROR_NONE == ret) {
99 int transaction_ver = 0;
100 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
101 /* LCOV_EXCL_START */
102 ERR("ctsvc_ipc_unmarshal_int() Fail");
103 pims_ipc_data_destroy(outdata);
104 return CONTACTS_ERROR_IPC;
107 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
110 pims_ipc_data_destroy(outdata);
116 int ctsvc_client_group_remove_contact(contacts_h contact, int group_id, int contact_id)
118 int ret = CONTACTS_ERROR_NONE;
120 pims_ipc_data_h indata = NULL;
121 pims_ipc_data_h outdata = NULL;
123 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
124 RETVM_IF(group_id <= 0 || contact_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER, "id should be greater than 0");
127 indata = pims_ipc_data_create(0);
128 if (indata == NULL) {
129 /* LCOV_EXCL_START */
130 ERR("pims_ipc_data_create() Fail");
131 return CONTACTS_ERROR_OUT_OF_MEMORY;
135 ret = ctsvc_ipc_marshal_handle(contact, indata);
136 if (CONTACTS_ERROR_NONE != ret) {
137 /* LCOV_EXCL_START */
138 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
139 pims_ipc_data_destroy(indata);
145 ret = ctsvc_ipc_marshal_int(group_id, indata);
146 if (ret != CONTACTS_ERROR_NONE) {
147 /* LCOV_EXCL_START */
148 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
149 pims_ipc_data_destroy(indata);
153 ret = ctsvc_ipc_marshal_int(contact_id, indata);
154 if (ret != CONTACTS_ERROR_NONE) {
155 /* LCOV_EXCL_START */
156 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
157 pims_ipc_data_destroy(indata);
163 if (ctsvc_ipc_call(CTSVC_IPC_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_REMOVE_CONTACT, indata, &outdata) != 0) {
164 /* LCOV_EXCL_START */
165 ERR("ctsvc_ipc_call() Fail");
166 pims_ipc_data_destroy(indata);
167 return CONTACTS_ERROR_IPC;
171 pims_ipc_data_destroy(indata);
174 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
175 /* LCOV_EXCL_START */
176 ERR("ctsvc_ipc_unmarshal_int() Fail");
177 pims_ipc_data_destroy(outdata);
178 return CONTACTS_ERROR_IPC;
182 if (CONTACTS_ERROR_NONE == ret) {
183 int transaction_ver = 0;
184 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
185 /* LCOV_EXCL_START */
186 ERR("ctsvc_ipc_unmarshal_int() Fail");
187 pims_ipc_data_destroy(outdata);
188 return CONTACTS_ERROR_IPC;
191 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
194 pims_ipc_data_destroy(outdata);
200 int ctsvc_client_group_set_group_order(contacts_h contact, int group_id, int previous_group_id, int next_group_id)
202 int ret = CONTACTS_ERROR_NONE;
204 pims_ipc_data_h indata = NULL;
205 pims_ipc_data_h outdata = NULL;
207 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
208 RETVM_IF(group_id <= 0 || previous_group_id < 0 || next_group_id < 0, CONTACTS_ERROR_INVALID_PARAMETER, "id should be greater than 0");
211 indata = pims_ipc_data_create(0);
212 if (indata == NULL) {
213 /* LCOV_EXCL_START */
214 ERR("pims_ipc_data_create() Fail");
215 return CONTACTS_ERROR_OUT_OF_MEMORY;
219 ret = ctsvc_ipc_marshal_handle(contact, indata);
220 if (CONTACTS_ERROR_NONE != ret) {
221 /* LCOV_EXCL_START */
222 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
223 pims_ipc_data_destroy(indata);
228 ret = ctsvc_ipc_marshal_int(group_id, indata);
229 if (ret != CONTACTS_ERROR_NONE) {
230 /* LCOV_EXCL_START */
231 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
232 pims_ipc_data_destroy(indata);
236 ret = ctsvc_ipc_marshal_int(previous_group_id, indata);
237 if (ret != CONTACTS_ERROR_NONE) {
238 /* LCOV_EXCL_START */
239 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
240 pims_ipc_data_destroy(indata);
244 ret = ctsvc_ipc_marshal_int(next_group_id, indata);
245 if (ret != CONTACTS_ERROR_NONE) {
246 /* LCOV_EXCL_START */
247 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
248 pims_ipc_data_destroy(indata);
254 if (ctsvc_ipc_call(CTSVC_IPC_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_SET_GROUP_ORDER, indata, &outdata) != 0) {
255 /* LCOV_EXCL_START */
256 ERR("ctsvc_ipc_call() Fail");
257 pims_ipc_data_destroy(indata);
258 return CONTACTS_ERROR_IPC;
262 pims_ipc_data_destroy(indata);
265 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
266 /* LCOV_EXCL_START */
267 ERR("ctsvc_ipc_unmarshal_int() Fail");
268 pims_ipc_data_destroy(outdata);
269 return CONTACTS_ERROR_IPC;
273 if (CONTACTS_ERROR_NONE == ret) {
274 int transaction_ver = 0;
275 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
276 /* LCOV_EXCL_START */
277 ERR("ctsvc_ipc_unmarshal_int() Fail");
278 pims_ipc_data_destroy(outdata);
279 return CONTACTS_ERROR_IPC;
282 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
285 pims_ipc_data_destroy(outdata);