From b70547e9686f50b2ec5671d2f1ca5b869120e9c2 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Wed, 24 Oct 2018 19:07:41 +0900 Subject: [PATCH] Add change_assistant notification from service to panel Change-Id: I67ff310dde7783ed7966b7cc828f7ce2aa2dbc31 --- client/ma.c | 2 - client/ma_dbus.c | 65 -------------------------- client/ma_dbus.h | 1 - client/ma_ui.c | 88 ++++++++++++++++++++++++++++++++++++ client/ma_ui_client.c | 30 ++++++++++++ client/ma_ui_client.h | 4 ++ client/ma_ui_dbus.c | 20 ++++++++ common/ma_defs.h | 1 + include/multi_assistant.h | 1 - include/multi_assistant_ui.h | 38 ++++++++++++++++ 10 files changed, 181 insertions(+), 69 deletions(-) diff --git a/client/ma.c b/client/ma.c index b0b432a..5af0ad7 100644 --- a/client/ma.c +++ b/client/ma.c @@ -963,5 +963,3 @@ int ma_send_result(const char* display_text, const char* utterance_text, const c return ret; } - - diff --git a/client/ma_dbus.c b/client/ma_dbus.c index 9c13d1f..54a2128 100644 --- a/client/ma_dbus.c +++ b/client/ma_dbus.c @@ -550,71 +550,6 @@ int ma_dbus_request_deinitialize(int pid) return result; } -int ma_dbus_request_speech_data(int pid) -{ - 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_REQUEST_SPEECH_DATA); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_MAC, "@@ Request multi-assistant recording audio format : Fail to make message"); //LCOV_EXCL_LINE - return MA_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_DEBUG, TAG_MAC, "[DEBUG] multi-assistant recording audio format"); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INVALID); - - DBusError err; - dbus_error_init(&err); - - DBusMessage* result_msg = NULL; - int result = MA_ERROR_OPERATION_FAILED; - - result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err); - dbus_message_unref(msg); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_DEBUG, TAG_MAC, "[ERROR] Dbus Error (%s)", err.message); //LCOV_EXCL_LINE - dbus_error_free(&err); - } - - if (NULL != result_msg) { - dbus_message_get_args(result_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); - result = MA_ERROR_OPERATION_FAILED; - } - dbus_message_unref(result_msg); - - if (0 == result) { - SLOG(LOG_DEBUG, TAG_MAC, "@@ multi-assistant request speech data : result = %d", result); - } else { - SLOG(LOG_ERROR, TAG_MAC, "@@ multi-assistant request speech data : result = %d", result); - } - } else { - SLOG(LOG_ERROR, TAG_MAC, "@@ Result message is NULL"); - ma_dbus_reconnect(); - result = MA_ERROR_TIMED_OUT; - } - - return result; -} - int ma_dbus_get_recording_audio_format(int pid, int *rate, ma_audio_channel_e *channel, ma_audio_type_e *audio_type) { diff --git a/client/ma_dbus.h b/client/ma_dbus.h index 86b7e85..eb6ea04 100644 --- a/client/ma_dbus.h +++ b/client/ma_dbus.h @@ -38,7 +38,6 @@ int ma_dbus_request_initialize(int pid); int ma_dbus_request_deinitialize(int pid); - int ma_dbus_get_recording_audio_format(int pid, int *rate, ma_audio_channel_e *channel, ma_audio_type_e *audio_type); int ma_dbus_send_asr_result(int pid, ma_asr_result_event_e event, const char* asr_result); diff --git a/client/ma_ui.c b/client/ma_ui.c index e5d9354..a3b9806 100644 --- a/client/ma_ui.c +++ b/client/ma_ui.c @@ -542,6 +542,37 @@ int __ma_ui_cb_send_result(const char* display_text, const char* utterance_text, return MA_ERROR_NONE; } +static void __ma_ui_notify_change_assistant(const char* app_id) +{ + ma_ui_change_assistant_cb callback = NULL; + void* user_data; + + ma_ui_client_get_change_assistant_cb(g_ma_ui, &callback, &user_data); + + if (NULL != callback) { + ma_ui_client_use_callback(g_ma_ui); + callback(app_id, user_data); + ma_ui_client_not_use_callback(g_ma_ui); + SLOG(LOG_DEBUG, TAG_MAUI, "[DEBUG] result callback is called"); + } else { + SLOG(LOG_DEBUG, TAG_MAUI, "[WARNING] result callback is NULL"); + } +} + +int __ma_ui_cb_change_assistant(const char* app_id) +{ + ma_state_e state; + if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) { + SLOG(LOG_ERROR, TAG_MAUI, "[ERROR] Invalid client"); + return MA_ERROR_INVALID_PARAMETER; + } + + SLOG(LOG_DEBUG, TAG_MAUI, "[DEBUG] change assitant, app_id(%s)", app_id); + __ma_ui_notify_change_assistant(app_id); + + return MA_ERROR_NONE; +} + int __ma_ui_cb_error(int reason, char* msg) { ma_state_e state; @@ -967,3 +998,60 @@ int ma_ui_unset_result_cb(void) return MA_ERROR_NONE; } +int ma_ui_set_change_assistant_cb(ma_ui_change_assistant_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; + } + + SLOG(LOG_DEBUG, TAG_MAUI, "[UI] Set a default assistant"); + + 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_change_assistant_cb(g_ma_ui, callback, user_data); + + return MA_ERROR_NONE; +} + +int ma_ui_unset_change_assistant_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_change_assistant_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 7cdec42..06839b0 100644 --- a/client/ma_ui_client.c +++ b/client/ma_ui_client.c @@ -27,6 +27,8 @@ typedef struct { void* result_user_data; ma_ui_asr_result_cb asr_result_cb; 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; @@ -113,6 +115,8 @@ int ma_ui_client_create(ma_h* ma) client->result_user_data = NULL; client->asr_result_cb = NULL; client->asr_result_user_data = NULL; + client->change_assistant_cb = NULL; + client->change_assistant_user_data = NULL; client->error_cb = NULL; client->error_user_data = NULL; @@ -346,6 +350,32 @@ int ma_ui_client_get_result_cb(ma_h ma, ma_ui_result_cb* callback, void** user_d return MA_ERROR_NONE; } +int ma_ui_client_set_change_assistant_cb(ma_h ma, ma_ui_change_assistant_cb callback, void* user_data) +{ + ma_ui_client_s* client = __ui_client_get(ma); + + if (NULL == client) + return MA_ERROR_INVALID_PARAMETER; + + client->change_assistant_cb = callback; + client->change_assistant_user_data = user_data; + + return MA_ERROR_NONE; +} + +int ma_ui_client_get_change_assistant_cb(ma_h ma, ma_ui_change_assistant_cb* callback, void** user_data) +{ + ma_ui_client_s* client = __ui_client_get(ma); + + if (NULL == client) + return MA_ERROR_INVALID_PARAMETER; + + *callback = client->change_assistant_cb; + *user_data = client->change_assistant_user_data; + + return MA_ERROR_NONE; +} + int ma_ui_client_set_error_cb(ma_h ma, ma_error_cb callback, void* user_data) { ma_ui_client_s* client = __ui_client_get(ma); diff --git a/client/ma_ui_client.h b/client/ma_ui_client.h index 0562dbd..358b6e5 100644 --- a/client/ma_ui_client.h +++ b/client/ma_ui_client.h @@ -59,6 +59,10 @@ int ma_ui_client_set_result_cb(ma_h ma, ma_ui_result_cb callback, void* user_dat int ma_ui_client_get_result_cb(ma_h ma, ma_ui_result_cb* callback, void** user_data); +int ma_ui_client_set_change_assistant_cb(ma_h ma, ma_ui_change_assistant_cb callback, void* user_data); + +int ma_ui_client_get_change_assistant_cb(ma_h ma, ma_ui_change_assistant_cb* callback, void** user_data); + int ma_ui_client_set_error_cb(ma_h ma, ma_error_cb callback, void* user_data); int ma_ui_client_get_error_cb(ma_h ma, ma_error_cb* callback, void** user_data); diff --git a/client/ma_ui_dbus.c b/client/ma_ui_dbus.c index 7cedc19..ab9967c 100644 --- a/client/ma_ui_dbus.c +++ b/client/ma_ui_dbus.c @@ -31,6 +31,7 @@ static DBusConnection* g_ui_conn_listener = NULL; extern int __ma_ui_cb_error(int reason, char* msg); 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); static Eina_Bool ma_ui_listener_event_callback(void* data, Ecore_Fd_Handler* fd_handler) @@ -153,6 +154,25 @@ static Eina_Bool ma_ui_listener_event_callback(void* data, Ecore_Fd_Handler* fd_ } /* MAS_UI_METHOD_SEND_RESULT */ + if (dbus_message_is_method_call(msg, if_name, MAS_UI_METHOD_CHANGE_ASSISTANT)) { + SLOG(LOG_DEBUG, TAG_MAUI, "[DEBUG] Send change assistant request"); + 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_MAUI, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } else { + SLOG(LOG_DEBUG, TAG_MAUI, "[DEBUG] multi-assistant ui Send change assistant request : app_id(%s)", app_id); + + __ma_ui_cb_change_assistant(app_id); + } + + } /* MAS_UI_METHOD_CHANGE_ASSISTANT */ + else if (dbus_message_is_signal(msg, if_name, MAS_UI_METHOD_ERROR)) { SLOG(LOG_DEBUG, TAG_MAUI, "[DEBUG] Get Error"); int reason; diff --git a/common/ma_defs.h b/common/ma_defs.h index a5da661..86ba562 100644 --- a/common/ma_defs.h +++ b/common/ma_defs.h @@ -83,6 +83,7 @@ extern "C" #define MAS_UI_METHOD_HELLO "mas_ui_method_hello" #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_ERROR "mas_ui_method_error" /************************************************************************************** diff --git a/include/multi_assistant.h b/include/multi_assistant.h index 4bd4da0..357d4f8 100644 --- a/include/multi_assistant.h +++ b/include/multi_assistant.h @@ -334,7 +334,6 @@ int ma_send_asr_result(ma_asr_result_event_e event, const char* asr_result); */ int ma_send_result(const char* display_text, const char* utterance_text, const char* result_json); - #ifdef __cplusplus } #endif diff --git a/include/multi_assistant_ui.h b/include/multi_assistant_ui.h index 5f8e1cc..377739a 100644 --- a/include/multi_assistant_ui.h +++ b/include/multi_assistant_ui.h @@ -92,6 +92,16 @@ typedef void (*ma_ui_asr_result_cb)(ma_asr_result_event_e event, const char* asr */ typedef void (*ma_ui_result_cb)(const char* display_text, const char* utterance_text, const char* result_json, void* user_data); +/** + * @brief Called when the multi-assistant service sends the request for changing assistant. + * @since_tizen 5.0 + * @remarks The @a app_id can be used only in the callback. To use outside, make a copy. + * + * @param[in] app_id The text shown on the display + * @param[in] user_data The user data passed from the callback registration function + * + */ +typedef void (*ma_ui_change_assistant_cb)(const char* app_id, void* user_data); /** * @brief Initializes multi-assistant UI. @@ -364,7 +374,35 @@ int ma_ui_set_result_cb(ma_ui_result_cb callback, void* user_data); */ int ma_ui_unset_result_cb(void); +/** + * @brief Sets a callback for getting change assistant info. + * @since_tizen 5.0 + * + * @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_change_assistant_cb(ma_ui_change_assistant_cb callback, void* user_data); +/** + * @brief Unsets a callback for getting change assistant info. + * @since_tizen 5.0 + * + * @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_change_assistant_cb(void); #ifdef __cplusplus } -- 2.34.1