Reduce duplicate code related with dbus 25/277325/2
authorInHong Han <inhong1.han@samsung.com>
Tue, 5 Jul 2022 07:15:24 +0000 (16:15 +0900)
committerInHong Han <inhong1.han@samsung.com>
Mon, 11 Jul 2022 08:20:09 +0000 (17:20 +0900)
Change-Id: Iea11d7c8eb98d52733af26080df6dbccbfebfc99

client/ma_ap_dbus.c
client/ma_dbus.c

index 3776c794d343fd24bd2f779894a600cee5801307..47295bef28ab55a39989b9e36c716312cf988680 100644 (file)
@@ -32,22 +32,22 @@ extern int __ma_ap_cb_audio_streaming_data_section_changed(ma_audio_streaming_da
 typedef enum {
        streaming_data_type_audio_data,
        streaming_data_type_streaming_section
-} streaming_data_type_e;
+} ap_streaming_data_type_e;
 
 typedef struct {
        unsigned int streaming_data_size;
        int streaming_data_type;
        int streaming_data_serial;
-} streaming_data_header;
+} ap_streaming_data_header;
 
 typedef struct {
        int event;
        unsigned int data_size;
-} streaming_data_audio_data_header;
+} ap_streaming_data_audio_data_header;
 
 typedef struct {
        int section;
-} streaming_data_streaming_section_header;
+} ap_streaming_data_streaming_section_header;
 
 static const char *message_port = "ma_streaming_port";
 static int g_local_port_id = -1;
