Add PREPROCESSING_INFORMATION changed handler 24/214024/3
authorJi-hoon Lee <dalton.lee@samsung.com>
Mon, 16 Sep 2019 06:45:05 +0000 (15:45 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Wed, 18 Sep 2019 05:15:14 +0000 (05:15 +0000)
Change-Id: I09b059e4ddebf772b2ed18afa520198806d8f178

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 c78c1d9781cc7fe2d20f5cd3d7868533e2de9ad6..627cea948f6fa06184c47f1c59c1a01eb0468e01 100644 (file)
@@ -620,6 +620,25 @@ int __ma_cb_wakeup_engine_command(const char* command)
        return 0;
 }
 
+int __ma_cb_preprocessing_information_changed(const char* app_id)
+{
+       ma_preprocessing_information_changed_cb callback = NULL;
+       void* user_data;
+
+       ma_client_get_preprocessing_information_changed_cb(g_ma, &callback, &user_data);
+
+       if (NULL != callback) {
+               ma_client_use_callback(g_ma);
+               callback(app_id, user_data);
+               ma_client_not_use_callback(g_ma);
+               SLOG(LOG_DEBUG, TAG_MAC, "[DEBUG] Preprocessing information changed callback is called, (%s)", app_id);
+       } else {
+               SLOG(LOG_DEBUG, TAG_MAC, "[WARNING] Preprocessing information changed callback is NULL");
+       }
+
+       return 0;
+}
+
 int ma_get_state(ma_state_e* state)
 {
        if (0 != __ma_get_feature_enabled()) {
@@ -1558,3 +1577,60 @@ int ma_set_preprocessing_allow_mode(ma_preprocessing_allow_mode_e mode, const ch
        }
        return ret;
 }
+
+int ma_set_preprocessing_information_changed_cb(ma_preprocessing_information_changed_cb callback, void* user_data)
+{
+       if (0 != __ma_get_feature_enabled()) {
+               return MA_ERROR_NOT_SUPPORTED;
+       }
+
+       SLOG(LOG_DEBUG, TAG_MAC, "[Client DEBUG] Set Multi-assistant preprocessing information changed cb");
+
+       if (NULL == callback) {
+               SLOG(LOG_ERROR, TAG_MAC, "[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)) {
+               SLOG(LOG_ERROR, TAG_MAC, "[ERROR] A handle is not available"); //LCOV_EXCL_LINE
+               return MA_ERROR_INVALID_STATE;
+       }
+
+       /* check state */
+       if (state != MA_STATE_INITIALIZED) {
+               SLOG(LOG_ERROR, TAG_MAC, "[ERROR] Invalid State: Current state is not 'Initialized' (%d)", state); //LCOV_EXCL_LINE
+               return MA_ERROR_INVALID_STATE;
+       }
+
+       ma_client_set_preprocessing_information_changed_cb(g_ma, callback, user_data);
+
+       return MA_ERROR_NONE;
+}
+
+int ma_unset_preprocessing_information_changed_cb(void)
+{
+       if (0 != __ma_get_feature_enabled()) {
+               return MA_ERROR_NOT_SUPPORTED;
+       }
+
+       SLOG(LOG_DEBUG, TAG_MAC, "[Client DEBUG] Unset Multi-assistant preprocessing information changed cb");
+
+       ma_state_e state;
+
+       if (0 != ma_client_get_client_state(g_ma, &state)) {
+               SLOG(LOG_ERROR, TAG_MAC, "[ERROR] A handle is not available"); //LCOV_EXCL_LINE
+               return MA_ERROR_INVALID_STATE;
+       }
+
+       /* check state */
+       if (state != MA_STATE_INITIALIZED) {
+               SLOG(LOG_ERROR, TAG_MAC, "[ERROR] Invalid State: Current state is not 'Initialized'"); //LCOV_EXCL_LINE
+               return MA_ERROR_INVALID_STATE;
+       }
+
+       ma_client_set_preprocessing_information_changed_cb(g_ma, NULL, NULL);
+
+       return MA_ERROR_NONE;
+}
\ No newline at end of file
index 167889b9fdf67ea08ee5140c7edee26b71a43d8a..34fc4667d70c695e40e07f3e8acdc0c7e47d469a 100644 (file)
@@ -36,6 +36,8 @@ typedef struct {
        void*                           active_state_changed_user_data;
        ma_wakeup_engine_command_cb             wakeup_engine_command_cb;
        void*                           wakeup_engine_command_user_data;
+       ma_preprocessing_information_changed_cb preprocessing_information_changed_cb;
+       void*                           preprocessing_information_changed_user_data;
 
        /* state */
        ma_state_e      previous_state;
@@ -481,4 +483,30 @@ int ma_client_get_wakeup_engine_command_cb(ma_h ma, ma_wakeup_engine_command_cb*
        *user_data = client->wakeup_engine_command_user_data;
 
        return MA_ERROR_NONE;
-}
\ No newline at end of file
+}
+
+int ma_client_set_preprocessing_information_changed_cb(ma_h ma, ma_preprocessing_information_changed_cb callback, void* user_data)
+{
+       ma_client_s* client = __client_get(ma);
+
+       if (NULL == client)
+               return MA_ERROR_INVALID_PARAMETER;
+
+       client->preprocessing_information_changed_cb = callback;
+       client->preprocessing_information_changed_user_data = user_data;
+
+       return MA_ERROR_NONE;
+}
+
+int ma_client_get_preprocessing_information_changed_cb(ma_h ma, ma_preprocessing_information_changed_cb* callback, void** user_data)
+{
+       ma_client_s* client = __client_get(ma);
+
+       if (NULL == client)
+               return MA_ERROR_INVALID_PARAMETER;
+
+       *callback = client->preprocessing_information_changed_cb;
+       *user_data = client->preprocessing_information_changed_user_data;
+
+       return MA_ERROR_NONE;
+}
index 4cfa1fb02dbccfa7ceda939dd34c016367e1ab10..280a0c3da27e7e83d5e35f5d7babeed9b9b64bdb 100644 (file)
@@ -84,6 +84,10 @@ int ma_client_set_wakeup_engine_command_cb(ma_h ma, ma_wakeup_engine_command_cb
 
 int ma_client_get_wakeup_engine_command_cb(ma_h ma, ma_wakeup_engine_command_cb* callback, void** user_data);
 
+int ma_client_set_preprocessing_information_changed_cb(ma_h ma, ma_preprocessing_information_changed_cb callback, void* user_data);
+
+int ma_client_get_preprocessing_information_changed_cb(ma_h ma, ma_preprocessing_information_changed_cb* callback, void** user_data);
+
 #ifdef __cplusplus
 }
 #endif
index b7bf0948a6ae5bf4f3e4dc79d7b0dccbeaa9513e..278be1d31b8c081495659a5df84e184d4b54039a 100644 (file)
@@ -32,6 +32,7 @@ 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_wakeup_engine_command(const char *command);
+extern int __ma_cb_preprocessing_information_changed(const char* app_id);
 
 static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler* fd_handler)
 {
@@ -160,6 +161,30 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler* fd_handle
                        SLOG(LOG_INFO, TAG_MAC, "@@@");
                } /* MAS_METHOD_WAKEUP_ENGINE_COMMAND */
 
+               else if (dbus_message_is_method_call(msg, if_name, MAS_METHOD_SEND_PREPROCESSING_INFORMATION)) {
+                       SLOG(LOG_INFO, TAG_MAC, "@@@ Activate");
+                       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_MAC, "@@ Get arguments error (%s)", err.message);
+                               dbus_error_free(&err);
+                       } else {
+                               char* temp_app_id = NULL;
+                               if (NULL != app_id && strcmp("#NULL", app_id)) {
+                                       temp_app_id = strdup(app_id);
+                               }
+                               __ma_cb_preprocessing_information_changed(temp_app_id);
+                               if (NULL != temp_app_id)
+                                       free(temp_app_id);
+                       }
+
+                       SLOG(LOG_INFO, TAG_MAC, "@@@");
+               } /* MAS_METHOD_SEND_PREPROCESSING_INFORMATION */
+
                else if (dbus_message_is_signal(msg, if_name, MAS_METHOD_ERROR)) {
                        SLOG(LOG_DEBUG, TAG_MAC, "[DEBUG] Get Error");
                        int reason;
index 6e24b848e301212d1beb3edb423952ee124f6664..c4cb5b4085455c22622dc5070894020ad4d43e64 100644 (file)
@@ -89,6 +89,7 @@ extern "C"
 #define MAS_METHOD_STREAMING_AUDIO_DATA                                "mas_method_streaming_audio_data"
 #define MAS_METHOD_WAKEUP_ENGINE_COMMAND                       "mas_method_wakeup_engine_command"
 #define MAS_METHOD_ERROR                                                       "mas_method_error"
+#define MAS_METHOD_SEND_PREPROCESSING_INFORMATION      "mas_method_send_preprocessing_information"
 
 #define MAS_UI_METHOD_HELLO                                                    "mas_ui_method_hello"
 #define MAS_UI_METHOD_SEND_ASR_RESULT                          "mas_ui_method_send_asr_result"
index fdc3748541a95771c95c2024c13337899324e39c..09b2ffcf2e67d9e9854ed77acb7a64e9817dbea0 100644 (file)
@@ -604,6 +604,40 @@ int ma_set_background_volume(double ratio);
  */
 int ma_set_preprocessing_allow_mode(ma_preprocessing_allow_mode_e mode, const char* app_id);
 
+/**
+ * @brief Sets the preprocessing information 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_STATE Invalid state
+ * @retval #MA_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @pre The state should be #MA_STATE_INITIALIZED.
+ * @see ma_preprocessing_information_changed_cb()
+ * @see ma_unset_preprocessing_information_changed_cb()
+ */
+int ma_set_preprocessing_information_changed_cb(ma_preprocessing_information_changed_cb callback, void* user_data);
+
+/**
+ * @brief Unsets the preprocessing information 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_preprocessing_information_changed_cb()
+ * @see ma_set_preprocessing_information_changed_cb()
+ */
+int ma_unset_preprocessing_information_changed_cb(void);
+
 #ifdef __cplusplus
 }
 #endif
index 7c496a8b358d30a7c9384c1a62ee85bfa0bfdc21..a80e3196c7de3885ad62e15a53a2a65d1bcd1f42 100644 (file)
@@ -250,6 +250,17 @@ typedef void *ma_assistant_info_h;
  * @param[in] user_data The user data passed from the callback registration function
  */
 typedef int (*ma_assistant_info_list_cb)(ma_assistant_info_h handle, void* user_data);
+
+/**
+ * @brief Called when the preprocessing information is changed.
+ * @since_tizen 5.5
+ *
+ * @remarks The @a app_id should not be released and can be used only in the callback. To use outside, make a copy.
+ * @remarks If the @a app_id is NULL, it means there is no preprocessing voice assistant available.
+ * @param[in] app_id The application id of current preprocessing voice assistant
+ */
+typedef void (*ma_preprocessing_information_changed_cb)(const char* app_id, void* user_data);
+
 #ifdef __cplusplus
 }
 #endif