mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-07-24 10:57:53 +02:00
GDBusInterface: add dup_object() method
This is needed for thread-safety ... yes, it would have been better to make get_object() return a full reference and have something like a peek_object() method return a borrowed reference for C convenience (only a single vfunc would have been needed). But such an ABI break is too late now... Signed-off-by: David Zeuthen <davidz@redhat.com>
This commit is contained in:
@@ -66,11 +66,16 @@ g_dbus_interface_get_info (GDBusInterface *interface_)
|
||||
}
|
||||
|
||||
/**
|
||||
* g_dbus_interface_get_object:
|
||||
* g_dbus_interface_get_object: (skip)
|
||||
* @interface_: An exported D-Bus interface.
|
||||
*
|
||||
* Gets the #GDBusObject that @interface_ belongs to, if any.
|
||||
*
|
||||
* <warning>It is not safe to use the returned object if @interface_
|
||||
* or the returned object is being used from other threads. See
|
||||
* g_dbus_interface_dup_object() for a thread-safe
|
||||
* alternative.</warning>
|
||||
*
|
||||
* Returns: (transfer none): A #GDBusObject or %NULL. The returned
|
||||
* reference belongs to @interface_ and should not be freed.
|
||||
*
|
||||
@@ -83,6 +88,39 @@ g_dbus_interface_get_object (GDBusInterface *interface_)
|
||||
return G_DBUS_INTERFACE_GET_IFACE (interface_)->get_object (interface_);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_dbus_interface_dup_object:
|
||||
* @interface_: An exported D-Bus interface.
|
||||
*
|
||||
* Gets the #GDBusObject that @interface_ belongs to, if any.
|
||||
*
|
||||
* Returns: (transfer full): A #GDBusObject or %NULL. The returned
|
||||
* reference should be freed with g_object_unref().
|
||||
*
|
||||
* Since: 2.32
|
||||
*
|
||||
* Rename to: g_dbus_interface_get_object
|
||||
*/
|
||||
GDBusObject *
|
||||
g_dbus_interface_dup_object (GDBusInterface *interface_)
|
||||
{
|
||||
GDBusObject *ret;
|
||||
g_return_val_if_fail (G_IS_DBUS_INTERFACE (interface_), NULL);
|
||||
if (G_LIKELY (G_DBUS_INTERFACE_GET_IFACE (interface_)->dup_object != NULL))
|
||||
{
|
||||
ret = G_DBUS_INTERFACE_GET_IFACE (interface_)->dup_object (interface_);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_warning ("No dup_object() vfunc on type %s - using get_object() in a way that is not thread-safe.",
|
||||
g_type_name_from_instance ((GTypeInstance *) interface_));
|
||||
ret = G_DBUS_INTERFACE_GET_IFACE (interface_)->get_object (interface_);
|
||||
if (ret != NULL)
|
||||
g_object_ref (ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_dbus_interface_set_object:
|
||||
* @interface_: An exported D-Bus interface.
|
||||
|
Reference in New Issue
Block a user