Asterisk - The Open Source Telephony Project  18.5.0
Macros
astobj.h File Reference

Object Model for Asterisk. More...

#include "asterisk/lock.h"
Include dependency graph for astobj.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define __ASTOBJ_HASH(type, hashes)   type *next[1]
 
#define ASTOBJ_COMPONENTS(type)
 Add ASTOBJ components to a struct (with locking support). More...
 
#define ASTOBJ_COMPONENTS_FULL(type, namelen, hashes)
 Add ASTOBJ components to a struct (with locking support). More...
 
#define ASTOBJ_COMPONENTS_NOLOCK(type)   ASTOBJ_COMPONENTS_NOLOCK_FULL(type,ASTOBJ_DEFAULT_NAMELEN,1)
 Add ASTOBJ components to a struct (without locking support). More...
 
#define ASTOBJ_COMPONENTS_NOLOCK_FULL(type, namelen, hashes)
 Add ASTOBJ components to a struct (without locking support). More...
 
#define ASTOBJ_CONTAINER_COMPONENTS(type)
 Create a container for ASTOBJs (with locking support). More...
 
#define ASTOBJ_CONTAINER_COMPONENTS_NOLOCK(type)   ASTOBJ_CONTAINER_COMPONENTS_NOLOCK_FULL(type,1,ASTOBJ_DEFAULT_BUCKETS)
 Create a container for ASTOBJs (without locking support). More...
 
#define ASTOBJ_CONTAINER_COMPONENTS_NOLOCK_FULL(type, hashes, buckets)   type *head
 Create a container for ASTOBJs (without locking support). More...
 
#define ASTOBJ_CONTAINER_DESTROY(container)   ASTOBJ_CONTAINER_DESTROY_FULL(container,1,ASTOBJ_DEFAULT_BUCKETS)
 Destroy a container. More...
 
#define ASTOBJ_CONTAINER_DESTROY_FULL(container, hashes, buckets)
 Destroy a container. More...
 
#define ASTOBJ_CONTAINER_DESTROYALL(container, destructor)
 Empty a container. More...
 
#define ASTOBJ_CONTAINER_DUMP(fd, s, slen, container)   ASTOBJ_CONTAINER_TRAVERSE(container, 1, do { ASTOBJ_DUMP(s,slen,iterator); ast_cli(fd, "%s", s); } while(0))
 Dump information about all the objects in a container to a file descriptor. More...
 
#define ASTOBJ_CONTAINER_FIND(container, namestr)
 Find an object in a container. More...
 
#define ASTOBJ_CONTAINER_FIND_FULL(container, data, field, hashfunc, hashoffset, comparefunc)
 Find an object in a container. More...
 
#define ASTOBJ_CONTAINER_FIND_UNLINK(container, namestr)
 Find and remove an object from a container. More...
 
#define ASTOBJ_CONTAINER_FIND_UNLINK_FULL(container, data, field, hashfunc, hashoffset, comparefunc)
 Find and remove an object in a container. More...
 
#define ASTOBJ_CONTAINER_INIT(container)   ASTOBJ_CONTAINER_INIT_FULL(container,1,ASTOBJ_DEFAULT_BUCKETS)
 Initialize a container. More...
 
#define ASTOBJ_CONTAINER_INIT_FULL(container, hashes, buckets)
 Initialize a container. More...
 
#define ASTOBJ_CONTAINER_LINK(container, newobj)   ASTOBJ_CONTAINER_LINK_FULL(container,newobj,(newobj)->name,name,ASTOBJ_DEFAULT_HASH,0,strcasecmp)
 Add an object to a container. More...
 
#define ASTOBJ_CONTAINER_LINK_END(container, newobj)
 Add an object to the end of a container. More...
 
#define ASTOBJ_CONTAINER_LINK_FULL(container, newobj, data, field, hashfunc, hashoffset, comparefunc)
 Add an object to a container. More...
 
#define ASTOBJ_CONTAINER_LINK_START(container, newobj)
 Add an object to the front of a container. More...
 
