Re: [g-a-devel] Need ATK experienced help



On, Wed Sep 02, 2009, Li Yuan wrote:

> Hi Quiring,
> 
> How did you implement ref_child function? Is there a cache?

The AtkObjectClass ref_child function hook looks like this: 

void
atkobjectclass_init (AtkObjectClass *class)
{
    debug ("Hooking AtkObjectClass interfaces.\n");

    class->get_n_children = _class_get_n_children;
    class->ref_child = _class_ref_child;
    class->get_index_in_parent = _class_get_index_in_parent;
    class->ref_state_set = _class_ref_state_set;
}

static AtkObject*
_class_ref_child (AtkObject *obj, int i)
{
    AtkObject *val = NULL;
    GList *list = NULL;

    debug ("_class_ref_child\n");

    list = g_object_get_data (G_OBJECT (obj), PAPI_CHILDREN);
    if (list)
    {
        val = g_list_nth_data (list, (guint) i);
        if (!val)
            return NULL;
    }
    if (val)
        g_object_ref (val);
    return val;
}

AtkObject instances are created with an initial refcount of 1:

        ...
        if (ifaces == IFACE_INVALID)
            self->obj = g_object_new (ATK_TYPE_OBJECT, NULL);
        else
            self->obj = g_object_new (atktype_get_type (ifaces), NULL);

where self->obj is a AtkObject* pointer and ifaces/IFACE_INVALID a bitwise
AtkInterfaceType combination.

AtkObject instances are valid as long as there is an encapsulating
Python object, so the ref count never should go down within the
application code in an unexpected or unintended manner.

Regards
Marcus

Attachment: pgpeVkK3wKs6Z.pgp
Description: PGP signature



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