From dad9dd52b5da442277f246897ef0cf60d740f980 Mon Sep 17 00:00:00 2001 From: hj kim Date: Tue, 14 Jan 2020 10:09:59 +0900 Subject: [PATCH] unify duplicated code regarding command_available Change-Id: I60137f3cd1efc81f8614a8c2d5913f97fc285cf9 --- src/media_controller_util.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/media_controller_util.c b/src/media_controller_util.c index 99736ef..717e76c 100644 --- a/src/media_controller_util.c +++ b/src/media_controller_util.c @@ -134,7 +134,7 @@ int mc_util_make_filter_interface_name(const char *prefix, const char *filter, c return MEDIA_CONTROLLER_ERROR_NONE; } -int mc_util_set_command_available(mc_priv_type_e priv_type, const char *name, const char *command_type, const char *command) +static int __send_command_available(mc_priv_type_e priv_type, const char *name, const char *command_type, const char *command, mc_msg_type_e msg_type) { int ret = MEDIA_CONTROLLER_ERROR_NONE; char *message = NULL; @@ -149,33 +149,21 @@ int mc_util_set_command_available(mc_priv_type_e priv_type, const char *name, co else message = g_strdup_printf("%s%s%s", name, command_type, command); - ret = mc_ipc_send_message_to_server(MC_MSG_CLIENT_SET, priv_type, message); + ret = mc_ipc_send_message_to_server(msg_type, priv_type, message); MC_SAFE_G_FREE(message); return ret; } -int mc_util_get_command_available(mc_priv_type_e priv_type, const char *name, const char *command_type, const char *command) +int mc_util_set_command_available(mc_priv_type_e priv_type, const char *name, const char *command_type, const char *command) { - int ret = MEDIA_CONTROLLER_ERROR_NONE; - char *message = NULL; - - if (!MC_STRING_VALID(name) || !MC_STRING_VALID(command_type)) { - mc_error("invalid query"); - return MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER; - } - - if (command == NULL) - message = g_strdup_printf("%s%s", name, command_type); - else - message = g_strdup_printf("%s%s%s", name, command_type, command); - - ret = mc_ipc_send_message_to_server(MC_MSG_CLIENT_GET, priv_type, message); - - MC_SAFE_G_FREE(message); + return __send_command_available(priv_type, name, command_type, command, MC_MSG_CLIENT_SET); +} - return ret; +int mc_util_get_command_available(mc_priv_type_e priv_type, const char *name, const char *command_type, const char *command) +{ + return __send_command_available(priv_type, name, command_type, command, MC_MSG_CLIENT_GET); } char *mc_util_generate_uuid(void) -- 2.7.4