#define ASTOBJ_CONTAINER_MARKALL(container)   ASTOBJ_CONTAINER_TRAVERSE(container, 1, ASTOBJ_MARK(iterator))
 Mark all the objects in a container. More...
 
#define ASTOBJ_CONTAINER_PRUNE_MARKED(container, destructor)
 Prune marked objects from a container. More...
 
#define ASTOBJ_CONTAINER_RDLOCK(container)   ast_mutex_lock(&(container)->_lock)
 Lock an ASTOBJ_CONTAINER for reading. More...
 
#define ASTOBJ_CONTAINER_TRAVERSE(container, continue, eval)
 Iterate through the objects in a container. More...
 
#define ASTOBJ_CONTAINER_UNLINK(container, obj)
 Remove an object from a container. More...
 
#define ASTOBJ_CONTAINER_UNLINK_START(container)
 Remove an object from the front of a container. More...
 
#define ASTOBJ_CONTAINER_UNLOCK(container)   ast_mutex_unlock(&(container)->_lock)
 Unlock an ASTOBJ_CONTAINER. More...
 
#define ASTOBJ_CONTAINER_UNMARKALL(container)   ASTOBJ_CONTAINER_TRAVERSE(container, 1, ASTOBJ_UNMARK(iterator))
 Unmark all the objects in a container. More...
 
#define ASTOBJ_CONTAINER_WRLOCK(container)   ast_mutex_lock(&(container)->_lock)
 Lock an ASTOBJ_CONTAINER for writing. More...
 
#define ASTOBJ_DEFAULT_BUCKETS   256
 
#define ASTOBJ_DEFAULT_HASH   ast_strhash
 
#define ASTOBJ_DEFAULT_NAMELEN   80
 
#define ASTOBJ_DUMP(s, slen, obj)   snprintf((s),(slen),"name: %s\nobjflags: %u\nrefcount: %u\n\n", (obj)->name, (obj)->objflags, (obj)->refcount);
 Dump information about an object into a string. More...
 
#define ASTOBJ_FLAG_MARKED   (1 << 0) /* Object has been marked for future operation */
 
#define ASTOBJ_INIT(object)
 Initialize an object. More...
 
#define ASTOBJ_MARK(object)
 Mark an ASTOBJ by adding the ASTOBJ_FLAG_MARKED flag to its objflags mask. More...
 
#define ASTOBJ_RDLOCK(object)   ast_mutex_lock(&(object)->_lock)
 Lock an ASTOBJ for reading. More...
 
#define ASTOBJ_REF(object)
 Increment an object reference count. More...
 
#define ASTOBJ_TRYWRLOCK(object)   ast_mutex_trylock(&(object)->_lock)
 
#define ASTOBJ_UNLOCK(object)   ast_mutex_unlock(&(object)->_lock)
 Unlock a locked object. More...
 
#define ASTOBJ_UNMARK(object)
 Unmark an ASTOBJ by subtracting the ASTOBJ_FLAG_MARKED flag from its objflags mask. More...
 
#define ASTOBJ_UNREF(object, destructor)
 Decrement the reference count on an object. More...
 
#define ASTOBJ_WRLOCK(object)   ast_mutex_lock(&(object)->_lock)
 Lock an ASTOBJ for writing. More...
 

Detailed Description

Object Model for Asterisk.

A set of macros implementing objects and containers. Macros are used for maximum performance, to support multiple inheritance, and to be easily integrated into existing structures without additional malloc calls, etc.

Deprecated:
Use astobj2.h instead

These macros expect to operate on two different object types, ASTOBJs and ASTOBJ_CONTAINERs. These are not actual types, as any struct can be converted into an ASTOBJ compatible object or container using the supplied macros.

Sample Usage:

