From 8f027901042c480f64ced26390f9f4ea01c058a2 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 11 Oct 2018 16:27:52 +0900 Subject: [PATCH] Enable sending change assistant requests Change-Id: I95bb27354a71285374a3433f7e44125e34f216d9 --- client/ma_ui.c | 3 +- client/ma_ui_dbus.c | 73 +++++++++++++++++++++++++++++++++++++++++++++ client/ma_ui_dbus.h | 2 ++ 3 files changed, 77 insertions(+), 1 deletion(-) diff --git a/client/ma_ui.c b/client/ma_ui.c index 44b00b0..12d8ad0 100644 --- a/client/ma_ui.c +++ b/client/ma_ui.c @@ -715,12 +715,13 @@ int ma_ui_change_assistant(const char* app_id) } /* check state */ - if (MA_STATE_INITIALIZED!= state) { + if (MA_STATE_READY != state) { SLOG(LOG_ERROR, TAG_MAUI, "[UI ERROR] Invalid state: Current state is not 'Initialized' (%d)", state); return MA_ERROR_INVALID_STATE; } int ret = -1; + ma_ui_dbus_request_change_assistant(app_id); /* ret = ma_config_mgr_change_assistant(app_id); if (0 != ret) { SLOG(LOG_ERROR, TAG_MAUI, "[UI ERROR] Fail to set default assistant")_; diff --git a/client/ma_ui_dbus.c b/client/ma_ui_dbus.c index 5630b06..7cedc19 100644 --- a/client/ma_ui_dbus.c +++ b/client/ma_ui_dbus.c @@ -634,3 +634,76 @@ int ma_ui_dbus_request_deinitialize(int pid) return result; } +int ma_ui_dbus_request_change_assistant(const char *appid) +{ + DBusError err; + dbus_error_init(&err); + + bool exist = dbus_bus_name_has_owner(g_ui_conn_sender, MA_SERVER_SERVICE_NAME, &err); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_MAUI, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + int ret; + if (false == exist) { + ret = __dbus_restore_daemon(); + if (MA_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_MAUI, "[ERROR] Fail to restore daemon"); + return MA_ERROR_TIMED_OUT; + } + 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_UI_METHOD_CHANGE_ASSISTANT); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_MAUI, "[ERROR] multi-assistant ui change assistant : Fail to make message"); + return MA_ERROR_OPERATION_FAILED; + } + + dbus_message_append_args(msg, DBUS_TYPE_STRING, &appid, DBUS_TYPE_INVALID); + DBusMessage* result_msg; + int result = MA_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_ui_conn_sender, msg, g_ui_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_MAUI, "[ERROR] Dbus Error (%s)", err.message); + 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_MAUI, "[ERROR] 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_MAUI, "[DEBUG] multi-assistant ui change assistant : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_MAUI, "[ERROR] multi-assistant ui change assistant : result = %d", result); + } + } else { + SLOG(LOG_ERROR, TAG_MAUI, "[ERROR] Result message is NULL "); + ma_ui_dbus_reconnect(); + result = MA_ERROR_TIMED_OUT; + } + + return result; +} + diff --git a/client/ma_ui_dbus.h b/client/ma_ui_dbus.h index ac7ea2d..326f0f8 100644 --- a/client/ma_ui_dbus.h +++ b/client/ma_ui_dbus.h @@ -38,6 +38,8 @@ int ma_ui_dbus_request_initialize(int pid); int ma_ui_dbus_request_deinitialize(int pid); +int ma_ui_dbus_request_change_assistant(const char* appid); + #ifdef __cplusplus } -- 2.34.1