From 7d0603b2183c5393ee0c966074f04208a963ec7e Mon Sep 17 00:00:00 2001 From: hj kim Date: Fri, 31 May 2019 10:34:50 +0900 Subject: [PATCH] Reduce code duplication regarding the getting ability Change-Id: I67b7260d2ec9c6625c00b39119fface90a5f4805 --- src/media_controller_db.c | 64 ++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/src/media_controller_db.c b/src/media_controller_db.c index ac1f3c5..7bb4238 100644 --- a/src/media_controller_db.c +++ b/src/media_controller_db.c @@ -551,26 +551,44 @@ int mc_db_get_icon_uri(void *handle, const char *server_name, char **uri) return ret; } -int mc_db_get_ability_supported(void *handle, const char *server_name, mc_ability_e ability, mc_ability_support_e *supported) +static int __mc_db_get_ability(void *handle, const char *server_name, unsigned long long *decided, unsigned long long *supported) { int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_ability_s basic_ability = {0, 0}; + unsigned long long _decided = 0; + unsigned long long _supported = 0; - mc_retvm_if(handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - mc_retvm_if(server_name == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "server_name is NULL"); - mc_retvm_if((ability < MC_ABILITY_ACTION || ability > MC_ABILITY_REPEAT), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "ability is Invalid"); + mc_retvm_if(!handle, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid handle"); + mc_retvm_if(!server_name, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid server_name"); - ret = __mc_db_get_ulonglong_value_of_key(handle, server_name, "ability_decided", &basic_ability.decided); + ret = __mc_db_get_ulonglong_value_of_key(handle, server_name, "ability_decided", &_decided); mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "__mc_db_get_text_value_of_key failed"); - ret = __mc_db_get_ulonglong_value_of_key(handle, server_name, "ability_supported", &basic_ability.supported); + ret = __mc_db_get_ulonglong_value_of_key(handle, server_name, "ability_supported", &_supported); mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "__mc_db_get_text_value_of_key failed"); - mc_secure_debug("IsDecided: %d", MC_BIT64_IS_TRUE(basic_ability.decided, ability)); - mc_secure_debug("IsSupported: %d", MC_BIT64_IS_TRUE(basic_ability.supported, ability)); + *decided = _decided; + *supported = _supported; + + return ret; + +} + +int mc_db_get_ability_supported(void *handle, const char *server_name, mc_ability_e ability, mc_ability_support_e *supported) +{ + int ret = MEDIA_CONTROLLER_ERROR_NONE; + unsigned long long _decided = 0; + unsigned long long _supported = 0; + + mc_retvm_if((ability < MC_ABILITY_ACTION || ability > MC_ABILITY_REPEAT), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "ability is Invalid"); + + ret = __mc_db_get_ability(handle, server_name, &_decided, &_supported); + mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "__mc_db_get_ability failed"); + + mc_secure_debug("IsDecided: %d", MC_BIT64_IS_TRUE(_decided, ability)); + mc_secure_debug("IsSupported: %d", MC_BIT64_IS_TRUE(_supported, ability)); - if (MC_BIT64_IS_TRUE(basic_ability.decided, ability)) { - if (MC_BIT64_IS_TRUE(basic_ability.supported, ability)) + if (MC_BIT64_IS_TRUE(_decided, ability)) { + if (MC_BIT64_IS_TRUE(_supported, ability)) *supported = MC_ABILITY_SUPPORTED_YES; else *supported = MC_ABILITY_SUPPORTED_NO; @@ -587,25 +605,19 @@ int mc_db_get_pb_action_ability(void *handle, const char *server_name, mc_playba { int ret = MEDIA_CONTROLLER_ERROR_NONE; media_controller_ability_s *basic_ability = NULL; + unsigned long long _decided = 0; + unsigned long long _supported = 0; - mc_retvm_if(handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - mc_retvm_if(server_name == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "server_name is NULL"); - mc_retvm_if(ability == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "ability is NULL"); + mc_retvm_if(!ability, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invliad ability"); - basic_ability = (media_controller_ability_s *)calloc(1, sizeof(media_controller_ability_s)); - mc_retvm_if(basic_ability == NULL, MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY, "malloc failed"); + ret = __mc_db_get_ability(handle, server_name, &_decided, &_supported); + mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "__mc_db_get_ability failed"); - ret = __mc_db_get_ulonglong_value_of_key(handle, server_name, "ability_decided", &basic_ability->decided); - if (ret != MEDIA_CONTROLLER_ERROR_NONE) { - MC_SAFE_FREE(basic_ability); - return ret; - } + basic_ability = (media_controller_ability_s *)calloc(1, sizeof(media_controller_ability_s)); + mc_retvm_if(!basic_ability, MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY, "malloc failed"); - ret = __mc_db_get_ulonglong_value_of_key(handle, server_name, "ability_supported", &basic_ability->supported); - if (ret != MEDIA_CONTROLLER_ERROR_NONE) { - MC_SAFE_FREE(basic_ability); - return ret; - } + basic_ability->decided = _decided; + basic_ability->supported = _supported; *ability = (mc_playback_ability_h)basic_ability; -- 2.7.4