struct sample_object {
ASTOBJ_COMPONENTS(struct sample_object);
};
struct sample_container {
ASTOBJ_CONTAINER_COMPONENTS(struct sample_object);
} super_container;
void sample_object_destroy(struct sample_object *obj)
{
free(obj);
}
int init_stuff()
{
struct sample_object *obj1;
struct sample_object *found_obj;
obj1 = malloc(sizeof(struct sample_object));
ASTOBJ_CONTAINER_INIT(&super_container);
ASTOBJ_INIT(obj1);
ast_copy_string(obj1->name, "obj1", sizeof(obj1->name));
ASTOBJ_CONTAINER_LINK(&super_container, obj1);
found_obj = ASTOBJ_CONTAINER_FIND(&super_container, "obj1");
if(found_obj) {
printf("Found object: %s", found_obj->name);
ASTOBJ_UNREF(found_obj,sample_object_destroy);
}
ASTOBJ_CONTAINER_DESTROYALL(&super_container,sample_object_destroy);
ASTOBJ_CONTAINER_DESTROY(&super_container);
return 0;
}

Definition in file astobj.h.

Macro Definition Documentation

◆ __ASTOBJ_HASH

#define __ASTOBJ_HASH (   type,
  hashes 
)    type *next[1]

Definition at line 117 of file astobj.h.

◆ ASTOBJ_COMPONENTS

#define ASTOBJ_COMPONENTS (   type)
Value:
ast_mutex_t _lock;
static const char type[]
Definition: chan_ooh323.c:109
#define ASTOBJ_COMPONENTS_NOLOCK(type)
Add ASTOBJ components to a struct (without locking support).
Definition: astobj.h:158

Add ASTOBJ components to a struct (with locking support).

Parameters
typeThe datatype of the object.

This macro works like ASTOBJ_COMPONENTS_NOLOCK() except it includes locking support.

Sample Usage:

struct sample_struct {
ASTOBJ_COMPONENTS(struct sample_struct);
};

Definition at line 175 of file astobj.h.

◆ ASTOBJ_COMPONENTS_FULL

#define ASTOBJ_COMPONENTS_FULL (   type,
  namelen,
  hashes 
)
Value:
ast_mutex_t _lock;
static const char type[]
Definition: chan_ooh323.c:109
#define ASTOBJ_COMPONENTS_NOLOCK_FULL(type, namelen, hashes)
Add ASTOBJ components to a struct (without locking support).
Definition: astobj.h:138

Add ASTOBJ components to a struct (with locking support).

Parameters
typeThe datatype of the object.
namelenThe length to make the name char array.
hashesThe number of containers the object can be present in.

This macro adds components to a struct to make it an ASTOBJ and includes support for locking.

Sample Usage:

struct sample_struct {
ASTOBJ_COMPONENTS_FULL(struct sample_struct,1,1);
};

Definition at line 195 of file astobj.h.

◆ ASTOBJ_COMPONENTS_NOLOCK

#define ASTOBJ_COMPONENTS_NOLOCK (   type)    ASTOBJ_COMPONENTS_NOLOCK_FULL(type,ASTOBJ_DEFAULT_NAMELEN,1)

Add ASTOBJ components to a struct (without locking support).

Parameters
typeThe datatype of the object.

This macro works like ASTOBJ_COMPONENTS_NOLOCK_FULL() except it only accepts a type and uses default values for namelen and hashes.

Sample Usage:

struct sample_struct_componets {
ASTOBJ_COMPONENTS_NOLOCK(struct sample_struct);
};

Definition at line 158 of file astobj.h.

◆ ASTOBJ_COMPONENTS_NOLOCK_FULL

#define ASTOBJ_COMPONENTS_NOLOCK_FULL (   type,
  namelen,
  hashes 
)
Value:
char name[namelen]; \
unsigned int refcount; \
unsigned int objflags; \
__ASTOBJ_HASH(type,hashes)
static const char type[]
Definition: chan_ooh323.c:109
static const char name[]
Definition: cdr_mysql.c:74

Add ASTOBJ components to a struct (without locking support).

Parameters
typeThe datatype of the object.
namelenThe length to make the name char array.
hashesThe number of containers the object can be present in.

