4 * Copyright (c) 2010 - 2012 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 unsigned int size = 0;
46 ret = *(int*) pims_ipc_data_get(outdata, &size);
47 if (CONTACTS_ERROR_NONE == ret) {
48 *name_display_order = *(int*) pims_ipc_data_get(outdata, &size);
50 pims_ipc_data_destroy(outdata);
56 API int contacts_setting_get_name_sorting_order(contacts_name_sorting_order_e *name_sorting_order)
58 int ret = CONTACTS_ERROR_NONE;
59 pims_ipc_data_h outdata = NULL;
61 RETVM_IF(name_sorting_order == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "The out param is NULL");
62 *name_sorting_order = 0;
64 if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_GET_NAME_SORTING_ORDER, NULL, &outdata) != 0) {
65 CTS_ERR("ctsvc_ipc_call Fail");
66 return CONTACTS_ERROR_IPC;
70 unsigned int size = 0;
71 ret = *(int*) pims_ipc_data_get(outdata, &size);
72 if (CONTACTS_ERROR_NONE == ret) {
73 *name_sorting_order = *(int*) pims_ipc_data_get(outdata, &size);
75 pims_ipc_data_destroy(outdata);
81 API int contacts_setting_set_name_display_order(contacts_name_display_order_e name_display_order)
83 int ret = CONTACTS_ERROR_NONE;
84 pims_ipc_data_h indata = NULL;
85 pims_ipc_data_h outdata = NULL;
87 RETVM_IF(name_display_order != CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST
88 && name_display_order != CONTACTS_NAME_DISPLAY_ORDER_LASTFIRST,
89 CONTACTS_ERROR_INVALID_PARAMETER, "name display order is invalid : %d", name_display_order);
91 indata = pims_ipc_data_create(0);
93 CTS_ERR("ipc data created fail!");
94 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
98 ret = ctsvc_ipc_marshal_int(name_display_order, indata);
99 if (ret != CONTACTS_ERROR_NONE) {
100 CTS_ERR("marshal fail");
101 pims_ipc_data_destroy(indata);
105 if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_SET_NAME_DISPLAY_ORDER, indata, &outdata) != 0) {
106 CTS_ERR("ctsvc_ipc_call Fail");
107 pims_ipc_data_destroy(indata);
108 return CONTACTS_ERROR_IPC;
110 pims_ipc_data_destroy(indata);
113 unsigned int size = 0;
114 ret = *(int*) pims_ipc_data_get(outdata, &size);
115 pims_ipc_data_destroy(outdata);
121 API int contacts_setting_set_name_sorting_order(contacts_name_sorting_order_e name_sorint_order)
123 int ret = CONTACTS_ERROR_NONE;
124 pims_ipc_data_h indata = NULL;
125 pims_ipc_data_h outdata = NULL;
127 RETVM_IF(name_sorint_order != CONTACTS_NAME_SORTING_ORDER_FIRSTLAST
128 && name_sorint_order != CONTACTS_NAME_SORTING_ORDER_LASTFIRST,
129 CONTACTS_ERROR_INVALID_PARAMETER, "name sorting order is invalid : %d", name_sorint_order);
131 indata = pims_ipc_data_create(0);
132 if (indata == NULL) {
133 CTS_ERR("ipc data created fail!");
134 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
138 ret = ctsvc_ipc_marshal_int(name_sorint_order, indata);
139 if (ret != CONTACTS_ERROR_NONE) {
140 CTS_ERR("marshal fail");
141 pims_ipc_data_destroy(indata);
145 if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_SET_NAME_SORTING_ORDER, indata, &outdata) != 0) {
146 CTS_ERR("ctsvc_ipc_call Fail");
147 pims_ipc_data_destroy(indata);
148 return CONTACTS_ERROR_IPC;
150 pims_ipc_data_destroy(indata);
153 unsigned int size = 0;
154 ret = *(int*) pims_ipc_data_get(outdata, &size);
155 pims_ipc_data_destroy(outdata);
163 contacts_setting_name_display_order_changed_cb cb;
165 }ctsvc_name_display_order_changed_cb_info_s;
167 static GSList *__setting_name_display_order_subscribe_list = NULL;
169 static void __ctsvc_setting_name_display_order_subscriber_callback(pims_ipc_h ipc, pims_ipc_data_h data, void *user_data)
172 unsigned int size = 0;
174 value = *(int*)pims_ipc_data_get(data, &size);
176 if (__setting_name_display_order_subscribe_list) {
178 for (l = __setting_name_display_order_subscribe_list;l;l=l->next) {
179 ctsvc_name_display_order_changed_cb_info_s *cb_info = l->data;
181 cb_info->cb((contacts_name_display_order_e)value, cb_info->user_data);
186 API int contacts_setting_add_name_display_order_changed_cb(
187 contacts_setting_name_display_order_changed_cb cb, void* user_data)
192 ctsvc_name_display_order_changed_cb_info_s *cb_info;
194 RETVM_IF(cb == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : callback is NULL");
196 ret = ctsvc_ipc_client_check_permission(CTSVC_PERMISSION_CONTACT_READ, &result);
197 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_ipc_client_check_permission fail (%d)", ret);
198 RETVM_IF(result == false, CONTACTS_ERROR_PERMISSION_DENIED, "Permission denied (contact read)");
200 ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
202 if (!__setting_name_display_order_subscribe_list) {
203 if (pims_ipc_subscribe(ctsvc_ipc_get_handle_for_change_subsciption(),
204 CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_SETTING_DISPLAY_ORDER_CHANGED,
205 __ctsvc_setting_name_display_order_subscriber_callback, NULL) != 0) {
206 CTS_ERR("pims_ipc_subscribe error\n");
207 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
208 return CONTACTS_ERROR_IPC;
212 for (l = __setting_name_display_order_subscribe_list;l;l=l->next) {
213 ctsvc_name_display_order_changed_cb_info_s *cb_info = l->data;
214 if (cb_info->cb == cb && cb_info->user_data == user_data) {
215 CTS_ERR("The same callback(%s) is already exist");
216 return CONTACTS_ERROR_INVALID_PARAMETER;
220 cb_info = calloc(1, sizeof(ctsvc_name_display_order_changed_cb_info_s));
221 cb_info->user_data = user_data;
223 __setting_name_display_order_subscribe_list = g_slist_append(__setting_name_display_order_subscribe_list, cb_info);
225 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
226 return CONTACTS_ERROR_NONE;
229 API int contacts_setting_remove_name_display_order_changed_cb(
230 contacts_setting_name_display_order_changed_cb cb, void* user_data)
232 RETVM_IF(cb == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : callback is NULL");
234 ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
236 if (__setting_name_display_order_subscribe_list) {
238 for (l = __setting_name_display_order_subscribe_list;l;l=l->next) {
239 ctsvc_name_display_order_changed_cb_info_s *cb_info = l->data;
240 if (cb == cb_info->cb && user_data == cb_info->user_data) {
241 __setting_name_display_order_subscribe_list = g_slist_remove(__setting_name_display_order_subscribe_list, cb_info);
246 if (g_slist_length(__setting_name_display_order_subscribe_list) == 0) {
247 pims_ipc_unsubscribe(ctsvc_ipc_get_handle_for_change_subsciption(),
248 CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_SETTING_DISPLAY_ORDER_CHANGED);
249 g_slist_free(__setting_name_display_order_subscribe_list);
250 __setting_name_display_order_subscribe_list = NULL;
254 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
255 return CONTACTS_ERROR_NONE;
260 contacts_setting_name_sorting_order_changed_cb cb;
262 }ctsvc_name_sorting_order_changed_cb_info_s;
264 static GSList *__setting_name_sorting_order_subscribe_list = NULL;
266 static void __ctsvc_setting_name_sorting_order_subscriber_callback(pims_ipc_h ipc, pims_ipc_data_h data, void *user_data)
269 unsigned int size = 0;
271 value = *(int*)pims_ipc_data_get(data, &size);
273 if (__setting_name_sorting_order_subscribe_list) {
275 for (l = __setting_name_sorting_order_subscribe_list;l;l=l->next) {
276 ctsvc_name_sorting_order_changed_cb_info_s *cb_info = l->data;
278 cb_info->cb((contacts_name_sorting_order_e)value, cb_info->user_data);
283 API int contacts_setting_add_name_sorting_order_changed_cb(
284 contacts_setting_name_sorting_order_changed_cb cb, void* user_data)
289 ctsvc_name_sorting_order_changed_cb_info_s *cb_info;
291 RETVM_IF(cb == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : callback is NULL");
293 ret = ctsvc_ipc_client_check_permission(CTSVC_PERMISSION_CONTACT_READ, &result);
294 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_ipc_client_check_permission fail (%d)", ret);
295 RETVM_IF(result == false, CONTACTS_ERROR_PERMISSION_DENIED, "Permission denied (contact read)");
297 ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
299 if (!__setting_name_sorting_order_subscribe_list) {
300 if (pims_ipc_subscribe(ctsvc_ipc_get_handle_for_change_subsciption(),
301 CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_SETTING_SORTING_ORDER_CHANGED,
302 __ctsvc_setting_name_sorting_order_subscriber_callback, NULL) != 0) {
303 CTS_ERR("pims_ipc_subscribe error\n");
304 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
305 return CONTACTS_ERROR_IPC;
309 for (l = __setting_name_sorting_order_subscribe_list;l;l=l->next) {
310 ctsvc_name_sorting_order_changed_cb_info_s *cb_info = l->data;
311 if (cb_info->cb == cb && cb_info->user_data == user_data) {
312 CTS_ERR("The same callback(%s) is already exist");
313 return CONTACTS_ERROR_INVALID_PARAMETER;
317 cb_info = calloc(1, sizeof(ctsvc_name_sorting_order_changed_cb_info_s));
318 cb_info->user_data = user_data;
320 __setting_name_sorting_order_subscribe_list = g_slist_append(__setting_name_sorting_order_subscribe_list, cb_info);
322 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
323 return CONTACTS_ERROR_NONE;
326 API int contacts_setting_remove_name_sorting_order_changed_cb(
327 contacts_setting_name_sorting_order_changed_cb cb, void* user_data)
329 RETVM_IF(cb == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : callback is NULL");
331 ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
333 if (__setting_name_sorting_order_subscribe_list) {
335 for (l = __setting_name_sorting_order_subscribe_list;l;l=l->next) {
336 ctsvc_name_sorting_order_changed_cb_info_s *cb_info = l->data;
337 if (cb == cb_info->cb && user_data == cb_info->user_data) {
338 __setting_name_sorting_order_subscribe_list = g_slist_remove(__setting_name_sorting_order_subscribe_list, cb_info);
343 if (g_slist_length(__setting_name_sorting_order_subscribe_list) == 0) {
344 pims_ipc_unsubscribe(ctsvc_ipc_get_handle_for_change_subsciption(),
345 CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_SETTING_SORTING_ORDER_CHANGED);
346 g_slist_free(__setting_name_sorting_order_subscribe_list);
347 __setting_name_sorting_order_subscribe_list = NULL;
351 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
352 return CONTACTS_ERROR_NONE;