From c43cb7dab35d5699f29856cf00fa5cdde5c2ce8a Mon Sep 17 00:00:00 2001 From: Gukhwan Cho Date: Tue, 1 Sep 2015 14:10:26 +0900 Subject: [PATCH] recovery subscription Change-Id: Ia33b89b4223f09c6e464def51637dac650e13d41 Signed-off-by: Gukhwan Cho --- client/ctsvc_client_noti.c | 53 ++++++++++++++++++--- client/ctsvc_client_setting.c | 108 +++++++++++++++++++++++++++--------------- client/ctsvc_client_setting.h | 25 ++++++++++ 3 files changed, 141 insertions(+), 45 deletions(-) create mode 100644 client/ctsvc_client_setting.h diff --git a/client/ctsvc_client_noti.c b/client/ctsvc_client_noti.c index f87f2f7..3de5616 100644 --- a/client/ctsvc_client_noti.c +++ b/client/ctsvc_client_noti.c @@ -29,6 +29,7 @@ #include "ctsvc_ipc_marshal.h" #include "ctsvc_mutex.h" #include "ctsvc_client_ipc.h" +#include "ctsvc_client_setting.h" #include "contacts_extension.h" typedef struct @@ -76,6 +77,28 @@ DATA_FREE: free(str); } +int __ctsvc_db_recover_for_change_subscription() +{ + GSList *it = NULL; + subscribe_info_s *info = NULL; + + for (it=__db_change_subscribe_list;it;it=it->next) { + if (NULL == it->data) continue; + + info = it->data; + if (info->view_uri) { + if (pims_ipc_subscribe(__ipc, CTSVC_IPC_SUBSCRIBE_MODULE, info->view_uri, + __ctsvc_db_subscriber_callback, (void*)info) != 0) { + CTS_ERR("pims_ipc_subscribe() Fail"); + return CONTACTS_ERROR_IPC; + } + } + } + + return CONTACTS_ERROR_NONE; +} + + /* This API should be called in CTS_MUTEX_PIMS_IPC_PUBSUB mutex */ pims_ipc_h ctsvc_ipc_get_handle_for_change_subsciption() { @@ -97,7 +120,7 @@ int ctsvc_ipc_create_for_change_subscription() snprintf(sock_file, sizeof(sock_file), CTSVC_SOCK_PATH"/.%s_for_subscribe", getuid(), CTSVC_IPC_SERVICE); __ipc = pims_ipc_create_for_subscribe(sock_file); if (NULL == __ipc) { - CTS_ERR("pims_ipc_create_for_subscribe error\n"); + CTS_ERR("pims_ipc_create_for_subscribe() Fail"); ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); return CONTACTS_ERROR_IPC; } @@ -109,17 +132,33 @@ int ctsvc_ipc_create_for_change_subscription() int ctsvc_ipc_recover_for_change_subscription() { + int ret; ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB); if (__ipc_pubsub_ref <= 0) { ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); return CONTACTS_ERROR_NONE; } + + pims_ipc_destroy_for_subscribe(__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"); + if (NULL == __ipc) { + CTS_ERR("pims_ipc_create_for_subscribe() Fail"); ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); return CONTACTS_ERROR_IPC; } + ret = ctsvc_setting_recover_for_change_subscription(); + if (CONTACTS_ERROR_NONE != ret) { + CTS_ERR("ctsvc_setting_recover_for_change_subscription() Fail(%d)", ret); + ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); + return ret; + } + ret = __ctsvc_db_recover_for_change_subscription(); + if (CONTACTS_ERROR_NONE != ret) { + CTS_ERR("__ctsvc_db_recover_changed_cb_with_info() Fail(%d)", ret); + ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); + return ret; + } + ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); return CONTACTS_ERROR_NONE; } @@ -161,12 +200,12 @@ API int contacts_db_add_changed_cb_with_info(const char* view_uri, if (STRING_EQUAL == strncmp(view_uri, CTSVC_VIEW_URI_PHONELOG, strlen(CTSVC_VIEW_URI_PHONELOG))) { ret = ctsvc_ipc_client_check_permission(CTSVC_PERMISSION_PHONELOG_READ, &result); - RETVM_IF(ret != CONTACTS_ERROR_NONE, ret, "ctsvc_ipc_client_check_permission fail (%d)", ret); + RETVM_IF(ret != CONTACTS_ERROR_NONE, ret, "ctsvc_ipc_client_check_permission() Fail(%d)", ret); RETVM_IF(result == false, CONTACTS_ERROR_PERMISSION_DENIED, "Permission denied (phonelog read)"); } else if (STRING_EQUAL == strncmp(view_uri, CTSVC_VIEW_URI_PERSON, strlen(CTSVC_VIEW_URI_PERSON))) { ret = ctsvc_ipc_client_check_permission(CTSVC_PERMISSION_CONTACT_READ, &result); - RETVM_IF(ret != CONTACTS_ERROR_NONE, ret, "ctsvc_ipc_client_check_permission fail (%d)", ret); + RETVM_IF(ret != CONTACTS_ERROR_NONE, ret, "ctsvc_ipc_client_check_permission() Fail(%d)", ret); RETVM_IF(result == false, CONTACTS_ERROR_PERMISSION_DENIED, "Permission denied (contact read)"); } else { @@ -196,7 +235,7 @@ API int contacts_db_add_changed_cb_with_info(const char* view_uri, 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"); + CTS_ERR("pims_ipc_subscribe() Fail"); free(info); ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); return CONTACTS_ERROR_IPC; @@ -218,7 +257,7 @@ API int contacts_db_add_changed_cb_with_info(const char* view_uri, cb_info = calloc(1, sizeof(db_callback_info_s)); if (NULL == cb_info) { - CTS_ERR("calloc() Failed"); + CTS_ERR("calloc() Fail"); ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); return CONTACTS_ERROR_OUT_OF_MEMORY; } diff --git a/client/ctsvc_client_setting.c b/client/ctsvc_client_setting.c index fc8a8f2..fc9f480 100644 --- a/client/ctsvc_client_setting.c +++ b/client/ctsvc_client_setting.c @@ -28,6 +28,21 @@ #include "ctsvc_client_ipc.h" #include "ctsvc_mutex.h" +typedef struct +{ + contacts_setting_name_display_order_changed_cb cb; + void *user_data; +}ctsvc_name_display_order_changed_cb_info_s; + +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_display_order_subscribe_list = NULL; +static GSList *__setting_name_sorting_order_subscribe_list = NULL; + API int contacts_setting_get_name_display_order(contacts_name_display_order_e *name_display_order) { int ret = CONTACTS_ERROR_NONE; @@ -179,14 +194,6 @@ API int contacts_setting_set_name_sorting_order(contacts_name_sorting_order_e na 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 ret; @@ -206,6 +213,59 @@ static void __ctsvc_setting_name_display_order_subscriber_callback(pims_ipc_h ip } } +static void __ctsvc_setting_name_sorting_order_subscriber_callback(pims_ipc_h ipc, pims_ipc_data_h data, void *user_data) +{ + int ret; + int value = -1; + + if (data) { + ret = ctsvc_ipc_unmarshal_int(data, &value); + WARN_IF(CONTACTS_ERROR_NONE != ret, "() Fail(%d)", ret); + } + + 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); + } + } +} + +int ctsvc_setting_recover_for_change_subscription() +{ + GSList *it; + + for (it = __setting_name_display_order_subscribe_list; it; it=it->next) { + ctsvc_name_display_order_changed_cb_info_s *cb_info = it->data; + if (cb_info->cb) { + 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() Fail"); + return CONTACTS_ERROR_IPC; + } + break; + } + } + + for (it = __setting_name_sorting_order_subscribe_list; it; it=it->next) { + ctsvc_name_sorting_order_changed_cb_info_s *cb_info = it->data; + if (cb_info->cb) { + 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() Fail"); + return CONTACTS_ERROR_IPC; + } + break; + } + } + + return CONTACTS_ERROR_NONE; +} + API int contacts_setting_add_name_display_order_changed_cb( contacts_setting_name_display_order_changed_cb cb, void* user_data) { @@ -226,7 +286,7 @@ API int contacts_setting_add_name_display_order_changed_cb( 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"); + CTS_ERR("pims_ipc_subscribe() Fail"); ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); return CONTACTS_ERROR_IPC; } @@ -284,34 +344,6 @@ API int contacts_setting_remove_name_display_order_changed_cb( 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 ret; - int value = -1; - - if (data) { - ret = ctsvc_ipc_unmarshal_int(data, &value); - WARN_IF(CONTACTS_ERROR_NONE != ret, "() Fail(%d)", ret); - } - - 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) { @@ -332,7 +364,7 @@ API int contacts_setting_add_name_sorting_order_changed_cb( 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"); + CTS_ERR("pims_ipc_subscribe() Fail"); ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); return CONTACTS_ERROR_IPC; } diff --git a/client/ctsvc_client_setting.h b/client/ctsvc_client_setting.h new file mode 100644 index 0000000..c7d9b4c --- /dev/null +++ b/client/ctsvc_client_setting.h @@ -0,0 +1,25 @@ +/* + * Contacts Service + * + * Copyright (c) 2015 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. + * + */ + +#ifndef __CTSVC_CLIENT_SETTING_H__ +#define __CTSVC_CLIENT_SETTING_H__ + +int ctsvc_setting_recover_for_change_subscription(); + +#endif /* __CTSVC_CLIENT_SETTING_H__ */ -- 2.7.4