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 <pims-ipc-data.h>
24 #include "ctsvc_internal.h"
25 #include "ctsvc_notify.h"
26 #include "ctsvc_ipc_define.h"
27 #include "ctsvc_ipc_marshal.h"
28 #include "ctsvc_client_ipc.h"
29 #include "ctsvc_mutex.h"
31 API int contacts_setting_get_name_display_order(contacts_name_display_order_e *name_display_order)
33 int ret = CONTACTS_ERROR_NONE;
34 pims_ipc_data_h outdata = NULL;
36 RETVM_IF(name_display_order == NULL, CONTACTS_ERROR_INVALID_PARAMETER,"The out param is NULL");
37 *name_display_order = 0;
39 if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_GET_NAME_DISPLAY_ORDER, NULL, &outdata) != 0) {
40 CTS_ERR("ctsvc_ipc_call Fail");
41 return CONTACTS_ERROR_IPC;
45 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
46 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
47 pims_ipc_data_destroy(outdata);
48 return CONTACTS_ERROR_IPC;
51 if (CONTACTS_ERROR_NONE == ret) {
52 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, (int *)name_display_order)) {
53 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
54 pims_ipc_data_destroy(outdata);
55 return CONTACTS_ERROR_IPC;
58 pims_ipc_data_destroy(outdata);
64 API int contacts_setting_get_name_sorting_order(contacts_name_sorting_order_e *name_sorting_order)
66 int ret = CONTACTS_ERROR_NONE;
67 pims_ipc_data_h outdata = NULL;
69 RETVM_IF(name_sorting_order == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "The out param is NULL");
70 *name_sorting_order = 0;
72 if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_GET_NAME_SORTING_ORDER, NULL, &outdata) != 0) {
73 CTS_ERR("ctsvc_ipc_call Fail");
74 return CONTACTS_ERROR_IPC;
78 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
79 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
80 pims_ipc_data_destroy(outdata);
81 return CONTACTS_ERROR_IPC;
83 if (CONTACTS_ERROR_NONE == ret) {
84 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, (int *)name_sorting_order)) {
85 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
86 pims_ipc_data_destroy(outdata);
87 return CONTACTS_ERROR_IPC;
90 pims_ipc_data_destroy(outdata);
96 API int contacts_setting_set_name_display_order(contacts_name_display_order_e name_display_order)
98 int ret = CONTACTS_ERROR_NONE;
99 pims_ipc_data_h indata = NULL;
100 pims_ipc_data_h outdata = NULL;
102 RETVM_IF(name_display_order != CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST
103 && name_display_order != CONTACTS_NAME_DISPLAY_ORDER_LASTFIRST,
104 CONTACTS_ERROR_INVALID_PARAMETER, "name display order is invalid : %d", name_display_order);
106 indata = pims_ipc_data_create(0);
107 if (indata == NULL) {
108 CTS_ERR("ipc data created fail!");
109 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
113 ret = ctsvc_ipc_marshal_int(name_display_order, indata);
114 if (ret != CONTACTS_ERROR_NONE) {
115 CTS_ERR("marshal fail");
116 pims_ipc_data_destroy(indata);
120 if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_SET_NAME_DISPLAY_ORDER, indata, &outdata) != 0) {
121 CTS_ERR("ctsvc_ipc_call Fail");
122 pims_ipc_data_destroy(indata);
123 return CONTACTS_ERROR_IPC;
125 pims_ipc_data_destroy(indata);
128 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
129 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
130 pims_ipc_data_destroy(outdata);
131 return CONTACTS_ERROR_IPC;
133 pims_ipc_data_destroy(outdata);
139 API int contacts_setting_set_name_sorting_order(contacts_name_sorting_order_e name_sorint_order)
141 int ret = CONTACTS_ERROR_NONE;
142 pims_ipc_data_h indata = NULL;
143 pims_ipc_data_h outdata = NULL;
145 RETVM_IF(name_sorint_order != CONTACTS_NAME_SORTING_ORDER_FIRSTLAST
146 && name_sorint_order != CONTACTS_NAME_SORTING_ORDER_LASTFIRST,
147 CONTACTS_ERROR_INVALID_PARAMETER, "name sorting order is invalid : %d", name_sorint_order);
149 indata = pims_ipc_data_create(0);
150 if (indata == NULL) {
151 CTS_ERR("ipc data created fail!");
152 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
156 ret = ctsvc_ipc_marshal_int(name_sorint_order, indata);
157 if (ret != CONTACTS_ERROR_NONE) {
158 CTS_ERR("marshal fail");
159 pims_ipc_data_destroy(indata);
163 if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_SET_NAME_SORTING_ORDER, indata, &outdata) != 0) {
164 CTS_ERR("ctsvc_ipc_call Fail");
165 pims_ipc_data_destroy(indata);
166 return CONTACTS_ERROR_IPC;
168 pims_ipc_data_destroy(indata);
171 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
172 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
173 pims_ipc_data_destroy(outdata);
174 return CONTACTS_ERROR_IPC;
176 pims_ipc_data_destroy(outdata);
184 contacts_setting_name_display_order_changed_cb cb;
186 }ctsvc_name_display_order_changed_cb_info_s;
188 static GSList *__setting_name_display_order_subscribe_list = NULL;
190 static void __ctsvc_setting_name_display_order_subscriber_callback(pims_ipc_h ipc, pims_ipc_data_h data, void *user_data)
196 ret = ctsvc_ipc_unmarshal_int(data, &value);
197 WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
199 if (__setting_name_display_order_subscribe_list) {
201 for (l = __setting_name_display_order_subscribe_list;l;l=l->next) {
202 ctsvc_name_display_order_changed_cb_info_s *cb_info = l->data;
204 cb_info->cb((contacts_name_display_order_e)value, cb_info->user_data);
209 API int contacts_setting_add_name_display_order_changed_cb(
210 contacts_setting_name_display_order_changed_cb cb, void* user_data)
215 ctsvc_name_display_order_changed_cb_info_s *cb_info;
217 RETVM_IF(cb == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : callback is NULL");
219 ret = ctsvc_ipc_client_check_permission(CTSVC_PERMISSION_CONTACT_READ, &result);
220 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_ipc_client_check_permission fail (%d)", ret);
221 RETVM_IF(result == false, CONTACTS_ERROR_PERMISSION_DENIED, "Permission denied (contact read)");
223 ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
225 if (NULL == __setting_name_display_order_subscribe_list) {
226 if (pims_ipc_subscribe(ctsvc_ipc_get_handle_for_change_subsciption(),
227 CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_SETTING_DISPLAY_ORDER_CHANGED,
228 __ctsvc_setting_name_display_order_subscriber_callback, NULL) != 0) {
229 CTS_ERR("pims_ipc_subscribe error\n");
230 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
231 return CONTACTS_ERROR_IPC;
235 for (l = __setting_name_display_order_subscribe_list;l;l=l->next) {
236 ctsvc_name_display_order_changed_cb_info_s *cb_info = l->data;
237 if (cb_info->cb == cb && cb_info->user_data == user_data) {
238 CTS_ERR("The same callback(%s) is already exist");
239 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
240 return CONTACTS_ERROR_INVALID_PARAMETER;
244 cb_info = calloc(1, sizeof(ctsvc_name_display_order_changed_cb_info_s));
245 if (NULL == cb_info) {
246 CTS_ERR("calloc() Failed");
247 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
248 return CONTACTS_ERROR_OUT_OF_MEMORY;
250 cb_info->user_data = user_data;
252 __setting_name_display_order_subscribe_list = g_slist_append(__setting_name_display_order_subscribe_list, cb_info);
254 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
255 return CONTACTS_ERROR_NONE;
258 API int contacts_setting_remove_name_display_order_changed_cb(
259 contacts_setting_name_display_order_changed_cb cb, void* user_data)
261 RETVM_IF(cb == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : callback is NULL");
263 ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
265 if (__setting_name_display_order_subscribe_list) {
267 for (l = __setting_name_display_order_subscribe_list;l;l=l->next) {
268 ctsvc_name_display_order_changed_cb_info_s *cb_info = l->data;
269 if (cb == cb_info->cb && user_data == cb_info->user_data) {
270 __setting_name_display_order_subscribe_list = g_slist_remove(__setting_name_display_order_subscribe_list, cb_info);
275 if (g_slist_length(__setting_name_display_order_subscribe_list) == 0) {
276 pims_ipc_unsubscribe(ctsvc_ipc_get_handle_for_change_subsciption(),
277 CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_SETTING_DISPLAY_ORDER_CHANGED);
278 g_slist_free(__setting_name_display_order_subscribe_list);
279 __setting_name_display_order_subscribe_list = NULL;
283 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
284 return CONTACTS_ERROR_NONE;
289 contacts_setting_name_sorting_order_changed_cb cb;
291 }ctsvc_name_sorting_order_changed_cb_info_s;
293 static GSList *__setting_name_sorting_order_subscribe_list = NULL;
295 static void __ctsvc_setting_name_sorting_order_subscriber_callback(pims_ipc_h ipc, pims_ipc_data_h data, void *user_data)
301 ret = ctsvc_ipc_unmarshal_int(data, &value);
302 WARN_IF(CONTACTS_ERROR_NONE != ret, "() Fail(%d)", ret);
305 if (__setting_name_sorting_order_subscribe_list) {
307 for (l = __setting_name_sorting_order_subscribe_list;l;l=l->next) {
308 ctsvc_name_sorting_order_changed_cb_info_s *cb_info = l->data;
310 cb_info->cb((contacts_name_sorting_order_e)value, cb_info->user_data);
315 API int contacts_setting_add_name_sorting_order_changed_cb(
316 contacts_setting_name_sorting_order_changed_cb cb, void* user_data)
321 ctsvc_name_sorting_order_changed_cb_info_s *cb_info;
323 RETVM_IF(cb == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : callback is NULL");
325 ret = ctsvc_ipc_client_check_permission(CTSVC_PERMISSION_CONTACT_READ, &result);
326 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_ipc_client_check_permission fail (%d)", ret);
327 RETVM_IF(result == false, CONTACTS_ERROR_PERMISSION_DENIED, "Permission denied (contact read)");
329 ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
331 if (NULL == __setting_name_sorting_order_subscribe_list) {
332 if (pims_ipc_subscribe(ctsvc_ipc_get_handle_for_change_subsciption(),
333 CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_SETTING_SORTING_ORDER_CHANGED,
334 __ctsvc_setting_name_sorting_order_subscriber_callback, NULL) != 0) {
335 CTS_ERR("pims_ipc_subscribe error\n");
336 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
337 return CONTACTS_ERROR_IPC;
341 for (l = __setting_name_sorting_order_subscribe_list;l;l=l->next) {
342 ctsvc_name_sorting_order_changed_cb_info_s *cb_info = l->data;
343 if (cb_info->cb == cb && cb_info->user_data == user_data) {
344 CTS_ERR("The same callback(%s) is already exist");
345 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
346 return CONTACTS_ERROR_INVALID_PARAMETER;
350 cb_info = calloc(1, sizeof(ctsvc_name_sorting_order_changed_cb_info_s));
351 if (NULL == cb_info) {
352 CTS_ERR("calloc() Failed");
353 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
354 return CONTACTS_ERROR_OUT_OF_MEMORY;
356 cb_info->user_data = user_data;
358 __setting_name_sorting_order_subscribe_list = g_slist_append(__setting_name_sorting_order_subscribe_list, cb_info);
360 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
361 return CONTACTS_ERROR_NONE;
364 API int contacts_setting_remove_name_sorting_order_changed_cb(
365 contacts_setting_name_sorting_order_changed_cb cb, void* user_data)
367 RETVM_IF(cb == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : callback is NULL");
369 ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
371 if (__setting_name_sorting_order_subscribe_list) {
373 for (l = __setting_name_sorting_order_subscribe_list;l;l=l->next) {
374 ctsvc_name_sorting_order_changed_cb_info_s *cb_info = l->data;
375 if (cb == cb_info->cb && user_data == cb_info->user_data) {
376 __setting_name_sorting_order_subscribe_list = g_slist_remove(__setting_name_sorting_order_subscribe_list, cb_info);
381 if (g_slist_length(__setting_name_sorting_order_subscribe_list) == 0) {
382 pims_ipc_unsubscribe(ctsvc_ipc_get_handle_for_change_subsciption(),
383 CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_SETTING_SORTING_ORDER_CHANGED);
384 g_slist_free(__setting_name_sorting_order_subscribe_list);
385 __setting_name_sorting_order_subscribe_list = NULL;
389 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
390 return CONTACTS_ERROR_NONE;