@@ -67,7 +67,7 @@ static void message_port_cb(int local_port_id,
        bundle_get_byte(message, "content", (void**)(&v), &size);
 
        if (size > STREAMING_BUFFER_SIZE) {
-               MA_SLOGE("[ERROR] bundle contains data bigger than %d : %zu", STREAMING_BUFFER_SIZE, size);
+               MA_SLOGE("[AP_ERROR] bundle contains data bigger than %d : %zu", STREAMING_BUFFER_SIZE, size);
                return;
        } else {
                if (v)
@@ -77,25 +77,25 @@ static void message_port_cb(int local_port_id,
        memcpy(pending_buffer + pending_buffer_size, buffer, size);
        pending_buffer_size += size;
 
-       while (pending_buffer_size >= sizeof(streaming_data_header)) {
-               streaming_data_header header;
-               memcpy(&header, pending_buffer, sizeof(streaming_data_header));
+       while (pending_buffer_size >= sizeof(ap_streaming_data_header)) {
+               ap_streaming_data_header header;
+               memcpy(&header, pending_buffer, sizeof(ap_streaming_data_header));
                if (pending_buffer_size >= header.streaming_data_size) {
                        static int last_serial = 0;
                        if (header.streaming_data_serial != last_serial + 1) {
-                               MA_SLOGE("[ERROR] SERIAL MISMATCH in [%d] : %d => %d",
+                               MA_SLOGE("[AP_ERROR] SERIAL MISMATCH in [%d] : %d => %d",
                                        header.streaming_data_type, last_serial, header.streaming_data_serial);
                        }
                        last_serial = header.streaming_data_serial;
 
                        if (streaming_data_type_audio_data == header.streaming_data_type) {
-                               streaming_data_audio_data_header audio_data_header;
-                               memcpy(&audio_data_header, pending_buffer + sizeof(streaming_data_header),
-                                       sizeof(streaming_data_audio_data_header));
+                               ap_streaming_data_audio_data_header audio_data_header;
+                               memcpy(&audio_data_header, pending_buffer + sizeof(ap_streaming_data_header),
+                                       sizeof(ap_streaming_data_audio_data_header));
 
                                static bool start_received = false;
                                if (audio_data_header.event == MA_AUDIO_STREAMING_EVENT_CONTINUE && !start_received) {
-                                       MA_SLOGE("[ERROR] CONTINUE without START, forcing to emit START event");
+                                       MA_SLOGE("[AP_ERROR] CONTINUE without START, forcing to emit START event");
                                        audio_data_header.event = MA_AUDIO_STREAMING_EVENT_START;
                                }
 
@@ -108,17 +108,17 @@ static void message_port_cb(int local_port_id,
                                        any useful information to the client application */
                                if (g_streaming_requested || MA_AUDIO_STREAMING_EVENT_CONTINUE != audio_data_header.event) {
                                        __ma_ap_cb_audio_streaming(audio_data_header.event,
-                                               pending_buffer + sizeof(streaming_data_header) + sizeof(streaming_data_audio_data_header),
+                                               pending_buffer + sizeof(ap_streaming_data_header) + sizeof(ap_streaming_data_audio_data_header),
                                                audio_data_header.data_size);
                                        if (0 == header.streaming_data_serial % 50 || MA_AUDIO_STREAMING_EVENT_CONTINUE != audio_data_header.event) {
-                                               MA_SLOGE("__ma_ap_cb_audio_streaming() called, event and serial : %d %d",
+                                               MA_SLOGE("[AP_ERROR] __ma_ap_cb_audio_streaming() called, event and serial : %d %d",
                                                        audio_data_header.event, header.streaming_data_serial);
                                        }
                                }
                        } else if (streaming_data_type_streaming_section == header.streaming_data_type) {
-                               streaming_data_streaming_section_header streaming_section_header;
-                               memcpy(&streaming_section_header, pending_buffer + sizeof(streaming_data_header),
-                                       sizeof(streaming_data_streaming_section_header));
+                               ap_streaming_data_streaming_section_header streaming_section_header;
+                               memcpy(&streaming_section_header, pending_buffer + sizeof(ap_streaming_data_header),
+                                       sizeof(ap_streaming_data_streaming_section_header));
 
                                __ma_ap_cb_audio_streaming_data_section_changed(streaming_section_header.section);
                        }
@@ -132,7 +132,7 @@ static void message_port_cb(int local_port_id,
        }
 }
 
-static int streaming_ipc_initialize()
+static int ap_streaming_ipc_initialize()
 {
 #if USE_TRUSTED_MESSAGE_PORT
        int port_id = message_port_register_trusted_local_port(message_port, message_port_cb, NULL);
@@ -149,7 +149,7 @@ static int streaming_ipc_initialize()
        return 0;
 }
 
-static int streaming_ipc_deinitialize()
+static int ap_streaming_ipc_deinitialize()
 {
 #if USE_TRUSTED_MESSAGE_PORT
        if (-1 != g_local_port_id) message_port_unregister_trusted_local_port(g_local_port_id);
@@ -164,12 +164,12 @@ int ma_ap_dbus_open_connection()
 {
        /* For now assume streaming is requested when initialized */
        g_streaming_requested = true;
-       return streaming_ipc_initialize();
+       return ap_streaming_ipc_initialize();
 }
 
 int ma_ap_dbus_close_connection()
 {
        g_streaming_requested = false;
-       return streaming_ipc_deinitialize();
+       return ap_streaming_ipc_deinitialize();
 }
 //LCOV_EXCL_STOP
index 24bebec21a2f73f44c6c258e483074f407152616..01ee6a774784c1bd36552abc2e012e5ea8f2cf5d 100644 (file)
@@ -786,6 +786,32 @@ int ma_dbus_request_hello()
        return result;
 }
 
+static int __send_dbus_message(DBusMessage* msg)
+{
+       dbus_message_set_no_reply(msg, TRUE);
+
+       DBusError error;
+       dbus_error_init (&error);
+       if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
+               //LCOV_EXCL_START
+               if (dbus_error_is_set (&error)) {
+                       MA_SLOGE("[Dbus ERROR] Fail to Send : %s", error.message); //LCOV_EXCL_LINE
+                       dbus_error_free (&error);
+               } else {
+                       MA_SLOGE("[Dbus ERROR] Fail to Send"); //LCOV_EXCL_LINE
+               }
+               return MA_ERROR_OPERATION_FAILED;
+               //LCOV_EXCL_STOP
+       } else {
+               MA_SLOGD("[Dbus DEBUG] Success to Send"); //LCOV_EXCL_LINE
+               dbus_connection_flush(g_conn_sender);
+       }
+
+       dbus_message_unref(msg);
+
+       return 0;
+}
+
 int ma_dbus_request_initialize(int pid)
 {
        if (0 != __dbus_check()) {
@@ -811,26 +837,15 @@ int ma_dbus_request_initialize(int pid)
                DBUS_TYPE_INT32, &pid,
                DBUS_TYPE_INVALID);
 
-       DBusError err;
-       dbus_error_init(&err);
-
-       dbus_message_set_no_reply(msg, TRUE);
-
-       if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
-               //LCOV_EXCL_START
-               MA_SLOGE("[Dbus ERROR] Fail to Send"); //LCOV_EXCL_LINE
+       if (MA_ERROR_OPERATION_FAILED == __send_dbus_message(msg))
                return MA_ERROR_OPERATION_FAILED;
-               //LCOV_EXCL_STOP
-       } else {
-               MA_SLOGD("[Dbus DEBUG] Success to Send"); //LCOV_EXCL_LINE
-               dbus_connection_flush(g_conn_sender);
-       }
-
-       dbus_message_unref(msg);
 
        /* add a rule for daemon error */
        char rule[256] = {0, };
        snprintf(rule, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", MA_SERVER_SERVICE_INTERFACE);
+
+       DBusError err;
+       dbus_error_init (&err);
        dbus_bus_add_match(g_conn_listener, rule, &err);
 
        if (dbus_error_is_set(&err)) {
@@ -1112,21 +1127,7 @@ int ma_dbus_send_asr_result(int pid, ma_asr_result_event_e event, const char* as
                DBUS_TYPE_STRING, &asr_result,
                DBUS_TYPE_INVALID);
 
-       dbus_message_set_no_reply(msg, TRUE);
-
-       if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
-               //LCOV_EXCL_START
-               MA_SLOGE("[Dbus ERROR] Fail to Send"); //LCOV_EXCL_LINE
-               return MA_ERROR_OPERATION_FAILED;
-               //LCOV_EXCL_STOP
-       } else {
-               MA_SLOGD("[Dbus DEBUG] Success to Send"); //LCOV_EXCL_LINE
-               dbus_connection_flush(g_conn_sender);
-       }
-
-       dbus_message_unref(msg);
-
-       return 0;
+       return __send_dbus_message(msg);
 }
 
 int ma_dbus_send_result(int pid, const char* display_text, const char* utterance_text, const char* result_json)
@@ -1179,31 +1180,7 @@ int ma_dbus_send_result(int pid, const char* display_text, const char* utterance
                DBUS_TYPE_STRING, &tmp_result_json,
                DBUS_TYPE_INVALID);
 
-       dbus_message_set_no_reply(msg, TRUE);
-
-       if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
-               //LCOV_EXCL_START
-               MA_SLOGE("[Dbus ERROR] Fail to Send"); //LCOV_EXCL_LINE
-               if (NULL != tmp_disp_text) {
-                       free(tmp_disp_text);
-                       tmp_disp_text = NULL;
-               }
-               if (NULL != tmp_utt_text) {
-                       free(tmp_utt_text);
-                       tmp_utt_text = NULL;
-               }
-               if (NULL != tmp_result_json) {
-                       free(tmp_result_json);
-                       tmp_result_json = NULL;
-               }
-               return MA_ERROR_OPERATION_FAILED;
-               //LCOV_EXCL_STOP
-       } else {
-               MA_SLOGD("[Dbus DEBUG] Success to Send"); //LCOV_EXCL_LINE
-               dbus_connection_flush(g_conn_sender);
-       }
-
-       dbus_message_unref(msg);
+       int ret = __send_dbus_message(msg);
 
        if (NULL != tmp_disp_text) {
                free(tmp_disp_text);
@@ -1218,7 +1195,7 @@ int ma_dbus_send_result(int pid, const char* display_text, const char* utterance
                tmp_result_json = NULL;
        }
 
-       return 0;
+       return ret;
 }
 
 int ma_dbus_send_recognition_result(int pid, ma_recognition_result_event_e result)
@@ -1247,28 +1224,7 @@ int ma_dbus_send_recognition_result(int pid, ma_recognition_result_event_e resul
                DBUS_TYPE_INT32, &result,
                DBUS_TYPE_INVALID);
 
-       dbus_message_set_no_reply(msg, TRUE);
-
-       DBusError error;
-       dbus_error_init (&error);
-       if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
-               //LCOV_EXCL_START
-               if (dbus_error_is_set (&error)) {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send : %s", error.message); //LCOV_EXCL_LINE
-                       dbus_error_free (&error);
-               } else {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send"); //LCOV_EXCL_LINE
-               }
-               return MA_ERROR_OPERATION_FAILED;
-               //LCOV_EXCL_STOP
-       } else {
-               MA_SLOGD("[Dbus DEBUG] Success to Send"); //LCOV_EXCL_LINE
-               dbus_connection_flush(g_conn_sender);
-       }
-
-       dbus_message_unref(msg);
-
-       return 0;
+       return __send_dbus_message(msg);
 }
 
 int ma_dbus_start_streaming_audio_data(int pid, ma_audio_streaming_data_type_e type)
@@ -1297,30 +1253,12 @@ int ma_dbus_start_streaming_audio_data(int pid, ma_audio_streaming_data_type_e t
                DBUS_TYPE_INT32, &type,
                DBUS_TYPE_INVALID);
 
-       dbus_message_set_no_reply(msg, TRUE);
+       int ret = __send_dbus_message(msg);
 
-       DBusError error;
-       dbus_error_init (&error);
-       if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
-               //LCOV_EXCL_START
-               if (dbus_error_is_set (&error)) {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send : %s", error.message); //LCOV_EXCL_LINE
-                       dbus_error_free (&error);
-               } else {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send"); //LCOV_EXCL_LINE
-               }
-               return MA_ERROR_OPERATION_FAILED;
-               //LCOV_EXCL_STOP
-       } else {
-               MA_SLOGD("[Dbus DEBUG] Success to Send"); //LCOV_EXCL_LINE
-               dbus_connection_flush(g_conn_sender);
-       }
-
-       dbus_message_unref(msg);
+       if (MA_ERROR_OPERATION_FAILED != ret)
+               g_streaming_requested = true;
 
-       g_streaming_requested = true;
-
-       return 0;
+       return ret;
 }
 
 int ma_dbus_stop_streaming_audio_data(int pid, ma_audio_streaming_data_type_e type)
@@ -1349,30 +1287,12 @@ int ma_dbus_stop_streaming_audio_data(int pid, ma_audio_streaming_data_type_e ty
                DBUS_TYPE_INT32, &type,
                DBUS_TYPE_INVALID);
 
-       dbus_message_set_no_reply(msg, TRUE);
-
-       DBusError error;
-       dbus_error_init (&error);
-       if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
-               //LCOV_EXCL_START
-               if (dbus_error_is_set (&error)) {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send : %s", error.message); //LCOV_EXCL_LINE
-                       dbus_error_free (&error);
-               } else {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send"); //LCOV_EXCL_LINE
-               }
-               return MA_ERROR_OPERATION_FAILED;
-               //LCOV_EXCL_STOP
-       } else {
-               MA_SLOGD("[Dbus DEBUG] Success to Send"); //LCOV_EXCL_LINE
-               dbus_connection_flush(g_conn_sender);
-       }
-
-       dbus_message_unref(msg);
+       int ret = __send_dbus_message(msg);
 
-       g_streaming_requested = false;
+       if (MA_ERROR_OPERATION_FAILED != ret)
+               g_streaming_requested = false;
 
-       return 0;
+       return ret;
 }
 
 int ma_dbus_update_voice_feedback_state(int pid, ma_voice_feedback_state_e state)
