Unify duplicated code 25/207325/3
authorhj kim <backto.kim@samsung.com>
Mon, 3 Jun 2019 07:50:01 +0000 (16:50 +0900)
committerhj kim <backto.kim@samsung.com>
Tue, 4 Jun 2019 01:28:53 +0000 (10:28 +0900)
Change-Id: Iec77817366b05a948011aaeabe41bc9f19b8caa5

src/media_controller_server.c

index 90500cc..bd71939 100644 (file)
@@ -30,6 +30,7 @@ static void __server_play_playlist_cmd_cb(const char *interface_name, const char
 static void __server_custom_cmd_cb(const char *interface_name, const char *signal_name, const char *message, const char *request_id, void *user_data);
 static void __server_event_reply_received_cb(const char *interface_name, const char *signal_name, const char *message, const char *request_id, void *user_data);
 static void __server_search_cmd_cb(const char *interface_name, const char *signal_name, const char *message, const char *request_id, void *user_data);
+static int __mc_server_update_ability(mc_server_h server, int support_item, mc_ability_support_e support, gboolean immediate_update);
 
 
 static mc_cb_event_s cb_event[MC_SERVER_EVENT_MAX] = {
@@ -870,6 +871,35 @@ int mc_server_foreach_playlist(mc_server_h server, mc_playlist_cb callback, void
        return ret;
 }
 
+static int __mc_server_set_ability(mc_server_h server, mc_server_receive_event_e event, mc_ability_support_e support)
+{
+       int ret = MEDIA_CONTROLLER_ERROR_NONE;
+       media_controller_server_s *mc_server = (media_controller_server_s *)server;
+       char *ability_signal = NULL;
+
+       switch (event) {
+       case MC_SERVER_EVENT_SHUFFLE:
+               ability_signal = (char *)MC_DBUS_SIGNAL_NAME_SHUFFLE_ABILITY;
+               break;
+
+       case MC_SERVER_EVENT_REPEAT:
+               ability_signal = (char *)MC_DBUS_SIGNAL_NAME_REPEAT_ABILITY;
+               break;
+
+       default:
+               mc_error("Not supported event [%d]", event);
+               return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
+       }
+
+       ret = __mc_server_update_ability(server, event, support, TRUE);
+       mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "fail to __mc_server_update_ability");
+
+       ret = __mc_server_send_message(mc_server, MC_DBUS_UPDATE_INTERFACE, ability_signal, support, 0, NULL);
+       mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "fail to __mc_server_send_message");
+
+       return ret;
+}
+
 static int __mc_server_set_updated_cb(mc_server_h server, mc_server_receive_event_e event, void *callback, void *user_data)
 {
        int ret = MEDIA_CONTROLLER_ERROR_NONE;
@@ -1122,30 +1152,12 @@ int mc_server_update_playback_ability(mc_server_h server)
 
 int mc_server_set_shuffle_ability(mc_server_h server, mc_ability_support_e support)
 {
-       int ret = MEDIA_CONTROLLER_ERROR_NONE;
-       media_controller_server_s *mc_server = (media_controller_server_s *)server;
-
-       ret = __mc_server_update_ability(server, MC_SERVER_EVENT_SHUFFLE, support, TRUE);
-       mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "fail to __mc_server_update_ability");
-
-       ret = __mc_server_send_message(mc_server, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_SHUFFLE_ABILITY, support, 0, NULL);
-       mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "fail to __mc_server_send_message");
-
-       return ret;
+       return __mc_server_set_ability(server, MC_SERVER_EVENT_SHUFFLE, support);
 }
 
 int mc_server_set_repeat_ability(mc_server_h server, mc_ability_support_e support)
 {
-       int ret = MEDIA_CONTROLLER_ERROR_NONE;
-       media_controller_server_s *mc_server = (media_controller_server_s *)server;
-
-       ret = __mc_server_update_ability(server, MC_SERVER_EVENT_REPEAT, support, TRUE);
-       mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "fail to __mc_server_update_ability");
-
-       ret = __mc_server_send_message(mc_server, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_REPEAT_ABILITY, support, 0, NULL);
-       mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "fail to __mc_server_send_message");
-
-       return ret;
+       return __mc_server_set_ability(server, MC_SERVER_EVENT_REPEAT, support);
 }
 
 int mc_server_create(mc_server_h *server)