From: Ji-hoon Lee Date: Fri, 11 Oct 2019 01:23:51 +0000 (+0900) Subject: Add APIs related to receiving preprocessing_result X-Git-Tag: submit/tizen/20191018.095018~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ad4fb8686cb6618a635b9e95aed88a14375d613b;p=platform%2Fcore%2Fuifw%2Fmulti-assistant.git Add APIs related to receiving preprocessing_result Change-Id: Iaf111dfe40a43369eefa02d6b8cec27900067e15 --- diff --git a/client/ma.c b/client/ma.c index b7c516f..c9e9c90 100644 --- a/client/ma.c +++ b/client/ma.c @@ -687,6 +687,25 @@ int __ma_cb_audio_streaming_data_section_changed(ma_audio_streaming_data_section return 0; } +int __ma_cb_preprocessing_result_received(bool result) +{ + ma_preprocessing_result_received_cb callback = NULL; + void* user_data; + + ma_client_get_preprocessing_result_received_cb(g_ma, &callback, &user_data); + + if (NULL != callback) { + ma_client_use_callback(g_ma); + callback(result, user_data); + ma_client_not_use_callback(g_ma); + SLOG(LOG_DEBUG, TAG_MAC, "[DEBUG] Preprocessing result received callback is called, (%d)", result); + } else { + SLOG(LOG_DEBUG, TAG_MAC, "[WARNING] Preprocessing result received callback is NULL"); + } + + return 0; +} + int ma_get_state(ma_state_e* state) { if (0 != __ma_get_feature_enabled()) { @@ -1823,3 +1842,60 @@ int ma_unset_audio_streaming_data_section_changed_cb(void) return MA_ERROR_NONE; } + +int ma_set_preprocessing_result_received_cb(ma_preprocessing_result_received_cb callback, void* user_data) +{ + if (0 != __ma_get_feature_enabled()) { + return MA_ERROR_NOT_SUPPORTED; + } + + SLOG(LOG_DEBUG, TAG_MAC, "[Client DEBUG] Set Multi-assistant preprocessing result received cb"); + + if (NULL == callback) { + SLOG(LOG_ERROR, TAG_MAC, "[ERROR] Invalid parameter"); //LCOV_EXCL_LINE + return MA_ERROR_INVALID_PARAMETER; + } + + ma_state_e state; + + if (0 != ma_client_get_client_state(g_ma, &state)) { + SLOG(LOG_ERROR, TAG_MAC, "[ERROR] A handle is not available"); //LCOV_EXCL_LINE + return MA_ERROR_INVALID_STATE; + } + + /* check state */ + if (state != MA_STATE_INITIALIZED) { + SLOG(LOG_ERROR, TAG_MAC, "[ERROR] Invalid State: Current state is not 'Initialized' (%d)", state); //LCOV_EXCL_LINE + return MA_ERROR_INVALID_STATE; + } + + ma_client_set_preprocessing_result_received_cb(g_ma, callback, user_data); + + return MA_ERROR_NONE; +} + +int ma_unset_preprocessing_result_received_cb(void) +{ + if (0 != __ma_get_feature_enabled()) { + return MA_ERROR_NOT_SUPPORTED; + } + + SLOG(LOG_DEBUG, TAG_MAC, "[Client DEBUG] Unset Multi-assistant preprocessing result received cb"); + + ma_state_e state; + + if (0 != ma_client_get_client_state(g_ma, &state)) { + SLOG(LOG_ERROR, TAG_MAC, "[ERROR] A handle is not available"); //LCOV_EXCL_LINE + return MA_ERROR_INVALID_STATE; + } + + /* check state */ + if (state != MA_STATE_INITIALIZED) { + SLOG(LOG_ERROR, TAG_MAC, "[ERROR] Invalid State: Current state is not 'Initialized'"); //LCOV_EXCL_LINE + return MA_ERROR_INVALID_STATE; + } + + ma_client_set_preprocessing_result_received_cb(g_ma, NULL, NULL); + + return MA_ERROR_NONE; +} \ No newline at end of file diff --git a/client/ma_client.c b/client/ma_client.c index a3efdf5..72c2f47 100644 --- a/client/ma_client.c +++ b/client/ma_client.c @@ -40,6 +40,8 @@ typedef struct { void* preprocessing_information_changed_user_data; ma_audio_streaming_data_section_changed_cb audio_streaming_data_section_changed_cb; void* audio_streaming_data_section_changed_user_data; + ma_preprocessing_result_received_cb preprocessing_result_received_cb; + void* preprocessing_result_received_user_data; /* state */ ma_state_e previous_state; @@ -127,6 +129,8 @@ int ma_client_create(ma_h* ma) client->preprocessing_information_changed_user_data = NULL; client->audio_streaming_data_section_changed_cb = NULL; client->audio_streaming_data_section_changed_user_data = NULL; + client->preprocessing_result_received_cb = NULL; + client->preprocessing_result_received_user_data = NULL; client->previous_state = MA_STATE_INITIALIZED; client->current_state = MA_STATE_INITIALIZED; @@ -542,3 +546,29 @@ int ma_client_get_audio_streaming_data_section_changed_cb(ma_h ma, ma_audio_stre return MA_ERROR_NONE; } + +int ma_client_set_preprocessing_result_received_cb(ma_h ma, ma_preprocessing_result_received_cb callback, void* user_data) +{ + ma_client_s* client = __client_get(ma); + + if (NULL == client) + return MA_ERROR_INVALID_PARAMETER; + + client->preprocessing_result_received_cb = callback; + client->preprocessing_result_received_user_data = user_data; + + return MA_ERROR_NONE; +} + +int ma_client_get_preprocessing_result_received_cb(ma_h ma, ma_preprocessing_result_received_cb* callback, void** user_data) +{ + ma_client_s* client = __client_get(ma); + + if (NULL == client) + return MA_ERROR_INVALID_PARAMETER; + + *callback = client->preprocessing_result_received_cb; + *user_data = client->preprocessing_result_received_user_data; + + return MA_ERROR_NONE; +} diff --git a/client/ma_client.h b/client/ma_client.h index 5cbe21a..72c6fff 100644 --- a/client/ma_client.h +++ b/client/ma_client.h @@ -92,6 +92,10 @@ int ma_client_set_audio_streaming_data_section_changed_cb(ma_h ma, ma_audio_stre int ma_client_get_audio_streaming_data_section_changed_cb(ma_h ma, ma_audio_streaming_data_section_changed_cb* callback, void** user_data); +int ma_client_set_preprocessing_result_received_cb(ma_h ma, ma_preprocessing_result_received_cb callback, void* user_data); + +int ma_client_get_preprocessing_result_received_cb(ma_h ma, ma_preprocessing_result_received_cb* callback, void** user_data); + #ifdef __cplusplus } #endif diff --git a/client/ma_dbus.c b/client/ma_dbus.c index 9e88d96..5668006 100644 --- a/client/ma_dbus.c +++ b/client/ma_dbus.c @@ -34,6 +34,7 @@ extern int __ma_cb_active_state_changed(int state); extern int __ma_cb_wakeup_engine_command(const char *command); extern int __ma_cb_preprocessing_information_changed(const char* app_id); extern int __ma_cb_audio_streaming_data_section_changed(ma_audio_streaming_data_section_e section); +extern int __ma_cb_preprocessing_result_received(bool result); static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler* fd_handler) { @@ -204,6 +205,24 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler* fd_handle SLOG(LOG_INFO, TAG_MAC, "@@@"); } /* MAS_METHOD_AUDIO_STREAMING_DATA_SECTION */ + else if (dbus_message_is_method_call(msg, if_name, MAS_METHOD_SEND_PREPROCESSING_RESULT)) { + SLOG(LOG_INFO, TAG_MAC, "@@@ Activate"); + int result; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_MAC, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + } else { + __ma_cb_preprocessing_result_received(result); + } + + SLOG(LOG_INFO, TAG_MAC, "@@@"); + } /* MAS_METHOD_SEND_PREPROCESSING_RESULT */ + else if (dbus_message_is_signal(msg, if_name, MAS_METHOD_ERROR)) { SLOG(LOG_DEBUG, TAG_MAC, "[DEBUG] Get Error"); int reason; diff --git a/common/ma_defs.h b/common/ma_defs.h index 9c3d197..6b62aa4 100644 --- a/common/ma_defs.h +++ b/common/ma_defs.h @@ -94,6 +94,7 @@ extern "C" #define MAS_METHOD_ERROR "mas_method_error" #define MAS_METHOD_SEND_PREPROCESSING_INFORMATION "mas_method_send_preprocessing_information" #define MAS_METHOD_AUDIO_STREAMING_DATA_SECTION "mas_method_audio_streaming_data_section" +#define MAS_METHOD_SEND_PREPROCESSING_RESULT "mas_method_send_preprocessing_result" #define MAS_UI_METHOD_HELLO "mas_ui_method_hello" #define MAS_UI_METHOD_SEND_ASR_RESULT "mas_ui_method_send_asr_result" diff --git a/include/multi_assistant.h b/include/multi_assistant.h index c8661db..4319f29 100644 --- a/include/multi_assistant.h +++ b/include/multi_assistant.h @@ -693,6 +693,40 @@ int ma_set_audio_streaming_data_section_changed_cb(ma_audio_streaming_data_secti */ int ma_unset_audio_streaming_data_section_changed_cb(void); +/** + * @brief Sets the preprocessing result received callback. + * @since_tizen 5.5 + * + * @param[in] callback The callback + * @param[in] user_data The user data passed to the callback function + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MA_ERROR_NONE Successful + * @retval #MA_ERROR_NOT_SUPPORTED Not supported + * @retval #MA_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MA_ERROR_INVALID_STATE Invalid state + * + * @pre The state should be #MA_STATE_INITIALIZED. + * @see ma_preprocessing_result_received_cb() + * @see ma_unset_preprocessing_result_received_cb() + */ +int ma_set_preprocessing_result_received_cb(ma_preprocessing_result_received_cb callback, void* user_data); + +/** + * @brief Unsets the preprocessing information changed callback. + * @since_tizen 5.5 + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MA_ERROR_NONE Successful + * @retval #MA_ERROR_NOT_SUPPORTED Not supported + * @retval #MA_ERROR_INVALID_STATE Invalid state + * + * @pre The state should be #MA_STATE_INITIALIZED. + * @see ma_preprocessing_result_received_cb() + * @see ma_set_preprocessing_result_received_cb() + */ +int ma_unset_preprocessing_result_received_cb(void); + #ifdef __cplusplus } #endif diff --git a/include/multi_assistant_common.h b/include/multi_assistant_common.h index 033f347..d4922f1 100644 --- a/include/multi_assistant_common.h +++ b/include/multi_assistant_common.h @@ -283,6 +283,15 @@ typedef void (*ma_preprocessing_information_changed_cb)(const char* app_id, void */ typedef void (*ma_audio_streaming_data_section_changed_cb)(ma_audio_streaming_data_section_e section, void* user_data); +/** + * @brief Called when the preprocessing result is received. + * @since_tizen 5.5 + * + * @param[in] is_success The value indicating whether the preprocessing succeeded or not + * @param[in] user_data The user data passed from the callback registration function + */ +typedef void (*ma_preprocessing_result_received_cb)(bool is_success, void* user_data); + #ifdef __cplusplus } #endif