Add private _g_bus_get_singleton_if_exists() function

This is used by g_test_dbus_down() to ensure the GDBusConnection
gets disposed, but not create one if the singleton already got
disposed.

https://bugzilla.gnome.org/show_bug.cgi?id=672985
This commit is contained in:
Xavier Claessens 2012-04-06 14:51:09 +02:00
parent 98569e53e3
commit 2e3d50631f
2 changed files with 22 additions and 0 deletions

View File

@ -6769,6 +6769,25 @@ get_uninitialized_connection (GBusType bus_type,
return ret;
}
/* May be called from any thread. Must not hold message_bus_lock. */
GDBusConnection *
_g_bus_get_singleton_if_exists (GBusType bus_type)
{
GWeakRef *singleton;
GDBusConnection *ret = NULL;
G_LOCK (message_bus_lock);
singleton = message_bus_get_singleton (bus_type, NULL);
if (singleton == NULL)
goto out;
ret = g_weak_ref_get (singleton);
out:
G_UNLOCK (message_bus_lock);
return ret;
}
/**
* g_bus_get_sync:
* @bus_type: A #GBusType.

View File

@ -143,6 +143,9 @@ void _g_dbus_object_proxy_add_interface (GDBusObjectProxy *proxy,
void _g_dbus_object_proxy_remove_interface (GDBusObjectProxy *proxy,
const gchar *interface_name);
/* Implemented in gdbusconnection.c */
GDBusConnection *_g_bus_get_singleton_if_exists (GBusType bus_type);
G_END_DECLS
#endif /* __G_DBUS_PRIVATE_H__ */