This macro adds components to a struct to make it an ASTOBJ. This macro differs from ASTOBJ_COMPONENTS_FULL in that it does not create a mutex for locking.

Sample Usage:

struct sample_struct {
ASTOBJ_COMPONENTS_NOLOCK_FULL(struct sample_struct,1,1);
};

Definition at line 138 of file astobj.h.

◆ ASTOBJ_CONTAINER_COMPONENTS

#define ASTOBJ_CONTAINER_COMPONENTS (   type)
Value:
ast_mutex_t _lock; \
ASTOBJ_CONTAINER_COMPONENTS_NOLOCK(type)
static const char type[]
Definition: chan_ooh323.c:109
Structure for mutex and tracking information.
Definition: lock.h:135

Create a container for ASTOBJs (with locking support).

Parameters
typeThe type of objects the container will hold.

This macro is used to create a container for ASTOBJs with locking support.

Sample Usage:

struct sample_struct_container {
ASTOBJ_CONTAINER_COMPONENTS(struct sample_struct);
};

Definition at line 731 of file astobj.h.

◆ ASTOBJ_CONTAINER_COMPONENTS_NOLOCK

#define ASTOBJ_CONTAINER_COMPONENTS_NOLOCK (   type)    ASTOBJ_CONTAINER_COMPONENTS_NOLOCK_FULL(type,1,ASTOBJ_DEFAULT_BUCKETS)

Create a container for ASTOBJs (without locking support).

Parameters
typeThe type of objects the container will hold.

This macro is used to create a container for ASTOBJs without locking support.

Sample Usage:

struct sample_struct_nolock_container {
ASTOBJ_CONTAINER_COMPONENTS_NOLOCK(struct sample_struct);
};

Definition at line 714 of file astobj.h.

◆ ASTOBJ_CONTAINER_COMPONENTS_NOLOCK_FULL

#define ASTOBJ_CONTAINER_COMPONENTS_NOLOCK_FULL (   type,
  hashes,
  buckets 
)    type *head

Create a container for ASTOBJs (without locking support).

Parameters
typeThe type of objects the container will hold.
hashesCurrently unused.
bucketsCurrently unused.

This macro is used to create a container for ASTOBJs without locking support.

Sample Usage:

struct sample_struct_nolock_container {
ASTOBJ_CONTAINER_COMPONENTS_NOLOCK_FULL(struct sample_struct,1,1);
};

Definition at line 308 of file astobj.h.

◆ ASTOBJ_CONTAINER_DESTROY

#define ASTOBJ_CONTAINER_DESTROY (   container)    ASTOBJ_CONTAINER_DESTROY_FULL(container,1,ASTOBJ_DEFAULT_BUCKETS)

Destroy a container.

Parameters
containerA pointer to the container to destory.

This macro frees up resources used by a container. It does not operate on the objects in the container. To unlink the objects from the container use ASTOBJ_CONTAINER_DESTROYALL().

Note
This macro should only be used on containers with locking support.

Definition at line 767 of file astobj.h.

Referenced by ast_netsock_release().

◆ ASTOBJ_CONTAINER_DESTROY_FULL

#define ASTOBJ_CONTAINER_DESTROY_FULL (   container,
  hashes,
  buckets 
)
Value:
do { \
ast_mutex_destroy(&(container)->_lock); \
} while(0)
struct ao2_container * container
Definition: res_fax.c:502

Destroy a container.

Parameters
containerA pointer to the container to destroy.
hashesCurrently unused.
bucketsCurrently unused.

This macro frees up resources used by a container. It does not operate on the objects in the container. To unlink the objects from the container use ASTOBJ_CONTAINER_DESTROYALL().

Note
This macro should only be used on containers with locking support.

Definition at line 349 of file astobj.h.

◆ ASTOBJ_CONTAINER_DESTROYALL

#define ASTOBJ_CONTAINER_DESTROYALL (   container,
  destructor 
)

Empty a container.

Parameters
containerA pointer to the container to operate on.
destructorA destructor function to call on each object.

