[libnotify] lazily start the daemon



commit 3dc04fac9093e14476450d26d0e09472b1c6759b
Author: Martin Pitt <martin pitt ubuntu com>
Date:   Tue Feb 23 22:25:34 2010 +0100

    lazily start the daemon
    
    notify_init() caused the daemon to be D-Bus activated already, even if the
    program that calls it doesn't send an actual notification for a long time (or
    potentially not at all).
    
    In order to optimize desktop startup speed, and to avoid unnecessary
    processes, launch the daemon on demand only.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=610880

 libnotify/notify.c |   90 +++++++++++++++++++++++++++-------------------------
 1 files changed, 47 insertions(+), 43 deletions(-)
---
diff --git a/libnotify/notify.c b/libnotify/notify.c
index b1455a2..ccc3ed3 100644
--- a/libnotify/notify.c
+++ b/libnotify/notify.c
@@ -77,9 +77,6 @@ _notify_update_spec_version (void)
 gboolean
 notify_init (const char *app_name)
 {
-        GError          *error = NULL;
-        DBusGConnection *bus = NULL;
-
         g_return_val_if_fail (app_name != NULL, FALSE);
         g_return_val_if_fail (*app_name != '\0', FALSE);
 
@@ -90,46 +87,6 @@ notify_init (const char *app_name)
 
         g_type_init ();
 
-        bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
-
-        if (error != NULL) {
-                g_message ("Unable to get session bus: %s", error->message);
-                g_error_free (error);
-                return FALSE;
-        }
-
-        _proxy = dbus_g_proxy_new_for_name (bus,
-                                            NOTIFY_DBUS_NAME,
-                                            NOTIFY_DBUS_CORE_OBJECT,
-                                            NOTIFY_DBUS_CORE_INTERFACE);
-        dbus_g_connection_unref (bus);
-
-        dbus_g_object_register_marshaller (notify_marshal_VOID__UINT_UINT,
-                                           G_TYPE_NONE,
-                                           G_TYPE_UINT,
-                                           G_TYPE_UINT, G_TYPE_INVALID);
-
-        dbus_g_object_register_marshaller (notify_marshal_VOID__UINT_STRING,
-                                           G_TYPE_NONE,
-                                           G_TYPE_UINT,
-                                           G_TYPE_STRING, G_TYPE_INVALID);
-
-        dbus_g_proxy_add_signal (_proxy,
-                                 "NotificationClosed",
-                                 G_TYPE_UINT,
-                                 G_TYPE_UINT,
-                                 G_TYPE_INVALID);
-        dbus_g_proxy_add_signal (_proxy,
-                                 "ActionInvoked",
-                                 G_TYPE_UINT,
-                                 G_TYPE_STRING,
-                                 G_TYPE_INVALID);
-
-        if (!_notify_update_spec_version ()) {
-               g_message ("Error getting spec version");
-               return FALSE;
-        }
-
         _initted = TRUE;
 
         return TRUE;
@@ -205,6 +162,53 @@ _notify_get_dbus_g_conn (void)
 DBusGProxy *
 _notify_get_g_proxy (void)
 {
+        GError          *error = NULL;
+        DBusGConnection *bus = NULL;
+
+        if (_proxy != NULL)
+                return _proxy;
+
+        /* lazily initialize D-Bus connection */
+        bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+
+        if (error != NULL) {
+                g_message ("Unable to get session bus: %s", error->message);
+                g_error_free (error);
+                return NULL;
+        }
+
+        _proxy = dbus_g_proxy_new_for_name (bus,
+                                            NOTIFY_DBUS_NAME,
+                                            NOTIFY_DBUS_CORE_OBJECT,
+                                            NOTIFY_DBUS_CORE_INTERFACE);
+        dbus_g_connection_unref (bus);
+
+        dbus_g_object_register_marshaller (notify_marshal_VOID__UINT_UINT,
+                                           G_TYPE_NONE,
+                                           G_TYPE_UINT,
+                                           G_TYPE_UINT, G_TYPE_INVALID);
+
+        dbus_g_object_register_marshaller (notify_marshal_VOID__UINT_STRING,
+                                           G_TYPE_NONE,
+                                           G_TYPE_UINT,
+                                           G_TYPE_STRING, G_TYPE_INVALID);
+
+        dbus_g_proxy_add_signal (_proxy,
+                                 "NotificationClosed",
+                                 G_TYPE_UINT,
+                                 G_TYPE_UINT,
+                                 G_TYPE_INVALID);
+        dbus_g_proxy_add_signal (_proxy,
+                                 "ActionInvoked",
+                                 G_TYPE_UINT,
+                                 G_TYPE_STRING,
+                                 G_TYPE_INVALID);
+
+        if (!_notify_update_spec_version ()) {
+               g_message ("Error getting spec version");
+               return NULL;
+        }
+
         return _proxy;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]