@@ -1401,28 +1321,7 @@ int ma_dbus_update_voice_feedback_state(int pid, ma_voice_feedback_state_e state
                DBUS_TYPE_INT32, &state,
                DBUS_TYPE_INVALID);
 
-       dbus_message_set_no_reply(msg, TRUE);
-
-       DBusError error;
-       dbus_error_init (&error);
-       if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
-               //LCOV_EXCL_START
-               if (dbus_error_is_set (&error)) {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send : %s", error.message); //LCOV_EXCL_LINE
-                       dbus_error_free (&error);
-               } else {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send"); //LCOV_EXCL_LINE
-               }
-               return MA_ERROR_OPERATION_FAILED;
-               //LCOV_EXCL_STOP
-       } else {
-               MA_SLOGD("[Dbus DEBUG] Success to Send"); //LCOV_EXCL_LINE
-               dbus_connection_flush(g_conn_sender);
-       }
-
-       dbus_message_unref(msg);
-
-       return 0;
+       return __send_dbus_message(msg);
 }
 
 int ma_dbus_send_assistant_specific_command(int pid, const char* command)
@@ -1458,39 +1357,14 @@ int ma_dbus_send_assistant_specific_command(int pid, const char* command)
                DBUS_TYPE_STRING, &tmp_command,
                DBUS_TYPE_INVALID);
 
