📄 astobj.h
字号:
do { \ typeof((container)->head) iterator; \ typeof((container)->head) next; \ ASTOBJ_CONTAINER_RDLOCK(container); \ next = (container)->head; \ while((continue) && (iterator = next)) { \ next = iterator->next[0]; \ eval; \ } \ ASTOBJ_CONTAINER_UNLOCK(container); \ } while(0)/*! \brief Find an object in a container. * * \param container A pointer to the container to search. * \param namestr The 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. * * \return A new reference to the object located or NULL if nothing is found. */#define ASTOBJ_CONTAINER_FIND(container,namestr) \ ({ \ typeof((container)->head) found = NULL; \ ASTOBJ_CONTAINER_TRAVERSE(container, !found, do { \ if (!(strcasecmp(iterator->name, (namestr)))) \ found = ASTOBJ_REF(iterator); \ } while (0)); \ found; \ })/*! \brief Find an object in a container. * * \param container A pointer to the container to search. * \param data The data to search for. * \param field The field/member of the container's objects to search. * \param hashfunc The hash function to use, currently not implemented. * \param hashoffset The hash offset to use, currently not implemented. * \param comparefunc The 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. * * \return A pointer to the object located or NULL if nothing is found. */#define ASTOBJ_CONTAINER_FIND_FULL(container,data,field,hashfunc,hashoffset,comparefunc) \ ({ \ typeof((container)->head) found = NULL; \ ASTOBJ_CONTAINER_TRAVERSE(container, !found, do { \ ASTOBJ_RDLOCK(iterator); \ if (!(comparefunc(iterator->field, (data)))) { \ found = ASTOBJ_REF(iterator); \ } \ ASTOBJ_UNLOCK(iterator); \ } while (0)); \ found; \ })/*! \brief Empty a container. * * \param container A pointer to the container to operate on. * \param destructor A 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. */#define ASTOBJ_CONTAINER_DESTROYALL(container,destructor) \ do { \ typeof((container)->head) iterator; \ ASTOBJ_CONTAINER_WRLOCK(container); \ while((iterator = (container)->head)) { \ (container)->head = (iterator)->next[0]; \ ASTOBJ_UNREF(iterator,destructor); \ } \ ASTOBJ_CONTAINER_UNLOCK(container); \ } while(0)/*! \brief Remove an object from a container. * * \param container A pointer to the container to operate on. * \param obj A 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. * * \return The container's reference to the removed object or NULL if no * matching object was found. */#define ASTOBJ_CONTAINER_UNLINK(container,obj) \ ({ \ typeof((container)->head) found = NULL; \ typeof((container)->head) prev = NULL; \ ASTOBJ_CONTAINER_TRAVERSE(container, !found, do { \ if (iterator == obj) { \ found = iterator; \ found->next[0] = NULL; \ ASTOBJ_CONTAINER_WRLOCK(container); \ if (prev) \ prev->next[0] = next; \ else \ (container)->head = next; \ ASTOBJ_CONTAINER_UNLOCK(container); \ } \ prev = iterator; \ } while (0)); \ found; \ })/*! \brief Find and remove an object from a container. * * \param container A pointer to the container to operate on. * \param namestr The 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. * * \return The container's reference to the removed object or NULL if no * matching object was found. */#define ASTOBJ_CONTAINER_FIND_UNLINK(container,namestr) \ ({ \ typeof((container)->head) found = NULL; \ typeof((container)->head) prev = NULL; \ ASTOBJ_CONTAINER_TRAVERSE(container, !found, do { \ if (!(strcasecmp(iterator->name, (namestr)))) { \ found = iterator; \ found->next[0] = NULL; \ ASTOBJ_CONTAINER_WRLOCK(container); \ if (prev) \ prev->next[0] = next; \ else \ (container)->head = next; \ ASTOBJ_CONTAINER_UNLOCK(container); \ } \ prev = iterator; \ } while (0)); \ found; \ })/*! \brief Find and remove an object in a container. * * \param container A pointer to the container to search. * \param data The data to search for. * \param field The field/member of the container's objects to search. * \param hashfunc The hash function to use, currently not implemented. * \param hashoffset The hash offset to use, currently not implemented. * \param comparefunc The 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. * * \return The container's reference to the removed object or NULL if no match * was found. */#define ASTOBJ_CONTAINER_FIND_UNLINK_FULL(container,data,field,hashfunc,hashoffset,comparefunc) \ ({ \ typeof((container)->head) found = NULL; \ typeof((container)->head) prev = NULL; \ ASTOBJ_CONTAINER_TRAVERSE(container, !found, do { \ ASTOBJ_RDLOCK(iterator); \ if (!(comparefunc(iterator->field, (data)))) { \ found = iterator; \ found->next[0] = NULL; \ ASTOBJ_CONTAINER_WRLOCK(container); \ if (prev) \ prev->next[0] = next; \ else \ (container)->head = next; \ ASTOBJ_CONTAINER_UNLOCK(container); \ } \ ASTOBJ_UNLOCK(iterator); \ prev = iterator; \ } while (0)); \ found; \ })/*! \brief Prune marked objects from a container. * * \param container A pointer to the container to prune. * \param destructor A 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. */#define ASTOBJ_CONTAINER_PRUNE_MARKED(container,destructor) \ do { \ typeof((container)->head) prev = NULL; \ ASTOBJ_CONTAINER_TRAVERSE(container, 1, do { \ ASTOBJ_RDLOCK(iterator); \ if (iterator->objflags & ASTOBJ_FLAG_MARKED) { \ ASTOBJ_CONTAINER_WRLOCK(container); \ if (prev) \ prev->next[0] = next; \ else \ (container)->head = next; \ ASTOBJ_CONTAINER_UNLOCK(container); \ ASTOBJ_UNLOCK(iterator); \ ASTOBJ_UNREF(iterator,destructor); \ continue; \ } \ ASTOBJ_UNLOCK(iterator); \ prev = iterator; \ } while (0)); \ } while(0)/*! \brief Add an object to a container. * * \param container A pointer to the container to operate on. * \param newobj A pointer to the object to be added. * \param data Currently unused. * \param field Currently unused. * \param hashfunc Currently unused. * \param hashoffset Currently unused. * \param comparefunc Currently 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. */#define ASTOBJ_CONTAINER_LINK_FULL(container,newobj,data,field,hashfunc,hashoffset,comparefunc) \ do { \ ASTOBJ_CONTAINER_WRLOCK(container); \ (newobj)->next[0] = (container)->head; \ (container)->head = ASTOBJ_REF(newobj); \ ASTOBJ_CONTAINER_UNLOCK(container); \ } while(0)#endif /* List model *//* Common to hash and linked list models *//*! \brief Create a container for ASTOBJs (without locking support). * * \param type The type of objects the container will hold. * * This macro is used to create a container for ASTOBJs without locking * support. * * <b>Sample Usage:</b> * \code * struct sample_struct_nolock_container { * ASTOBJ_CONTAINER_COMPONENTS_NOLOCK(struct sample_struct); * }; * \endcode */#define ASTOBJ_CONTAINER_COMPONENTS_NOLOCK(type) \ ASTOBJ_CONTAINER_COMPONENTS_NOLOCK_FULL(type,1,ASTOBJ_DEFAULT_BUCKETS)/*! \brief Create a container for ASTOBJs (with locking support). * * \param type The type of objects the container will hold. * * This macro is used to create a container for ASTOBJs with locking support. * * <b>Sample Usage:</b> * \code * struct sample_struct_container { * ASTOBJ_CONTAINER_COMPONENTS(struct sample_struct); * }; * \endcode */#define ASTOBJ_CONTAINER_COMPONENTS(type) \ ast_mutex_t _lock; \ ASTOBJ_CONTAINER_COMPONENTS_NOLOCK(type)/*! \brief Initialize a container. * * \param container A pointer to the container to initialize. * * This macro initializes a container. It should only be used on containers * that support locking. * * <b>Sample Usage:</b> * \code * struct sample_struct_container { * ASTOBJ_CONTAINER_COMPONENTS(struct sample_struct); * } container; * * int func() * { * ASTOBJ_CONTAINER_INIT(&container); * } * \endcode */#define ASTOBJ_CONTAINER_INIT(container) \ ASTOBJ_CONTAINER_INIT_FULL(container,1,ASTOBJ_DEFAULT_BUCKETS)/*! \brief Destroy a container. * * \param container A 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. */#define ASTOBJ_CONTAINER_DESTROY(container) \ ASTOBJ_CONTAINER_DESTROY_FULL(container,1,ASTOBJ_DEFAULT_BUCKETS)/*! \brief Add an object to a container. * * \param container A pointer to the container to operate on. * \param newobj A 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. */#define ASTOBJ_CONTAINER_LINK(container,newobj) \ ASTOBJ_CONTAINER_LINK_FULL(container,newobj,(newobj)->name,name,ASTOBJ_DEFAULT_HASH,0,strcasecmp)/*! \brief Mark all the objects in a container. * \param container A pointer to the container to operate on. */#define ASTOBJ_CONTAINER_MARKALL(container) \ ASTOBJ_CONTAINER_TRAVERSE(container, 1, ASTOBJ_MARK(iterator))/*! \brief Unmark all the objects in a container. * \param container A pointer to the container to operate on. */#define ASTOBJ_CONTAINER_UNMARKALL(container) \ ASTOBJ_CONTAINER_TRAVERSE(container, 1, ASTOBJ_UNMARK(iterator))/*! \brief Dump information about an object into a string. * * \param s A pointer to the string buffer to use. * \param slen The length of s. * \param obj A 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. */#define ASTOBJ_DUMP(s,slen,obj) \ snprintf((s),(slen),"name: %s\nobjflags: %d\nrefcount: %d\n\n", (obj)->name, (obj)->objflags, (obj)->refcount);/*! \brief Dump information about all the objects in a container to a file descriptor. * * \param fd The file descriptor to write to. * \param s A string buffer, same as #ASTOBJ_DUMP(). * \param slen The length of s, same as #ASTOBJ_DUMP(). * \param container A 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. */#define ASTOBJ_CONTAINER_DUMP(fd,s,slen,container) \ ASTOBJ_CONTAINER_TRAVERSE(container, 1, do { ASTOBJ_DUMP(s,slen,iterator); ast_cli(fd, s); } while(0))#if defined(__cplusplus) || defined(c_plusplus)}#endif#endif /* _ASTERISK_ASTOBJ_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -