return ECORE_CALLBACK_PASS_ON;
}
+static void __vc_dbus_connection_free()
+{
+ if (NULL != g_conn_listener) {
+ dbus_connection_close(g_conn_listener);
+ dbus_connection_unref(g_conn_listener);
+ g_conn_listener = NULL;
+ }
+ if (NULL != g_conn_sender) {
+ dbus_connection_close(g_conn_sender);
+ dbus_connection_unref(g_conn_sender);
+ g_conn_sender = NULL;
+ }
+}
+
int vc_dbus_open_connection()
{
if (NULL != g_conn_sender && NULL != g_conn_listener) {
if (NULL == g_conn_listener) {
SLOG(LOG_ERROR, TAG_VCC, "Fail to get dbus connection ");
+ __vc_dbus_connection_free();
return VC_ERROR_OPERATION_FAILED;
}
if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
SLOG(LOG_ERROR, TAG_VCC, "fail dbus_bus_request_name()");
+ __vc_dbus_connection_free();
return -2;
}
if (NULL != g_fd_handler) {
SLOG(LOG_WARN, TAG_VCC, "The handler already exists.");
+ __vc_dbus_connection_free();
return 0;
}
if (dbus_error_is_set(&err)) {
SLOG(LOG_ERROR, TAG_VCC, "Match Error (%s)", err.message);
dbus_error_free(&err);
+ __vc_dbus_connection_free();
return VC_ERROR_OPERATION_FAILED;
}
int fd = 0;
if (1 != dbus_connection_get_unix_fd(g_conn_listener, &fd)) {
SLOG(LOG_ERROR, TAG_VCC, "fail to get fd from dbus ");
+ __vc_dbus_connection_free();
return VC_ERROR_OPERATION_FAILED;
} else {
SLOG(LOG_DEBUG, TAG_VCC, "Get fd from dbus : %d", fd);
g_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)listener_event_callback, g_conn_listener, NULL, NULL);
if (NULL == g_fd_handler) {
SLOG(LOG_ERROR, TAG_VCC, "fail to get fd handler from ecore ");
+ __vc_dbus_connection_free();
return VC_ERROR_OPERATION_FAILED;
}
dbus_error_free(&err);
}
- dbus_connection_close(g_conn_sender);
- dbus_connection_close(g_conn_listener);
-
- dbus_connection_unref(g_conn_sender);
- dbus_connection_unref(g_conn_listener);
-
- g_conn_sender = NULL;
- g_conn_listener = NULL;
+ __vc_dbus_connection_free();
return 0;
}
int vc_dbus_reconnect()
{
+ if (!g_conn_sender || !g_conn_listener) {
+ vc_dbus_close_connection();
+
+ if (0 != vc_dbus_open_connection()) {
+ SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to reconnect");
+ return -1;
+ }
+
+ SLOG(LOG_DEBUG, TAG_VCC, "[DBUS] Reconnect");
+ return 0;
+ }
+
bool sender_connected = dbus_connection_get_is_connected(g_conn_sender);
bool listener_connected = dbus_connection_get_is_connected(g_conn_listener);
SLOG(LOG_WARN, TAG_VCC, "[DBUS] Sender(%s) Listener(%s)",
return ECORE_CALLBACK_PASS_ON;
}
+static void __vc_mgr_dbus_connection_free()
+{
+ if (NULL != g_m_conn_listener) {
+ dbus_connection_close(g_m_conn_listener);
+ dbus_connection_unref(g_m_conn_listener);
+ g_m_conn_listener = NULL;
+ }
+ if (NULL != g_m_conn_sender) {
+ dbus_connection_close(g_m_conn_sender);
+ dbus_connection_unref(g_m_conn_sender);
+ g_m_conn_sender = NULL;
+ }
+}
+
int vc_mgr_dbus_open_connection()
{
if (NULL != g_m_conn_sender && NULL != g_m_conn_listener) {
if (NULL == g_m_conn_listener) {
SLOG(LOG_ERROR, TAG_VCM, "Fail to get dbus connection ");
+ __vc_mgr_dbus_connection_free();
return VC_ERROR_OPERATION_FAILED;
}
if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
SLOG(LOG_ERROR, TAG_VCM, "fail dbus_bus_request_name()");
+ __vc_mgr_dbus_connection_free();
return -2;
}
if (NULL != g_m_fd_handler) {
SLOG(LOG_WARN, TAG_VCM, "The handler already exists.");
+ __vc_mgr_dbus_connection_free();
return 0;
}
if (dbus_error_is_set(&err)) {
SLOG(LOG_ERROR, TAG_VCM, "Match Error (%s)", err.message);
dbus_error_free(&err);
+ __vc_mgr_dbus_connection_free();
return VC_ERROR_OPERATION_FAILED;
}
int fd = 0;
if (1 != dbus_connection_get_unix_fd(g_m_conn_listener, &fd)) {
SLOG(LOG_ERROR, TAG_VCM, "fail to get fd from dbus ");
+ __vc_mgr_dbus_connection_free();
return VC_ERROR_OPERATION_FAILED;
} else {
SLOG(LOG_DEBUG, TAG_VCM, "Get fd from dbus : %d", fd);
if (NULL == g_m_fd_handler) {
SLOG(LOG_ERROR, TAG_VCM, "fail to get fd handler from ecore ");
+ __vc_mgr_dbus_connection_free();
return VC_ERROR_OPERATION_FAILED;
}
dbus_error_free(&err);
}
- dbus_connection_close(g_m_conn_sender);
- dbus_connection_close(g_m_conn_listener);
-
- dbus_connection_unref(g_m_conn_sender);
- dbus_connection_unref(g_m_conn_listener);
-
- g_m_conn_sender = NULL;
- g_m_conn_listener = NULL;
+ __vc_mgr_dbus_connection_free();
return 0;
}
int vc_mgr_dbus_reconnect()
{
+ if (!g_m_conn_sender || !g_m_conn_listener) {
+ vc_mgr_dbus_close_connection();
+
+ if (0 != vc_mgr_dbus_open_connection()) {
+ SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to reconnect");
+ return -1;
+ }
+
+ SLOG(LOG_DEBUG, TAG_VCM, "[DBUS] Reconnect");
+ return 0;
+ }
+
bool sender_connected = dbus_connection_get_is_connected(g_m_conn_sender);
bool listener_connected = dbus_connection_get_is_connected(g_m_conn_listener);
return ECORE_CALLBACK_PASS_ON;
}
+static void __vc_mgr_dbus_connection_free()
+{
+ if (NULL != g_w_conn_listener) {
+ dbus_connection_close(g_w_conn_listener);
+ dbus_connection_unref(g_w_conn_listener);
+ g_w_conn_listener = NULL;
+ }
+ if (NULL != g_w_conn_sender) {
+ dbus_connection_close(g_w_conn_sender);
+ dbus_connection_unref(g_w_conn_sender);
+ g_w_conn_sender = NULL;
+ }
+}
+
int vc_widget_dbus_open_connection()
{
if (NULL != g_w_conn_sender && NULL != g_w_conn_listener) {
if (NULL == g_w_conn_listener) {
SLOG(LOG_ERROR, TAG_VCW, "Fail to get dbus connection ");
+ __vc_mgr_dbus_connection_free();
return VC_ERROR_OPERATION_FAILED;
}
if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
SLOG(LOG_ERROR, TAG_VCW, "fail dbus_bus_request_name()");
+ __vc_mgr_dbus_connection_free();
return -2;
}
if (NULL != g_w_fd_handler) {
SLOG(LOG_WARN, TAG_VCW, "The handler already exists.");
+ __vc_mgr_dbus_connection_free();
return 0;
}
if (dbus_error_is_set(&err)) {
SLOG(LOG_ERROR, TAG_VCW, "Match Error (%s)", err.message);
dbus_error_free(&err);
+ __vc_mgr_dbus_connection_free();
return VC_ERROR_OPERATION_FAILED;
}
int fd = 0;
if (1 != dbus_connection_get_unix_fd(g_w_conn_listener, &fd)) {
SLOG(LOG_ERROR, TAG_VCW, "fail to get fd from dbus ");
+ __vc_mgr_dbus_connection_free();
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_mgr_dbus_connection_free();
return VC_ERROR_OPERATION_FAILED;
}
dbus_error_free(&err);
}
- dbus_connection_close(g_w_conn_sender);
- dbus_connection_close(g_w_conn_listener);
-
- dbus_connection_unref(g_w_conn_sender);
- dbus_connection_unref(g_w_conn_listener);
-
- g_w_conn_sender = NULL;
- g_w_conn_listener = NULL;
+ __vc_mgr_dbus_connection_free();
return 0;
}
int vc_widget_dbus_reconnect()
{
+ if (!g_w_conn_sender || !g_w_conn_listener) {
+ vc_widget_dbus_close_connection();
+
+ if (0 != vc_widget_dbus_open_connection()) {
+ SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to reconnect");
+ return -1;
+ }
+
+ SLOG(LOG_DEBUG, TAG_VCW, "[DBUS] Reconnect");
+ return 0;
+ }
+
bool sender_connected = dbus_connection_get_is_connected(g_w_conn_sender);
bool listener_connected = dbus_connection_get_is_connected(g_w_conn_listener);
SLOG(LOG_DEBUG, TAG_VCW, "[DBUS] Sender(%s) Listener(%s)",