Add internal APIs for handling service state notification 22/219622/3
authorJi-hoon Lee <dalton.lee@samsung.com>
Fri, 6 Dec 2019 09:59:12 +0000 (18:59 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Tue, 10 Dec 2019 06:20:41 +0000 (15:20 +0900)
Change-Id: Ifbc77e08697375c82db0ea8f9a75efa088b11ff9

client/ma.c
client/ma_client.c
client/ma_client.h
client/ma_dbus.c
common/ma_defs.h
include/multi_assistant_internal.h

index c62d2fd8856f8347b9845fdfb76524ef018c8dc0..013873050e9a377486f613242c656f0c1c760dbc 100644 (file)
@@ -819,6 +819,35 @@ int __ma_cb_preprocessing_result_received(bool result)
 
        return 0;
 }
+
+int __ma_cb_service_state_changed(int state)
+{
+       ma_service_state_changed_cb callback = NULL;
+       void* user_data;
+
+       ma_client_set_service_state(g_ma, (ma_service_state_e)state);
+
+       ma_service_state_e current_state;
+       ma_service_state_e previous_state;
+       ma_client_get_service_state(g_ma, &current_state, &previous_state);
+
+       ma_client_get_service_state_changed_cb(g_ma, &callback, &user_data);
+       if (NULL != callback) {
+               ma_client_use_callback(g_ma);
+               callback(previous_state, current_state, user_data);
+               ma_client_not_use_callback(g_ma);
+               MA_SLOGD("[DEBUG] service state changed callback is called %d", current_state);
+       } else {
+               MA_SLOGD("[WARNING] service state changed callback is NULL");
+       }
+
+       MA_SLOGD(
+               "[INFO] previous : %d , current : %d service state changed",
+               previous_state, current_state
+       );
+
+       return 0;
+}
 //LCOV_EXCL_STOP
 
 int ma_get_state(ma_state_e* state)
@@ -2059,4 +2088,61 @@ int ma_set_assistant_language(const char* language)
        return ret;
 }
 
