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);
46 ERR("pims_ipc_data_create() Fail");
47 return CONTACTS_ERROR_OUT_OF_MEMORY;
50 ret = ctsvc_ipc_marshal_handle(contact, indata);
51 if (CONTACTS_ERROR_NONE != ret) {
52 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
53 pims_ipc_data_destroy(indata);
57 ret = ctsvc_ipc_marshal_int(group_id, indata);
58 if (ret != CONTACTS_ERROR_NONE) {
59 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
60 pims_ipc_data_destroy(indata);
63 ret = ctsvc_ipc_marshal_int(contact_id, indata);
64 if (ret != CONTACTS_ERROR_NONE) {
65 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
66 pims_ipc_data_destroy(indata);
71 if (ctsvc_ipc_call(CTSVC_IPC_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_ADD_CONTACT, indata, &outdata) != 0) {
72 ERR("ctsvc_ipc_call() Fail");
73 pims_ipc_data_destroy(indata);
74 return CONTACTS_ERROR_IPC;
77 pims_ipc_data_destroy(indata);
80 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
81 ERR("ctsvc_ipc_unmarshal_int() Fail");
82 pims_ipc_data_destroy(outdata);
83 return CONTACTS_ERROR_IPC;
86 if (CONTACTS_ERROR_NONE == ret) {
87 int transaction_ver = 0;
88 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
89 ERR("ctsvc_ipc_unmarshal_int() Fail");
90 pims_ipc_data_destroy(outdata);
91 return CONTACTS_ERROR_IPC;
93 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
96 pims_ipc_data_destroy(outdata);
102 int ctsvc_client_group_remove_contact(contacts_h contact, int group_id, int contact_id)
104 int ret = CONTACTS_ERROR_NONE;
106 pims_ipc_data_h indata = NULL;
107 pims_ipc_data_h outdata = NULL;
109 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
110 RETVM_IF(group_id <= 0 || contact_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER, "id should be greater than 0");
113 indata = pims_ipc_data_create(0);
114 if (indata == NULL) {
115 ERR("pims_ipc_data_create() Fail");
116 return CONTACTS_ERROR_OUT_OF_MEMORY;
119 ret = ctsvc_ipc_marshal_handle(contact, indata);
120 if (CONTACTS_ERROR_NONE != ret) {
121 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
122 pims_ipc_data_destroy(indata);
127 ret = ctsvc_ipc_marshal_int(group_id, indata);
128 if (ret != CONTACTS_ERROR_NONE) {
129 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
130 pims_ipc_data_destroy(indata);
133 ret = ctsvc_ipc_marshal_int(contact_id, indata);
134 if (ret != CONTACTS_ERROR_NONE) {
135 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
136 pims_ipc_data_destroy(indata);
141 if (ctsvc_ipc_call(CTSVC_IPC_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_REMOVE_CONTACT, indata, &outdata) != 0) {
142 ERR("ctsvc_ipc_call() Fail");
143 pims_ipc_data_destroy(indata);
144 return CONTACTS_ERROR_IPC;
147 pims_ipc_data_destroy(indata);
150 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
151 ERR("ctsvc_ipc_unmarshal_int() Fail");
152 pims_ipc_data_destroy(outdata);
153 return CONTACTS_ERROR_IPC;
156 if (CONTACTS_ERROR_NONE == ret) {
157 int transaction_ver = 0;
158 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
159 ERR("ctsvc_ipc_unmarshal_int() Fail");
160 pims_ipc_data_destroy(outdata);
161 return CONTACTS_ERROR_IPC;
163 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
166 pims_ipc_data_destroy(outdata);
172 int ctsvc_client_group_set_group_order(contacts_h contact, int group_id, int previous_group_id, int next_group_id)
174 int ret = CONTACTS_ERROR_NONE;
176 pims_ipc_data_h indata = NULL;
177 pims_ipc_data_h outdata = NULL;
179 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
180 RETVM_IF(group_id <= 0 || previous_group_id < 0 || next_group_id < 0, CONTACTS_ERROR_INVALID_PARAMETER, "id should be greater than 0");
183 indata = pims_ipc_data_create(0);
184 if (indata == NULL) {
185 ERR("pims_ipc_data_create() Fail");
186 return CONTACTS_ERROR_OUT_OF_MEMORY;
189 ret = ctsvc_ipc_marshal_handle(contact, indata);
190 if (CONTACTS_ERROR_NONE != ret) {
191 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
192 pims_ipc_data_destroy(indata);
196 ret = ctsvc_ipc_marshal_int(group_id, indata);
197 if (ret != CONTACTS_ERROR_NONE) {
198 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
199 pims_ipc_data_destroy(indata);
202 ret = ctsvc_ipc_marshal_int(previous_group_id, indata);
203 if (ret != CONTACTS_ERROR_NONE) {
204 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
205 pims_ipc_data_destroy(indata);
208 ret = ctsvc_ipc_marshal_int(next_group_id, indata);
209 if (ret != CONTACTS_ERROR_NONE) {
210 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
211 pims_ipc_data_destroy(indata);
216 if (ctsvc_ipc_call(CTSVC_IPC_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_SET_GROUP_ORDER, indata, &outdata) != 0) {
217 ERR("ctsvc_ipc_call() Fail");
218 pims_ipc_data_destroy(indata);
219 return CONTACTS_ERROR_IPC;
222 pims_ipc_data_destroy(indata);
225 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
226 ERR("ctsvc_ipc_unmarshal_int() Fail");
227 pims_ipc_data_destroy(outdata);
228 return CONTACTS_ERROR_IPC;
231 if (CONTACTS_ERROR_NONE == ret) {
232 int transaction_ver = 0;
233 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
234 ERR("ctsvc_ipc_unmarshal_int() Fail");
235 pims_ipc_data_destroy(outdata);
236 return CONTACTS_ERROR_IPC;
238 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
241 pims_ipc_data_destroy(outdata);