mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-09-27 17:52:58 +02:00
gsocketconnectable: Add a to_string() virtual method
Add string serialisation functions for GNetworkAddress, GSocketAddress, GUnixSocketAddress, GInetSocketAddress, GNetworkService and GSocketConnectable. These are intended for use in debug output, not for serialisation in network or disc protocols. They are implemented as a new virtual method on GSocketConnectable: g_socket_connectable_to_string(). GInetSocketAddress and GUnixSocketAddress now implement GSocketConnectable directly to implement to_string(). Previously they implemented it via their abstract parent class, GSocketAddress. https://bugzilla.gnome.org/show_bug.cgi?id=737116
This commit is contained in:
@@ -146,3 +146,34 @@ g_socket_connectable_proxy_enumerate (GSocketConnectable *connectable)
|
||||
else
|
||||
return (* iface->enumerate) (connectable);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_socket_connectable_to_string:
|
||||
* @connectable: a #GSocketConnectable
|
||||
*
|
||||
* Format a #GSocketConnectable as a string. This is a human-readable format for
|
||||
* use in debugging output, and is not a stable serialization format. It is not
|
||||
* suitable for use in user interfaces as it exposes too much information for a
|
||||
* user.
|
||||
*
|
||||
* If the #GSocketConnectable implementation does not support string formatting,
|
||||
* the implementation’s type name will be returned as a fallback.
|
||||
*
|
||||
* Returns: (transfer full): the formatted string
|
||||
*
|
||||
* Since: 2.48.0
|
||||
*/
|
||||
gchar *
|
||||
g_socket_connectable_to_string (GSocketConnectable *connectable)
|
||||
{
|
||||
GSocketConnectableIface *iface;
|
||||
|
||||
g_return_val_if_fail (G_IS_SOCKET_CONNECTABLE (connectable), NULL);
|
||||
|
||||
iface = G_SOCKET_CONNECTABLE_GET_IFACE (connectable);
|
||||
|
||||
if (iface->to_string != NULL)
|
||||
return iface->to_string (connectable);
|
||||
else
|
||||
return g_strdup (G_OBJECT_TYPE_NAME (connectable));
|
||||
}
|
||||
|
Reference in New Issue
Block a user