-       dbus_message_set_no_reply(msg, TRUE);
-
-       DBusError error;
-       dbus_error_init (&error);
-       if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
-               //LCOV_EXCL_START
-
-               if (NULL != tmp_command) {
-                       free(tmp_command);
-                       tmp_command = NULL;
-               }
-
-               if (dbus_error_is_set (&error)) {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send : %s", error.message); //LCOV_EXCL_LINE
-                       dbus_error_free (&error);
-               } else {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send"); //LCOV_EXCL_LINE
-               }
-               return MA_ERROR_OPERATION_FAILED;
-               //LCOV_EXCL_STOP
-       } else {
-               MA_SLOGD("[Dbus DEBUG] Success to Send"); //LCOV_EXCL_LINE
-               dbus_connection_flush(g_conn_sender);
-       }
+       int ret = __send_dbus_message(msg);
 
        if (NULL != tmp_command) {
                free(tmp_command);
                tmp_command = NULL;
        }
 
-       dbus_message_unref(msg);
-
-       return 0;
+       return ret;
 }
 
 int ma_dbus_set_background_volume(int pid, double ratio)
@@ -1519,29 +1393,7 @@ int ma_dbus_set_background_volume(int pid, double ratio)
                DBUS_TYPE_DOUBLE, &ratio,
                DBUS_TYPE_INVALID);
 
