Introduce ENABLE_COMMON_UI protocol to support UI customization 65/202665/3
authorJi-hoon Lee <dalton.lee@samsung.com>
Tue, 2 Apr 2019 09:04:40 +0000 (18:04 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Thu, 11 Apr 2019 04:56:00 +0000 (13:56 +0900)
Change-Id: I8d0a7cfea08a773bb827b511fbb0b373dd8a289d

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_ui.h

index ff563a473209ea3ed59e90adfb4c43f859fcd815..ba0e1d8ef2831bfef647aeec41a018f910bcda29 100644 (file)
@@ -656,6 +656,26 @@ int __ma_ui_cb_send_recognition_result(ma_recognition_result_event_e result)
        return MA_ERROR_NONE;
 }
 
+
+int __ma_ui_cb_enable_common_ui(bool enable)
+{
+       ma_ui_enable_common_ui_cb callback = NULL;
+       void* user_data;
+
+       ma_ui_client_get_enable_common_ui_cb(g_ma_ui, &callback, &user_data);
+
+       if (NULL != callback) {
+               ma_ui_client_use_callback(g_ma_ui);
+               callback(enable, user_data);
+               ma_ui_client_not_use_callback(g_ma_ui);
+               SLOG(LOG_DEBUG, TAG_MAUI, "[DEBUG] enable common UI callback is called");
+       } else {
+               SLOG(LOG_DEBUG, TAG_MAUI, "[WARNING] enable common UI callback is NULL");
+       }
+
+       return MA_ERROR_NONE;
+}
+
 int ma_ui_get_state(ma_state_e* state)
 {
        if (0 != __ma_ui_get_feature_enabled()) {
@@ -1142,3 +1162,58 @@ int ma_ui_unset_recognition_result_cb(void)
        return MA_ERROR_NONE;
 }
 
+int ma_ui_set_enable_common_ui_cb(ma_ui_enable_common_ui_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;
+       }
+
+       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_enable_common_ui_cb(g_ma_ui, callback, user_data);
+
+       return MA_ERROR_NONE;
+}
+
+int ma_ui_unset_enable_common_ui_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_enable_common_ui_cb(g_ma_ui, NULL, NULL);
+
+       return MA_ERROR_NONE;
+}
+
index 34e9809182a80492ec3dbd520d6ac502b3cb452c..ac6edf5ecef544e0a8d2580d35b7b7d925a5bee3 100644 (file)
@@ -29,21 +29,21 @@ typedef struct {
        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;
        ma_state_changed_cb             state_changed_cb;
        void*                           state_changed_user_data;
        ma_language_changed_cb  lang_changed_cb;
        void*                           lang_changed_user_data;
+       ma_ui_recognition_result_cb     recognition_result_cb;
+       void*                                   recognition_result_user_data;
+       ma_ui_enable_common_ui_cb       enable_common_ui_cb;
+       void*                                   enable_common_ui_user_data;
 
        /* ASR result */
        ma_asr_result_event_e   asr_result_event;
        char*                   asr_result_text;
 
-       ma_ui_recognition_result_cb     recognition_result_cb;
-       void*                                   recognition_result_user_data;
-
        /* state */
        ma_state_e              previous_state;
        ma_state_e              current_state;
@@ -127,6 +127,10 @@ int ma_ui_client_create(ma_h* ma)
        client->state_changed_user_data = NULL;
        client->lang_changed_cb = NULL;
        client->lang_changed_user_data = NULL;
+       client->recognition_result_cb = NULL;
+       client->recognition_result_user_data = NULL;
+       client->enable_common_ui_cb = NULL;
+       client->enable_common_ui_user_data = NULL;
 
        client->asr_result_event = 0;
        client->asr_result_text = NULL;
@@ -483,3 +487,28 @@ int ma_ui_client_get_recognition_result_cb(ma_h ma, ma_ui_recognition_result_cb*
        return MA_ERROR_NONE;
 }
 
+int ma_ui_client_set_enable_common_ui_cb(ma_h ma, ma_ui_enable_common_ui_cb callback, void* user_data)
+{
+       ma_ui_client_s* client = __ui_client_get(ma);
+
+       if (NULL == client)
+               return MA_ERROR_INVALID_PARAMETER;
+
+       client->enable_common_ui_cb = callback;
+       client->enable_common_ui_user_data = user_data;
+
+       return MA_ERROR_NONE;
+}
+
+int ma_ui_client_get_enable_common_ui_cb(ma_h ma, ma_ui_enable_common_ui_cb* callback, void** user_data)
+{
+       ma_ui_client_s* client = __ui_client_get(ma);
+
+       if (NULL == client)
+               return MA_ERROR_INVALID_PARAMETER;
+
+       *callback = client->enable_common_ui_cb;
+       *user_data = client->enable_common_ui_user_data;
+
+       return MA_ERROR_NONE;
+}
index 66a9345975496e1ea34a87aa9e8270fb6089e085..2c71ba3ddf402eb7e12bbed0477b2ce34162414a 100644 (file)
@@ -79,6 +79,9 @@ int ma_ui_client_set_recognition_result_cb(ma_h ma, ma_ui_recognition_result_cb
 
 int ma_ui_client_get_recognition_result_cb(ma_h ma, ma_ui_recognition_result_cb* callback, void** user_data);
 
+int ma_ui_client_set_enable_common_ui_cb(ma_h ma, ma_ui_enable_common_ui_cb callback, void* user_data);
+
+int ma_ui_client_get_enable_common_ui_cb(ma_h ma, ma_ui_enable_common_ui_cb* callback, void** user_data);
 
 #ifdef __cplusplus
 }
index a418a69ba0779b88e9dc79e331bf6b8133c8d5af..6419379ebac26ec4eb9a0cbc69dd3eab6c6093dd 100644 (file)
@@ -33,6 +33,7 @@ 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);
 extern int __ma_ui_cb_send_recognition_result(int result);
