unify duplicated code regarding command_available 42/222342/3
authorhj kim <backto.kim@samsung.com>
Tue, 14 Jan 2020 01:09:59 +0000 (10:09 +0900)
committerhj kim <backto.kim@samsung.com>
Wed, 15 Jan 2020 05:27:46 +0000 (05:27 +0000)
Change-Id: I60137f3cd1efc81f8614a8c2d5913f97fc285cf9

src/media_controller_util.c

index 99736ef..717e76c 100644 (file)
@@ -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)