return 0;
}
+static int __send_sync_dbus_message(DBusMessage* msg, bool need_add_rule)
+{
+ DBusError err;
+ dbus_error_init(&err);
+
+ 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)) {
+ MAUI_SLOGE("[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)) {
+ MAUI_SLOGE("[ERROR] Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ result = MA_ERROR_OPERATION_FAILED;
+ }
+
+ dbus_message_unref(result_msg);
+
+ if (0 == result) {
+ if (need_add_rule) {
+ /* add a rule for daemon error */
+ char rule_err[256] = {0, };
+ snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", MA_SERVER_SERVICE_INTERFACE);
+ dbus_bus_add_match(g_ui_conn_listener, rule_err, &err);
+
+ if (dbus_error_is_set(&err)) {
+ MAUI_SLOGE("Match Error (%s)", err.message);
+ dbus_error_free(&err);
+ }
+ }
+
+ MAUI_SLOGD("[SUCCESS] Success to send meesage : result = %d", result);
+ } else {
+ MAUI_SLOGE("[ERROR] Fail to send message : result = %d", result);
+ }
+ } else {
+ MAUI_SLOGE("[ERROR] Result message is NULL ");
+ ma_ui_dbus_reconnect();
+ result = MA_ERROR_TIMED_OUT;
+ }
+
+ return result;
+}
+
int ma_ui_dbus_request_hello()
{
DBusMessage* msg;
return ret;
}
-int ma_ui_dbus_request_initialize(int pid)
+static int __check_damon_exists()
{
DBusError err;
dbus_error_init(&err);
return MA_ERROR_OPERATION_FAILED;
}
+ return MA_ERROR_NONE;
+}
+
+int ma_ui_dbus_request_initialize(int pid)
+{
+ int ret = __check_damon_exists();
+ if (MA_ERROR_NONE != ret)
+ return ret;
+
DBusMessage* msg;
msg = dbus_message_new_method_call(
DBUS_TYPE_INT32, &pid,
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)) {
- MAUI_SLOGE("[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)) {
- MAUI_SLOGE("[ERROR] Get arguments error (%s)", err.message);
- dbus_error_free(&err);
- result = MA_ERROR_OPERATION_FAILED;
- }
-
- dbus_message_unref(result_msg);
-
- if (0 == result) {
- /* add a rule for daemon error */
- char rule_err[256] = {0, };
- snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", MA_SERVER_SERVICE_INTERFACE);
- dbus_bus_add_match(g_ui_conn_listener, rule_err, &err);
-
- if (dbus_error_is_set(&err)) {
- MAUI_SLOGE("Match Error (%s)", err.message);
- dbus_error_free(&err);
- }
-
- MAUI_SLOGD("[ERROR] multi-assistant ui initialize : result = %d", result);
- } else {
- MAUI_SLOGE("[ERROR] multi-assistant ui initialize : result = %d", result);
- }
- } else {
- MAUI_SLOGE("[ERROR] Result message is NULL ");
- ma_ui_dbus_reconnect();
- result = MA_ERROR_TIMED_OUT;
- }
-
- return result;}
+ return __send_sync_dbus_message(msg, true);
+}
int ma_ui_dbus_request_deinitialize(int pid)
{
+ int ret = __check_damon_exists();
+ if (MA_ERROR_NONE != ret)
+ return ret;
+
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)) {
- MAUI_SLOGE("[ERROR] Dbus Error (%s)", err.message);
- dbus_error_free(&err);
- }
-
- int ret;
- if (false == exist) {
- ret = __dbus_restore_daemon();
- if (MA_ERROR_NONE != ret) {
- MAUI_SLOGE("[ERROR] Fail to restore daemon");
- return MA_ERROR_TIMED_OUT;
- }
- return MA_ERROR_OPERATION_FAILED;
- }
-
/* remove a rule for daemon error */
char rule_err[256] = {0, };
snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", MA_SERVER_SERVICE_INTERFACE);
dbus_message_append_args(msg, DBUS_TYPE_INT32, &pid, 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)) {
- MAUI_SLOGE("[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)) {
- MAUI_SLOGE("[ERROR] Get arguments error (%s)", err.message);
- dbus_error_free(&err);
- result = MA_ERROR_OPERATION_FAILED;
- }
-
- dbus_message_unref(result_msg);
-
- if (0 == result) {
- MAUI_SLOGD("[DEBUG] multi-assistant ui finalize : result = %d", result);
- } else {
- MAUI_SLOGE("[ERROR] multi-assistant ui finalize : result = %d", result);
- }
- } else {
- MAUI_SLOGE("[ERROR] Result message is NULL ");
- ma_ui_dbus_reconnect();
- result = MA_ERROR_TIMED_OUT;
- }
-
- return result;
+ return __send_sync_dbus_message(msg, false);
}
int ma_ui_dbus_request_change_assistant(const char *appid)
}
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)) {
- MAUI_SLOGE("[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)) {
- MAUI_SLOGE("[ERROR] Get arguments error (%s)", err.message);
- dbus_error_free(&err);
- result = MA_ERROR_OPERATION_FAILED;
- }
-
- dbus_message_unref(result_msg);
-
- if (0 == result) {
- MAUI_SLOGD("[DEBUG] multi-assistant ui change assistant : result = %d", result);
- } else {
- MAUI_SLOGE("[ERROR] multi-assistant ui change assistant : result = %d", result);
- }
- } else {
- MAUI_SLOGE("[ERROR] Result message is NULL ");
- ma_ui_dbus_reconnect();
- result = MA_ERROR_TIMED_OUT;
- }
-
- return result;
+ return __send_sync_dbus_message(msg, false);
}