+extern int __ma_ui_cb_enable_common_ui(int enable);
 
 static Eina_Bool ma_ui_listener_event_callback(void* data, Ecore_Fd_Handler* fd_handler)
 {
@@ -219,7 +220,27 @@ static Eina_Bool ma_ui_listener_event_callback(void* data, Ecore_Fd_Handler* fd_
                                __ma_ui_cb_send_recognition_result(result);
                        }
 
-               } /* MAS_UI_METHOD_SEND_RESULT */
+               } /* MAS_UI_METHOD_SEND_RECOGNITION_RESULT */
+
+               if (dbus_message_is_method_call(msg, if_name, MAS_UI_METHOD_ENABLE_COMMON_UI)) {
+                       SLOG(LOG_DEBUG, TAG_MAUI, "[DEBUG] Send recognition result");
+                       int enable = 0;
+
+                       dbus_message_get_args(msg, &err,
+                               DBUS_TYPE_INT32, &enable,
+                               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 Enable common UI : enable(%d)", enable);
+
+                               __ma_ui_cb_enable_common_ui((enable) ? true : false);
+                       }
+
+               } /* MAS_UI_METHOD_ENABLE_COMMON_UI */
+
                else if (dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameOwnerChanged")) {
                        SLOG(LOG_DEBUG, TAG_MAUI, "[DEBUG] Owner Changed");
                        /* remove a rule for daemon error */
index 9b411d13baa7255572b34af2f955a85e23f1e6d5..093a9429cc904268e8d9e53c0f43220384a3e030 100644 (file)
@@ -91,8 +91,9 @@ extern "C"
 #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_SEND_RECOGNITION_RESULT          "mas_ui_method_send_recognition_result"
 #define MAS_UI_METHOD_ERROR                                                    "mas_ui_method_error"
+#define MAS_UI_METHOD_SEND_RECOGNITION_RESULT          "mas_ui_method_send_recognition_result"
+#define MAS_UI_METHOD_ENABLE_COMMON_UI                         "mas_ui_method_enable_common_ui"
 
 /**************************************************************************************
  *** Definitions for xml file
index a5f31e30de9e1c6d843e7c2a45d92482b2eff484..ac7f6b3056c76ce959bb7b6a0ce61724b25ec7e7 100644 (file)
@@ -115,6 +115,18 @@ typedef void (*ma_ui_change_assistant_cb)(const char* app_id, void* user_data);
  */
 typedef void (*ma_ui_recognition_result_cb)(ma_recognition_result_event_e result, void* user_data);
 
+/**
+ * @brief Called when the multi-assistant service enables or disables the common UI.
+ * @since_tizen 5.5
+ *
+ * @param[in] enable The status whether the common UI is enabled
+ * @param[in] user_data The user data passed from the callback registration function
+ *
+ * @see ma_ui_set_enable_common_ui_cb()
+ * @see ma_ui_set_enable_common_ui_cb()
+ */
+typedef void (*ma_ui_enable_common_ui_cb)(bool enable, void* user_data);
+
 /**
  * @brief Initializes multi-assistant UI.
  * @since_tizen 5.0
@@ -445,6 +457,37 @@ int ma_ui_set_recognition_result_cb(ma_ui_recognition_result_cb callback, void*
  * @pre The state should be #MA_STATE_INITIALIZED.
  */
 int ma_ui_unset_recognition_result_cb(void);
+
+/**
+ * @brief Sets a callback for getting common UI enabled status.
+ * @since_tizen 5.5
+ *
+ * @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_enable_common_ui_cb(ma_ui_enable_common_ui_cb callback, void* user_data);
+
+/**
+ * @brief Unsets a callback for common UI enabled status.
+ * @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.
+ */
+int ma_ui_unset_enable_common_ui_cb(void);
+
 #ifdef __cplusplus
 }
 #endif