static int g_volume_set_privilege_allowed = -1;
static cynara *p_cynara = NULL;
+#define MAX_WAKE_WORD_LENGTH 20
+#define MAX_EXTRA_DATA_SIZE 1024
+#define MAX_EXTRA_DATA_DESC_LENGTH 1024
+
+typedef struct {
+ char wake_word[MAX_WAKE_WORD_LENGTH];
+ unsigned char extra_data[MAX_EXTRA_DATA_SIZE];
+ int extra_data_length;
+ char extra_data_desc[MAX_EXTRA_DATA_DESC_LENGTH];
+} wakeup_info_t;
+
+static wakeup_info_t g_wakeup_info;
+
static void __ma_notify_state_changed(void* data);
static void __ma_notify_error(void* data);
}
//LCOV_EXCL_START
-int __ma_cb_active_state_changed(int state)
+int __ma_cb_active_state_changed(int state, const char* wakeup_word,
+ const unsigned char* extra_data, int extra_data_length, const char* extra_data_desc)
{
- ma_active_state_changed_cb callback = NULL;
- void* user_data;
+ if (wakeup_word) strncpy(g_wakeup_info.wake_word, wakeup_word, MAX_WAKE_WORD_LENGTH);
+ else g_wakeup_info.wake_word[0] = '\0';
+ g_wakeup_info.wake_word[MAX_WAKE_WORD_LENGTH - 1] = '\0';
+
+ if (extra_data && extra_data_length > 0 && extra_data_length <= MAX_EXTRA_DATA_SIZE) {
+ memcpy(g_wakeup_info.extra_data, extra_data, extra_data_length);
+ g_wakeup_info.extra_data_length = extra_data_length;
+ } else {
+ memset(g_wakeup_info.extra_data, 0x00, MAX_EXTRA_DATA_SIZE);
+ g_wakeup_info.extra_data_length = 0;
+ }
+
+ if (extra_data_desc) strncpy(g_wakeup_info.extra_data_desc, extra_data_desc, MAX_EXTRA_DATA_DESC_LENGTH);
+ else g_wakeup_info.extra_data_desc[0] = '\0';
+ g_wakeup_info.extra_data_desc[MAX_EXTRA_DATA_DESC_LENGTH - 1] = '\0';
- ma_client_get_active_state_changed_cb(g_ma, &callback, &user_data);
+ MA_SLOGD("%s %p %d %s", g_wakeup_info.wake_word,
+ g_wakeup_info.extra_data, g_wakeup_info.extra_data_length, g_wakeup_info.extra_data_desc);
+
+ ma_active_state_changed_cb active_state_callback = NULL;
+ void* active_state_user_data;
+
+ ma_client_get_active_state_changed_cb(g_ma, &active_state_callback, &active_state_user_data);
ma_active_state_e current_state;
ma_active_state_e previous_state;
current_state = (ma_active_state_e)state;
ma_client_set_client_active_state(g_ma, current_state);
- if (NULL != callback) {
+ if (NULL != active_state_callback) {
ma_client_use_callback(g_ma);
- callback(previous_state, current_state, user_data);
+ active_state_callback(previous_state, current_state, active_state_user_data);
ma_client_not_use_callback(g_ma);
MA_SLOGD("[DEBUG] Active state changed callback is called %d", current_state); //LCOV_EXCL_LINE
} else {
ma_client_get_previous_active_state(g_ma, ¤t_state, &previous_state);
MA_SLOGD(
- "[INFO] previous : %d , current : %d active state changed",
- previous_state, current_state
+ "[INFO] previous : %d , current : %d , wakeup_word : %s active state changed",
+ previous_state, current_state, wakeup_word
);
if (MA_ACTIVE_STATE_ACTIVE == state) {
ma_start_receiving_audio_streaming_data(MA_AUDIO_STREAMING_DATA_TYPE_CURRENT_UTTERANCE);
}
return ret;
}
+
+int ma_get_wakeup_info_wake_word(char** wake_word)
+{
+ if (wake_word) {
+ *wake_word = g_wakeup_info.wake_word;
+ }
+ return 0;
+}
+
+int ma_get_wakeup_info_extra_data(unsigned char** extra_data, int* extra_data_length, char **extra_data_desc)
+{
+ if (extra_data) {
+ *extra_data = g_wakeup_info.extra_data;
+ }
+
+ if (extra_data_length) {
+ *extra_data_length = g_wakeup_info.extra_data_length;
+ }
+
+ if (extra_data_desc) {
+ *extra_data_desc = g_wakeup_info.extra_data_desc;
+ }
+
+ return 0;
+}
+
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_active_state_changed(int state, const char* wakeup_word,
+ const unsigned char* extra_data, int extra_data_length, const char* extra_data_desc);
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);
else if (dbus_message_is_method_call(msg, if_name, MAS_METHOD_ACTIVE_STATE_CHANGE)) {
int state;
+ char* wakeup_word = NULL;
+ unsigned char* extra_data = NULL;
+ int extra_data_length = 0;
+ char* extra_data_desc = NULL;
+
dbus_message_get_args(msg, &err,
DBUS_TYPE_INT32, &state,
+ DBUS_TYPE_STRING, &wakeup_word,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
+ &extra_data, &extra_data_length,
+ DBUS_TYPE_STRING, &extra_data_desc,
DBUS_TYPE_INVALID);
MA_SLOGI("@@@ Active state : %d", state); //LCOV_EXCL_LINE
dbus_error_free(&err);
//LCOV_EXCL_STOP
} else {
- MA_SLOGD("@@ state(%d)", state); //LCOV_EXCL_LINE
- __ma_cb_active_state_changed(state);
+ char* temp_wakeup_word = NULL;
+ if (NULL != wakeup_word && strcmp("#NULL", wakeup_word)) {
+ temp_wakeup_word = strdup(wakeup_word);
+ }
+ char* temp_extra_data_desc = NULL;
+ if (NULL != extra_data_desc && strcmp("#NULL", extra_data_desc)) {
+ temp_extra_data_desc = strdup(extra_data_desc);
+ }
+ MA_SLOGD("@@ state(%d), wakeup_word(%s)", state, temp_wakeup_word); //LCOV_EXCL_LINE
+ __ma_cb_active_state_changed(state, temp_wakeup_word, extra_data, extra_data_length, temp_extra_data_desc);
+ if (NULL != temp_wakeup_word)
+ free(temp_wakeup_word);
+ if (NULL != temp_extra_data_desc)
+ free(temp_extra_data_desc);
}
MA_SLOGI("@@@"); //LCOV_EXCL_LINE
*/
int ma_remove_wake_word(const char* wake_word, const char *language);
+/**
+ * @brief Retrieves wake word information of the last wakeup event.
+ * @since_tizen 7.0
+ *
+ * @remarks You must not release @a wake_word using free().
+ * @a wake_word can be changed whenever @a ma_active_state_changed_cb is called.
+ * @param[out] wake_word The wake word information, if exists.
+ *
+ * @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
+ * @retval #MA_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @pre The state should be #MA_STATE_READY.
+ * @see ma_active_state_changed_cb()
+ */
+int ma_get_wakeup_info_wake_word(char** wake_word);
+
+/**
+ * @brief Retrieves extra data information of the last wakeup event.
+ * @details When required, wakeup engine adds extra data information
+ * that can be processed by the voice assistant.
+ * The information MUST be defined by both wakeup engine and voice assistant.
+ * @since_tizen 7.0
+ *
+ * @remarks You must not release @a extra_data and @a extra_data_desc using free().
+ * @a extra_data can be changed whenever @a ma_active_state_changed_cb is called.
+ * @param[out] extra_data The extra data information, if exists.
+ * @param[out] extra_data_length The length of extra data.
+ * @param[out] extra_data_desc The string value describing the type of extra data.
+ *
+ * @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
+ * @retval #MA_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @pre The state should be #MA_STATE_READY.
+ * @see ma_active_state_changed_cb()
+ */
+int ma_get_wakeup_info_extra_data(unsigned char** extra_data, int* extra_data_length, char **extra_data_desc);
+
#ifdef __cplusplus
}
#endif