From: Ji-hoon Lee Date: Fri, 10 Jan 2020 09:31:36 +0000 (+0900) Subject: Add APIs for receiving voice key status change event X-Git-Tag: submit/tizen_5.5/20200409.014144~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6481e80ba58fcd588ba5a50bddcc25cc4bf74333;p=platform%2Fcore%2Fuifw%2Fmulti-assistant.git Add APIs for receiving voice key status change event This patch includes some future features as a internal API. Change-Id: I2017fd0519679ea054cb7c7fb35ea7cfdaf02086 Signed-off-by: Suyeon Hwang (cherry picked from commit 1d941a288ea5ebc07e811c338314a9e5df308426) --- diff --git a/assistant-parser/src/ma_assistant_parser.c b/assistant-parser/src/ma_assistant_parser.c index 0921734..38818c2 100644 --- a/assistant-parser/src/ma_assistant_parser.c +++ b/assistant-parser/src/ma_assistant_parser.c @@ -55,6 +55,8 @@ #define MA_METADATA_LANGUAGE "http://tizen.org/metadata/multi-assistant/language" #define MA_METADATA_ASSISTANT_WAKEUP_ENGINE_APPID "http://tizen.org/metadata/multi-assistant/wakeup_engine_appid" #define MA_METADATA_ASSISTANT_CUSTOM_UI "http://tizen.org/metadata/multi-assistant/custom_ui" +#define MA_METADATA_ASSISTANT_VOICE_KEY_SUPPORT_MODE "http://tizen.org/metadata/multi-assistant/voice_key_support_mode" +#define MA_METADATA_ASSISTANT_VOICE_KEY_TAP_DURATION "http://tizen.org/metadata/multi-assistant/voice_key_tap_duration" /* Define Macro */ @@ -427,6 +429,14 @@ static int __write_metadata_inxml(const char *pkgid, const char *appid, GList *l cur = xmlNewNode(NULL, (const xmlChar*)MA_TAG_ASSISTANT_CUSTOM_UI); xmlNodeSetContent(cur, (const xmlChar*)md->value); xmlAddChild(root, cur); + } else if (!strncmp(md->key, MA_METADATA_ASSISTANT_VOICE_KEY_SUPPORT_MODE, strlen(MA_METADATA_ASSISTANT_VOICE_KEY_SUPPORT_MODE))) { + cur = xmlNewNode(NULL, (const xmlChar*)MA_TAG_ASSISTANT_VOICE_KEY_SUPPORT_MODE); + xmlNodeSetContent(cur, (const xmlChar*)md->value); + xmlAddChild(root, cur); + } else if (!strncmp(md->key, MA_METADATA_ASSISTANT_VOICE_KEY_TAP_DURATION, strlen(MA_METADATA_ASSISTANT_VOICE_KEY_TAP_DURATION))) { + cur = xmlNewNode(NULL, (const xmlChar*)MA_TAG_ASSISTANT_VOICE_KEY_TAP_DURATION); + xmlNodeSetContent(cur, (const xmlChar*)md->value); + xmlAddChild(root, cur); } else { LOGW("[WARNING] Unknown metadata type"); } diff --git a/client/ma.c b/client/ma.c index 7df5770..27eb0b4 100644 --- a/client/ma.c +++ b/client/ma.c @@ -932,6 +932,26 @@ int __ma_cb_service_state_changed(int state) return 0; } + +int __ma_cb_voice_key_status_changed(int status) +{ + ma_voice_key_status_changed_cb callback = NULL; + void* user_data; + + ma_client_get_voice_key_status_changed_cb(g_ma, &callback, &user_data); + if (NULL != callback) { + ma_client_use_callback(g_ma); + callback(status, user_data); + ma_client_not_use_callback(g_ma); + MA_SLOGI("[INFO] voice key status changed callback is called %d", status); + } else { + MA_SLOGW("[WARNING] voice key status changed callback is NULL"); + } + + MA_SLOGI("[INFO] status : changed %d", status); + + return 0; +} //LCOV_EXCL_STOP int ma_get_state(ma_state_e* state) @@ -2229,4 +2249,61 @@ int ma_unset_service_state_changed_cb(void) return MA_ERROR_NONE; } +int ma_set_voice_key_status_changed_cb(ma_voice_key_status_changed_cb callback, void* user_data) +{ + if (0 != __ma_get_feature_enabled()) { + return MA_ERROR_NOT_SUPPORTED; + } + + MA_SLOGD("[Client DEBUG] Set Multi-assistant voice key status 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_voice_key_status_changed_cb(g_ma, callback, user_data); + + return MA_ERROR_NONE; +} + +int ma_unset_voice_key_status_changed_cb(void) +{ + if (0 != __ma_get_feature_enabled()) { + return MA_ERROR_NOT_SUPPORTED; + } + + MA_SLOGD("[Client DEBUG] Unset Multi-assistant voice key status 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_voice_key_status_changed_cb(g_ma, NULL, NULL); + + return MA_ERROR_NONE; +} + //LCOV_EXCL_STOP diff --git a/client/ma_client.c b/client/ma_client.c index 53dd2b8..159d581 100644 --- a/client/ma_client.c +++ b/client/ma_client.c @@ -44,6 +44,8 @@ typedef struct { void* preprocessing_result_received_user_data; ma_service_state_changed_cb service_state_changed_cb; void* service_state_changed_user_data; + ma_voice_key_status_changed_cb voice_key_status_changed_cb; + void* voice_key_status_changed_user_data; /* state */ ma_state_e previous_state; @@ -145,6 +147,8 @@ int ma_client_create(ma_h* ma) client->audio_streaming_data_section_changed_user_data = NULL; client->preprocessing_result_received_cb = NULL; client->preprocessing_result_received_user_data = NULL; + client->voice_key_status_changed_cb = NULL; + client->voice_key_status_changed_user_data = NULL; client->previous_state = MA_STATE_INITIALIZED; client->current_state = MA_STATE_INITIALIZED; @@ -785,4 +789,32 @@ int ma_client_get_service_state_changed_cb(ma_h ma, ma_service_state_changed_cb* } //LCOV_EXCL_STOP -#endif \ No newline at end of file +int ma_client_set_voice_key_status_changed_cb(ma_h ma, ma_voice_key_status_changed_cb callback, void* user_data) +{ + ma_client_s* client = __client_get(ma); + + if (NULL == client) + return MA_ERROR_INVALID_PARAMETER; + + client->voice_key_status_changed_cb = callback; + client->voice_key_status_changed_user_data = user_data; + + return MA_ERROR_NONE; +} + +//LCOV_EXCL_START +int ma_client_get_voice_key_status_changed_cb(ma_h ma, ma_voice_key_status_changed_cb* callback, void** user_data) +{ + ma_client_s* client = __client_get(ma); + + if (NULL == client) + return MA_ERROR_INVALID_PARAMETER; + + *callback = client->voice_key_status_changed_cb; + *user_data = client->voice_key_status_changed_user_data; + + return MA_ERROR_NONE; +} +//LCOV_EXCL_STOP + +#endif diff --git a/client/ma_client.h b/client/ma_client.h index fb85243..c9b52f6 100644 --- a/client/ma_client.h +++ b/client/ma_client.h @@ -134,6 +134,10 @@ int ma_client_set_service_state_changed_cb(ma_h ma, ma_service_state_changed_cb int ma_client_get_service_state_changed_cb(ma_h ma, ma_service_state_changed_cb* callback, void** user_data); +int ma_client_set_voice_key_status_changed_cb(ma_h ma, ma_voice_key_status_changed_cb callback, void* user_data); + +int ma_client_get_voice_key_status_changed_cb(ma_h ma, ma_voice_key_status_changed_cb* callback, void** user_data); + #endif #ifdef __cplusplus diff --git a/client/ma_dbus.c b/client/ma_dbus.c index 0111bb6..ceeadc0 100644 --- a/client/ma_dbus.c +++ b/client/ma_dbus.c @@ -39,6 +39,7 @@ 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); +extern int __ma_cb_voice_key_status_changed(int status); #define STREAMING_BUFFER_SIZE 4096 @@ -373,6 +374,24 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler* fd_handle MA_SLOGI("@@@"); } /* MAS_METHOD_SEND_WAKEUP_ENGINE_COMMAND */ + else if (dbus_message_is_method_call(msg, if_name, MAS_METHOD_VOICE_KEY_STATUS_CHANGE)) { + MA_SLOGI("@@@ Activate"); + int status = 0; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &status, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + MA_SLOGE("@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + } else { + __ma_cb_voice_key_status_changed(status); + } + + MA_SLOGI("@@@"); + } /* MAS_METHOD_VOICE_KEY_STATUS_CHANGE */ + else if (dbus_message_is_signal(msg, if_name, MAS_METHOD_ERROR)) { int reason; char* err_msg; diff --git a/common/ma_defs.h b/common/ma_defs.h index 55a7cfd..3456a50 100644 --- a/common/ma_defs.h +++ b/common/ma_defs.h @@ -98,6 +98,7 @@ extern "C" #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_METHOD_VOICE_KEY_STATUS_CHANGE "mas_method_voice_key_status_change" #define MAS_UI_METHOD_HELLO "mas_ui_method_hello" #define MAS_UI_METHOD_SEND_ASR_RESULT "mas_ui_method_send_asr_result" @@ -120,6 +121,9 @@ extern "C" #define MA_TAG_ASSISTANT_WAKEUP_WORD "wakeup-word" #define MA_TAG_ASSISTANT_WAKEUP_ENGINE_APPID "wakeup-engine-appid" #define MA_TAG_ASSISTANT_CUSTOM_UI "custom-ui" +#define MA_TAG_ASSISTANT_VOICE_KEY_SUPPORT_MODE "voice-key-support-mode" +#define MA_TAG_ASSISTANT_VOICE_KEY_TAP_DURATION "voice-key-tap-duration" + /************************************************************************************** *** Definitions for ETC diff --git a/include/multi_assistant_internal.h b/include/multi_assistant_internal.h index aa80310..9e16dc0 100644 --- a/include/multi_assistant_internal.h +++ b/include/multi_assistant_internal.h @@ -53,6 +53,19 @@ typedef enum { MA_SERVICE_STATE_VOICE_FEEDBACK = 4, /**< 'VoiceFeedback' state */ } ma_service_state_e; +/** + * @brief Enumerations for voice key's status. + * @details If the voice key gets released within the timeout value for tap events, + * the voice key's status value will be "released after tap". + * Otherwise, "released after push" will be chosen. + * @since_tizen 5.5 + */ +typedef enum { + MA_VOICE_KEY_STATUS_PRESSED = 0, /**< 'Pressed' state */ + MA_VOICE_KEY_STATUS_RELEASED_AFTER_PUSH = 1, /**< 'Released' state after push */ + MA_VOICE_KEY_STATUS_RELEASED_AFTER_TAP = 2, /**< 'Released' state after tap*/ +} ma_voice_key_status_e; + /** * @brief Called when the service state is changed. * @since_tizen 5.5 @@ -63,6 +76,18 @@ typedef enum { */ typedef void (*ma_service_state_changed_cb)(ma_service_state_e previous, ma_service_state_e current, void* user_data); +/** + * @brief Called when the multi-assistant service sends voice key status change event. + * @since_tizen 5.5 + * + * @param[in] status The current value for voice key's status + * @param[in] user_data The user data passed from the callback registration function + * + * @see ma_set_voice_key_status_changed_cb() + * @see ma_unset_voice_key_status_changed_cb() + */ +typedef void (*ma_voice_key_status_changed_cb)(ma_voice_key_status_e status, void* user_data); + /** * @brief Sets the service state changed callback. * @since_tizen 5.5 @@ -97,6 +122,40 @@ int ma_set_service_state_changed_cb(ma_service_state_changed_cb callback, void* */ int ma_unset_service_state_changed_cb(void); +/** + * @brief Sets a voice key status 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_voice_key_status_changed_cb() + * @see ma_unset_voice_key_status_changed_cb() + */ +int ma_set_voice_key_status_changed_cb(ma_voice_key_status_changed_cb callback, void* user_data); + +/** + * @brief Unsets a voice key status 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_set_voice_key_status_changed_cb() + * @see ma_voice_key_status_changed_cb() + */ +int ma_unset_voice_key_status_changed_cb(void); + #ifdef __cplusplus } #endif