Commit c9244d28 authored by Thomas Haller's avatar Thomas Haller

shared: add nm_g_type_find_implementing_class_for_property() helper

A helper method, only useful for printf debugging -- and thus
unused in the source-tree.

It is relatively cumbersome to lookup the GType that implements
a property. For example, for NMDeviceBond.driver, it should return
NMDevice (which implements the "driver" property).
parent fc9d6610
......@@ -1413,6 +1413,53 @@ nm_g_object_class_find_property_from_gtype (GType gtype,
/*****************************************************************************/
/**
* nm_g_type_find_implementing_class_for_property:
* @gtype: the GObject type which has a property @pname
* @pname: the name of the property to look up
*
* This is only a helper function for printf debugging. It's not
* used in actual code. Hence, the function just asserts that
* @pname and @gtype arguments are suitable. It cannot fail.
*
* Returns: the most ancestor type of @gtype, that
* implements the property @pname. It means, it
* searches the type hierarchy to find the type
* that added @pname.
*/
GType
nm_g_type_find_implementing_class_for_property (GType gtype,
const char *pname)
{
nm_auto_unref_gtypeclass GObjectClass *klass = NULL;
GParamSpec *pspec;
g_return_val_if_fail (pname, G_TYPE_INVALID);
klass = g_type_class_ref (gtype);
g_return_val_if_fail (G_IS_OBJECT_CLASS (klass), G_TYPE_INVALID);
pspec = g_object_class_find_property (klass, pname);
g_return_val_if_fail (pspec, G_TYPE_INVALID);
gtype = G_TYPE_FROM_CLASS (klass);
while (TRUE) {
nm_auto_unref_gtypeclass GObjectClass *k = NULL;
k = g_type_class_ref (g_type_parent (gtype));
g_return_val_if_fail (G_IS_OBJECT_CLASS (k), G_TYPE_INVALID);
if (g_object_class_find_property (k, pname) != pspec)
return gtype;
gtype = G_TYPE_FROM_CLASS (k);
}
}
/*****************************************************************************/
static void
_str_append_escape (GString *s, char ch)
{
......
......@@ -795,6 +795,11 @@ GParamSpec *nm_g_object_class_find_property_from_gtype (GType gtype,
/*****************************************************************************/
GType nm_g_type_find_implementing_class_for_property (GType gtype,
const char *pname);
/*****************************************************************************/
typedef enum {
NM_UTILS_STR_UTF8_SAFE_FLAG_NONE = 0,
NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL = 0x0001,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment