From f48d7d08433c3d34016ae3db91bb9ee4a0f657f1 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 16 Sep 2019 15:45:05 +0900 Subject: [PATCH] Add PREPROCESSING_INFORMATION changed handler Change-Id: I09b059e4ddebf772b2ed18afa520198806d8f178 --- client/ma.c | 76 ++++++++++++++++++++++++++++++++ client/ma_client.c | 30 ++++++++++++- client/ma_client.h | 4 ++ client/ma_dbus.c | 25 +++++++++++ common/ma_defs.h | 1 + include/multi_assistant.h | 34 ++++++++++++++ include/multi_assistant_common.h | 11 +++++ 7 files changed, 180 insertions(+), 1 deletion(-) diff --git a/client/ma.c b/client/ma.c index c78c1d9..627cea9 100644 --- a/client/ma.c +++ b/client/ma.c @@ -620,6 +620,25 @@ int __ma_cb_wakeup_engine_command(const char* command) return 0; } +int __ma_cb_preprocessing_information_changed(const char* app_id) +{ + ma_preprocessing_information_changed_cb callback = NULL; + void* user_data; + + ma_client_get_preprocessing_information_changed_cb(g_ma, &callback, &user_data); + + if (NULL != callback) { + ma_client_use_callback(g_ma); + callback(app_id, user_data); + ma_client_not_use_callback(g_ma); + SLOG(LOG_DEBUG, TAG_MAC, "[DEBUG] Preprocessing information changed callback is called, (%s)", app_id); + } else { + SLOG(LOG_DEBUG, TAG_MAC, "[WARNING] Preprocessing information changed callback is NULL"); + } + + return 0; +} + int ma_get_state(ma_state_e* state) { if (0 != __ma_get_feature_enabled()) { @@ -1558,3 +1577,60 @@ int ma_set_preprocessing_allow_mode(ma_preprocessing_allow_mode_e mode, const ch } return ret; } + +int ma_set_preprocessing_information_changed_cb(ma_preprocessing_information_changed_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 information changed 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_information_changed_cb(g_ma, callback, user_data); + + return MA_ERROR_NONE; +} + +int ma_unset_preprocessing_information_changed_cb(void) +{ + if (0 != __ma_get_feature_enabled()) { + return MA_ERROR_NOT_SUPPORTED; + } + + SLOG(LOG_DEBUG, TAG_MAC, "[Client DEBUG] Unset Multi-assistant preprocessing information changed 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_information_changed_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 167889b..34fc466 100644 --- a/client/ma_client.c +++ b/client/ma_client.c @@ -36,6 +36,8 @@ typedef struct { void* active_state_changed_user_data; ma_wakeup_engine_command_cb wakeup_engine_command_cb; void* wakeup_engine_command_user_data; + ma_preprocessing_information_changed_cb preprocessing_information_changed_cb; + void* preprocessing_information_changed_user_data; /* state */ ma_state_e previous_state; @@ -481,4 +483,30 @@ int ma_client_get_wakeup_engine_command_cb(ma_h ma, ma_wakeup_engine_command_cb* *user_data = client->wakeup_engine_command_user_data; return MA_ERROR_NONE; -} \ No newline at end of file +} + +int ma_client_set_preprocessing_information_changed_cb(ma_h ma, ma_preprocessing_information_changed_cb callback, void* user_data) +{ + ma_client_s* client = __client_get(ma); + + if (NULL == client) + return MA_ERROR_INVALID_PARAMETER; + + client->preprocessing_information_changed_cb = callback; + client->preprocessing_information_changed_user_data = user_data; + + return MA_ERROR_NONE; +} + +int ma_client_get_preprocessing_information_changed_cb(ma_h ma, ma_preprocessing_information_changed_cb* callback, void** user_data) +{ + ma_client_s* client = __client_get(ma); + + if (NULL == client) + return MA_ERROR_INVALID_PARAMETER; + + *callback = client->preprocessing_information_changed_cb; + *user_data = client->preprocessing_information_changed_user_data; + + return MA_ERROR_NONE; +} diff --git a/client/ma_client.h b/client/ma_client.h index 4cfa1fb..280a0c3 100644 --- a/client/ma_client.h +++ b/client/ma_client.h @@ -84,6 +84,10 @@ int ma_client_set_wakeup_engine_command_cb(ma_h ma, ma_wakeup_engine_command_cb int ma_client_get_wakeup_engine_command_cb(ma_h ma, ma_wakeup_engine_command_cb* callback, void** user_data); +int ma_client_set_preprocessing_information_changed_cb(ma_h ma, ma_preprocessing_information_changed_cb callback, void* user_data); + +int ma_client_get_preprocessing_information_changed_cb(ma_h ma, ma_preprocessing_information_changed_cb* callback, void** user_data); + #ifdef __cplusplus } #endif diff --git a/client/ma_dbus.c b/client/ma_dbus.c index b7bf094..278be1d 100644 --- a/client/ma_dbus.c +++ b/client/ma_dbus.c @@ -32,6 +32,7 @@ extern int __ma_cb_error(int reason, char* msg); extern int __ma_cb_audio_streaming(int event, char* buffer, int len); 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); static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler* fd_handler) { @@ -160,6 +161,30 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler* fd_handle SLOG(LOG_INFO, TAG_MAC, "@@@"); } /* MAS_METHOD_WAKEUP_ENGINE_COMMAND */ + else if (dbus_message_is_method_call(msg, if_name, MAS_METHOD_SEND_PREPROCESSING_INFORMATION)) { + SLOG(LOG_INFO, TAG_MAC, "@@@ Activate"); + char* app_id = NULL; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_STRING, &app_id, + 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 { + char* temp_app_id = NULL; + if (NULL != app_id && strcmp("#NULL", app_id)) { + temp_app_id = strdup(app_id); + } + __ma_cb_preprocessing_information_changed(temp_app_id); + if (NULL != temp_app_id) + free(temp_app_id); + } + + SLOG(LOG_INFO, TAG_MAC, "@@@"); + } /* MAS_METHOD_SEND_PREPROCESSING_INFORMATION */ + 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 6e24b84..c4cb5b4 100644 --- a/common/ma_defs.h +++ b/common/ma_defs.h @@ -89,6 +89,7 @@ extern "C" #define MAS_METHOD_STREAMING_AUDIO_DATA "mas_method_streaming_audio_data" #define MAS_METHOD_WAKEUP_ENGINE_COMMAND "mas_method_wakeup_engine_command" #define MAS_METHOD_ERROR "mas_method_error" +#define MAS_METHOD_SEND_PREPROCESSING_INFORMATION "mas_method_send_preprocessing_information" #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 fdc3748..09b2ffc 100644 --- a/include/multi_assistant.h +++ b/include/multi_assistant.h @@ -604,6 +604,40 @@ int ma_set_background_volume(double ratio); */ int ma_set_preprocessing_allow_mode(ma_preprocessing_allow_mode_e mode, const char* app_id); +/** + * @brief Sets the preprocessing information changed 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_STATE Invalid state + * @retval #MA_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre The state should be #MA_STATE_INITIALIZED. + * @see ma_preprocessing_information_changed_cb() + * @see ma_unset_preprocessing_information_changed_cb() + */ +int ma_set_preprocessing_information_changed_cb(ma_preprocessing_information_changed_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_information_changed_cb() + * @see ma_set_preprocessing_information_changed_cb() + */ +int ma_unset_preprocessing_information_changed_cb(void); + #ifdef __cplusplus } #endif diff --git a/include/multi_assistant_common.h b/include/multi_assistant_common.h index 7c496a8..a80e319 100644 --- a/include/multi_assistant_common.h +++ b/include/multi_assistant_common.h @@ -250,6 +250,17 @@ typedef void *ma_assistant_info_h; * @param[in] user_data The user data passed from the callback registration function */ typedef int (*ma_assistant_info_list_cb)(ma_assistant_info_h handle, void* user_data); + +/** + * @brief Called when the preprocessing information is changed. + * @since_tizen 5.5 + * + * @remarks The @a app_id should not be released and can be used only in the callback. To use outside, make a copy. + * @remarks If the @a app_id is NULL, it means there is no preprocessing voice assistant available. + * @param[in] app_id The application id of current preprocessing voice assistant + */ +typedef void (*ma_preprocessing_information_changed_cb)(const char* app_id, void* user_data); + #ifdef __cplusplus } #endif -- 2.34.1