This macro loops through a container removing all the items from it using ASTOBJ_UNREF(). This does not destroy the container itself, use ASTOBJ_CONTAINER_DESTROY() for that.

Note
If any object in the container is only referenced by the container, the destructor will be called for that object once it has been removed.

Definition at line 455 of file astobj.h.

Referenced by ast_netsock_release().

◆ ASTOBJ_CONTAINER_DUMP

#define ASTOBJ_CONTAINER_DUMP (   fd,
  s,
  slen,
  container 
)    ASTOBJ_CONTAINER_TRAVERSE(container, 1, do { ASTOBJ_DUMP(s,slen,iterator); ast_cli(fd, "%s", s); } while(0))

Dump information about all the objects in a container to a file descriptor.

Parameters
fdThe file descriptor to write to.
sA string buffer, same as ASTOBJ_DUMP().
slenThe length of s, same as ASTOBJ_DUMP().
containerA pointer to the container to dump.

This macro dumps a text representation of the name, objectflags, and refcount fields of all the objects in a container to the specified file descriptor.

Definition at line 816 of file astobj.h.

◆ ASTOBJ_CONTAINER_FIND

#define ASTOBJ_CONTAINER_FIND (   container,
  namestr 
)

Find an object in a container.

Parameters
containerA pointer to the container to search.
namestrThe name to search for.

Use this function to find an object with the specfied name in a container.

Note
When the returned object is no longer in use, ASTOBJ_UNREF() should be used to free the additional reference created by this macro.
Returns
A new reference to the object located or NULL if nothing is found.

Definition at line 403 of file astobj.h.

◆ ASTOBJ_CONTAINER_FIND_FULL

#define ASTOBJ_CONTAINER_FIND_FULL (   container,
  data,
  field,
  hashfunc,
  hashoffset,
  comparefunc 
)

Find an object in a container.

Parameters
containerA pointer to the container to search.
dataThe data to search for.
fieldThe field/member of the container's objects to search.
hashfuncThe hash function to use, currently not implemented.
hashoffsetThe hash offset to use, currently not implemented.
comparefuncThe function used to compare the field and data values.

This macro iterates through a container passing the specified field and data elements to the specified comparefunc. The function should return 0 when a match is found.

Note
When the returned object is no longer in use, ASTOBJ_UNREF() should be used to free the additional reference created by this macro.
Returns
A pointer to the object located or NULL if nothing is found.

Definition at line 430 of file astobj.h.

◆ ASTOBJ_CONTAINER_FIND_UNLINK

#define ASTOBJ_CONTAINER_FIND_UNLINK (   container,
  namestr 
)

Find and remove an object from a container.

Parameters
containerA pointer to the container to operate on.
namestrThe name of the object to remove.

This macro iterates through a container and removes the first object with the specfied name from the container.

Note
This macro does not destroy any objects, it simply unlinks them. No destructors are called.
Returns
The container's reference to the removed object or NULL if no matching object was found.

Definition at line 514 of file astobj.h.

◆ ASTOBJ_CONTAINER_FIND_UNLINK_FULL

#define ASTOBJ_CONTAINER_FIND_UNLINK_FULL (   container,
  data,
  field,
  hashfunc,
  hashoffset,
  comparefunc 
)

Find and remove an object in a container.

Parameters
containerA pointer to the container to search.
dataThe data to search for.
fieldThe field/member of the container's objects to search.
hashfuncThe hash function to use, currently not implemented.
hashoffsetThe hash offset to use, currently not implemented.
comparefuncThe function used to compare the field and data values.

This macro iterates through a container passing the specified field and data elements to the specified comparefunc. The function should return 0 when a match is found. If a match is found it is removed from the list.

Note
This macro does not destroy any objects, it simply unlinks them. No destructors are called.
Returns
The container's reference to the removed object or NULL if no match was found.

Definition at line 553 of file astobj.h.

◆ ASTOBJ_CONTAINER_INIT

