Add change_assistant notification from service to panel 41/191841/2
authorJi-hoon Lee <dalton.lee@samsung.com>
Wed, 24 Oct 2018 10:07:41 +0000 (19:07 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Wed, 24 Oct 2018 10:08:55 +0000 (19:08 +0900)
Change-Id: I67ff310dde7783ed7966b7cc828f7ce2aa2dbc31

client/ma.c
client/ma_dbus.c
client/ma_dbus.h
client/ma_ui.c
client/ma_ui_client.c
client/ma_ui_client.h
client/ma_ui_dbus.c
common/ma_defs.h
include/multi_assistant.h
include/multi_assistant_ui.h

index b0b432abf67de01b156e60bb00497ecf86347971..5af0ad772474afcd8d7235b7b3597ecf6a443008 100644 (file)
@@ -963,5 +963,3 @@ int ma_send_result(const char* display_text, const char* utterance_text, const c
 
        return ret;
 }
-
-
index 9c13d1f72b49b6a1f8400192b278cb025d562a39..54a21283db54f48d60515dde45bf86592c535ed4 100644 (file)
@@ -550,71 +550,6 @@ int ma_dbus_request_deinitialize(int pid)
        return result;
 }
 
-int ma_dbus_request_speech_data(int pid)
-{
-       if (0 != __dbus_check()) {
-               return MA_ERROR_OPERATION_FAILED;
-       }
-
-       DBusMessage* msg;
-
-       msg = dbus_message_new_method_call(
-                         MA_SERVER_SERVICE_NAME,
-                         MA_SERVER_SERVICE_OBJECT_PATH,
-                         MA_SERVER_SERVICE_INTERFACE,
-                         MA_METHOD_REQUEST_SPEECH_DATA);
-
-       if (NULL == msg) {
-               SLOG(LOG_ERROR, TAG_MAC, "@@ Request multi-assistant recording audio format : Fail to make message"); //LCOV_EXCL_LINE
-               return MA_ERROR_OPERATION_FAILED;
-       } else {
-               SLOG(LOG_DEBUG, TAG_MAC, "[DEBUG] multi-assistant recording audio format");
-       }
-
-       dbus_message_append_args(msg,
-               DBUS_TYPE_INT32, &pid,
-               DBUS_TYPE_INVALID);
-
-       DBusError err;
-       dbus_error_init(&err);
-
-       DBusMessage* result_msg = NULL;
-       int result = MA_ERROR_OPERATION_FAILED;
-
-       result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
-       dbus_message_unref(msg);
-
-       if (dbus_error_is_set(&err)) {
-               SLOG(LOG_DEBUG, TAG_MAC, "[ERROR] Dbus Error (%s)", err.message); //LCOV_EXCL_LINE
-               dbus_error_free(&err);
-       }
-
-       if (NULL != result_msg) {
-               dbus_message_get_args(result_msg, &err,
-                               DBUS_TYPE_INT32, &result,
-                               DBUS_TYPE_INVALID);
-
-               if (dbus_error_is_set(&err)) {
-                       SLOG(LOG_ERROR, TAG_MAC, "@@ Get arguments error (%s)", err.message);
-                       dbus_error_free(&err);
-                       result = MA_ERROR_OPERATION_FAILED;
-               }
-               dbus_message_unref(result_msg);
-
-               if (0 == result) {
-                       SLOG(LOG_DEBUG, TAG_MAC, "@@ multi-assistant request speech data : result = %d", result);
-               } else {
-                       SLOG(LOG_ERROR, TAG_MAC, "@@ multi-assistant request speech data : result = %d", result);
-               }
-       } else {
-               SLOG(LOG_ERROR, TAG_MAC, "@@ Result message is NULL");
-               ma_dbus_reconnect();
-               result = MA_ERROR_TIMED_OUT;
-       }
-
-       return result;
-}
-
 
 int ma_dbus_get_recording_audio_format(int pid, int *rate, ma_audio_channel_e *channel, ma_audio_type_e *audio_type)
 {
index 86b7e85112f2389233109838982a0a894abe2303..eb6ea048f587d4f03d92f8566e2febaac17261ae 100644 (file)
@@ -38,7 +38,6 @@ int ma_dbus_request_initialize(int pid);
 
 int ma_dbus_request_deinitialize(int pid);
 
-
 int ma_dbus_get_recording_audio_format(int pid, int *rate, ma_audio_channel_e *channel, ma_audio_type_e *audio_type);
 
 int ma_dbus_send_asr_result(int pid, ma_asr_result_event_e event, const char* asr_result);
index e5d9354bb4fd9e26b126e221b1758b8736317de4..a3b9806b1cfc760401b205abd6ff6a0e1c636cbf 100644 (file)
@@ -542,6 +542,37 @@ int __ma_ui_cb_send_result(const char* display_text, const char* utterance_text,
        return MA_ERROR_NONE;
 }
 
+static void __ma_ui_notify_change_assistant(const char* app_id)
+{
+       ma_ui_change_assistant_cb callback = NULL;
+       void* user_data;
+
+       ma_ui_client_get_change_assistant_cb(g_ma_ui, &callback, &user_data);
+
+       if (NULL != callback) {
+               ma_ui_client_use_callback(g_ma_ui);
+               callback(app_id, user_data);
+               ma_ui_client_not_use_callback(g_ma_ui);
+               SLOG(LOG_DEBUG, TAG_MAUI, "[DEBUG] result callback is called");
+       } else {
+               SLOG(LOG_DEBUG, TAG_MAUI, "[WARNING] result callback is NULL");
+       }
+}
+
+int __ma_ui_cb_change_assistant(const char* app_id)
+{
+       ma_state_e state;
+       if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) {
+               SLOG(LOG_ERROR, TAG_MAUI, "[ERROR] Invalid client");
+               return MA_ERROR_INVALID_PARAMETER;
+       }
+
+       SLOG(LOG_DEBUG, TAG_MAUI, "[DEBUG] change assitant, app_id(%s)", app_id);
+       __ma_ui_notify_change_assistant(app_id);
+
+       return MA_ERROR_NONE;
+}
+
 int __ma_ui_cb_error(int reason, char* msg)
 {
        ma_state_e state;
@@ -967,3 +998,60 @@ int ma_ui_unset_result_cb(void)
        return MA_ERROR_NONE;
 }
 
