Add APIs for receiving voice key status change event 04/223804/9
authorJi-hoon Lee <dalton.lee@samsung.com>
Fri, 10 Jan 2020 09:31:36 +0000 (18:31 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Fri, 27 Mar 2020 15:36:06 +0000 (15:36 +0000)
Change-Id: I2017fd0519679ea054cb7c7fb35ea7cfdaf02086

assistant-parser/src/ma_assistant_parser.c
client/ma.c
client/ma_client.c
client/ma_client.h
client/ma_dbus.c
common/ma_defs.h
include/multi_assistant.h
include/multi_assistant_common.h

index 0921734ccfe3f5fab687292d3f10beec2f8bf525..38818c2eeea0b61d1173c3bab0be24bea5ca1cc4 100644 (file)
@@ -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");
                        }
index b56f72938904a91512be9f358419590b167b7e13..194850b18492e08eada7911d13ab07824cab9d0d 100644 (file)
@@ -915,6 +915,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_SLOGD("[DEBUG] voice key status changed callback is called %d", status);
+       } else {
+               MA_SLOGD("[WARNING] voice key status changed callback is NULL");
+       }
+
+       MA_SLOGD("[INFO] status : changed %d", status);
+
+       return 0;
+}
 //LCOV_EXCL_STOP
 
 int ma_get_state(ma_state_e* state)
@@ -2217,4 +2237,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
index 53dd2b89ca6722a1dcb45d3a4773612f2928aead..159d581e4ed096275745626a92fbe26e50310f6a 100644 (file)
@@ -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
index fb852430be6e7fc76998b8cf825e769b65d6e89f..c9b52f633cf8f78faada9cf34d0c27a140775664 100644 (file)
@@ -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
index 221232d952c55b7b057f8f18a629012828eda0c5..0399c52042558f310624d872067a8d06066fdd59 100644 (file)
@@ -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;
index e76b7fede74b2f3e610f9f7ead548081c4cae6d2..c646763c88a32a9244959b3945950112f3350dd4 100644 (file)
@@ -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
index 87eb02571c352440dec54b7e42ceaace65f46b87..5bf251f6b4574b939552c078b2a187de993f53fe 100644 (file)
@@ -749,6 +749,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 6.0
+ *
+ * @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 6.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.
+ * @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
index c81debf2a93624d78f968227860974081b343e4b..046975d164ea34133265ae117aa2b3b7f710c64e 100644 (file)
@@ -173,6 +173,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 6.0
+  */
+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 client state is changed.
  * @since_tizen 5.0
@@ -305,6 +318,18 @@ typedef void (*ma_audio_streaming_data_section_changed_cb)(ma_audio_streaming_da
  */
 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 6.0
+ *
+ * @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);
+
 #ifdef __cplusplus
 }
 #endif