#define ASTOBJ_CONTAINER_INIT (   container)    ASTOBJ_CONTAINER_INIT_FULL(container,1,ASTOBJ_DEFAULT_BUCKETS)

Initialize a container.

Parameters
containerA pointer to the container to initialize.

This macro initializes a container. It should only be used on containers that support locking.

Sample Usage:

struct sample_struct_container {
ASTOBJ_CONTAINER_COMPONENTS(struct sample_struct);
int func()
{
}

Definition at line 754 of file astobj.h.

Referenced by ast_netsock_init().

◆ ASTOBJ_CONTAINER_INIT_FULL

#define ASTOBJ_CONTAINER_INIT_FULL (   container,
  hashes,
  buckets 
)
Value:
do { \
ast_mutex_init(&(container)->_lock); \
} while(0)
struct ao2_container * container
Definition: res_fax.c:502

Initialize a container.

Parameters
containerA pointer to the container to initialize.
hashesCurrently unused.
bucketsCurrently unused.

This macro initializes a container. It should only be used on containers that support locking.

Sample Usage:

struct sample_struct_container {
ASTOBJ_CONTAINER_COMPONENTS_FULL(struct sample_struct,1,1);
int func()
{
}

Definition at line 332 of file astobj.h.

◆ ASTOBJ_CONTAINER_LINK

#define ASTOBJ_CONTAINER_LINK (   container,
  newobj 
)    ASTOBJ_CONTAINER_LINK_FULL(container,newobj,(newobj)->name,name,ASTOBJ_DEFAULT_HASH,0,strcasecmp)

Add an object to a container.

Parameters
containerA pointer to the container to operate on.
newobjA pointer to the object to be added.

Currently this macro adds an object to the head of a container. One day it should add an object in alphabetical order.

Definition at line 778 of file astobj.h.

Referenced by ast_netsock_bindaddr().

◆ ASTOBJ_CONTAINER_LINK_END

#define ASTOBJ_CONTAINER_LINK_END (   container,
  newobj 
)

Add an object to the end of a container.

Parameters
containerA pointer to the container to operate on.
newobjA pointer to the object to be added.

This macro adds an object to the end of a container.

Definition at line 582 of file astobj.h.

◆ ASTOBJ_CONTAINER_LINK_FULL

#define ASTOBJ_CONTAINER_LINK_FULL (   container,
  newobj,
  data,
  field,
  hashfunc,
  hashoffset,
  comparefunc 
)

Add an object to a container.

Parameters
containerA pointer to the container to operate on.
newobjA pointer to the object to be added.
dataCurrently unused.
fieldCurrently unused.
hashfuncCurrently unused.
hashoffsetCurrently unused.
comparefuncCurrently unused.

Currently this function adds an object to the head of the list. One day it will support adding objects atthe position specified using the various options this macro offers.

Definition at line 688 of file astobj.h.

◆ ASTOBJ_CONTAINER_LINK_START

#define ASTOBJ_CONTAINER_LINK_START (   container,
  newobj 
)

Add an object to the front of a container.

Parameters
containerA pointer to the container to operate on.
newobjA pointer to the object to be added.

This macro adds an object to the start of a container.

Definition at line 612 of file astobj.h.

◆ ASTOBJ_CONTAINER_MARKALL

#define ASTOBJ_CONTAINER_MARKALL (   container)    ASTOBJ_CONTAINER_TRAVERSE(container, 1, ASTOBJ_MARK(iterator))

Mark all the objects in a container.

Parameters
containerA pointer to the container to operate on.

Definition at line 784 of file astobj.h.

◆ ASTOBJ_CONTAINER_PRUNE_MARKED

#define ASTOBJ_CONTAINER_PRUNE_MARKED (   container,
  destructor 
)

Prune marked objects from a container.

Parameters
containerA pointer to the container to prune.
destructorA destructor function to call on each marked object.

This macro iterates through the specfied container and prunes any marked objects executing the specfied destructor if necessary.

Definition at line 653 of file astobj.h.

