From: jiyong.min Date: Tue, 21 May 2019 00:54:26 +0000 (+0900) Subject: Reduce to execute connect & disconnect db repeatly X-Git-Tag: accepted/tizen/unified/20190530.043002~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F14%2F206514%2F3;p=platform%2Fcore%2Fapi%2Fmedia-controller.git Reduce to execute connect & disconnect db repeatly Change-Id: Ic87ce76d99184e991349033a74fcc560d22f00c1 --- diff --git a/svc/include/media_controller_db_util.h b/svc/include/media_controller_db_util.h index 49e4cbe..6a237d0 100644 --- a/svc/include/media_controller_db_util.h +++ b/svc/include/media_controller_db_util.h @@ -31,10 +31,10 @@ int mc_db_util_delete_whole_server_tables(void *handle); int mc_db_util_init_latest_server_table(void *handle); int mc_db_parse_and_update_db(uid_t uid, const char *data, int data_size); int mc_db_util_remove_dead_application(uid_t uid, const char *app_id, mc_priv_type_e priv_type); -int mc_db_util_activate_server_table(uid_t uid, const char *app_id); -int mc_db_util_deactivate_server_table(uid_t uid, const char *app_id); -int mc_db_util_insert_to_list(uid_t uid, const char *app_id, mc_priv_type_e priv_type); -int mc_db_util_delete_from_list(uid_t uid, const char *app_id, mc_priv_type_e priv_type); +int mc_db_util_activate_server_table(void *db_handle, const char *app_id); +int mc_db_util_deactivate_server_table(void *db_handle, const char *app_id); +int mc_db_util_insert_to_list(void *db_handle, const char *app_id, mc_priv_type_e priv_type); +int mc_db_util_delete_from_list(void *db_handle, const char *app_id, mc_priv_type_e priv_type); #endif /*__TIZEN_MULTIMEDIA_MEDIA_CONTROLLER_DB_UTIL_H__*/ diff --git a/svc/media_controller_db_util.c b/svc/media_controller_db_util.c index 49f1754..8ef6c20 100644 --- a/svc/media_controller_db_util.c +++ b/svc/media_controller_db_util.c @@ -732,84 +732,66 @@ ERROR: return ret; } -int mc_db_util_activate_server_table(uid_t uid, const char *app_id) +int mc_db_util_activate_server_table(void *db_handle, const char *app_id) { int ret = MEDIA_CONTROLLER_ERROR_NONE; char *sql_str = NULL; - void* _db_handle = NULL; mc_debug_fenter(); - mc_retvm_if(app_id == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "message is NULL"); - - ret = mc_db_connect(&_db_handle, uid, TRUE); - if (ret != MEDIA_CONTROLLER_ERROR_NONE) { - mc_error("mc_db_connect error : %d", ret); - mc_db_disconnect(_db_handle); - return ret; - } + mc_retvm_if(db_handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid handle"); + mc_retvm_if(app_id == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid app_id"); - if (__mc_db_is_latest(_db_handle, app_id)) { - ret = __mc_update_latest_server_info(_db_handle, app_id, MC_SERVER_STATE_ACTIVATE, MC_PLAYBACK_STATE_STOPPED, FALSE); + if (__mc_db_is_latest(db_handle, app_id)) { + ret = __mc_update_latest_server_info(db_handle, app_id, MC_SERVER_STATE_ACTIVATE, MC_PLAYBACK_STATE_STOPPED, FALSE); } else { sql_str = sqlite3_mprintf(DB_CREATE_SERVER_TABLE, app_id, app_id, DB_META_FIELD, app_id, app_id); - ret = mc_db_util_update_db(_db_handle, sql_str); + ret = mc_db_util_update_db(db_handle, sql_str); SQLITE3_SAFE_FREE(sql_str); } - mc_db_disconnect(_db_handle); - mc_debug_fleave(); return ret; } -int mc_db_util_deactivate_server_table(uid_t uid, const char *app_id) +int mc_db_util_deactivate_server_table(void *db_handle, const char *app_id) { int ret = MEDIA_CONTROLLER_ERROR_NONE; char *sql_str = NULL; - void* _db_handle = NULL; mc_debug_fenter(); - mc_retvm_if(app_id == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "message is NULL"); - - ret = mc_db_connect(&_db_handle, uid, TRUE); - if (ret != MEDIA_CONTROLLER_ERROR_NONE) { - mc_error("mc_db_connect error : %d", ret); - mc_db_disconnect(_db_handle); - return ret; - } + mc_retvm_if(db_handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid handle"); + mc_retvm_if(app_id == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid app_id"); /* Update server_state to deactivated, if the server is latest. * Drop the table of server_name, if it is not latest. */ - if (__mc_db_is_latest(_db_handle, app_id)) { - ret = __mc_update_latest_server_info(_db_handle, app_id, MC_SERVER_STATE_DEACTIVATE, MC_PLAYBACK_STATE_STOPPED, FALSE); + if (__mc_db_is_latest(db_handle, app_id)) { + ret = __mc_update_latest_server_info(db_handle, app_id, MC_SERVER_STATE_DEACTIVATE, MC_PLAYBACK_STATE_STOPPED, FALSE); } else { sql_str = sqlite3_mprintf(DB_DROP_TABLE, app_id); - ret = mc_db_util_update_db(_db_handle, sql_str); + ret = mc_db_util_update_db(db_handle, sql_str); SQLITE3_SAFE_FREE(sql_str); } - mc_db_disconnect(_db_handle); - mc_debug_fleave(); return ret; } -int mc_db_util_insert_to_list(uid_t uid, const char *app_id, mc_priv_type_e priv_type) +int mc_db_util_insert_to_list(void *db_handle, const char *app_id, mc_priv_type_e priv_type) { int ret = MEDIA_CONTROLLER_ERROR_NONE; char *sql_str = NULL; - void* _db_handle = NULL; mc_debug_fenter(); - mc_retvm_if(app_id == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "message is NULL"); + mc_retvm_if(db_handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid handle"); + mc_retvm_if(app_id == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid app_id"); - mc_secure_debug("[uid: %d] app_id: %s, priv_type: %d", uid, app_id, priv_type); + mc_secure_debug("app_id: %s, priv_type: %d", app_id, priv_type); if (priv_type == MC_PRIV_TYPE_SERVER) { sql_str = sqlite3_mprintf(DB_INSERT_TO_SERVER_LIST, app_id, app_id); @@ -822,36 +804,28 @@ int mc_db_util_insert_to_list(uid_t uid, const char *app_id, mc_priv_type_e priv } mc_retvm_if(sql_str == NULL, MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY, "sql_str is NULL"); - ret = mc_db_connect(&_db_handle, uid, TRUE); - if (ret != MEDIA_CONTROLLER_ERROR_NONE) { - mc_error("mc_db_connect error : %d", ret); - goto ERROR; - } - - ret = mc_db_util_update_db(_db_handle, sql_str); + ret = mc_db_util_update_db(db_handle, sql_str); if (ret != MEDIA_CONTROLLER_ERROR_NONE) mc_error("media_db_update_db error : %d", ret); -ERROR: SQLITE3_SAFE_FREE(sql_str); - mc_db_disconnect(_db_handle); mc_debug_fleave(); return ret; } -int mc_db_util_delete_from_list(uid_t uid, const char *app_id, mc_priv_type_e priv_type) +int mc_db_util_delete_from_list(void *db_handle, const char *app_id, mc_priv_type_e priv_type) { int ret = MEDIA_CONTROLLER_ERROR_NONE; char *sql_str = NULL; - void* _db_handle = NULL; mc_debug_fenter(); - mc_retvm_if(app_id == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "message is NULL"); + mc_retvm_if(db_handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid handle"); + mc_retvm_if(app_id == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid app_id"); - mc_secure_debug("[uid: %d] app_id: %s, priv_type: %d", uid, app_id, priv_type); + mc_secure_debug("app_id: %s, priv_type: %d", app_id, priv_type); if (priv_type == MC_PRIV_TYPE_SERVER) { sql_str = sqlite3_mprintf(DB_DELETE_FROM_SERVER_LIST, app_id); @@ -864,19 +838,11 @@ int mc_db_util_delete_from_list(uid_t uid, const char *app_id, mc_priv_type_e pr } mc_retvm_if(sql_str == NULL, MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY, "sql_str is NULL"); - ret = mc_db_connect(&_db_handle, uid, TRUE); - if (ret != MEDIA_CONTROLLER_ERROR_NONE) { - mc_error("mc_db_connect error : %d", ret); - goto ERROR; - } - - ret = mc_db_util_update_db(_db_handle, sql_str); + ret = mc_db_util_update_db(db_handle, sql_str); if (ret != MEDIA_CONTROLLER_ERROR_NONE) mc_error("media_db_update_db error : %d", ret); -ERROR: SQLITE3_SAFE_FREE(sql_str); - mc_db_disconnect(_db_handle); mc_debug_fleave(); @@ -886,11 +852,19 @@ ERROR: int mc_db_util_remove_dead_application(uid_t uid, const char *app_id, const mc_priv_type_e priv_type) { int ret = MEDIA_CONTROLLER_ERROR_NONE; + void *db_handle = NULL; - mc_retvm_if(app_id == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "app_id is NULL"); + mc_retvm_if(app_id == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid app_id"); + + ret = mc_db_connect(&db_handle, uid, TRUE); + if (ret != MEDIA_CONTROLLER_ERROR_NONE) { + mc_error("mc_db_connect error : %d", ret); + mc_db_disconnect(db_handle); + return ret; + } /* Delete application from server/client list */ - ret = mc_db_util_delete_from_list(uid, app_id, priv_type); + ret = mc_db_util_delete_from_list(db_handle, app_id, priv_type); if (ret != MEDIA_CONTROLLER_ERROR_NONE) mc_secure_error("mc_db_util_delete_from_list error : %d", ret); @@ -898,10 +872,12 @@ int mc_db_util_remove_dead_application(uid_t uid, const char *app_id, const mc_p * Update application information if it is latest. */ if (priv_type == MC_PRIV_TYPE_SERVER) { - ret = mc_db_util_deactivate_server_table(uid, app_id); + ret = mc_db_util_deactivate_server_table(db_handle, app_id); if (ret != MEDIA_CONTROLLER_ERROR_NONE) mc_secure_error("mc_db_util_deactivate_server_table error : %d", ret); } + mc_db_disconnect(db_handle); + return ret; } diff --git a/svc/media_controller_svc.c b/svc/media_controller_svc.c index be9a7a7..8bcd15c 100644 --- a/svc/media_controller_svc.c +++ b/svc/media_controller_svc.c @@ -444,23 +444,38 @@ static int _mc_service_get_data(GList **connected_list, mc_comm_msg_s *request_m static int __mc_service_add_to_db(mc_comm_msg_s *request_msg) { int ret = MEDIA_CONTROLLER_ERROR_NONE; + void *db_handle = NULL; + mc_debug_fenter(); mc_retvm_if(!request_msg, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid request message"); mc_retvm_if(!request_msg->msg, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid message"); mc_retvm_if(((request_msg->priv_type != MC_PRIV_TYPE_SERVER) && (request_msg->priv_type != MC_PRIV_TYPE_CLIENT)), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid priv_type[%d]", request_msg->priv_type); - ret = mc_db_util_insert_to_list(request_msg->uid, request_msg->msg, request_msg->priv_type); - mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "mc_db_util_insert_to_list failed (%d)", ret); + ret = mc_db_connect(&db_handle, request_msg->uid, TRUE); + if (ret != MEDIA_CONTROLLER_ERROR_NONE) { + mc_error("mc_db_connect error : %d", ret); + mc_db_disconnect(db_handle); + return ret; + } + + ret = mc_db_util_insert_to_list(db_handle, request_msg->msg, request_msg->priv_type); + if (ret != MEDIA_CONTROLLER_ERROR_NONE) { + mc_error("mc_db_util_insert_to_list failed (%d)", ret); + mc_db_disconnect(db_handle); + return ret; + } if (request_msg->priv_type == MC_PRIV_TYPE_SERVER) { - ret = mc_db_util_activate_server_table(request_msg->uid, request_msg->msg); + ret = mc_db_util_activate_server_table(db_handle, request_msg->msg); if (ret != MEDIA_CONTROLLER_ERROR_NONE) { mc_secure_error("mc_db_util_activate_server_table failed (%d)", ret); - mc_db_util_delete_from_list(request_msg->uid, request_msg->msg, request_msg->priv_type); + mc_db_util_delete_from_list(db_handle, request_msg->msg, request_msg->priv_type); } } + mc_db_disconnect(db_handle); + mc_debug_fleave(); return ret; @@ -469,21 +484,33 @@ static int __mc_service_add_to_db(mc_comm_msg_s *request_msg) static int __mc_service_remove_from_db(mc_comm_msg_s *request_msg) { int ret = MEDIA_CONTROLLER_ERROR_NONE; + void *db_handle = NULL; + mc_debug_fenter(); mc_retvm_if(!request_msg, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid request message"); mc_retvm_if(!request_msg->msg, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid message"); mc_retvm_if(((request_msg->priv_type != MC_PRIV_TYPE_SERVER) && (request_msg->priv_type != MC_PRIV_TYPE_CLIENT)), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid priv_type[%d]", request_msg->priv_type); - ret = mc_db_util_delete_from_list(request_msg->uid, request_msg->msg, request_msg->priv_type); - mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "mc_db_util_insert_to_list failed (%d)", ret); + ret = mc_db_connect(&db_handle, request_msg->uid, TRUE); + if (ret != MEDIA_CONTROLLER_ERROR_NONE) { + mc_error("mc_db_connect error : %d", ret); + mc_db_disconnect(db_handle); + return ret; + } + + ret = mc_db_util_delete_from_list(db_handle, request_msg->msg, request_msg->priv_type); + if (ret != MEDIA_CONTROLLER_ERROR_NONE) + mc_error("mc_db_util_delete_from_list failed (%d)", ret); if (request_msg->priv_type == MC_PRIV_TYPE_SERVER) { - ret = mc_db_util_deactivate_server_table(request_msg->uid, request_msg->msg); + ret = mc_db_util_deactivate_server_table(db_handle, request_msg->msg); if (ret != MEDIA_CONTROLLER_ERROR_NONE) mc_secure_error("mc_db_util_deactivate_server_table failed (%d)", ret); } + mc_db_disconnect(db_handle); + mc_debug_fleave(); return ret;