Wed Oct 28 11:53:24 2009

Asterisk developer's documentation


AstObj2 Containers

Containers are data structures meant to store several objects, and perform various operations on them. Internally, objects are stored in lists, hash tables or other data structures depending on the needs.

Note:
NOTA BENE: at the moment the only container we support is the hash table and its degenerate form, the list.
Operations on container include:

Note that the entire operation is run with the container locked, so noone else can change its content while we work on it. However, we pay this with the fact that doing anything blocking in the callback keeps the container blocked. The mechanism is very flexible because the callback function fn() can do basically anything e.g. counting, deleting records, etc. possibly using arg to store the results.

       struct ao2_container *c = ... // our container
       struct ao2_iterator i;
       void *o;

       i = ao2_iterator_init(c, flags);

       while ( (o = ao2_iterator_next(&i)) ) {
      ... do something on o ...
      ao2_ref(o, -1);
       }

       ao2_iterator_destroy(&i);

The difference with the callback is that the control on how to iterate is left to us.

Containers are ao2 objects themselves, and this is why their implementation is simple too.

Before declaring containers, we need to declare the types of the arguments passed to the constructor - in turn, this requires to define callback and hash functions and their arguments.


Generated on Wed Oct 28 11:53:24 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6