◆ ASTOBJ_CONTAINER_RDLOCK

#define ASTOBJ_CONTAINER_RDLOCK (   container)    ast_mutex_lock(&(container)->_lock)

Lock an ASTOBJ_CONTAINER for reading.

Definition at line 278 of file astobj.h.

◆ ASTOBJ_CONTAINER_TRAVERSE

#define ASTOBJ_CONTAINER_TRAVERSE (   container,
  continue,
  eval 
)

Iterate through the objects in a container.

Parameters
containerA pointer to the container to traverse.
continueA condition to allow the traversal to continue.
evalA statement to evaluate in the iteration loop.

This is macro is a little complicated, but it may help to think of it as a loop. Basically it iterates through the specfied containter as long as the condition is met. Two variables, iterator and next, are provided for use in your eval statement. See the sample code for an example.

Sample Usage:

ASTOBJ_CONTAINER_TRAVERSE(&sample_container,1, {
ASTOBJ_RDLOCK(iterator);
printf("Currently iterating over '%s'\n", iterator->name);
ASTOBJ_UNLOCK(iterator);
} );
ASTOBJ_CONTAINER_TRAVERSE(&sample_container,1, sample_func(iterator));

Definition at line 378 of file astobj.h.

Referenced by ast_netsock_find().

◆ ASTOBJ_CONTAINER_UNLINK

#define ASTOBJ_CONTAINER_UNLINK (   container,
  obj 
)

Remove an object from a container.

Parameters
containerA pointer to the container to operate on.
objA pointer to the object to remove.

This macro iterates through a container and removes the specfied object if it exists in the container.

Note
This macro does not destroy any objects, it simply unlinks them from the list. No destructors are called.
Returns
The container's reference to the removed object or NULL if no matching object was found.

Definition at line 480 of file astobj.h.

◆ ASTOBJ_CONTAINER_UNLINK_START

#define ASTOBJ_CONTAINER_UNLINK_START (   container)

Remove an object from the front of a container.

Parameters
containerA pointer to the container to operate on.

This macro removes the first object in a container.

Note
This macro does not destroy any objects, it simply unlinks them from the list. No destructors are called.
Returns
The container's reference to the removed object or NULL if no matching object was found.

Definition at line 632 of file astobj.h.

◆ ASTOBJ_CONTAINER_UNLOCK

#define ASTOBJ_CONTAINER_UNLOCK (   container)    ast_mutex_unlock(&(container)->_lock)

Unlock an ASTOBJ_CONTAINER.

Definition at line 285 of file astobj.h.

◆ ASTOBJ_CONTAINER_UNMARKALL

#define ASTOBJ_CONTAINER_UNMARKALL (   container)    ASTOBJ_CONTAINER_TRAVERSE(container, 1, ASTOBJ_UNMARK(iterator))

Unmark all the objects in a container.

Parameters
containerA pointer to the container to operate on.

Definition at line 790 of file astobj.h.

◆ ASTOBJ_CONTAINER_WRLOCK

#define ASTOBJ_CONTAINER_WRLOCK (   container)    ast_mutex_lock(&(container)->_lock)

Lock an ASTOBJ_CONTAINER for writing.

Definition at line 282 of file astobj.h.

◆ ASTOBJ_DEFAULT_BUCKETS

#define ASTOBJ_DEFAULT_BUCKETS   256

Definition at line 92 of file astobj.h.

◆ ASTOBJ_DEFAULT_HASH

#define ASTOBJ_DEFAULT_HASH   ast_strhash

Definition at line 93 of file astobj.h.

◆ ASTOBJ_DEFAULT_NAMELEN

#define ASTOBJ_DEFAULT_NAMELEN   80

Definition at line 91 of file astobj.h.

◆ ASTOBJ_DUMP

#define ASTOBJ_DUMP (   s,
  slen,
  obj 
)    snprintf((s),(slen),"name: %s\nobjflags: %u\nrefcount: %u\n\n", (obj)->name, (obj)->objflags, (obj)->refcount);

