From: Gukhwan Cho Date: Thu, 17 Sep 2015 13:54:43 +0000 (+0900) Subject: create subscription by adding changed_cb API X-Git-Tag: accepted/tizen/mobile/20151119.033537~13^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f56983c7f7625fab11ae70b445e5e5213fab4336;p=platform%2Fcore%2Fpim%2Fcontacts-service.git create subscription by adding changed_cb API Change-Id: I7348f85be5877af5375a072582fc64e4096e41ad Signed-off-by: Gukhwan Cho --- diff --git a/client/ctsvc_client_db_helper.c b/client/ctsvc_client_db_helper.c index 35d53b9..dbbebd6 100644 --- a/client/ctsvc_client_db_helper.c +++ b/client/ctsvc_client_db_helper.c @@ -1445,12 +1445,19 @@ int ctsvc_client_db_get_status(contacts_h contact, contacts_db_status_e *status) int ctsvc_client_db_add_status_changed_cb(contacts_h contact, contacts_db_status_changed_cb cb, void* user_data) { + int ret; status_callback_info_s *cb_info = NULL; RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL"); RETVM_IF(NULL == cb, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : callback is null"); + ret = ctsvc_ipc_create_for_change_subscription(); + if (CONTACTS_ERROR_NONE != ret) { + CTS_ERR("ctsvc_ipc_create_for_change_subscription() Fail(%d)", ret); + return ret; + } + ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB); if (pims_ipc_subscribe(ctsvc_ipc_get_handle_for_change_subsciption(), @@ -1478,12 +1485,19 @@ int ctsvc_client_db_add_status_changed_cb(contacts_h contact, int ctsvc_client_db_remove_status_changed_cb(contacts_h contact, contacts_db_status_changed_cb cb, void* user_data) { + int ret; GSList *l; RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL"); RETVM_IF(NULL == cb, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : callback is null"); + ret = ctsvc_ipc_destroy_for_change_subscription(false); + if (CONTACTS_ERROR_NONE != ret) { + CTS_ERR("ctsvc_ipc_destroy_for_change_subscription() Fail(%d)", ret); + return ret; + } + ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB); for (l = __status_change_subscribe_list;l;l=l->next) { status_callback_info_s *cb_info = l->data; diff --git a/client/ctsvc_client_ipc.h b/client/ctsvc_client_ipc.h index 6c6b874..900025e 100644 --- a/client/ctsvc_client_ipc.h +++ b/client/ctsvc_client_ipc.h @@ -35,7 +35,7 @@ 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(); +int ctsvc_ipc_destroy_for_change_subscription(bool is_disconnect); int ctsvc_ipc_recover_for_change_subscription(); int ctsvc_ipc_call(char *module, char *function, pims_ipc_h data_in, pims_ipc_data_h *data_out); diff --git a/client/ctsvc_client_noti.c b/client/ctsvc_client_noti.c index 3de5616..9aaa9be 100644 --- a/client/ctsvc_client_noti.c +++ b/client/ctsvc_client_noti.c @@ -163,9 +163,18 @@ int ctsvc_ipc_recover_for_change_subscription() return CONTACTS_ERROR_NONE; } -int ctsvc_ipc_destroy_for_change_subscription() +int ctsvc_ipc_destroy_for_change_subscription(bool is_disconnect) { ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB); + if (is_disconnect) { + if (0 < __ipc_pubsub_ref) { + pims_ipc_destroy_for_subscribe(__ipc); + __ipc = NULL; + __ipc_pubsub_ref = 0; + } + ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB); + return CONTACTS_ERROR_NONE; + } if (1 == __ipc_pubsub_ref) { pims_ipc_destroy_for_subscribe(__ipc); @@ -213,6 +222,12 @@ API int contacts_db_add_changed_cb_with_info(const char* view_uri, return CONTACTS_ERROR_INVALID_PARAMETER; } + ret = ctsvc_ipc_create_for_change_subscription(); + if (CONTACTS_ERROR_NONE != ret) { + CTS_ERR("ctsvc_ipc_create_for_change_subscription() Fail(%d)", ret); + return ret; + } + ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB); for (it=__db_change_subscribe_list;it;it=it->next) { @@ -272,6 +287,7 @@ API int contacts_db_add_changed_cb_with_info(const char* view_uri, API int contacts_db_remove_changed_cb_with_info(const char* view_uri, contacts_db_change_cb_with_info cb, void* user_data) { + int ret; GSList *it = NULL; subscribe_info_s *info = NULL; @@ -284,6 +300,12 @@ API int contacts_db_remove_changed_cb_with_info(const char* view_uri, return CONTACTS_ERROR_INVALID_PARAMETER; } + ret = ctsvc_ipc_destroy_for_change_subscription(false); + if (CONTACTS_ERROR_NONE != ret) { + CTS_ERR("ctsvc_ipc_destroy_for_change_subscription() Fail(%d)", ret); + return ret; + } + ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB); for (it=__db_change_subscribe_list;it;it=it->next) { diff --git a/client/ctsvc_client_service_helper.c b/client/ctsvc_client_service_helper.c index 83d5d42..e51d8e0 100644 --- a/client/ctsvc_client_service_helper.c +++ b/client/ctsvc_client_service_helper.c @@ -120,7 +120,6 @@ int ctsvc_client_connect(contacts_h contact) return ret; } ctsvc_view_uri_init(); - ctsvc_ipc_create_for_change_subscription(); } else CTS_DBG("System : Contacts service has been already connected(%d)", _ctsvc_connection + 1); @@ -155,7 +154,7 @@ int ctsvc_client_disconnect(contacts_h contact) base->connection_count--; if (1 == _ctsvc_connection) { - ctsvc_ipc_destroy_for_change_subscription(); + ctsvc_ipc_destroy_for_change_subscription(true); ctsvc_view_uri_deinit(); ctsvc_inotify_close(); ctsvc_socket_final(); @@ -215,7 +214,6 @@ int ctsvc_client_connect_on_thread(contacts_h contact) return ret; } ctsvc_view_uri_init(); - ctsvc_ipc_create_for_change_subscription(); } else if (0 < _ctsvc_connection_on_thread) CTS_DBG("System : Contacts service has been already connected"); @@ -250,7 +248,8 @@ int ctsvc_client_disconnect_on_thread(contacts_h contact) base->connection_count--; if (1 == _ctsvc_connection_on_thread) { - ctsvc_ipc_destroy_for_change_subscription(); + if (0 == _ctsvc_connection) + ctsvc_ipc_destroy_for_change_subscription(true); ctsvc_view_uri_deinit(); ctsvc_inotify_close(); ctsvc_socket_final(); diff --git a/client/ctsvc_client_setting.c b/client/ctsvc_client_setting.c index cf1aabd..13b1c02 100644 --- a/client/ctsvc_client_setting.c +++ b/client/ctsvc_client_setting.c @@ -280,6 +280,12 @@ API int contacts_setting_add_name_display_order_changed_cb( RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_ipc_client_check_permission fail (%d)", ret); RETVM_IF(result == false, CONTACTS_ERROR_PERMISSION_DENIED, "Permission denied (contact read)"); + ret = ctsvc_ipc_create_for_change_subscription(); + if (CONTACTS_ERROR_NONE != ret) { + CTS_ERR("ctsvc_ipc_create_for_change_subscription() Fail(%d)", ret); + return ret; + } + ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB); if (NULL == __setting_name_display_order_subscribe_list) { @@ -318,8 +324,15 @@ API int 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 cb, void* user_data) { + int ret; RETVM_IF(cb == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : callback is NULL"); + ret = ctsvc_ipc_destroy_for_change_subscription(false); + if (CONTACTS_ERROR_NONE != ret) { + CTS_ERR("ctsvc_ipc_destroy_for_change_subscription() Fail(%d)", ret); + return ret; + } + ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB); if (__setting_name_display_order_subscribe_list) { @@ -358,6 +371,12 @@ API int contacts_setting_add_name_sorting_order_changed_cb( RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_ipc_client_check_permission fail (%d)", ret); RETVM_IF(result == false, CONTACTS_ERROR_PERMISSION_DENIED, "Permission denied (contact read)"); + ret = ctsvc_ipc_create_for_change_subscription(); + if (CONTACTS_ERROR_NONE != ret) { + CTS_ERR("ctsvc_ipc_create_for_change_subscription() Fail(%d)", ret); + return ret; + } + ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB); if (NULL == __setting_name_sorting_order_subscribe_list) { @@ -396,8 +415,15 @@ API int 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 cb, void* user_data) { + int ret; RETVM_IF(cb == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : callback is NULL"); + ret = ctsvc_ipc_destroy_for_change_subscription(false); + if (CONTACTS_ERROR_NONE != ret) { + CTS_ERR("ctsvc_ipc_destroy_for_change_subscription() Fail(%d)", ret); + return ret; + } + ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB); if (__setting_name_sorting_order_subscribe_list) {