From: Ji-hoon Lee Date: Fri, 6 Dec 2019 09:59:12 +0000 (+0900) Subject: Add internal APIs for handling service state notification X-Git-Tag: submit/tizen/20200113.120709~3^2~2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=88d1bae8a553fe7b8f50a3c29a5221e1b1774bec;p=platform%2Fcore%2Fuifw%2Fmulti-assistant.git Add internal APIs for handling service state notification Change-Id: Ifbc77e08697375c82db0ea8f9a75efa088b11ff9 --- diff --git a/client/ma.c b/client/ma.c index c62d2fd..0138730 100644 --- a/client/ma.c +++ b/client/ma.c @@ -819,6 +819,35 @@ int __ma_cb_preprocessing_result_received(bool result) return 0; } + +int __ma_cb_service_state_changed(int state) +{ + ma_service_state_changed_cb callback = NULL; + void* user_data; + + ma_client_set_service_state(g_ma, (ma_service_state_e)state); + + ma_service_state_e current_state; + ma_service_state_e previous_state; + ma_client_get_service_state(g_ma, ¤t_state, &previous_state); + + ma_client_get_service_state_changed_cb(g_ma, &callback, &user_data); + if (NULL != callback) { + ma_client_use_callback(g_ma); + callback(previous_state, current_state, user_data); + ma_client_not_use_callback(g_ma); + MA_SLOGD("[DEBUG] service state changed callback is called %d", current_state); + } else { + MA_SLOGD("[WARNING] service state changed callback is NULL"); + } + + MA_SLOGD( + "[INFO] previous : %d , current : %d service state changed", + previous_state, current_state + ); + + return 0; +} //LCOV_EXCL_STOP int ma_get_state(ma_state_e* state) @@ -2059,4 +2088,61 @@ int ma_set_assistant_language(const char* language) return ret; } +int ma_set_service_state_changed_cb(ma_service_state_changed_cb callback, void* user_data) +{ + if (0 != __ma_get_feature_enabled()) { + return MA_ERROR_NOT_SUPPORTED; + } + + MA_SLOGD("[Client DEBUG] Set Multi-assistant service state changed cb"); + + if (NULL == callback) { + MA_SLOGE("[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)) { + MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE + return MA_ERROR_INVALID_STATE; + } + + /* check state */ + if (state != MA_STATE_INITIALIZED) { + MA_SLOGE("[ERROR] Invalid State: Current state is not 'Initialized' (%d)", state); //LCOV_EXCL_LINE + return MA_ERROR_INVALID_STATE; + } + + ma_client_set_service_state_changed_cb(g_ma, callback, user_data); + + return MA_ERROR_NONE; +} + +int ma_unset_service_state_changed_cb(void) +{ + if (0 != __ma_get_feature_enabled()) { + return MA_ERROR_NOT_SUPPORTED; + } + + MA_SLOGD("[Client DEBUG] Unset Multi-assistant service state changed cb"); + + ma_state_e state; + + if (0 != ma_client_get_client_state(g_ma, &state)) { + MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE + return MA_ERROR_INVALID_STATE; + } + + /* check state */ + if (state != MA_STATE_INITIALIZED) { + MA_SLOGE("[ERROR] Invalid State: Current state is not 'Initialized'"); //LCOV_EXCL_LINE + return MA_ERROR_INVALID_STATE; + } + + ma_client_set_service_state_changed_cb(g_ma, NULL, NULL); + + return MA_ERROR_NONE; +} + //LCOV_EXCL_STOP \ No newline at end of file diff --git a/client/ma_client.c b/client/ma_client.c index cab8913..53dd2b8 100644 --- a/client/ma_client.c +++ b/client/ma_client.c @@ -42,6 +42,8 @@ typedef struct { void* audio_streaming_data_section_changed_user_data; ma_preprocessing_result_received_cb preprocessing_result_received_cb; void* preprocessing_result_received_user_data; + ma_service_state_changed_cb service_state_changed_cb; + void* service_state_changed_user_data; /* state */ ma_state_e previous_state; @@ -51,6 +53,9 @@ typedef struct { ma_active_state_e previous_active_state; ma_active_state_e current_active_state; + ma_service_state_e previous_service_state; + ma_service_state_e current_service_state; + #ifdef MA_PREPROCESSING_SEQUENTIAL_MODE ma_preprocessing_allow_mode_e preprocessing_allow_mode; ma_audio_streaming_data_type_e audio_streaming_data_type; @@ -147,6 +152,9 @@ int ma_client_create(ma_h* ma) client->previous_active_state = MA_ACTIVE_STATE_INACTIVE; client->current_active_state = MA_ACTIVE_STATE_INACTIVE; + client->previous_service_state = MA_SERVICE_STATE_INACTIVE; + client->current_service_state = MA_SERVICE_STATE_INACTIVE; + #ifdef MA_PREPROCESSING_SEQUENTIAL_MODE client->preprocessing_allow_mode = MA_PREPROCESSING_ALLOW_NONE; client->audio_streaming_data_type = MA_AUDIO_STREAMING_DATA_TYPE_CURRENT_UTTERANCE; @@ -718,4 +726,63 @@ int ma_client_pop_preprocessing_audio_data(ma_h ma, speech_data** data) return MA_ERROR_NONE; } + +//LCOV_EXCL_START +int ma_client_set_service_state(ma_h ma, ma_service_state_e state) +{ + ma_client_s* client = __client_get(ma); + + if (NULL == client) + return MA_ERROR_INVALID_PARAMETER; + + client->previous_service_state = client->current_service_state; + client->current_service_state = state; + + return MA_ERROR_NONE; +} +//LCOV_EXCL_STOP + +//LCOV_EXCL_START +int ma_client_get_service_state(ma_h ma, ma_service_state_e* current_state, ma_service_state_e* previous_state) +{ + ma_client_s* client = __client_get(ma); + + if (NULL == client) + return MA_ERROR_INVALID_PARAMETER; + + *current_state = client->current_service_state; + *previous_state = client->previous_service_state; + + return MA_ERROR_NONE; +} +//LCOV_EXCL_STOP + +int ma_client_set_service_state_changed_cb(ma_h ma, ma_service_state_changed_cb callback, void* user_data) +{ + ma_client_s* client = __client_get(ma); + + if (NULL == client) + return MA_ERROR_INVALID_PARAMETER; + + client->service_state_changed_cb = callback; + client->service_state_changed_user_data = user_data; + + return MA_ERROR_NONE; +} + +//LCOV_EXCL_START +int ma_client_get_service_state_changed_cb(ma_h ma, ma_service_state_changed_cb* callback, void** user_data) +{ + ma_client_s* client = __client_get(ma); + + if (NULL == client) + return MA_ERROR_INVALID_PARAMETER; + + *callback = client->service_state_changed_cb; + *user_data = client->service_state_changed_user_data; + + return MA_ERROR_NONE; +} +//LCOV_EXCL_STOP + #endif \ No newline at end of file diff --git a/client/ma_client.h b/client/ma_client.h index b63fc71..fb85243 100644 --- a/client/ma_client.h +++ b/client/ma_client.h @@ -20,6 +20,7 @@ #include "ma_main.h" #include "multi_assistant_common.h" +#include "multi_assistant_internal.h" #ifdef __cplusplus @@ -124,6 +125,15 @@ typedef struct { int ma_client_push_preprocessing_audio_data(ma_h ma, speech_data* data); int ma_client_pop_preprocessing_audio_data(ma_h ma, speech_data** data); + +int ma_client_set_service_state(ma_h ma, ma_service_state_e state); + +int ma_client_get_service_state(ma_h ma, ma_service_state_e* current_state, ma_service_state_e* previous_state); + +int ma_client_set_service_state_changed_cb(ma_h ma, ma_service_state_changed_cb callback, void* user_data); + +int ma_client_get_service_state_changed_cb(ma_h ma, ma_service_state_changed_cb* callback, void** user_data); + #endif #ifdef __cplusplus diff --git a/client/ma_dbus.c b/client/ma_dbus.c index 1c0ccd6..271d4fb 100644 --- a/client/ma_dbus.c +++ b/client/ma_dbus.c @@ -31,6 +31,7 @@ static DBusConnection* g_conn_listener = NULL; 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_service_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); @@ -143,6 +144,24 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler* fd_handle MA_SLOGI("@@@"); } /* MAS_METHOD_ACTIVE_STATE_CHANGE */ + else if (dbus_message_is_method_call(msg, if_name, MAS_METHOD_SERVICE_STATE_CHANGE)) { + int state; + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &state, + DBUS_TYPE_INVALID); + + MA_SLOGI("@@@ Service state : %d", state); + if (dbus_error_is_set(&err)) { + MA_SLOGE("@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + } else { + MA_SLOGD("@@ state(%d)", state); + __ma_cb_service_state_changed(state); + } + + MA_SLOGI("@@@"); + } /* MAS_METHOD_ACTIVE_STATE_CHANGE */ + else if (dbus_message_is_method_call(msg, if_name, MAS_METHOD_WAKEUP_ENGINE_COMMAND)) { char* command = NULL; diff --git a/common/ma_defs.h b/common/ma_defs.h index 127adcf..55a7cfd 100644 --- a/common/ma_defs.h +++ b/common/ma_defs.h @@ -97,6 +97,7 @@ extern "C" #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_METHOD_SEND_WAKEUP_ENGINE_COMMAND "mas_method_send_wakeup_engine_command" +#define MAS_METHOD_SERVICE_STATE_CHANGE "mas_method_service_state_change" #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_internal.h b/include/multi_assistant_internal.h index aaea945..aa80310 100644 --- a/include/multi_assistant_internal.h +++ b/include/multi_assistant_internal.h @@ -41,6 +41,62 @@ extern "C" */ int ma_set_assistant_language(const char* language); +/** + * @brief Enumerations for multi-assistant service state. + * @since_tizen 5.5 + */ +typedef enum { + MA_SERVICE_STATE_INACTIVE = 0, /**< 'Inactive' state */ + MA_SERVICE_STATE_LISTENING = 1, /**< 'Listening' state */ + MA_SERVICE_STATE_UTTERANCE = 2, /**< 'Utterance' state */ + MA_SERVICE_STATE_PROCESSING = 3, /**< 'Processing' state */ + MA_SERVICE_STATE_VOICE_FEEDBACK = 4, /**< 'VoiceFeedback' state */ +} ma_service_state_e; + +/** + * @brief Called when the service state is changed. + * @since_tizen 5.5 + * + * @param[in] previous The previous service state + * @param[in] current The current service state + * @param[in] user_data The user data passed from the callback registration function + */ +typedef void (*ma_service_state_changed_cb)(ma_service_state_e previous, ma_service_state_e current, void* user_data); + +/** + * @brief Sets the service state 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_PARAMETER Invalid parameter + * @retval #MA_ERROR_INVALID_STATE Invalid state + * + * @pre The state should be #MA_STATE_INITIALIZED. + * @see ma_service_state_changed_cb() + * @see ma_unset_service_state_changed_cb() + */ +int ma_set_service_state_changed_cb(ma_service_state_changed_cb callback, void* user_data); + +/** + * @brief Unsets the service state 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_service_state_changed_cb() + * @see ma_set_service_state_changed_cb() + */ +int ma_unset_service_state_changed_cb(void); + #ifdef __cplusplus } #endif