Dump information about an object into a string.

Parameters
sA pointer to the string buffer to use.
slenThe length of s.
objA pointer to the object to dump.

This macro dumps a text representation of the name, objectflags, and refcount fields of an object to the specfied string buffer.

Definition at line 802 of file astobj.h.

◆ ASTOBJ_FLAG_MARKED

#define ASTOBJ_FLAG_MARKED   (1 << 0) /* Object has been marked for future operation */

Definition at line 95 of file astobj.h.

◆ ASTOBJ_INIT

#define ASTOBJ_INIT (   object)
Value:
do { \
ast_mutex_init(&(object)->_lock); \
object->name[0] = '\0'; \
object->refcount = 1; \
} while(0)

Initialize an object.

Parameters
objectA pointer to the object to operate on.
Note
This should only be used on objects that support locking (objects created with ASTOBJ_COMPONENTS() or ASTOBJ_COMPONENTS_FULL())

Definition at line 266 of file astobj.h.

Referenced by ast_netsock_bindaddr().

◆ ASTOBJ_MARK

#define ASTOBJ_MARK (   object)
Value:
do { \
ASTOBJ_WRLOCK(object); \
(object)->objflags |= ASTOBJ_FLAG_MARKED; \
ASTOBJ_UNLOCK(object); \
} while(0)
#define ASTOBJ_FLAG_MARKED
Definition: astobj.h:95

Mark an ASTOBJ by adding the ASTOBJ_FLAG_MARKED flag to its objflags mask.

Parameters
objectA pointer to the object to operate on.

This macro "marks" an object. Marked objects can later be unlinked from a container using ASTOBJ_CONTAINER_PRUNE_MARKED().

Definition at line 243 of file astobj.h.

◆ ASTOBJ_RDLOCK

#define ASTOBJ_RDLOCK (   object)    ast_mutex_lock(&(object)->_lock)

Lock an ASTOBJ for reading.

Definition at line 102 of file astobj.h.

Referenced by ast_netsock_find().

◆ ASTOBJ_REF

#define ASTOBJ_REF (   object)

Increment an object reference count.

Parameters
objectA pointer to the object to operate on.
Returns
The object.

Definition at line 203 of file astobj.h.

◆ ASTOBJ_TRYWRLOCK

#define ASTOBJ_TRYWRLOCK (   object)    ast_mutex_trylock(&(object)->_lock)

Definition at line 108 of file astobj.h.

◆ ASTOBJ_UNLOCK

#define ASTOBJ_UNLOCK (   object)    ast_mutex_unlock(&(object)->_lock)

Unlock a locked object.

Definition at line 111 of file astobj.h.

Referenced by ast_netsock_find().

◆ ASTOBJ_UNMARK

#define ASTOBJ_UNMARK (   object)
Value:
do { \
ASTOBJ_WRLOCK(object); \
(object)->objflags &= ~ASTOBJ_FLAG_MARKED; \
ASTOBJ_UNLOCK(object); \
} while(0)
#define ASTOBJ_FLAG_MARKED
Definition: astobj.h:95

Unmark an ASTOBJ by subtracting the ASTOBJ_FLAG_MARKED flag from its objflags mask.

Parameters
objectA pointer to the object to operate on.

Definition at line 253 of file astobj.h.

◆ ASTOBJ_UNREF

#define ASTOBJ_UNREF (   object,
  destructor 
)

Decrement the reference count on an object.

Parameters
objectA pointer the object to operate on.
destructorThe destructor to call if the object is no longer referenced. It will be passed the pointer as an argument.

This macro unreferences an object and calls the specfied destructor if the object is no longer referenced. The destructor should free the object if it was dynamically allocated.

Definition at line 220 of file astobj.h.

Referenced by ast_netsock_unref().

◆ ASTOBJ_WRLOCK

#define ASTOBJ_WRLOCK (   object)    ast_mutex_lock(&(object)->_lock)

Lock an ASTOBJ for writing.

Definition at line 106 of file astobj.h.