From dfa7d9e369afb880c35517943456062250bb0c29 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Tue, 2 Apr 2019 18:04:40 +0900 Subject: [PATCH] Introduce ENABLE_COMMON_UI protocol to support UI customization Change-Id: I8d0a7cfea08a773bb827b511fbb0b373dd8a289d --- client/ma_ui.c | 75 ++++++++++++++++++++++++++++++++++++ client/ma_ui_client.c | 37 ++++++++++++++++-- client/ma_ui_client.h | 3 ++ client/ma_ui_dbus.c | 23 ++++++++++- common/ma_defs.h | 3 +- include/multi_assistant_ui.h | 43 +++++++++++++++++++++ 6 files changed, 178 insertions(+), 6 deletions(-) diff --git a/client/ma_ui.c b/client/ma_ui.c index ff563a4..ba0e1d8 100644 --- a/client/ma_ui.c +++ b/client/ma_ui.c @@ -656,6 +656,26 @@ int __ma_ui_cb_send_recognition_result(ma_recognition_result_event_e result) return MA_ERROR_NONE; } + +int __ma_ui_cb_enable_common_ui(bool enable) +{ + ma_ui_enable_common_ui_cb callback = NULL; + void* user_data; + + ma_ui_client_get_enable_common_ui_cb(g_ma_ui, &callback, &user_data); + + if (NULL != callback) { + ma_ui_client_use_callback(g_ma_ui); + callback(enable, user_data); + ma_ui_client_not_use_callback(g_ma_ui); + SLOG(LOG_DEBUG, TAG_MAUI, "[DEBUG] enable common UI callback is called"); + } else { + SLOG(LOG_DEBUG, TAG_MAUI, "[WARNING] enable common UI callback is NULL"); + } + + return MA_ERROR_NONE; +} + int ma_ui_get_state(ma_state_e* state) { if (0 != __ma_ui_get_feature_enabled()) { @@ -1142,3 +1162,58 @@ int ma_ui_unset_recognition_result_cb(void) return MA_ERROR_NONE; } +int ma_ui_set_enable_common_ui_cb(ma_ui_enable_common_ui_cb callback, void* user_data) +{ + if (0 != __ma_ui_get_feature_enabled()) { + SLOG(LOG_DEBUG, TAG_MAUI, "@@@ [UI] not supported"); + return MA_ERROR_NOT_SUPPORTED; + } + + if (NULL == callback) { + SLOG(LOG_ERROR, TAG_MAUI, "[UI ERROR] Invalid parameter"); + return MA_ERROR_INVALID_PARAMETER; + } + + ma_state_e state; + if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) { + SLOG(LOG_ERROR, TAG_MAUI, "[UI ERROR] A handle is not available"); + return MA_ERROR_INVALID_STATE; + } + + /* check state */ + if (MA_STATE_INITIALIZED != state) { + SLOG(LOG_ERROR, TAG_MAUI, "[UI ERROR] Invalid state: Current state is not 'Initialized' (%d)", state); + return MA_ERROR_INVALID_STATE; + } + + ma_ui_client_set_enable_common_ui_cb(g_ma_ui, callback, user_data); + + return MA_ERROR_NONE; +} + +int ma_ui_unset_enable_common_ui_cb(void) +{ + if (0 != __ma_ui_get_feature_enabled()) { + SLOG(LOG_DEBUG, TAG_MAUI, "@@@ [UI] not supported"); + return MA_ERROR_NOT_SUPPORTED; + } + + SLOG(LOG_DEBUG, TAG_MAUI, "[UI] Set a default assistant"); + + ma_state_e state; + if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) { + SLOG(LOG_ERROR, TAG_MAUI, "[UI ERROR] A handle is not available"); + return MA_ERROR_INVALID_STATE; + } + + /* check state */ + if (MA_STATE_INITIALIZED != state) { + SLOG(LOG_ERROR, TAG_MAUI, "[UI ERROR] Invalid state: Current state is not 'Initialized' (%d)", state); + return MA_ERROR_INVALID_STATE; + } + + ma_ui_client_set_enable_common_ui_cb(g_ma_ui, NULL, NULL); + + return MA_ERROR_NONE; +} + diff --git a/client/ma_ui_client.c b/client/ma_ui_client.c index 34e9809..ac6edf5 100644 --- a/client/ma_ui_client.c +++ b/client/ma_ui_client.c @@ -29,21 +29,21 @@ typedef struct { void* asr_result_user_data; ma_ui_change_assistant_cb change_assistant_cb; void* change_assistant_user_data; - ma_error_cb error_cb; void* error_user_data; ma_state_changed_cb state_changed_cb; void* state_changed_user_data; ma_language_changed_cb lang_changed_cb; void* lang_changed_user_data; + ma_ui_recognition_result_cb recognition_result_cb; + void* recognition_result_user_data; + ma_ui_enable_common_ui_cb enable_common_ui_cb; + void* enable_common_ui_user_data; /* ASR result */ ma_asr_result_event_e asr_result_event; char* asr_result_text; - ma_ui_recognition_result_cb recognition_result_cb; - void* recognition_result_user_data; - /* state */ ma_state_e previous_state; ma_state_e current_state; @@ -127,6 +127,10 @@ int ma_ui_client_create(ma_h* ma) client->state_changed_user_data = NULL; client->lang_changed_cb = NULL; client->lang_changed_user_data = NULL; + client->recognition_result_cb = NULL; + client->recognition_result_user_data = NULL; + client->enable_common_ui_cb = NULL; + client->enable_common_ui_user_data = NULL; client->asr_result_event = 0; client->asr_result_text = NULL; @@ -483,3 +487,28 @@ int ma_ui_client_get_recognition_result_cb(ma_h ma, ma_ui_recognition_result_cb* return MA_ERROR_NONE; } +int ma_ui_client_set_enable_common_ui_cb(ma_h ma, ma_ui_enable_common_ui_cb callback, void* user_data) +{ + ma_ui_client_s* client = __ui_client_get(ma); + + if (NULL == client) + return MA_ERROR_INVALID_PARAMETER; + + client->enable_common_ui_cb = callback; + client->enable_common_ui_user_data = user_data; + + return MA_ERROR_NONE; +} + +int ma_ui_client_get_enable_common_ui_cb(ma_h ma, ma_ui_enable_common_ui_cb* callback, void** user_data) +{ + ma_ui_client_s* client = __ui_client_get(ma); + + if (NULL == client) + return MA_ERROR_INVALID_PARAMETER; + + *callback = client->enable_common_ui_cb; + *user_data = client->enable_common_ui_user_data; + + return MA_ERROR_NONE; +} diff --git a/client/ma_ui_client.h b/client/ma_ui_client.h index 66a9345..2c71ba3 100644 --- a/client/ma_ui_client.h +++ b/client/ma_ui_client.h @@ -79,6 +79,9 @@ int ma_ui_client_set_recognition_result_cb(ma_h ma, ma_ui_recognition_result_cb int ma_ui_client_get_recognition_result_cb(ma_h ma, ma_ui_recognition_result_cb* callback, void** user_data); +int ma_ui_client_set_enable_common_ui_cb(ma_h ma, ma_ui_enable_common_ui_cb callback, void* user_data); + +int ma_ui_client_get_enable_common_ui_cb(ma_h ma, ma_ui_enable_common_ui_cb* callback, void** user_data); #ifdef __cplusplus } diff --git a/client/ma_ui_dbus.c b/client/ma_ui_dbus.c index a418a69..6419379 100644 --- a/client/ma_ui_dbus.c +++ b/client/ma_ui_dbus.c @@ -33,6 +33,7 @@ extern int __ma_ui_cb_send_asr_result(int event, char* asr_result); extern int __ma_ui_cb_send_result(const char* display_text, const char* utterance_text, const char* result_json); extern int __ma_ui_cb_change_assistant(const char* app_id); extern int __ma_ui_cb_send_recognition_result(int result); +extern int __ma_ui_cb_enable_common_ui(int enable); static Eina_Bool ma_ui_listener_event_callback(void* data, Ecore_Fd_Handler* fd_handler) { @@ -219,7 +220,27 @@ static Eina_Bool ma_ui_listener_event_callback(void* data, Ecore_Fd_Handler* fd_ __ma_ui_cb_send_recognition_result(result); } - } /* MAS_UI_METHOD_SEND_RESULT */ + } /* MAS_UI_METHOD_SEND_RECOGNITION_RESULT */ + + if (dbus_message_is_method_call(msg, if_name, MAS_UI_METHOD_ENABLE_COMMON_UI)) { + SLOG(LOG_DEBUG, TAG_MAUI, "[DEBUG] Send recognition result"); + int enable = 0; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &enable, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_MAUI, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } else { + SLOG(LOG_DEBUG, TAG_MAUI, "[DEBUG] multi-assistant ui Enable common UI : enable(%d)", enable); + + __ma_ui_cb_enable_common_ui((enable) ? true : false); + } + + } /* MAS_UI_METHOD_ENABLE_COMMON_UI */ + else if (dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameOwnerChanged")) { SLOG(LOG_DEBUG, TAG_MAUI, "[DEBUG] Owner Changed"); /* remove a rule for daemon error */ diff --git a/common/ma_defs.h b/common/ma_defs.h index 9b411d1..093a942 100644 --- a/common/ma_defs.h +++ b/common/ma_defs.h @@ -91,8 +91,9 @@ extern "C" #define MAS_UI_METHOD_SEND_ASR_RESULT "mas_ui_method_send_asr_result" #define MAS_UI_METHOD_SEND_RESULT "mas_ui_method_send_result" #define MAS_UI_METHOD_CHANGE_ASSISTANT "mas_ui_method_change_assistant" -#define MAS_UI_METHOD_SEND_RECOGNITION_RESULT "mas_ui_method_send_recognition_result" #define MAS_UI_METHOD_ERROR "mas_ui_method_error" +#define MAS_UI_METHOD_SEND_RECOGNITION_RESULT "mas_ui_method_send_recognition_result" +#define MAS_UI_METHOD_ENABLE_COMMON_UI "mas_ui_method_enable_common_ui" /************************************************************************************** *** Definitions for xml file diff --git a/include/multi_assistant_ui.h b/include/multi_assistant_ui.h index a5f31e3..ac7f6b3 100644 --- a/include/multi_assistant_ui.h +++ b/include/multi_assistant_ui.h @@ -115,6 +115,18 @@ typedef void (*ma_ui_change_assistant_cb)(const char* app_id, void* user_data); */ typedef void (*ma_ui_recognition_result_cb)(ma_recognition_result_event_e result, void* user_data); +/** + * @brief Called when the multi-assistant service enables or disables the common UI. + * @since_tizen 5.5 + * + * @param[in] enable The status whether the common UI is enabled + * @param[in] user_data The user data passed from the callback registration function + * + * @see ma_ui_set_enable_common_ui_cb() + * @see ma_ui_set_enable_common_ui_cb() + */ +typedef void (*ma_ui_enable_common_ui_cb)(bool enable, void* user_data); + /** * @brief Initializes multi-assistant UI. * @since_tizen 5.0 @@ -445,6 +457,37 @@ int ma_ui_set_recognition_result_cb(ma_ui_recognition_result_cb callback, void* * @pre The state should be #MA_STATE_INITIALIZED. */ int ma_ui_unset_recognition_result_cb(void); + +/** + * @brief Sets a callback for getting common UI enabled status. + * @since_tizen 5.5 + * + * @param[in] callback The callback function + * @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. + */ +int ma_ui_set_enable_common_ui_cb(ma_ui_enable_common_ui_cb callback, void* user_data); + +/** + * @brief Unsets a callback for common UI enabled status. + * @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. + */ +int ma_ui_unset_enable_common_ui_cb(void); + #ifdef __cplusplus } #endif -- 2.34.1