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 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
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);
46 CTS_ERR("ipc data created fail!");
47 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
51 ret = ctsvc_ipc_marshal_handle(contact, indata);
52 if (CONTACTS_ERROR_NONE != ret) {
53 CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
54 pims_ipc_data_destroy(indata);
58 ret = ctsvc_ipc_marshal_int(group_id, indata);
59 if (ret != CONTACTS_ERROR_NONE) {
60 CTS_ERR("marshal fail");
61 pims_ipc_data_destroy(indata);
64 ret = ctsvc_ipc_marshal_int(contact_id, indata);
65 if (ret != CONTACTS_ERROR_NONE) {
66 CTS_ERR("marshal fail");
67 pims_ipc_data_destroy(indata);
72 if (ctsvc_ipc_call(CTSVC_IPC_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_ADD_CONTACT, indata, &outdata) != 0) {
73 CTS_ERR("ctsvc_ipc_call failed");
74 pims_ipc_data_destroy(indata);
75 return CONTACTS_ERROR_IPC;
78 pims_ipc_data_destroy(indata);
81 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
82 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
83 pims_ipc_data_destroy(outdata);
84 return CONTACTS_ERROR_IPC;
87 if (CONTACTS_ERROR_NONE == ret) {
88 int transaction_ver = 0;
89 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
90 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
91 pims_ipc_data_destroy(outdata);
92 return CONTACTS_ERROR_IPC;
94 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
97 pims_ipc_data_destroy(outdata);
103 int ctsvc_client_group_remove_contact(contacts_h contact, int group_id, int contact_id)
105 int ret = CONTACTS_ERROR_NONE;
107 pims_ipc_data_h indata = NULL;
108 pims_ipc_data_h outdata = NULL;
110 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
111 RETVM_IF(group_id <= 0 || contact_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
114 indata = pims_ipc_data_create(0);
115 if (indata == NULL) {
116 CTS_ERR("ipc data created fail!");
117 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
120 ret = ctsvc_ipc_marshal_handle(contact, indata);
121 if (CONTACTS_ERROR_NONE != ret) {
122 CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
123 pims_ipc_data_destroy(indata);
128 ret = ctsvc_ipc_marshal_int(group_id, indata);
129 if (ret != CONTACTS_ERROR_NONE) {
130 CTS_ERR("marshal fail");
131 pims_ipc_data_destroy(indata);
134 ret = ctsvc_ipc_marshal_int(contact_id, indata);
135 if (ret != CONTACTS_ERROR_NONE) {
136 CTS_ERR("marshal fail");
137 pims_ipc_data_destroy(indata);
142 if (ctsvc_ipc_call(CTSVC_IPC_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_REMOVE_CONTACT, indata, &outdata) != 0) {
143 CTS_ERR("ctsvc_ipc_call failed");
144 pims_ipc_data_destroy(indata);
145 return CONTACTS_ERROR_IPC;
148 pims_ipc_data_destroy(indata);
151 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
152 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
153 pims_ipc_data_destroy(outdata);
154 return CONTACTS_ERROR_IPC;
157 if (CONTACTS_ERROR_NONE == ret) {
158 int transaction_ver = 0;
159 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
160 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
161 pims_ipc_data_destroy(outdata);
162 return CONTACTS_ERROR_IPC;
164 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
167 pims_ipc_data_destroy(outdata);
173 int ctsvc_client_group_set_group_order(contacts_h contact, int group_id, int previous_group_id, int next_group_id)
175 int ret = CONTACTS_ERROR_NONE;
177 pims_ipc_data_h indata = NULL;
178 pims_ipc_data_h outdata = NULL;
180 RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
181 RETVM_IF(group_id <= 0 || previous_group_id < 0 || next_group_id < 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
184 indata = pims_ipc_data_create(0);
185 if (indata == NULL) {
186 CTS_ERR("ipc data created fail!");
187 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
190 ret = ctsvc_ipc_marshal_handle(contact, indata);
191 if (CONTACTS_ERROR_NONE != ret) {
192 CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
193 pims_ipc_data_destroy(indata);
197 ret = ctsvc_ipc_marshal_int(group_id, indata);
198 if (ret != CONTACTS_ERROR_NONE) {
199 CTS_ERR("marshal fail");
200 pims_ipc_data_destroy(indata);
203 ret = ctsvc_ipc_marshal_int(previous_group_id, indata);
204 if (ret != CONTACTS_ERROR_NONE) {
205 CTS_ERR("marshal fail");
206 pims_ipc_data_destroy(indata);
209 ret = ctsvc_ipc_marshal_int(next_group_id, indata);
210 if (ret != CONTACTS_ERROR_NONE) {
211 CTS_ERR("marshal fail");
212 pims_ipc_data_destroy(indata);
217 if (ctsvc_ipc_call(CTSVC_IPC_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_SET_GROUP_ORDER, indata, &outdata) != 0) {
218 CTS_ERR("ctsvc_ipc_call failed");
219 pims_ipc_data_destroy(indata);
220 return CONTACTS_ERROR_IPC;
223 pims_ipc_data_destroy(indata);
226 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
227 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
228 pims_ipc_data_destroy(outdata);
229 return CONTACTS_ERROR_IPC;
232 if (CONTACTS_ERROR_NONE == ret) {
233 int transaction_ver = 0;
234 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
235 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
236 pims_ipc_data_destroy(outdata);
237 return CONTACTS_ERROR_IPC;
239 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
242 pims_ipc_data_destroy(outdata);