*/
+#include <pthread.h>
+
#include "vc_main.h"
#include "vc_widget_client.h"
#include "vc_widget_dbus.h"
+static pthread_mutex_t g_w_dbus_mutex = PTHREAD_MUTEX_INITIALIZER;
+
static int g_w_waiting_time = 3000;
static Ecore_Fd_Handler* g_w_fd_handler = NULL;
int vc_widget_dbus_open_connection()
{
+ pthread_mutex_lock(&g_w_dbus_mutex);
+
if (NULL != g_w_conn_sender && NULL != g_w_conn_listener) {
SLOG(LOG_WARN, TAG_VCW, "Already existed connection ");
+ pthread_mutex_unlock(&g_w_dbus_mutex);
return 0;
}
if (NULL == g_w_conn_sender) {
SLOG(LOG_ERROR, TAG_VCW, "Fail to get dbus connection ");
+ pthread_mutex_unlock(&g_w_dbus_mutex);
return VC_ERROR_OPERATION_FAILED;
}
if (NULL == g_w_conn_listener) {
SLOG(LOG_ERROR, TAG_VCW, "Fail to get dbus connection ");
__vc_widget_dbus_connection_free();
+ pthread_mutex_unlock(&g_w_dbus_mutex);
return VC_ERROR_OPERATION_FAILED;
}
if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
SLOG(LOG_ERROR, TAG_VCW, "fail dbus_bus_request_name()");
__vc_widget_dbus_connection_free();
+ pthread_mutex_unlock(&g_w_dbus_mutex);
return -2;
}
if (NULL != g_w_fd_handler) {
SLOG(LOG_WARN, TAG_VCW, "The handler already exists.");
__vc_widget_dbus_connection_free();
+ pthread_mutex_unlock(&g_w_dbus_mutex);
return 0;
}
SLOG(LOG_ERROR, TAG_VCW, "Match Error (%s)", err.message);
dbus_error_free(&err);
__vc_widget_dbus_connection_free();
+ pthread_mutex_unlock(&g_w_dbus_mutex);
return VC_ERROR_OPERATION_FAILED;
}
if (1 != dbus_connection_get_unix_fd(g_w_conn_listener, &fd)) {
SLOG(LOG_ERROR, TAG_VCW, "fail to get fd from dbus ");
__vc_widget_dbus_connection_free();
+ pthread_mutex_unlock(&g_w_dbus_mutex);
return VC_ERROR_OPERATION_FAILED;
} else {
SLOG(LOG_DEBUG, TAG_VCW, "Get fd from dbus : %d", fd);
if (NULL == g_w_fd_handler) {
SLOG(LOG_ERROR, TAG_VCW, "fail to get fd handler from ecore ");
__vc_widget_dbus_connection_free();
+ pthread_mutex_unlock(&g_w_dbus_mutex);
return VC_ERROR_OPERATION_FAILED;
}
+ pthread_mutex_unlock(&g_w_dbus_mutex);
return 0;
}
int vc_widget_dbus_close_connection()
{
+ pthread_mutex_lock(&g_w_dbus_mutex);
+
DBusError err;
dbus_error_init(&err);
__vc_widget_dbus_connection_free();
+ pthread_mutex_unlock(&g_w_dbus_mutex);
+
return 0;
}