+int ma_ui_set_change_assistant_cb(ma_ui_change_assistant_cb callback, void* user_data)
+{
+       if (0 != __ma_ui_get_feature_enabled()) {
+               SLOG(LOG_DEBUG, TAG_MAUI, "@@@ [UI] not supported");
+               return MA_ERROR_NOT_SUPPORTED;
+       }
+
+       SLOG(LOG_DEBUG, TAG_MAUI, "[UI] Set a default assistant");
+
+       if (NULL == callback) {
+               SLOG(LOG_ERROR, TAG_MAUI, "[UI ERROR] Invalid parameter");
+               return MA_ERROR_INVALID_PARAMETER;
+       }
+
+       ma_state_e state;
+       if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) {
+               SLOG(LOG_ERROR, TAG_MAUI, "[UI ERROR] A handle is not available");
+               return MA_ERROR_INVALID_STATE;
+       }
+
+       /* check state */
+       if (MA_STATE_INITIALIZED!= state) {
+               SLOG(LOG_ERROR, TAG_MAUI, "[UI ERROR] Invalid state: Current state is not 'Initialized' (%d)", state);
+               return MA_ERROR_INVALID_STATE;
+       }
+
+       ma_ui_client_set_change_assistant_cb(g_ma_ui, callback, user_data);
+
+       return MA_ERROR_NONE;
+}
+
+int ma_ui_unset_change_assistant_cb(void)
+{
+       if (0 != __ma_ui_get_feature_enabled()) {
+               SLOG(LOG_DEBUG, TAG_MAUI, "@@@ [UI] not supported");
+               return MA_ERROR_NOT_SUPPORTED;
+       }
+
+       SLOG(LOG_DEBUG, TAG_MAUI, "[UI] Set a default assistant");
+
+       ma_state_e state;
+       if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) {
+               SLOG(LOG_ERROR, TAG_MAUI, "[UI ERROR] A handle is not available");
+               return MA_ERROR_INVALID_STATE;
+       }
+
+       /* check state */
+       if (MA_STATE_INITIALIZED!= state) {
+               SLOG(LOG_ERROR, TAG_MAUI, "[UI ERROR] Invalid state: Current state is not 'Initialized' (%d)", state);
+               return MA_ERROR_INVALID_STATE;
+       }
+
+       ma_ui_client_set_change_assistant_cb(g_ma_ui, NULL, NULL);
+
+       return MA_ERROR_NONE;
+}
+
index 7cdec42b5a04586411a4e205bd1fe7703edf5565..06839b0c095410ae999e1de0c7220119e2c86ae2 100644 (file)
@@ -27,6 +27,8 @@ typedef struct {
        void*                           result_user_data;
        ma_ui_asr_result_cb             asr_result_cb;
        void*                           asr_result_user_data;
+       ma_ui_change_assistant_cb       change_assistant_cb;
+       void*                           change_assistant_user_data;
 
        ma_error_cb                     error_cb;
        void*                           error_user_data;
@@ -113,6 +115,8 @@ int ma_ui_client_create(ma_h* ma)
        client->result_user_data = NULL;
        client->asr_result_cb = NULL;
        client->asr_result_user_data = NULL;
+       client->change_assistant_cb = NULL;
+       client->change_assistant_user_data = NULL;
 
        client->error_cb = NULL;
        client->error_user_data = NULL;
@@ -346,6 +350,32 @@ int ma_ui_client_get_result_cb(ma_h ma, ma_ui_result_cb* callback, void** user_d
        return MA_ERROR_NONE;
 }
 
+int ma_ui_client_set_change_assistant_cb(ma_h ma, ma_ui_change_assistant_cb callback, void* user_data)
+{
+       ma_ui_client_s* client = __ui_client_get(ma);
+
+       if (NULL == client)
+               return MA_ERROR_INVALID_PARAMETER;
+
+       client->change_assistant_cb = callback;
+       client->change_assistant_user_data = user_data;
+
+       return MA_ERROR_NONE;
+}
+
+int ma_ui_client_get_change_assistant_cb(ma_h ma, ma_ui_change_assistant_cb* callback, void** user_data)
+{
+       ma_ui_client_s* client = __ui_client_get(ma);
+
+       if (NULL == client)
+               return MA_ERROR_INVALID_PARAMETER;
+
+       *callback = client->change_assistant_cb;
+       *user_data = client->change_assistant_user_data;
+
+       return MA_ERROR_NONE;
+}
+
 int ma_ui_client_set_error_cb(ma_h ma, ma_error_cb callback, void* user_data)
 {
        ma_ui_client_s* client = __ui_client_get(ma);
index 0562dbd1cf76a781473b30137d7416647dff2b03..358b6e5a7340b1af392a58ec94534550b1c0b464 100644 (file)
@@ -59,6 +59,10 @@ int ma_ui_client_set_result_cb(ma_h ma, ma_ui_result_cb callback, void* user_dat
 
 int ma_ui_client_get_result_cb(ma_h ma, ma_ui_result_cb* callback, void** user_data);
 
+int ma_ui_client_set_change_assistant_cb(ma_h ma, ma_ui_change_assistant_cb callback, void* user_data);
+
+int ma_ui_client_get_change_assistant_cb(ma_h ma, ma_ui_change_assistant_cb* callback, void** user_data);
+
 int ma_ui_client_set_error_cb(ma_h ma, ma_error_cb callback, void* user_data);
 
 int ma_ui_client_get_error_cb(ma_h ma, ma_error_cb* callback, void** user_data);
index 7cedc1983437f77c61cd97c674161fbe1e49fb26..ab9967c5d7ad6412088742412f90d1fd789c378e 100644 (file)
@@ -31,6 +31,7 @@ static DBusConnection* g_ui_conn_listener = NULL;
 extern int __ma_ui_cb_error(int reason, char* msg);
 extern int __ma_ui_cb_send_asr_result(int event, char* asr_result);
 extern int __ma_ui_cb_send_result(const char* display_text, const char* utterance_text, const char* result_json);
+extern int __ma_ui_cb_change_assistant(const char* app_id);
 
 
 static Eina_Bool ma_ui_listener_event_callback(void* data, Ecore_Fd_Handler* fd_handler)
@@ -153,6 +154,25 @@ static Eina_Bool ma_ui_listener_event_callback(void* data, Ecore_Fd_Handler* fd_
 
                } /* MAS_UI_METHOD_SEND_RESULT */
 
+               if (dbus_message_is_method_call(msg, if_name, MAS_UI_METHOD_CHANGE_ASSISTANT)) {
+                       SLOG(LOG_DEBUG, TAG_MAUI, "[DEBUG] Send change assistant request");
+                       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_MAUI, "[ERROR] Dbus Error (%s)", err.message);
+                               dbus_error_free(&err);
+                       } else {
+                               SLOG(LOG_DEBUG, TAG_MAUI, "[DEBUG] multi-assistant ui Send change assistant request : app_id(%s)", app_id);
+
+                               __ma_ui_cb_change_assistant(app_id);
+                       }
+
+               } /* MAS_UI_METHOD_CHANGE_ASSISTANT */
+
                else if (dbus_message_is_signal(msg, if_name, MAS_UI_METHOD_ERROR)) {
                        SLOG(LOG_DEBUG, TAG_MAUI, "[DEBUG] Get Error");
                        int reason;
index a5da66105d9870cd30873601ae70f3d4d8d7f23e..86ba5620c9f81ace7cbdae6cf8bcb22f4110efff 100644 (file)
@@ -83,6 +83,7 @@ extern "C"
 #define MAS_UI_METHOD_HELLO                                            "mas_ui_method_hello"
 #define MAS_UI_METHOD_SEND_ASR_RESULT                  "mas_ui_method_send_asr_result"
 #define MAS_UI_METHOD_SEND_RESULT                              "mas_ui_method_send_result"
+#define MAS_UI_METHOD_CHANGE_ASSISTANT                 "mas_ui_method_change_assistant"
 #define MAS_UI_METHOD_ERROR                                            "mas_ui_method_error"
 
 /**************************************************************************************
index 4bd4da05dafde220cdf69758e8e424773e128ff1..357d4f88e9e053c27253a08f3e960bc7cac8f683 100644 (file)
@@ -334,7 +334,6 @@ int ma_send_asr_result(ma_asr_result_event_e event, const char* asr_result);
  */
 int ma_send_result(const char* display_text, const char* utterance_text, const char* result_json);
 
-
 #ifdef __cplusplus
 }
 #endif
index 5f8e1cc62ff215fbd216111bfd9c3389159960ac..377739a088ce0da6d0b7ad87f139deed03a5ce04 100644 (file)
@@ -92,6 +92,16 @@ typedef void (*ma_ui_asr_result_cb)(ma_asr_result_event_e event, const char* asr
  */
 typedef void (*ma_ui_result_cb)(const char* display_text, const char* utterance_text, const char* result_json, void* user_data);
 
+/**
+ * @brief Called when the multi-assistant service sends the request for changing assistant.
+ * @since_tizen 5.0
+ * @remarks The @a app_id can be used only in the callback. To use outside, make a copy.
+ *
+ * @param[in] app_id The text shown on the display
+ * @param[in] user_data The user data passed from the callback registration function
+ *
+ */
+typedef void (*ma_ui_change_assistant_cb)(const char* app_id, void* user_data);
 
 /**
  * @brief Initializes multi-assistant UI.
@@ -364,7 +374,35 @@ int ma_ui_set_result_cb(ma_ui_result_cb callback, void* user_data);
  */
 int ma_ui_unset_result_cb(void);
 
+/**
+ * @brief Sets a callback for getting change assistant info.
+ * @since_tizen 5.0
+ *
+ * @param[in] callback The callback function
+ * @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.
+ */
+int ma_ui_set_change_assistant_cb(ma_ui_change_assistant_cb callback, void* user_data);
 
+/**
+ * @brief Unsets a callback for getting change assistant info.
+ * @since_tizen 5.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.
+ */
+int ma_ui_unset_change_assistant_cb(void);
 
 #ifdef __cplusplus
 }