mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-13 17:38:59 +00:00
freetdm: iterators refactoring
add channel iterator
This commit is contained in:
@@ -386,7 +386,7 @@ typedef struct ftdm_conf_parameter {
|
||||
} ftdm_conf_parameter_t;
|
||||
|
||||
/*! \brief Opaque general purpose iterator */
|
||||
typedef void ftdm_iterator_t;
|
||||
typedef struct ftdm_iterator ftdm_iterator_t;
|
||||
|
||||
/*! \brief Channel commands that can be executed through ftdm_channel_command() */
|
||||
typedef enum {
|
||||
@@ -1032,8 +1032,19 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_add_var(ftdm_channel_t *ftdmchan, const c
|
||||
FT_DECLARE(const char *) ftdm_channel_get_var(ftdm_channel_t *ftdmchan, const char *var_name);
|
||||
|
||||
/*! \brief Get an iterator to iterate over the channel variables
|
||||
* \note The iterator pointer returned is only valid while the channel is open and it'll be destroyed when the channel is closed. */
|
||||
FT_DECLARE(ftdm_iterator_t *) ftdm_channel_get_var_iterator(const ftdm_channel_t *ftdmchan);
|
||||
* \param ftdmchan The channel structure containing the variables
|
||||
* \param iter Optional iterator. You can reuse an old iterator (not previously freed) to avoid the extra allocation of a new iterator.
|
||||
* \note The iterator pointer returned is only valid while the channel is open and it'll be destroyed when the channel is closed.
|
||||
* This iterator is completely non-thread safe, if you are adding variables or removing variables while iterating
|
||||
* results are unpredictable
|
||||
*/
|
||||
FT_DECLARE(ftdm_iterator_t *) ftdm_channel_get_var_iterator(const ftdm_channel_t *ftdmchan, ftdm_iterator_t *iter);
|
||||
|
||||
/*! \brief Get iterator current value (depends on the iterator type)
|
||||
* \note Channel iterators return a pointer to ftdm_channel_t
|
||||
* Variable iterators return a pointer to the variable name (not the variable value)
|
||||
*/
|
||||
FT_DECLARE(void *) ftdm_iterator_current(ftdm_iterator_t *iter);
|
||||
|
||||
/*! \brief Get variable name and value for the current iterator position */
|
||||
FT_DECLARE(ftdm_status_t) ftdm_channel_get_current_var(ftdm_iterator_t *iter, const char **var_name, const char **var_val);
|
||||
@@ -1041,6 +1052,11 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_get_current_var(ftdm_iterator_t *iter, co
|
||||
/*! \brief Advance iterator */
|
||||
FT_DECLARE(ftdm_iterator_t *) ftdm_iterator_next(ftdm_iterator_t *iter);
|
||||
|
||||
/*! \brief Free iterator
|
||||
* \note You must free an iterator after using it unless you plan to reuse it
|
||||
*/
|
||||
FT_DECLARE(ftdm_status_t) ftdm_iterator_free(ftdm_iterator_t *iter);
|
||||
|
||||
/*! \brief Get the span pointer associated to the channel */
|
||||
FT_DECLARE(ftdm_span_t *) ftdm_channel_get_span(const ftdm_channel_t *ftdmchan);
|
||||
|
||||
@@ -1144,6 +1160,12 @@ FT_DECLARE(uint32_t) ftdm_span_get_id(const ftdm_span_t *span);
|
||||
/*! \brief Get the span name */
|
||||
FT_DECLARE(const char *) ftdm_span_get_name(const ftdm_span_t *span);
|
||||
|
||||
/*! \brief Get iterator for the span channels
|
||||
* \param span The span containing the channels
|
||||
* \param iter Optional iterator. You can reuse an old iterator (not previously freed) to avoid the extra allocation of a new iterator.
|
||||
*/
|
||||
FT_DECLARE(ftdm_iterator_t *) ftdm_span_get_chan_iterator(const ftdm_span_t *span, ftdm_iterator_t *iter);
|
||||
|
||||
/*!
|
||||
* \brief Execute a text command. The text command output will be returned and must be free'd
|
||||
*
|
||||
|
@@ -619,6 +619,9 @@ FT_DECLARE(ftdm_status_t) ftdm_span_trigger_signals(const ftdm_span_t *span);
|
||||
#define ftdm_log_chan(fchan, level, format, ...) ftdm_log(level, "[s%dc%d][%d:%d] " format, fchan->span_id, fchan->chan_id, fchan->physical_span_id, fchan->physical_chan_id, __VA_ARGS__)
|
||||
#define ftdm_log_chan_msg(fchan, level, msg) ftdm_log(level, "[s%dc%d][%d:%d] " msg, fchan->span_id, fchan->chan_id, fchan->physical_span_id, fchan->physical_chan_id)
|
||||
|
||||
#define ftdm_span_lock(span) ftdm_mutex_lock(span->mutex)
|
||||
#define ftdm_span_unlock(span) ftdm_mutex_unlock(span->mutex)
|
||||
|
||||
FT_DECLARE_DATA extern const char *FTDM_LEVEL_NAMES[9];
|
||||
|
||||
static __inline__ void ftdm_abort(void)
|
||||
|
@@ -366,6 +366,23 @@ typedef ftdm_status_t (*ftdm_span_start_t)(ftdm_span_t *span);
|
||||
typedef ftdm_status_t (*ftdm_span_stop_t)(ftdm_span_t *span);
|
||||
typedef ftdm_status_t (*ftdm_channel_sig_read_t)(ftdm_channel_t *ftdmchan, void *data, ftdm_size_t size);
|
||||
|
||||
typedef enum {
|
||||
FTDM_ITERATOR_VARS = 1,
|
||||
FTDM_ITERATOR_CHANS,
|
||||
} ftdm_iterator_type_t;
|
||||
|
||||
struct ftdm_iterator {
|
||||
ftdm_iterator_type_t type;
|
||||
unsigned int allocated:1;
|
||||
union {
|
||||
struct {
|
||||
int32_t index;
|
||||
const ftdm_span_t *span;
|
||||
} chaniter;
|
||||
ftdm_hash_iterator_t *hashiter;
|
||||
} pvt;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user