-       dbus_message_set_no_reply(msg, TRUE);
-
-       DBusError error;
-       dbus_error_init (&error);
-       if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
-               //LCOV_EXCL_START
-
-               if (dbus_error_is_set (&error)) {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send : %s", error.message); //LCOV_EXCL_LINE
-                       dbus_error_free (&error);
-               } else {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send"); //LCOV_EXCL_LINE
-               }
-               return MA_ERROR_OPERATION_FAILED;
-               //LCOV_EXCL_STOP
-       } else {
-               MA_SLOGD("[Dbus DEBUG] Success to Send"); //LCOV_EXCL_LINE
-               dbus_connection_flush(g_conn_sender);
-       }
-
-       dbus_message_unref(msg);
-
-       return 0;
+       return __send_dbus_message(msg);
 }
 
 int ma_dbus_set_preprocessing_allow_mode(int pid, ma_preprocessing_allow_mode_e mode, const char *app_id)
@@ -1578,38 +1430,14 @@ int ma_dbus_set_preprocessing_allow_mode(int pid, ma_preprocessing_allow_mode_e
                DBUS_TYPE_STRING, &tmp_app_id,
                DBUS_TYPE_INVALID);
 
-       dbus_message_set_no_reply(msg, TRUE);
-
-       DBusError error;
-       dbus_error_init (&error);
-       if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
-               //LCOV_EXCL_START
-
-               if (dbus_error_is_set (&error)) {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send : %s", error.message); //LCOV_EXCL_LINE
-                       dbus_error_free (&error);
-               } else {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send"); //LCOV_EXCL_LINE
-               }
-               if (NULL != tmp_app_id) {
-                       free(tmp_app_id);
-                       tmp_app_id = NULL;
-               }
-               return MA_ERROR_OPERATION_FAILED;
-               //LCOV_EXCL_STOP
-       } else {
-               MA_SLOGD("[Dbus DEBUG] Success to Send"); //LCOV_EXCL_LINE
-               dbus_connection_flush(g_conn_sender);
-       }
-
-       dbus_message_unref(msg);
+       int ret = __send_dbus_message(msg);
 
        if (NULL != tmp_app_id) {
                free(tmp_app_id);
                tmp_app_id = NULL;
        }
 
-       return 0;
+       return ret;
 }
 
 int ma_dbus_send_preprocessing_result(int pid, bool result)
@@ -1639,28 +1467,7 @@ int ma_dbus_send_preprocessing_result(int pid, bool result)
                DBUS_TYPE_INT32, &tmp_result,
                DBUS_TYPE_INVALID);
 
-       dbus_message_set_no_reply(msg, TRUE);
-
-       DBusError error;
-       dbus_error_init (&error);
-       if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
-               //LCOV_EXCL_START
-               if (dbus_error_is_set (&error)) {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send : %s", error.message); //LCOV_EXCL_LINE
-                       dbus_error_free (&error);
-               } else {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send"); //LCOV_EXCL_LINE
-               }
-               return MA_ERROR_OPERATION_FAILED;
-               //LCOV_EXCL_STOP
-       } else {
-               MA_SLOGD("[Dbus DEBUG] Success to Send"); //LCOV_EXCL_LINE
-               dbus_connection_flush(g_conn_sender);
-       }
-
-       dbus_message_unref(msg);
-
-       return 0;
+       return __send_dbus_message(msg);
 }
 
 int ma_dbus_set_wake_word_audio_require_flag(int pid, bool require)
