From: Donghee Ye Date: Sat, 7 Sep 2013 10:15:44 +0000 (+0900) Subject: Add API to subscribe setting name dirplay/sorting order changes X-Git-Tag: accepted/tizen/20131003.163911~17 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F46%2F9846%2F3;p=platform%2Fcore%2Fpim%2Fcontacts-service.git Add API to subscribe setting name dirplay/sorting order changes contacts_setting_add_name_display_order_changed_cb contacts_setting_remove_name_display_order_changed_cb contacts_setting_add_name_sorting_order_changed_cb contacts_setting_remove_name_sorting_order_changed_cb Change-Id: I8efe818af7e4864b99a690a0267aba24401e666b --- diff --git a/client/ctsvc_client_ipc.h b/client/ctsvc_client_ipc.h index ab0af18..a30e012 100644 --- a/client/ctsvc_client_ipc.h +++ b/client/ctsvc_client_ipc.h @@ -33,6 +33,7 @@ int ctsvc_ipc_disconnect_on_thread(void); bool ctsvc_ipc_is_busy(); +pims_ipc_h ctsvc_ipc_get_handle_for_change_subsciption(); int ctsvc_ipc_create_for_change_subscription(); int ctsvc_ipc_destroy_for_change_subscription(); diff --git a/client/ctsvc_client_noti.c b/client/ctsvc_client_noti.c index 61e3e62..4d7df5e 100644 --- a/client/ctsvc_client_noti.c +++ b/client/ctsvc_client_noti.c @@ -1,179 +1,195 @@ -/* - * Contacts Service - * - * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include - -#include "contacts.h" -#include "ctsvc_internal.h" -#include "ctsvc_ipc_define.h" -#include "ctsvc_mutex.h" - -typedef struct -{ - contacts_db_change_cb_with_info cb; - void *user_data; -}callback_info_s; - -typedef struct -{ - char *view_uri; - GSList *callbacks; -}subscribe_info_s; - -static pims_ipc_h __ipc = NULL; -static GSList *__subscribe_list = NULL; - -static void __ctsvc_subscriber_callback(pims_ipc_h ipc, pims_ipc_data_h data, void *user_data) -{ - unsigned int size = 0; - char *str = NULL; - subscribe_info_s *info = user_data; - +/* + * Contacts Service + * + * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include + +#include "contacts.h" +#include "ctsvc_internal.h" +#include "ctsvc_ipc_define.h" +#include "ctsvc_mutex.h" + +typedef struct +{ + contacts_db_change_cb_with_info cb; + void *user_data; +}db_callback_info_s; + +typedef struct +{ + char *view_uri; + GSList *callbacks; +}subscribe_info_s; + +static pims_ipc_h __ipc = NULL; +static GSList *__db_change_subscribe_list = NULL; + +static void __ctsvc_db_subscriber_callback(pims_ipc_h ipc, pims_ipc_data_h data, void *user_data) +{ + unsigned int size = 0; + char *str = NULL; + subscribe_info_s *info = user_data; + if (data) - str = (char*)pims_ipc_data_get(data, &size); + str = (char*)pims_ipc_data_get(data, &size); if (!str) { CTS_ERR("There is no changed data"); return; - } - - if (info) { - GSList *l; - for (l = info->callbacks;l;l=l->next) { - callback_info_s *cb_info = l->data; - cb_info->cb(info->view_uri, str, cb_info->user_data); - } - } -} - -int ctsvc_ipc_create_for_change_subscription() -{ - ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB); - - if (!__ipc) { - __ipc = pims_ipc_create_for_subscribe(CTSVC_IPC_SOCKET_PATH_FOR_CHANGE_SUBSCRIPTION); - if (!__ipc) { - CTS_ERR("pims_ipc_create_for_subscribe error\n"); - ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); - return CONTACTS_ERROR_IPC; - } - } - ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); - return CONTACTS_ERROR_NONE; -} - -int ctsvc_ipc_destroy_for_change_subscription() -{ - ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB); - - pims_ipc_destroy_for_subscribe(__ipc); - __ipc = NULL; - - ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); - return CONTACTS_ERROR_NONE; -} - -API int contacts_db_add_changed_cb_with_info(const char* view_uri, - contacts_db_change_cb_with_info cb, void* user_data) -{ - GSList *it = NULL; - subscribe_info_s *info = NULL; - callback_info_s *cb_info; - - ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB); - - for (it=__subscribe_list;it;it=it->next) { - if (!it->data) continue; - - info = it->data; - if (strcmp(info->view_uri, view_uri) == 0) - break; - else - info = NULL; - } - - if (!info) { - info = calloc(1, sizeof(subscribe_info_s)); - if (NULL == info) { - CTS_ERR("calloc() Failed"); - ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); - return CONTACTS_ERROR_OUT_OF_MEMORY; - } - - if (pims_ipc_subscribe(__ipc, CTSVC_IPC_SUBSCRIBE_MODULE, (char*)view_uri, - __ctsvc_subscriber_callback, (void*)info) != 0) { - CTS_ERR("pims_ipc_subscribe error\n"); - free(info); - ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); - return CONTACTS_ERROR_IPC; - } - info->view_uri = strdup(view_uri); - __subscribe_list = g_slist_append(__subscribe_list, info); - } - - cb_info = calloc(1, sizeof(callback_info_s)); - cb_info->user_data = user_data; - cb_info->cb = cb; - info->callbacks = g_slist_append(info->callbacks, cb_info); - - ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); - return CONTACTS_ERROR_NONE; -} - -API int contacts_db_remove_changed_cb_with_info(const char* view_uri, - contacts_db_change_cb_with_info cb, void* user_data) -{ - GSList *it = NULL; - subscribe_info_s *info = NULL; - - ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB); - - for (it=__subscribe_list;it;it=it->next) { - if (!it->data) continue; - - info = it->data; - if (strcmp(info->view_uri, view_uri) == 0) - break; - else - info = NULL; - } - - if (info) { - GSList *l; - for(l = info->callbacks;l;l=l->next) { - callback_info_s *cb_info = l->data; - if (cb == cb_info->cb && user_data == cb_info->user_data) { - info->callbacks = g_slist_remove(info->callbacks, cb_info); - break; - } - } - if (g_slist_length(info->callbacks) == 0) { - pims_ipc_unsubscribe(__ipc, CTSVC_IPC_SUBSCRIBE_MODULE, info->view_uri); - __subscribe_list = g_slist_remove(__subscribe_list, info); - free(info->view_uri); - free(info); - } - } - - ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); - return CONTACTS_ERROR_NONE; -} - + } + + if (info) { + GSList *l; + for (l = info->callbacks;l;l=l->next) { + db_callback_info_s *cb_info = l->data; + cb_info->cb(info->view_uri, str, cb_info->user_data); + } + } +} + +// This API should be called in CTS_MUTEX_PIMS_IPC_PUBSUB mutex +pims_ipc_h ctsvc_ipc_get_handle_for_change_subsciption() +{ + return __ipc; +} + +int ctsvc_ipc_create_for_change_subscription() +{ + ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB); + + if (!__ipc) { + __ipc = pims_ipc_create_for_subscribe(CTSVC_IPC_SOCKET_PATH_FOR_CHANGE_SUBSCRIPTION); + if (!__ipc) { + CTS_ERR("pims_ipc_create_for_subscribe error\n"); + ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); + return CONTACTS_ERROR_IPC; + } + } + ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); + return CONTACTS_ERROR_NONE; +} + +int ctsvc_ipc_destroy_for_change_subscription() +{ + ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB); + + pims_ipc_destroy_for_subscribe(__ipc); + __ipc = NULL; + + ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); + return CONTACTS_ERROR_NONE; +} + +API int contacts_db_add_changed_cb_with_info(const char* view_uri, + contacts_db_change_cb_with_info cb, void* user_data) +{ + GSList *it = NULL; + subscribe_info_s *info = NULL; + db_callback_info_s *cb_info; + + ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB); + + for (it=__db_change_subscribe_list;it;it=it->next) { + if (!it->data) continue; + + info = it->data; + if (strcmp(info->view_uri, view_uri) == 0) + break; + else + info = NULL; + } + + if (!info) { + info = calloc(1, sizeof(subscribe_info_s)); + if (NULL == info) { + CTS_ERR("calloc() Failed"); + ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); + return CONTACTS_ERROR_OUT_OF_MEMORY; + } + + if (pims_ipc_subscribe(__ipc, CTSVC_IPC_SUBSCRIBE_MODULE, (char*)view_uri, + __ctsvc_db_subscriber_callback, (void*)info) != 0) { + CTS_ERR("pims_ipc_subscribe error\n"); + free(info); + ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); + return CONTACTS_ERROR_IPC; + } + info->view_uri = strdup(view_uri); + __db_change_subscribe_list = g_slist_append(__db_change_subscribe_list, info); + } + else { + GSList *l; + for (l = info->callbacks;l;l=l->next) { + db_callback_info_s *cb_info = l->data; + if (cb_info->cb == cb && cb_info->user_data == user_data) { + CTS_ERR("The same callback(%s) is already exist", view_uri); + ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + } + } + + cb_info = calloc(1, sizeof(db_callback_info_s)); + cb_info->user_data = user_data; + cb_info->cb = cb; + info->callbacks = g_slist_append(info->callbacks, cb_info); + + ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); + return CONTACTS_ERROR_NONE; +} + +API int contacts_db_remove_changed_cb_with_info(const char* view_uri, + contacts_db_change_cb_with_info cb, void* user_data) +{ + GSList *it = NULL; + subscribe_info_s *info = NULL; + + ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB); + + for (it=__db_change_subscribe_list;it;it=it->next) { + if (!it->data) continue; + + info = it->data; + if (strcmp(info->view_uri, view_uri) == 0) + break; + else + info = NULL; + } + + if (info) { + GSList *l; + for(l = info->callbacks;l;l=l->next) { + db_callback_info_s *cb_info = l->data; + if (cb == cb_info->cb && user_data == cb_info->user_data) { + info->callbacks = g_slist_remove(info->callbacks, cb_info); + break; + } + } + if (g_slist_length(info->callbacks) == 0) { + pims_ipc_unsubscribe(__ipc, CTSVC_IPC_SUBSCRIBE_MODULE, info->view_uri); + __db_change_subscribe_list = g_slist_remove(__db_change_subscribe_list, info); + free(info->view_uri); + free(info); + } + } + + ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); + return CONTACTS_ERROR_NONE; +} diff --git a/client/ctsvc_client_setting.c b/client/ctsvc_client_setting.c index 0aebe12..1d5a35f 100644 --- a/client/ctsvc_client_setting.c +++ b/client/ctsvc_client_setting.c @@ -1,162 +1,338 @@ -/* - * Contacts Service - * - * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include - -#include "contacts.h" -#include "ctsvc_internal.h" -#include "ctsvc_ipc_define.h" -#include "ctsvc_ipc_marshal.h" -#include "ctsvc_client_ipc.h" - -API int contacts_setting_get_name_display_order(contacts_name_display_order_e *name_display_order) -{ - int ret = CONTACTS_ERROR_NONE; - pims_ipc_data_h outdata = NULL; - - RETVM_IF(name_display_order == NULL, CONTACTS_ERROR_INVALID_PARAMETER,"The out param is NULL"); - *name_display_order = 0; - RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected"); - - if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_GET_NAME_DISPLAY_ORDER, NULL, &outdata) != 0) { - CTS_ERR("ctsvc_ipc_call failed"); - return CONTACTS_ERROR_IPC; - } - - if (outdata) { - unsigned int size = 0; - ret = *(int*) pims_ipc_data_get(outdata, &size); - if (CONTACTS_ERROR_NONE == ret) { - *name_display_order = *(int*) pims_ipc_data_get(outdata, &size); - } - pims_ipc_data_destroy(outdata); - } - - return ret; -} - -API int contacts_setting_get_name_sorting_order(contacts_name_sorting_order_e *name_sorting_order) -{ - int ret = CONTACTS_ERROR_NONE; - pims_ipc_data_h outdata = NULL; - - RETVM_IF(name_sorting_order == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "The out param is NULL"); - *name_sorting_order = 0; - RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected"); - - if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_GET_NAME_SORTING_ORDER, NULL, &outdata) != 0) { - CTS_ERR("ctsvc_ipc_call failed"); - return CONTACTS_ERROR_IPC; - } - - if (outdata) { - unsigned int size = 0; - ret = *(int*) pims_ipc_data_get(outdata, &size); - if (CONTACTS_ERROR_NONE == ret) { - *name_sorting_order = *(int*) pims_ipc_data_get(outdata, &size); - } - pims_ipc_data_destroy(outdata); - } - - return ret; -} - -API int contacts_setting_set_name_display_order(contacts_name_display_order_e name_display_order) -{ - int ret = CONTACTS_ERROR_NONE; - pims_ipc_data_h indata = NULL; - pims_ipc_data_h outdata = NULL; - - RETVM_IF(name_display_order != CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST - && name_display_order != CONTACTS_NAME_DISPLAY_ORDER_LASTFIRST, - CONTACTS_ERROR_INVALID_PARAMETER, "name display order is invalid : %d", name_display_order); - RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected"); - - indata = pims_ipc_data_create(0); - if (indata == NULL) { - CTS_ERR("ipc data created fail!"); - ret = CONTACTS_ERROR_OUT_OF_MEMORY; - return ret; - } - - ret = ctsvc_ipc_marshal_int(name_display_order, indata); - if (ret != CONTACTS_ERROR_NONE) { - CTS_ERR("marshal fail"); - pims_ipc_data_destroy(indata); - return ret; - } - - if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_SET_NAME_DISPLAY_ORDER, indata, &outdata) != 0) { - CTS_ERR("ctsvc_ipc_call failed"); - pims_ipc_data_destroy(indata); - return CONTACTS_ERROR_IPC; - } - pims_ipc_data_destroy(indata); - - if (outdata) { - unsigned int size = 0; - ret = *(int*) pims_ipc_data_get(outdata, &size); - pims_ipc_data_destroy(outdata); - } - - return ret; -} - -API int contacts_setting_set_name_sorting_order(contacts_name_sorting_order_e name_sorint_order) -{ - int ret = CONTACTS_ERROR_NONE; - pims_ipc_data_h indata = NULL; - pims_ipc_data_h outdata = NULL; - - RETVM_IF(name_sorint_order != CONTACTS_NAME_SORTING_ORDER_FIRSTLAST - && name_sorint_order != CONTACTS_NAME_SORTING_ORDER_LASTFIRST, - CONTACTS_ERROR_INVALID_PARAMETER, "name sorting order is invalid : %d", name_sorint_order); - RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected"); - - indata = pims_ipc_data_create(0); - if (indata == NULL) { - CTS_ERR("ipc data created fail!"); - ret = CONTACTS_ERROR_OUT_OF_MEMORY; - return ret; - } - - ret = ctsvc_ipc_marshal_int(name_sorint_order, indata); - if (ret != CONTACTS_ERROR_NONE) { - CTS_ERR("marshal fail"); - pims_ipc_data_destroy(indata); - return ret; - } - - if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_SET_NAME_SORTING_ORDER, indata, &outdata) != 0) { - CTS_ERR("ctsvc_ipc_call failed"); - pims_ipc_data_destroy(indata); - return CONTACTS_ERROR_IPC; - } - pims_ipc_data_destroy(indata); - - if (outdata) { - unsigned int size = 0; - ret = *(int*) pims_ipc_data_get(outdata, &size); - pims_ipc_data_destroy(outdata); - } - - return ret; -} - +/* + * Contacts Service + * + * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include + +#include "contacts.h" +#include "ctsvc_internal.h" +#include "ctsvc_notify.h" +#include "ctsvc_ipc_define.h" +#include "ctsvc_ipc_marshal.h" +#include "ctsvc_client_ipc.h" +#include "ctsvc_mutex.h" + +API int contacts_setting_get_name_display_order(contacts_name_display_order_e *name_display_order) +{ + int ret = CONTACTS_ERROR_NONE; + pims_ipc_data_h outdata = NULL; + + RETVM_IF(name_display_order == NULL, CONTACTS_ERROR_INVALID_PARAMETER,"The out param is NULL"); + *name_display_order = 0; + RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected"); + + if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_GET_NAME_DISPLAY_ORDER, NULL, &outdata) != 0) { + CTS_ERR("ctsvc_ipc_call failed"); + return CONTACTS_ERROR_IPC; + } + + if (outdata) { + unsigned int size = 0; + ret = *(int*) pims_ipc_data_get(outdata, &size); + if (CONTACTS_ERROR_NONE == ret) { + *name_display_order = *(int*) pims_ipc_data_get(outdata, &size); + } + pims_ipc_data_destroy(outdata); + } + + return ret; +} + +API int contacts_setting_get_name_sorting_order(contacts_name_sorting_order_e *name_sorting_order) +{ + int ret = CONTACTS_ERROR_NONE; + pims_ipc_data_h outdata = NULL; + + RETVM_IF(name_sorting_order == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "The out param is NULL"); + *name_sorting_order = 0; + RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected"); + + if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_GET_NAME_SORTING_ORDER, NULL, &outdata) != 0) { + CTS_ERR("ctsvc_ipc_call failed"); + return CONTACTS_ERROR_IPC; + } + + if (outdata) { + unsigned int size = 0; + ret = *(int*) pims_ipc_data_get(outdata, &size); + if (CONTACTS_ERROR_NONE == ret) { + *name_sorting_order = *(int*) pims_ipc_data_get(outdata, &size); + } + pims_ipc_data_destroy(outdata); + } + + return ret; +} + +API int contacts_setting_set_name_display_order(contacts_name_display_order_e name_display_order) +{ + int ret = CONTACTS_ERROR_NONE; + pims_ipc_data_h indata = NULL; + pims_ipc_data_h outdata = NULL; + + RETVM_IF(name_display_order != CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST + && name_display_order != CONTACTS_NAME_DISPLAY_ORDER_LASTFIRST, + CONTACTS_ERROR_INVALID_PARAMETER, "name display order is invalid : %d", name_display_order); + RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected"); + + indata = pims_ipc_data_create(0); + if (indata == NULL) { + CTS_ERR("ipc data created fail!"); + ret = CONTACTS_ERROR_OUT_OF_MEMORY; + return ret; + } + + ret = ctsvc_ipc_marshal_int(name_display_order, indata); + if (ret != CONTACTS_ERROR_NONE) { + CTS_ERR("marshal fail"); + pims_ipc_data_destroy(indata); + return ret; + } + + if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_SET_NAME_DISPLAY_ORDER, indata, &outdata) != 0) { + CTS_ERR("ctsvc_ipc_call failed"); + pims_ipc_data_destroy(indata); + return CONTACTS_ERROR_IPC; + } + pims_ipc_data_destroy(indata); + + if (outdata) { + unsigned int size = 0; + ret = *(int*) pims_ipc_data_get(outdata, &size); + pims_ipc_data_destroy(outdata); + } + + return ret; +} + +API int contacts_setting_set_name_sorting_order(contacts_name_sorting_order_e name_sorint_order) +{ + int ret = CONTACTS_ERROR_NONE; + pims_ipc_data_h indata = NULL; + pims_ipc_data_h outdata = NULL; + + RETVM_IF(name_sorint_order != CONTACTS_NAME_SORTING_ORDER_FIRSTLAST + && name_sorint_order != CONTACTS_NAME_SORTING_ORDER_LASTFIRST, + CONTACTS_ERROR_INVALID_PARAMETER, "name sorting order is invalid : %d", name_sorint_order); + RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected"); + + indata = pims_ipc_data_create(0); + if (indata == NULL) { + CTS_ERR("ipc data created fail!"); + ret = CONTACTS_ERROR_OUT_OF_MEMORY; + return ret; + } + + ret = ctsvc_ipc_marshal_int(name_sorint_order, indata); + if (ret != CONTACTS_ERROR_NONE) { + CTS_ERR("marshal fail"); + pims_ipc_data_destroy(indata); + return ret; + } + + if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_SET_NAME_SORTING_ORDER, indata, &outdata) != 0) { + CTS_ERR("ctsvc_ipc_call failed"); + pims_ipc_data_destroy(indata); + return CONTACTS_ERROR_IPC; + } + pims_ipc_data_destroy(indata); + + if (outdata) { + unsigned int size = 0; + ret = *(int*) pims_ipc_data_get(outdata, &size); + pims_ipc_data_destroy(outdata); + } + + return ret; +} + +typedef struct +{ + contacts_setting_name_display_order_changed_cb cb; + void *user_data; +}ctsvc_name_display_order_changed_cb_info_s; + +static GSList *__setting_name_display_order_subscribe_list = NULL; + +static void __ctsvc_setting_name_display_order_subscriber_callback(pims_ipc_h ipc, pims_ipc_data_h data, void *user_data) +{ + int value = -1; + unsigned int size = 0; + if (data) + value = *(int*)pims_ipc_data_get(data, &size); + + if (__setting_name_display_order_subscribe_list) { + GSList *l; + for (l = __setting_name_display_order_subscribe_list;l;l=l->next) { + ctsvc_name_display_order_changed_cb_info_s *cb_info = l->data; + if (cb_info->cb) + cb_info->cb((contacts_name_display_order_e)value, cb_info->user_data); + } + } +} + +API int contacts_setting_add_name_display_order_changed_cb( + contacts_setting_name_display_order_changed_cb cb, void* user_data) +{ + GSList *l; + ctsvc_name_display_order_changed_cb_info_s *cb_info; + + ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB); + + if (!__setting_name_display_order_subscribe_list) { + if (pims_ipc_subscribe(ctsvc_ipc_get_handle_for_change_subsciption(), + CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_SETTING_DISPLAY_ORDER_CHANGED, + __ctsvc_setting_name_display_order_subscriber_callback, NULL) != 0) { + CTS_ERR("pims_ipc_subscribe error\n"); + ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); + return CONTACTS_ERROR_IPC; + } + } + + for (l = __setting_name_display_order_subscribe_list;l;l=l->next) { + ctsvc_name_display_order_changed_cb_info_s *cb_info = l->data; + if (cb_info->cb == cb && cb_info->user_data == user_data) { + CTS_ERR("The same callback(%s) is already exist"); + return CONTACTS_ERROR_SYSTEM; + } + } + + cb_info = calloc(1, sizeof(ctsvc_name_display_order_changed_cb_info_s)); + cb_info->user_data = user_data; + cb_info->cb = cb; + __setting_name_display_order_subscribe_list = g_slist_append(__setting_name_display_order_subscribe_list, cb_info); + + ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); + return CONTACTS_ERROR_NONE; +} + +API int contacts_setting_remove_name_display_order_changed_cb( + contacts_setting_name_display_order_changed_cb cb, void* user_data) +{ + ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB); + + if (__setting_name_display_order_subscribe_list) { + GSList *l; + for(l = __setting_name_display_order_subscribe_list;l;l=l->next) { + ctsvc_name_display_order_changed_cb_info_s *cb_info = l->data; + if (cb == cb_info->cb && user_data == cb_info->user_data) { + __setting_name_display_order_subscribe_list = g_slist_remove(__setting_name_display_order_subscribe_list, cb_info); + free(cb_info); + break; + } + } + if (g_slist_length(__setting_name_display_order_subscribe_list) == 0) { + pims_ipc_unsubscribe(ctsvc_ipc_get_handle_for_change_subsciption(), + CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_SETTING_DISPLAY_ORDER_CHANGED); + g_slist_free(__setting_name_display_order_subscribe_list); + __setting_name_display_order_subscribe_list = NULL; + } + } + + ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); + return CONTACTS_ERROR_NONE; +} + +typedef struct +{ + contacts_setting_name_sorting_order_changed_cb cb; + void *user_data; +}ctsvc_name_sorting_order_changed_cb_info_s; + +static GSList *__setting_name_sorting_order_subscribe_list = NULL; + +static void __ctsvc_setting_name_sorting_order_subscriber_callback(pims_ipc_h ipc, pims_ipc_data_h data, void *user_data) +{ + int value = -1; + unsigned int size = 0; + if (data) + value = *(int*)pims_ipc_data_get(data, &size); + + if (__setting_name_sorting_order_subscribe_list) { + GSList *l; + for (l = __setting_name_sorting_order_subscribe_list;l;l=l->next) { + ctsvc_name_sorting_order_changed_cb_info_s *cb_info = l->data; + if (cb_info->cb) + cb_info->cb((contacts_name_sorting_order_e)value, cb_info->user_data); + } + } +} + +API int contacts_setting_add_name_sorting_order_changed_cb( + contacts_setting_name_sorting_order_changed_cb cb, void* user_data) +{ + GSList *l; + ctsvc_name_sorting_order_changed_cb_info_s *cb_info; + + ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB); + + if (!__setting_name_sorting_order_subscribe_list) { + if (pims_ipc_subscribe(ctsvc_ipc_get_handle_for_change_subsciption(), + CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_SETTING_SORTING_ORDER_CHANGED, + __ctsvc_setting_name_sorting_order_subscriber_callback, NULL) != 0) { + CTS_ERR("pims_ipc_subscribe error\n"); + ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); + return CONTACTS_ERROR_IPC; + } + } + + for (l = __setting_name_sorting_order_subscribe_list;l;l=l->next) { + ctsvc_name_sorting_order_changed_cb_info_s *cb_info = l->data; + if (cb_info->cb == cb && cb_info->user_data == user_data) { + CTS_ERR("The same callback(%s) is already exist"); + return CONTACTS_ERROR_SYSTEM; + } + } + + cb_info = calloc(1, sizeof(ctsvc_name_sorting_order_changed_cb_info_s)); + cb_info->user_data = user_data; + cb_info->cb = cb; + __setting_name_sorting_order_subscribe_list = g_slist_append(__setting_name_sorting_order_subscribe_list, cb_info); + + ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); + return CONTACTS_ERROR_NONE; +} + +API int contacts_setting_remove_name_sorting_order_changed_cb( + contacts_setting_name_sorting_order_changed_cb cb, void* user_data) +{ + ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB); + + if (__setting_name_sorting_order_subscribe_list) { + GSList *l; + for(l = __setting_name_sorting_order_subscribe_list;l;l=l->next) { + ctsvc_name_sorting_order_changed_cb_info_s *cb_info = l->data; + if (cb == cb_info->cb && user_data == cb_info->user_data) { + __setting_name_sorting_order_subscribe_list = g_slist_remove(__setting_name_sorting_order_subscribe_list, cb_info); + free(cb_info); + break; + } + } + if (g_slist_length(__setting_name_sorting_order_subscribe_list) == 0) { + pims_ipc_unsubscribe(ctsvc_ipc_get_handle_for_change_subsciption(), + CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_SETTING_SORTING_ORDER_CHANGED); + g_slist_free(__setting_name_sorting_order_subscribe_list); + __setting_name_sorting_order_subscribe_list = NULL; + } + } + + ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); + return CONTACTS_ERROR_NONE; +} + diff --git a/common/ctsvc_notify.h b/common/ctsvc_notify.h index 91e9b64..28594f7 100644 --- a/common/ctsvc_notify.h +++ b/common/ctsvc_notify.h @@ -45,5 +45,7 @@ #define CTSVC_NOTI_PHONELOG_CHANGED "/opt/usr/data/contacts-svc/.CONTACTS_SVC_PLOG_CHANGED" #define CTSVC_NOTI_SPEEDDIAL_CHANGED "/opt/usr/data/contacts-svc/.CONTACTS_SVC_SPEED_CHANGED" +#define CTSVC_SETTING_DISPLAY_ORDER_CHANGED "contacts.setting.display_order" +#define CTSVC_SETTING_SORTING_ORDER_CHANGED "contacts.setting.sorting_order" #endif /* __TIZEN_SOCIAL_CTSVC_NOTIFY_H__ */ diff --git a/include/contacts_setting.h b/include/contacts_setting.h index c1e8d55..563a717 100755 --- a/include/contacts_setting.h +++ b/include/contacts_setting.h @@ -118,6 +118,102 @@ API int contacts_setting_get_name_sorting_order(contacts_name_sorting_order_e *n API int contacts_setting_set_name_sorting_order(contacts_name_sorting_order_e name_sorting_order); /** + * @brief Called when designated view changes. + * + * @param[in] name_display_order Name display order setting value + * @param[in] user_data The user data passed from the callback registration function + * + * @see contacts_setting_add_name_display_order_changed_cb() + * @see contacts_setting_remove_name_display_order_changed_cb() + */ +typedef void (*contacts_setting_name_display_order_changed_cb)(contacts_name_display_order_e name_display_order, void* user_data); + + +/** + * @brief Registers a callback function. + * + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre This function requires an open connection to the contacts service by contacts_connect2(). + * + * @see contacts_connect2() + * @see contacts_setting_remove_name_display_order_changed_cb() + */ + +API int contacts_setting_add_name_display_order_changed_cb(contacts_setting_name_display_order_changed_cb callback, void* user_data); + +/** + * @brief Unregisters a callback function. + * + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre This function requires an open connection to the contacts service by contacts_connect2(). + * + * @see contacts_connect2() + * @see contacts_setting_add_name_display_order_changed_cb() + */ + +API int contacts_setting_remove_name_display_order_changed_cb(contacts_setting_name_display_order_changed_cb callback, void* user_data); + +/** + * @brief Called when designated view changes. + * + * @param[in] name_sorting_order Name sorting order setting value + * @param[in] user_data The user data passed from the callback registration function + * + * @see contacts_setting_add_name_sorting_order_changed_cb() + * @see contacts_setting_remove_name_sorting_order_changed_cb() + */ +typedef void (*contacts_setting_name_sorting_order_changed_cb)(contacts_name_sorting_order_e name_sorting_order, void* user_data); + + +/** + * @brief Registers a callback function. + * + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre This function requires an open connection to the contacts service by contacts_connect2(). + * + * @see contacts_connect2() + * @see contacts_setting_remove_name_sorting_order_changed_cb() + */ + +API int contacts_setting_add_name_sorting_order_changed_cb(contacts_setting_name_sorting_order_changed_cb callback, void* user_data); + +/** + * @brief Unregisters a callback function. + * + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre This function requires an open connection to the contacts service by contacts_connect2(). + * + * @see contacts_connect2() + * @see contacts_setting_add_name_sorting_order_changed_cb() + */ + +API int contacts_setting_remove_name_sorting_order_changed_cb(contacts_setting_name_sorting_order_changed_cb callback, void* user_data); + +/** * @} */ diff --git a/native/ctsvc_setting.c b/native/ctsvc_setting.c index eb107bc..433847f 100644 --- a/native/ctsvc_setting.c +++ b/native/ctsvc_setting.c @@ -27,10 +27,15 @@ #include "contacts.h" #include "ctsvc_internal.h" +#include "ctsvc_notify.h" #include "ctsvc_setting.h" #include "ctsvc_normalize.h" #include "ctsvc_localize.h" +#ifdef _CONTACTS_IPC_SERVER +#include "ctsvc_server_change_subject.h" +#endif + static int primary_sort = -1; static int secondary_sort = -1; @@ -61,6 +66,9 @@ API int contacts_setting_set_name_display_order(contacts_name_display_order_e or RETVM_IF(CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST != order && CONTACTS_NAME_DISPLAY_ORDER_LASTFIRST != order, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : The parameter(order:%d) is Invalid", name_display_order); + if (order == name_display_order) + return CONTACTS_ERROR_NONE; + ret = vconf_set_int(CTSVC_VCONF_DISPLAY_ORDER, order); RETVM_IF(ret<0, CONTACTS_ERROR_SYSTEM, "System : vconf_set_int(display order) Failed(%d)", ret); @@ -89,6 +97,9 @@ API int contacts_setting_set_name_sorting_order(contacts_name_sorting_order_e or RETVM_IF(CONTACTS_NAME_SORTING_ORDER_FIRSTLAST != order && CONTACTS_NAME_SORTING_ORDER_LASTFIRST != order, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : The parameter(order:%d) is Invalid", name_sorting_order); + if (order == name_sorting_order) + return CONTACTS_ERROR_NONE; + ret = vconf_set_int(CTSVC_VCONF_SORTING_ORDER, order); RETVM_IF(ret<0, CONTACTS_ERROR_SYSTEM, "System : vconf_set_int(sort order) Failed(%d)", ret); @@ -100,11 +111,21 @@ API int contacts_setting_set_name_sorting_order(contacts_name_sorting_order_e or static void ctsvc_vconf_display_order_cb(keynode_t *key, void *data) { name_display_order = vconf_keynode_get_int(key); + +#ifdef _CONTACTS_IPC_SERVER + // publish display order changed + ctsvc_change_subject_publish_setting(CTSVC_SETTING_DISPLAY_ORDER_CHANGED, name_display_order); +#endif } static void ctsvc_vconf_sorting_order_cb(keynode_t *key, void *data) { name_sorting_order = vconf_keynode_get_int(key); + +#ifdef _CONTACTS_IPC_SERVER + // publish sort order changed + ctsvc_change_subject_publish_setting(CTSVC_SETTING_SORTING_ORDER_CHANGED, name_sorting_order); +#endif } void ctscts_set_sort_memory(int sort_type) @@ -200,3 +221,35 @@ int ctsvc_get_secondary_sort(void) return secondary_sort; } +#ifdef _CONTACTS_NATIVE +API int contacts_setting_add_name_display_order_changed_cb( + contacts_setting_name_display_order_changed_cb cb, void* user_data) +{ + CTS_ERR("Please use contacts-service2 instead of contacts-service3"); + return CONTACTS_ERROR_INTERNAL; +} + +API int contacts_setting_remove_name_display_order_changed_cb( + contacts_setting_name_display_order_changed_cb cb, void* user_data) +{ + CTS_ERR("Please use contacts-service2 instead of contacts-service3"); + return CONTACTS_ERROR_INTERNAL; + +} + +API int contacts_setting_add_name_sorting_order_changed_cb( + contacts_setting_name_sorting_order_changed_cb cb, void* user_data) +{ + CTS_ERR("Please use contacts-service2 instead of contacts-service3"); + return CONTACTS_ERROR_INTERNAL; +} + + +API int contacts_setting_remove_name_sorting_order_changed_cb( + contacts_setting_name_sorting_order_changed_cb cb, void* user_data) +{ + CTS_ERR("Please use contacts-service2 instead of contacts-service3"); + return CONTACTS_ERROR_INTERNAL; +} + +#endif diff --git a/server/ctsvc_server_change_subject.c b/server/ctsvc_server_change_subject.c index da6aced..536b097 100644 --- a/server/ctsvc_server_change_subject.c +++ b/server/ctsvc_server_change_subject.c @@ -1,128 +1,146 @@ -/* - * Contacts Service Helper - * - * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include - -#include "contacts.h" -#include "ctsvc_internal.h" - -#include "ctsvc_ipc_define.h" -#include "ctsvc_server_change_subject.h" - -#define CTSVC_SUBSCRIBE_MAX_LEN 1024 - -static __thread char *__phone_log_chanaged_info = NULL; -static __thread unsigned int __phone_log_buf_size = 0; - -static __thread char *__person_changed_info = NULL; -static __thread unsigned int __person_buf_size = 0; - -static gboolean __ctsvc_publish_changes_with_data(const char *view_uri, char *data) -{ - pims_ipc_data_h indata = NULL; - if( NULL == data ) - return true; - - indata = pims_ipc_data_create(0); - if (!indata) { - CTS_ERR("pims_ipc_data_create error\n"); - return false; - } - - if (pims_ipc_data_put(indata, data, strlen(data) + 1) != 0) { - CTS_ERR("pims_ipc_data_put error\n"); - return false; - } - - if (pims_ipc_svc_publish(CTSVC_IPC_SUBSCRIBE_MODULE, (char*)view_uri, indata) != 0) { - CTS_ERR("pims_ipc_svc_publish error (%s)\n", view_uri); - return false; - } - - pims_ipc_data_destroy(indata); - - return true; -} - -void ctsvc_change_subject_publish_changed_info() -{ - __ctsvc_publish_changes_with_data(_contacts_person._uri, __person_changed_info); - __ctsvc_publish_changes_with_data(_contacts_phone_log._uri, __phone_log_chanaged_info); - ctsvc_change_subject_clear_changed_info(); -} - -void ctsvc_change_subject_clear_changed_info() -{ - free(__phone_log_chanaged_info); - __phone_log_chanaged_info = NULL; - __phone_log_buf_size = 0; - - free(__person_changed_info); - __person_changed_info = NULL; - __person_buf_size = 0; -} - -void ctsvc_change_subject_add_changed_phone_log_id(contacts_changed_e type, int id) -{ - CTS_FN_CALL; - int len = 0; - int info_len = 0; - char changed_info[30] = {0}; - - if (!__phone_log_chanaged_info) { - __phone_log_chanaged_info = (char*)calloc(CTSVC_SUBSCRIBE_MAX_LEN, sizeof(char)); - __phone_log_buf_size = CTSVC_SUBSCRIBE_MAX_LEN; - __phone_log_chanaged_info[0] = '\0'; - } - - len = snprintf(changed_info, sizeof(changed_info), "%d:%d,", type, id); - info_len = strlen(__phone_log_chanaged_info); - CTS_DBG("%s(len : %d), %s (crrent_len : %d), max_len : %d", - changed_info, len, __phone_log_chanaged_info, info_len, __phone_log_buf_size); - if (info_len + len > __phone_log_buf_size) { - __phone_log_chanaged_info = realloc(__phone_log_chanaged_info, __phone_log_buf_size * 2); - __phone_log_buf_size *= 2; - } - snprintf(__phone_log_chanaged_info + info_len, __phone_log_buf_size - info_len, "%s", changed_info); - CTS_DBG("%s", __phone_log_chanaged_info); -} - -void ctsvc_change_subject_add_changed_person_id(contacts_changed_e type, int id) -{ - CTS_FN_CALL; - int len = 0; - int info_len = 0; - char changed_info[30] = {0}; - - if (!__person_changed_info) { - __person_changed_info = (char*)calloc(CTSVC_SUBSCRIBE_MAX_LEN, sizeof(char)); - __person_buf_size = CTSVC_SUBSCRIBE_MAX_LEN; - __person_changed_info[0] = '\0'; - } - - len = snprintf(changed_info, sizeof(changed_info), "%d:%d,", type, id); - info_len = strlen(__person_changed_info); - if (info_len + len > __person_buf_size) { - __person_changed_info = realloc(__person_changed_info, __person_buf_size * 2); - __person_buf_size *= 2; - } - snprintf(__person_changed_info + info_len, __person_buf_size - info_len, "%s", changed_info); -} +/* + * Contacts Service Helper + * + * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include + +#include "contacts.h" +#include "ctsvc_internal.h" + +#include "ctsvc_ipc_define.h" +#include "ctsvc_server_change_subject.h" + +#define CTSVC_SUBSCRIBE_MAX_LEN 1024 + +static __thread char *__phone_log_chanaged_info = NULL; +static __thread unsigned int __phone_log_buf_size = 0; + +static __thread char *__person_changed_info = NULL; +static __thread unsigned int __person_buf_size = 0; + +static gboolean __ctsvc_publish_changes_with_data(const char *view_uri, char *data) +{ + pims_ipc_data_h indata = NULL; + if( NULL == data ) + return true; + + indata = pims_ipc_data_create(0); + if (!indata) { + CTS_ERR("pims_ipc_data_create error\n"); + return false; + } + + if (pims_ipc_data_put(indata, data, strlen(data) + 1) != 0) { + CTS_ERR("pims_ipc_data_put error\n"); + return false; + } + + if (pims_ipc_svc_publish(CTSVC_IPC_SUBSCRIBE_MODULE, (char*)view_uri, indata) != 0) { + CTS_ERR("pims_ipc_svc_publish error (%s)\n", view_uri); + return false; + } + + pims_ipc_data_destroy(indata); + + return true; +} + +void ctsvc_change_subject_publish_changed_info() +{ + __ctsvc_publish_changes_with_data(_contacts_person._uri, __person_changed_info); + __ctsvc_publish_changes_with_data(_contacts_phone_log._uri, __phone_log_chanaged_info); + ctsvc_change_subject_clear_changed_info(); +} + +void ctsvc_change_subject_clear_changed_info() +{ + free(__phone_log_chanaged_info); + __phone_log_chanaged_info = NULL; + __phone_log_buf_size = 0; + + free(__person_changed_info); + __person_changed_info = NULL; + __person_buf_size = 0; +} + +void ctsvc_change_subject_add_changed_phone_log_id(contacts_changed_e type, int id) +{ + CTS_FN_CALL; + int len = 0; + int info_len = 0; + char changed_info[30] = {0}; + + if (!__phone_log_chanaged_info) { + __phone_log_chanaged_info = (char*)calloc(CTSVC_SUBSCRIBE_MAX_LEN, sizeof(char)); + __phone_log_buf_size = CTSVC_SUBSCRIBE_MAX_LEN; + __phone_log_chanaged_info[0] = '\0'; + } + + len = snprintf(changed_info, sizeof(changed_info), "%d:%d,", type, id); + info_len = strlen(__phone_log_chanaged_info); + CTS_DBG("%s(len : %d), %s (crrent_len : %d), max_len : %d", + changed_info, len, __phone_log_chanaged_info, info_len, __phone_log_buf_size); + if (info_len + len > __phone_log_buf_size) { + __phone_log_chanaged_info = realloc(__phone_log_chanaged_info, __phone_log_buf_size * 2); + __phone_log_buf_size *= 2; + } + snprintf(__phone_log_chanaged_info + info_len, __phone_log_buf_size - info_len, "%s", changed_info); + CTS_DBG("%s", __phone_log_chanaged_info); +} + +void ctsvc_change_subject_add_changed_person_id(contacts_changed_e type, int id) +{ + CTS_FN_CALL; + int len = 0; + int info_len = 0; + char changed_info[30] = {0}; + + if (!__person_changed_info) { + __person_changed_info = (char*)calloc(CTSVC_SUBSCRIBE_MAX_LEN, sizeof(char)); + __person_buf_size = CTSVC_SUBSCRIBE_MAX_LEN; + __person_changed_info[0] = '\0'; + } + + len = snprintf(changed_info, sizeof(changed_info), "%d:%d,", type, id); + info_len = strlen(__person_changed_info); + if (info_len + len > __person_buf_size) { + __person_changed_info = realloc(__person_changed_info, __person_buf_size * 2); + __person_buf_size *= 2; + } + snprintf(__person_changed_info + info_len, __person_buf_size - info_len, "%s", changed_info); +} + +void ctsvc_change_subject_publish_setting(const char *setting_id, int value) +{ + pims_ipc_data_h indata = NULL; + indata = pims_ipc_data_create(0); + RETM_IF(NULL == indata, "pims_ipc_data_create error"); + + if (pims_ipc_data_put(indata, (void*)&value, sizeof(int)) != 0) { + CTS_ERR("pims_ipc_data_put error"); + pims_ipc_data_destroy(indata); + return; + } + + if (pims_ipc_svc_publish(CTSVC_IPC_SUBSCRIBE_MODULE, (char*)setting_id, indata) != 0) + CTS_ERR("pims_ipc_svc_publish error (%s)", setting_id); + + pims_ipc_data_destroy(indata); +} diff --git a/server/ctsvc_server_change_subject.h b/server/ctsvc_server_change_subject.h index af27d00..dec3579 100644 --- a/server/ctsvc_server_change_subject.h +++ b/server/ctsvc_server_change_subject.h @@ -1,5 +1,5 @@ /* - * Contacts Service Helper + * Contacts Service * * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved. * @@ -28,4 +28,6 @@ void ctsvc_change_subject_clear_changed_info(); void ctsvc_change_subject_add_changed_phone_log_id(contacts_changed_e type, int id); void ctsvc_change_subject_add_changed_person_id(contacts_changed_e type, int id); -#endif // __CTSVC_SERVER_CHANGE_SUBJECT_H__ \ No newline at end of file +void ctsvc_change_subject_publish_setting(const char *setting_id, int value); + +#endif // __CTSVC_SERVER_CHANGE_SUBJECT_H__