aboutsummaryrefslogtreecommitdiffstats
path: root/shell/e-shell-nm.c
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@novell.com>2006-04-18 23:51:43 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2006-04-18 23:51:43 +0800
commitab7c700749f00c81fb6ceb56ec2ea2f79be1734a (patch)
tree3adbb9d2b4fcaaf94583ab6cc3142ce33b5efea0 /shell/e-shell-nm.c
parent9e929ed567809d60a9eabf29289d72ccd2325e11 (diff)
downloadgsoc2013-evolution-ab7c700749f00c81fb6ceb56ec2ea2f79be1734a.tar.gz
gsoc2013-evolution-ab7c700749f00c81fb6ceb56ec2ea2f79be1734a.tar.zst
gsoc2013-evolution-ab7c700749f00c81fb6ceb56ec2ea2f79be1734a.zip
Intercept the Disconnected signal and setup a timeout to try and reconnect
2006-04-18 Jeffrey Stedfast <fejj@novell.com> * e-shell-nm.c (e_shell_network_monitor): Intercept the Disconnected signal and setup a timeout to try and reconnect when the dbus daemon comes back up. svn path=/trunk/; revision=31828
Diffstat (limited to 'shell/e-shell-nm.c')
-rw-r--r--shell/e-shell-nm.c105
1 files changed, 72 insertions, 33 deletions
diff --git a/shell/e-shell-nm.c b/shell/e-shell-nm.c
index 1ce00eb594..8ec467ebf7 100644
--- a/shell/e-shell-nm.c
+++ b/shell/e-shell-nm.c
@@ -1,3 +1,4 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Shreyas Srinivasan <sshreyas@novell.com>
*
@@ -33,19 +34,31 @@
#include <dbus/dbus-glib.h>
#include <NetworkManager/NetworkManager.h>
-int shell_dbus_initialize (EShellWindow *window);
+typedef enum _ShellLineStatus {
+ E_SHELL_LINE_DOWN,
+ E_SHELL_LINE_UP
+} ShellLineStatus;
-enum _ShellLineStatus {
- E_SHELL_LINE_DOWN,
- E_SHELL_LINE_UP
-};
+static gboolean init_dbus (EShellWindow *window);
-typedef enum _ShellLineStatus ShellLineStatus;
+static DBusConnection *dbus_connection = NULL;
-static DBusHandlerResult e_shell_network_monitor (DBusConnection *connection G_GNUC_UNUSED,
- DBusMessage *message,
- void* user_data)
+
+static gboolean
+reinit_dbus (gpointer user_data)
+{
+ if (init_dbus (user_data))
+ return FALSE;
+
+ /* keep trying to re-establish dbus connection */
+
+ return TRUE;
+}
+
+static DBusHandlerResult
+e_shell_network_monitor (DBusConnection *connection G_GNUC_UNUSED,
+ DBusMessage *message, void *user_data)
{
DBusError error;
const char *object;
@@ -57,21 +70,30 @@ static DBusHandlerResult e_shell_network_monitor (DBusConnection *connection G_G
dbus_error_init (&error);
object = dbus_message_get_path (message);
-
+
+ if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected") &&
+ strcmp (dbus_message_get_path (message), DBUS_PATH_LOCAL) == 0) {
+ dbus_connection_unref (dbus_connection);
+ dbus_connection = NULL;
+
+ g_timeout_add (3000, reinit_dbus, window);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceNoLongerActive"))
- status = E_SHELL_LINE_DOWN;
+ status = E_SHELL_LINE_DOWN;
else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceNowActive"))
- status = E_SHELL_LINE_UP;
- else
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ status = E_SHELL_LINE_UP;
+ else
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
if (!dbus_message_get_args (message, &error, DBUS_TYPE_OBJECT_PATH,
- &object, DBUS_TYPE_INVALID))
+ &object, DBUS_TYPE_INVALID))
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
line_status = e_shell_get_line_status (shell);
-
+
if (line_status == E_SHELL_LINE_STATUS_ONLINE && status == E_SHELL_LINE_DOWN) {
shell_state = GNOME_Evolution_FORCED_OFFLINE;
e_shell_go_offline (shell, window, shell_state);
@@ -79,38 +101,55 @@ static DBusHandlerResult e_shell_network_monitor (DBusConnection *connection G_G
shell_state = GNOME_Evolution_USER_ONLINE;
e_shell_go_online (shell, window, shell_state);
}
-
+
return DBUS_HANDLER_RESULT_HANDLED;
}
-int e_shell_dbus_initialise (EShellWindow *window)
+static gboolean
+init_dbus (EShellWindow *window)
{
- DBusConnection *connection;
DBusError error;
- g_type_init ();
-
+ if (dbus_connection != NULL)
+ return TRUE;
+
dbus_error_init (&error);
- connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
- if (connection == NULL) {
+ if (!(dbus_connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error))) {
+ g_warning ("could not get system bus: %s\n", error.message);
dbus_error_free (&error);
return FALSE;
}
-
- dbus_connection_setup_with_g_main (connection, NULL);
-
- if (!dbus_connection_add_filter (connection, e_shell_network_monitor, window, NULL))
- return FALSE;
-
- dbus_bus_add_match (connection,
+
+ dbus_connection_setup_with_g_main (dbus_connection, NULL);
+ dbus_connection_set_exit_on_disconnect (dbus_connection, FALSE);
+
+ if (!dbus_connection_add_filter (dbus_connection, e_shell_network_monitor, window, NULL))
+ goto exception;
+
+ dbus_bus_add_match (dbus_connection,
"type='signal',"
"interface='" NM_DBUS_INTERFACE "',"
"sender='" NM_DBUS_SERVICE "',"
"path='" NM_DBUS_PATH "'", &error);
if (dbus_error_is_set (&error)) {
dbus_error_free (&error);
- return FALSE;
+ goto exception;
}
-
+
return TRUE;
+
+ exception:
+
+ dbus_connection_unref (dbus_connection);
+ dbus_connection = NULL;
+
+ return FALSE;
+}
+
+
+int e_shell_dbus_initialise (EShellWindow *window)
+{
+ g_type_init ();
+
+ return init_dbus (window);
}