@@ -1690,28 +1497,7 @@ int ma_dbus_set_wake_word_audio_require_flag(int pid, bool require)
                DBUS_TYPE_INT32, &tmp_require,
                DBUS_TYPE_INVALID);
 
-       dbus_message_set_no_reply(msg, TRUE);
-
-       DBusError error;
-       dbus_error_init (&error);
-       if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
-               //LCOV_EXCL_START
-               if (dbus_error_is_set (&error)) {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send : %s", error.message); //LCOV_EXCL_LINE
-                       dbus_error_free (&error);
-               } else {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send"); //LCOV_EXCL_LINE
-               }
-               return MA_ERROR_OPERATION_FAILED;
-               //LCOV_EXCL_STOP
-       } else {
-               MA_SLOGD("[Dbus DEBUG] Success to Send"); //LCOV_EXCL_LINE
-               dbus_connection_flush(g_conn_sender);
-       }
-
-       dbus_message_unref(msg);
-
-       return 0;
+       return __send_dbus_message(msg);
 }
 
 int ma_dbus_set_assistant_wakeup_language(int pid, const char* language)
@@ -1747,40 +1533,17 @@ int ma_dbus_set_assistant_wakeup_language(int pid, const char* language)
                DBUS_TYPE_STRING, &tmp_language,
                DBUS_TYPE_INVALID);
 
-       dbus_message_set_no_reply(msg, TRUE);
-
-       DBusError error;
-       dbus_error_init (&error);
-       if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
-               //LCOV_EXCL_START
-               if (dbus_error_is_set (&error)) {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send : %s", error.message); //LCOV_EXCL_LINE
-                       dbus_error_free (&error);
-               } else {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send"); //LCOV_EXCL_LINE
-               }
-               if (NULL != tmp_language) {
-                       free(tmp_language);
-                       tmp_language = NULL;
-               }
-               return MA_ERROR_OPERATION_FAILED;
-               //LCOV_EXCL_STOP
-       } else {
-               MA_SLOGD("[Dbus DEBUG] Success to Send"); //LCOV_EXCL_LINE
-               dbus_connection_flush(g_conn_sender);
-       }
+       int ret = __send_dbus_message(msg);
 
        if (NULL != tmp_language) {
                free(tmp_language);
                tmp_language = NULL;
        }
 
-       dbus_message_unref(msg);
-
-       return 0;
+       return ret;
 }
 
-int ma_dbus_add_wake_word(int pid, const char* wake_word, const char* language)
+static int __send_wake_word_message(int pid, const char* wake_word, const char* language, bool is_add_message)
 {
        if (0 != __dbus_check()) {
                return MA_ERROR_OPERATION_FAILED;
@@ -1792,13 +1555,16 @@ int ma_dbus_add_wake_word(int pid, const char* wake_word, const char* language)
                          MA_SERVER_SERVICE_NAME,
                          MA_SERVER_SERVICE_OBJECT_PATH,
                          MA_SERVER_SERVICE_INTERFACE,
-                         MA_METHOD_ADD_WAKE_WORD);
+                         is_add_message ? MA_METHOD_ADD_WAKE_WORD : MA_METHOD_REMOVE_WAKE_WORD);
 
        if (NULL == msg) {
                MA_SLOGE("@@ Request multi-assistant add wake word : Fail to make message"); //LCOV_EXCL_LINE
                return MA_ERROR_OPERATION_FAILED;
        } else {
-               MA_SLOGD("[DEBUG] multi-assistant add wake word"); //LCOV_EXCL_LINE
+               if (is_add_message)
+                       MA_SLOGD("[DEBUG] multi-assistant add wake word"); //LCOV_EXCL_LINE
+               else
+                       MA_SLOGD("[DEBUG] multi-assistant remove wake word"); //LCOV_EXCL_LINE
        }
 
        char* tmp_wake_word = NULL;
@@ -1821,32 +1587,7 @@ int ma_dbus_add_wake_word(int pid, const char* wake_word, const char* language)
                DBUS_TYPE_STRING, &tmp_language,
                DBUS_TYPE_INVALID);
 