+int ma_set_service_state_changed_cb(ma_service_state_changed_cb callback, void* user_data)
+{
+       if (0 != __ma_get_feature_enabled()) {
+               return MA_ERROR_NOT_SUPPORTED;
+       }
+
+       MA_SLOGD("[Client DEBUG] Set Multi-assistant service state 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_service_state_changed_cb(g_ma, callback, user_data);
+
+       return MA_ERROR_NONE;
+}
+
+int ma_unset_service_state_changed_cb(void)
+{
+       if (0 != __ma_get_feature_enabled()) {
+               return MA_ERROR_NOT_SUPPORTED;
+       }
+
+       MA_SLOGD("[Client DEBUG] Unset Multi-assistant service state 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_service_state_changed_cb(g_ma, NULL, NULL);
+
+       return MA_ERROR_NONE;
+}
+
 //LCOV_EXCL_STOP
\ No newline at end of file
index cab8913543ead8d5a874da0c493d70766685cb22..53dd2b89ca6722a1dcb45d3a4773612f2928aead 100644 (file)
@@ -42,6 +42,8 @@ typedef struct {
        void*                           audio_streaming_data_section_changed_user_data;
        ma_preprocessing_result_received_cb     preprocessing_result_received_cb;
        void*                           preprocessing_result_received_user_data;
+       ma_service_state_changed_cb             service_state_changed_cb;
+       void*                           service_state_changed_user_data;
 
        /* state */
        ma_state_e      previous_state;
@@ -51,6 +53,9 @@ typedef struct {
        ma_active_state_e       previous_active_state;
        ma_active_state_e       current_active_state;
 
+       ma_service_state_e      previous_service_state;
+       ma_service_state_e      current_service_state;
+
 #ifdef MA_PREPROCESSING_SEQUENTIAL_MODE
        ma_preprocessing_allow_mode_e preprocessing_allow_mode;
        ma_audio_streaming_data_type_e audio_streaming_data_type;
@@ -147,6 +152,9 @@ int ma_client_create(ma_h* ma)
        client->previous_active_state = MA_ACTIVE_STATE_INACTIVE;
        client->current_active_state = MA_ACTIVE_STATE_INACTIVE;
 
+       client->previous_service_state = MA_SERVICE_STATE_INACTIVE;
+       client->current_service_state = MA_SERVICE_STATE_INACTIVE;
+
 #ifdef MA_PREPROCESSING_SEQUENTIAL_MODE
        client->preprocessing_allow_mode = MA_PREPROCESSING_ALLOW_NONE;
        client->audio_streaming_data_type = MA_AUDIO_STREAMING_DATA_TYPE_CURRENT_UTTERANCE;
@@ -718,4 +726,63 @@ int ma_client_pop_preprocessing_audio_data(ma_h ma, speech_data** data)
 
        return MA_ERROR_NONE;
 }
+
+//LCOV_EXCL_START
+int ma_client_set_service_state(ma_h ma, ma_service_state_e state)
+{
+       ma_client_s* client = __client_get(ma);
+
+       if (NULL == client)
+               return MA_ERROR_INVALID_PARAMETER;
+
+       client->previous_service_state = client->current_service_state;
+       client->current_service_state = state;
+
+       return MA_ERROR_NONE;
+}
+//LCOV_EXCL_STOP
+
+//LCOV_EXCL_START
+int ma_client_get_service_state(ma_h ma, ma_service_state_e* current_state, ma_service_state_e* previous_state)
+{
+       ma_client_s* client = __client_get(ma);
+
+       if (NULL == client)
+               return MA_ERROR_INVALID_PARAMETER;
+
+       *current_state = client->current_service_state;
+       *previous_state = client->previous_service_state;
+
+       return MA_ERROR_NONE;
+}
+//LCOV_EXCL_STOP
+
+int ma_client_set_service_state_changed_cb(ma_h ma, ma_service_state_changed_cb callback, void* user_data)
+{
+       ma_client_s* client = __client_get(ma);
+
+       if (NULL == client)
+               return MA_ERROR_INVALID_PARAMETER;
+
+       client->service_state_changed_cb = callback;
+       client->service_state_changed_user_data = user_data;
+
+       return MA_ERROR_NONE;
+}
+
+//LCOV_EXCL_START
+int ma_client_get_service_state_changed_cb(ma_h ma, ma_service_state_changed_cb* callback, void** user_data)
+{
+       ma_client_s* client = __client_get(ma);
+
+       if (NULL == client)
+               return MA_ERROR_INVALID_PARAMETER;
+
+       *callback = client->service_state_changed_cb;
+       *user_data = client->service_state_changed_user_data;
+
+       return MA_ERROR_NONE;
+}
+//LCOV_EXCL_STOP
+
 #endif
\ No newline at end of file
index b63fc719910f79e81b9ae92879494f0e9309fbe5..fb852430be6e7fc76998b8cf825e769b65d6e89f 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "ma_main.h"
 #include "multi_assistant_common.h"
+#include "multi_assistant_internal.h"
 
 
 #ifdef __cplusplus
@@ -124,6 +125,15 @@ typedef struct {
 int ma_client_push_preprocessing_audio_data(ma_h ma, speech_data* data);
 
 int ma_client_pop_preprocessing_audio_data(ma_h ma, speech_data** data);
+
+int ma_client_set_service_state(ma_h ma, ma_service_state_e state);
+
+int ma_client_get_service_state(ma_h ma, ma_service_state_e* current_state, ma_service_state_e* previous_state);
+
+int ma_client_set_service_state_changed_cb(ma_h ma, ma_service_state_changed_cb callback, void* user_data);
+
+int ma_client_get_service_state_changed_cb(ma_h ma, ma_service_state_changed_cb* callback, void** user_data);
+
 #endif
 
 #ifdef __cplusplus
index 1c0ccd699ccf263e7d299afce81a62eba0eecf92..271d4fbd4d18d5dc08bd238074583b526adc32df 100644 (file)
@@ -31,6 +31,7 @@ static DBusConnection* g_conn_listener = NULL;
 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_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);
 extern int __ma_cb_audio_streaming_data_section_changed(ma_audio_streaming_data_section_e section);
@@ -143,6 +144,24 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler* fd_handle
                        MA_SLOGI("@@@");
                } /* MAS_METHOD_ACTIVE_STATE_CHANGE */
 
+               else if (dbus_message_is_method_call(msg, if_name, MAS_METHOD_SERVICE_STATE_CHANGE)) {
+                       int state;
+                       dbus_message_get_args(msg, &err,
+                                       DBUS_TYPE_INT32, &state,
+                                       DBUS_TYPE_INVALID);
+
+                       MA_SLOGI("@@@ Service state : %d", state);
+                       if (dbus_error_is_set(&err)) {
+                               MA_SLOGE("@@ Get arguments error (%s)", err.message);
+                               dbus_error_free(&err);
+                       } else {
+                               MA_SLOGD("@@ state(%d)", state);
+                               __ma_cb_service_state_changed(state);
+                       }
+
+                       MA_SLOGI("@@@");
+               } /* MAS_METHOD_ACTIVE_STATE_CHANGE */
+
                else if (dbus_message_is_method_call(msg, if_name, MAS_METHOD_WAKEUP_ENGINE_COMMAND)) {
                        char* command = NULL;
 
index 127adcf636b497f4f98b669b28595b8896826f20..55a7cfd3c56291b6710854540e3cbf4da3566e81 100644 (file)
@@ -97,6 +97,7 @@ extern "C"
 #define MAS_METHOD_AUDIO_STREAMING_DATA_SECTION                "mas_method_audio_streaming_data_section"
 #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_UI_METHOD_HELLO                                                    "mas_ui_method_hello"
 #define MAS_UI_METHOD_SEND_ASR_RESULT                          "mas_ui_method_send_asr_result"
index aaea94529c2ec8950f75bc93dc206d4a505e7758..aa80310b324b8c6b94b072374d2a37daaf097b36 100644 (file)
@@ -41,6 +41,62 @@ extern "C"
  */
 int ma_set_assistant_language(const char* language);
 
+/**
+ * @brief Enumerations for multi-assistant service state.
+ * @since_tizen 5.5
+ */
+typedef enum {
+       MA_SERVICE_STATE_INACTIVE = 0,                  /**< 'Inactive' state */
+       MA_SERVICE_STATE_LISTENING = 1,                 /**< 'Listening' state */
+       MA_SERVICE_STATE_UTTERANCE = 2,                 /**< 'Utterance' state */
+       MA_SERVICE_STATE_PROCESSING = 3,                /**< 'Processing' state */
+       MA_SERVICE_STATE_VOICE_FEEDBACK = 4,    /**< 'VoiceFeedback' state */
+} ma_service_state_e;
+
+/**
+ * @brief Called when the service state is changed.
+ * @since_tizen 5.5
+ *
+ * @param[in] previous The previous service state
+ * @param[in] current The current service state
+ * @param[in] user_data The user data passed from the callback registration function
+ */
+typedef void (*ma_service_state_changed_cb)(ma_service_state_e previous, ma_service_state_e current, void* user_data);
+
+/**
+ * @brief Sets the service state 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_service_state_changed_cb()
+ * @see ma_unset_service_state_changed_cb()
+ */
+int ma_set_service_state_changed_cb(ma_service_state_changed_cb callback, void* user_data);
+
+/**
+ * @brief Unsets the service state 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_service_state_changed_cb()
+ * @see ma_set_service_state_changed_cb()
+ */
+int ma_unset_service_state_changed_cb(void);
+
 #ifdef __cplusplus
 }
 #endif