aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@novell.com>2006-04-18 23:28:45 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2006-04-18 23:28:45 +0800
commit9e929ed567809d60a9eabf29289d72ccd2325e11 (patch)
treeb2a528b722cfdee20669f5a35221bd0ab5a3fb90 /plugins
parentefa26d3275772e4d7c8db1a78039fb7741b0f1a1 (diff)
downloadgsoc2013-evolution-9e929ed567809d60a9eabf29289d72ccd2325e11.tar
gsoc2013-evolution-9e929ed567809d60a9eabf29289d72ccd2325e11.tar.gz
gsoc2013-evolution-9e929ed567809d60a9eabf29289d72ccd2325e11.tar.bz2
gsoc2013-evolution-9e929ed567809d60a9eabf29289d72ccd2325e11.tar.lz
gsoc2013-evolution-9e929ed567809d60a9eabf29289d72ccd2325e11.tar.xz
gsoc2013-evolution-9e929ed567809d60a9eabf29289d72ccd2325e11.tar.zst
gsoc2013-evolution-9e929ed567809d60a9eabf29289d72ccd2325e11.zip
Don't try and send a dbus message if the bus is down.
2006-04-18 Jeffrey Stedfast <fejj@novell.com> * new-mail-notify.c (org_gnome_message_reading_notify): Don't try and send a dbus message if the bus is down. (org_gnome_new_mail_notify): Same. (init_dbus): New function to init the dbus connection and setup handlers for when the bus gets unexpectedly disconnected. (e_plugin_lib_enable): When the plugin gets disabled, unref the dbus connection and reset it back to NULL. svn path=/trunk/; revision=31827
Diffstat (limited to 'plugins')
-rw-r--r--plugins/new-mail-notify/ChangeLog21
-rw-r--r--plugins/new-mail-notify/new-mail-notify.c107
2 files changed, 91 insertions, 37 deletions
diff --git a/plugins/new-mail-notify/ChangeLog b/plugins/new-mail-notify/ChangeLog
index 98b6014166..385c54446b 100644
--- a/plugins/new-mail-notify/ChangeLog
+++ b/plugins/new-mail-notify/ChangeLog
@@ -1,3 +1,13 @@
+2006-04-18 Jeffrey Stedfast <fejj@novell.com>
+
+ * new-mail-notify.c (org_gnome_message_reading_notify): Don't try
+ and send a dbus message if the bus is down.
+ (org_gnome_new_mail_notify): Same.
+ (init_dbus): New function to init the dbus connection and setup
+ handlers for when the bus gets unexpectedly disconnected.
+ (e_plugin_lib_enable): When the plugin gets disabled, unref the
+ dbus connection and reset it back to NULL.
+
2005-08-23 Not Zed <NotZed@Ximian.com>
* new-mail-notify.c: forward-define e_plugin_lib_enable, remove
@@ -5,12 +15,11 @@
(send_dbus_message): remove spurious check for bus==NULL.
2005-07-11 Vivek Jain <jvivek@novell.com>
-
- * new-mail-notify.c :(send_dbus_message)
- check whether memory could be allocated. Return if the
- message is NULL so that we don't unref it again, will save crash.
- **Fixes #274329 sort of bugs, in case reported even after
- david's fix.
+
+ * new-mail-notify.c (send_dbus_message): check whether memory
+ could be allocated. Return if the message is NULL so that we don't
+ unref it again, will save crash. **Fixes #274329 sort of bugs, in
+ case reported even after david's fix.
2005-05-11 Not Zed <NotZed@Ximian.com>
diff --git a/plugins/new-mail-notify/new-mail-notify.c b/plugins/new-mail-notify/new-mail-notify.c
index 34b4fd95e0..d2af002338 100644
--- a/plugins/new-mail-notify/new-mail-notify.c
+++ b/plugins/new-mail-notify/new-mail-notify.c
@@ -35,24 +35,24 @@
#define DBUS_PATH "/org/gnome/evolution/mail/newmail"
#define DBUS_INTERFACE "org.gnome.evolution.mail.dbus.Signal"
+int e_plugin_lib_enable (EPluginLib *ep, int enable);
void org_gnome_new_mail_notify (EPlugin *ep, EMEventTargetFolder *t);
void org_gnome_message_reading_notify (EPlugin *ep, EMEventTargetMessage *t);
-static DBusConnection *bus;
+static gboolean init_dbus (void);
+
+static DBusConnection *bus = NULL;
+static gboolean enabled = FALSE;
static void
-send_dbus_message (const char *message_name, const char *data)
+send_dbus_message (const char *name, const char *data)
{
DBusMessage *message;
-
+
/* Create a new message on the DBUS_INTERFACE */
- message = dbus_message_new_signal (DBUS_PATH,
- DBUS_INTERFACE,
- message_name);
-
- if (message == NULL)
+ if (!(message = dbus_message_new_signal (DBUS_PATH, DBUS_INTERFACE, name)))
return;
-
+
/* Appends the data as an argument to the message */
dbus_message_append_args (message,
#if DBUS_VERSION >= 310
@@ -63,10 +63,8 @@ send_dbus_message (const char *message_name, const char *data)
DBUS_TYPE_INVALID);
/* Sends the message */
- dbus_connection_send (bus,
- message,
- NULL);
-
+ dbus_connection_send (bus, message, NULL);
+
/* Frees the message */
dbus_message_unref (message);
}
@@ -74,39 +72,86 @@ send_dbus_message (const char *message_name, const char *data)
void
org_gnome_message_reading_notify (EPlugin *ep, EMEventTargetMessage *t)
{
- send_dbus_message ("MessageReading", t->folder->name);
+ if (bus != NULL)
+ send_dbus_message ("MessageReading", t->folder->name);
}
void
org_gnome_new_mail_notify (EPlugin *ep, EMEventTargetFolder *t)
{
- send_dbus_message ("Newmail", t->uri);
+ if (bus != NULL)
+ send_dbus_message ("Newmail", t->uri);
+}
+
+
+static gboolean
+reinit_dbus (gpointer user_data)
+{
+ if (!enabled || init_dbus ())
+ return FALSE;
+
+ /* keep trying to re-establish dbus connection */
+
+ return TRUE;
+}
+
+static DBusHandlerResult
+filter_function (DBusConnection *connection, DBusMessage *message, void *user_data)
+{
+ if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected") &&
+ strcmp (dbus_message_get_path (message), DBUS_PATH_LOCAL) == 0) {
+ dbus_connection_unref (bus);
+ bus = NULL;
+
+ g_timeout_add (3000, reinit_dbus, NULL);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static gboolean
+init_dbus (void)
+{
+ DBusError error;
+
+ if (bus != NULL)
+ return TRUE;
+
+ dbus_error_init (&error);
+ if (!(bus = dbus_bus_get (DBUS_BUS_SESSION, &error))) {
+ g_warning ("could not get system bus: %s\n", error.message);
+ dbus_error_free (&error);
+ return FALSE;
+ }
+
+ dbus_connection_setup_with_g_main (bus, NULL);
+ dbus_connection_set_exit_on_disconnect (bus, FALSE);
+
+ dbus_connection_add_filter (bus, filter_function, NULL, NULL);
+
+ return TRUE;
}
-int e_plugin_lib_enable (EPluginLib *ep, int enable);
int
e_plugin_lib_enable (EPluginLib *ep, int enable)
{
if (enable) {
- DBusError error;
-
- dbus_error_init (&error);
- bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
- if (!bus) {
- g_warning("Failed to connect to the D-BUS daemon: %s\n", error.message);
-
- /* Could not determine address of the D-BUS session bus */
- /* Plugin will be disabled */
- dbus_error_free (&error);
+ if (!init_dbus ())
return -1;
+
+ enabled = TRUE;
+ } else {
+ if (bus != NULL) {
+ dbus_connection_unref (bus);
+ bus = NULL;
}
-
- /* Set up this connection to work in a GLib event loop */
- dbus_connection_setup_with_g_main (bus, NULL);
+
+ enabled = FALSE;
}
- /* else unref the bus if set? */
-
+
return 0;
}