-       dbus_message_set_no_reply(msg, TRUE);
-
-       DBusError error;
-       dbus_error_init (&error);
-       if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
-               //LCOV_EXCL_START
-               if (dbus_error_is_set (&error)) {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send : %s", error.message); //LCOV_EXCL_LINE
-                       dbus_error_free (&error);
-               } else {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send"); //LCOV_EXCL_LINE
-               }
-               if (NULL != tmp_wake_word) {
-                       free(tmp_wake_word);
-                       tmp_wake_word = NULL;
-               }
-               if (NULL != tmp_language) {
-                       free(tmp_language);
-                       tmp_language = NULL;
-               }
-               return MA_ERROR_OPERATION_FAILED;
-               //LCOV_EXCL_STOP
-       } else {
-               MA_SLOGD("[Dbus DEBUG] Success to Send"); //LCOV_EXCL_LINE
-               dbus_connection_flush(g_conn_sender);
-       }
+       int ret = __send_dbus_message(msg);
 
        if (NULL != tmp_wake_word) {
                free(tmp_wake_word);
@@ -1857,89 +1598,15 @@ int ma_dbus_add_wake_word(int pid, const char* wake_word, const char* language)
                tmp_language = NULL;
        }
 
-       dbus_message_unref(msg);
+       return ret;
+}
 
-       return 0;
+int ma_dbus_add_wake_word(int pid, const char* wake_word, const char* language)
+{
+       return __send_wake_word_message(pid, wake_word, language, true);
 }
 
 int ma_dbus_remove_wake_word(int pid, const char* wake_word, const char* language)
 {
-       if (0 != __dbus_check()) {
-               return MA_ERROR_OPERATION_FAILED;
-       }
-
-       DBusMessage* msg;
-
-       msg = dbus_message_new_method_call(
-                         MA_SERVER_SERVICE_NAME,
-                         MA_SERVER_SERVICE_OBJECT_PATH,
-                         MA_SERVER_SERVICE_INTERFACE,
-                         MA_METHOD_REMOVE_WAKE_WORD);
-
-       if (NULL == msg) {
-               MA_SLOGE("@@ Request multi-assistant remove wake word : Fail to make message"); //LCOV_EXCL_LINE
-               return MA_ERROR_OPERATION_FAILED;
-       } else {
-               MA_SLOGD("[DEBUG] multi-assistant remove wake word"); //LCOV_EXCL_LINE
-       }
-
-       char* tmp_wake_word = NULL;
-       if (NULL != wake_word) {
-               tmp_wake_word = strdup(wake_word);
-       } else {
-               tmp_wake_word = strdup("#NULL");
-       }
-
-       char* tmp_language = NULL;
-       if (NULL != language) {
-               tmp_language = strdup(language);
-       } else {
-               tmp_language = strdup("#NULL");
-       }
-
-       dbus_message_append_args(msg,
-               DBUS_TYPE_INT32, &pid,
-               DBUS_TYPE_STRING, &tmp_wake_word,
-               DBUS_TYPE_STRING, &tmp_language,
-               DBUS_TYPE_INVALID);
-
-       dbus_message_set_no_reply(msg, TRUE);
-
-       DBusError error;
-       dbus_error_init (&error);
-       if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
-               //LCOV_EXCL_START
-               if (dbus_error_is_set (&error)) {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send : %s", error.message); //LCOV_EXCL_LINE
-                       dbus_error_free (&error);
-               } else {
-                       MA_SLOGE("[Dbus ERROR] Fail to Send"); //LCOV_EXCL_LINE
-               }
-               if (NULL != tmp_wake_word) {
-                       free(tmp_wake_word);
-                       tmp_wake_word = NULL;
-               }
-               if (NULL != tmp_language) {
-                       free(tmp_language);
-                       tmp_language = NULL;
-               }
-               return MA_ERROR_OPERATION_FAILED;
-               //LCOV_EXCL_STOP
-       } else {
-               MA_SLOGD("[Dbus DEBUG] Success to Send"); //LCOV_EXCL_LINE
-               dbus_connection_flush(g_conn_sender);
-       }
-
-       if (NULL != tmp_wake_word) {
-               free(tmp_wake_word);
-               tmp_wake_word = NULL;
-       }
-       if (NULL != tmp_language) {
-               free(tmp_language);
-               tmp_language = NULL;
-       }
-
-       dbus_message_unref(msg);
-
-       return 0;
+       return __send_wake_word_message(pid, wake_word, language, false);
 }