diff options
Diffstat (limited to 'include/asterisk')
-rw-r--r-- | include/asterisk/res_pjsip_session.h | 4 | ||||
-rw-r--r-- | include/asterisk/vector.h | 62 |
2 files changed, 66 insertions, 0 deletions
diff --git a/include/asterisk/res_pjsip_session.h b/include/asterisk/res_pjsip_session.h index c41cc3ab9..5e8eb3acc 100644 --- a/include/asterisk/res_pjsip_session.h +++ b/include/asterisk/res_pjsip_session.h @@ -457,6 +457,10 @@ struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint * * \param session The session to terminate * \param response The response code to use for termination if possible + * + * \warning Calling this function MAY cause the last session reference to be + * released and the session destructor to be called. If you need to do something + * with session after this call, be sure to bump the ref count before calling terminate. */ void ast_sip_session_terminate(struct ast_sip_session *session, int response); diff --git a/include/asterisk/vector.h b/include/asterisk/vector.h index 6b4e63242..2073baedf 100644 --- a/include/asterisk/vector.h +++ b/include/asterisk/vector.h @@ -48,6 +48,9 @@ size_t current; \ } +/*! \brief Integer vector definition */ +AST_VECTOR(ast_vector_int, int); + /*! * \brief Define a vector structure with a read/write lock * @@ -241,6 +244,29 @@ }) /*! + * \brief Default a vector up to size with the given value. + * + * \note If a size of 0 is given then all elements in the given vector are set. + * \note The vector will grow to the given size if needed. + * + * \param vec Vector to default. + * \param size The number of elements to default + * \param value The default value to set each element to + */ +#define AST_VECTOR_DEFAULT(vec, size, value) ({ \ + int res = 0; \ + typeof((size)) __size = (size) ? (size) : AST_VECTOR_SIZE(vec); \ + size_t idx; \ + for (idx = 0; idx < __size; ++idx) { \ + res = AST_VECTOR_REPLACE(vec, idx, value); \ + if (res == -1) { \ + break; \ + } \ + } \ + res; \ +}) + +/*! * \brief Insert an element at a specific position in a vector, growing the vector if needed. * * \param vec Vector to insert into. @@ -553,6 +579,42 @@ }) /*! + * \brief Get the nth index from a vector that matches the given comparison + * + * \param vec Vector to get from. + * \param nth The nth index to find + * \param value Value to pass into comparator. + * \param cmp Comparator function/macros (called as \c cmp(elem, value)) + * + * \return a pointer to the element that was found or NULL + */ +#define AST_VECTOR_GET_INDEX_NTH(vec, nth, value, cmp) ({ \ + int res = -1; \ + size_t idx; \ + typeof(nth) __nth = (nth); \ + typeof(value) __value = (value); \ + for (idx = 0; idx < (vec)->current; ++idx) { \ + if (cmp((vec)->elems[idx], __value) && !(--__nth)) { \ + res = (int)idx; \ + break; \ + } \ + } \ + res; \ +}) + +/*! + * \brief Get the 1st index from a vector that matches the given comparison + * + * \param vec Vector to get from. + * \param value Value to pass into comparator. + * \param cmp Comparator function/macros (called as \c cmp(elem, value)) + * + * \return a pointer to the element that was found or NULL + */ +#define AST_VECTOR_GET_INDEX(vec, value, cmp) \ + AST_VECTOR_GET_INDEX_NTH(vec, 1, value, cmp) + +/*! * \brief Get an element from a vector that matches the given comparison * * \param vec Vector to get from. |