📄 channel.h
字号:
* \param block blocking or not * Set an option on a channel (see frame.h), optionally blocking awaiting the reply * Returns 0 on success and -1 on failure */int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block);/*! Pick the best codec *//* Choose the best codec... Uhhh... Yah. */int ast_best_codec(int fmts);/*! Checks the value of an option *//*! * Query the value of an option * Works similarly to setoption except only reads the options. */int ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block);/*! Checks for HTML support on a channel *//*! Returns 0 if channel does not support HTML or non-zero if it does */int ast_channel_supports_html(struct ast_channel *channel);/*! Sends HTML on given channel *//*! Send HTML or URL on link. Returns 0 on success or -1 on failure */int ast_channel_sendhtml(struct ast_channel *channel, int subclass, const char *data, int datalen);/*! Sends a URL on a given link *//*! Send URL on link. Returns 0 on success or -1 on failure */int ast_channel_sendurl(struct ast_channel *channel, const char *url);/*! Defers DTMF *//*! Defer DTMF so that you only read things like hangups and audio. Returns non-zero if channel was already DTMF-deferred or 0 if channel is just now being DTMF-deferred */int ast_channel_defer_dtmf(struct ast_channel *chan);/*! Undo defer. ast_read will return any dtmf characters that were queued */void ast_channel_undefer_dtmf(struct ast_channel *chan);/*! Initiate system shutdown -- prevents new channels from being allocated. If "hangup" is non-zero, all existing channels will receive soft hangups */void ast_begin_shutdown(int hangup);/*! Cancels an existing shutdown and returns to normal operation */void ast_cancel_shutdown(void);/*! Returns number of active/allocated channels */int ast_active_channels(void);/*! Returns non-zero if Asterisk is being shut down */int ast_shutting_down(void);/*! Activate a given generator */int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params);/*! Deactivate an active generator */void ast_deactivate_generator(struct ast_channel *chan);/*! * \brief Set caller ID number, name and ANI * * \note The channel does not need to be locked before calling this function. */void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani);/*! Set the file descriptor on the channel */void ast_channel_set_fd(struct ast_channel *chan, int which, int fd);/*! Add a channel to an optimized waitfor */void ast_poll_channel_add(struct ast_channel *chan0, struct ast_channel *chan1);/*! Delete a channel from an optimized waitfor */void ast_poll_channel_del(struct ast_channel *chan0, struct ast_channel *chan1);/*! Start a tone going */int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);/*! Stop a tone from playing */void ast_tonepair_stop(struct ast_channel *chan);/*! Play a tone pair for a given amount of time */int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);/*! * \brief Automatically service a channel for us... * * \retval 0 success * \retval -1 failure, or the channel is already being autoserviced */int ast_autoservice_start(struct ast_channel *chan);/*! * \brief Stop servicing a channel for us... * * \note if chan is locked prior to calling ast_autoservice_stop, it * is likely that there will be a deadlock between the thread that calls * ast_autoservice_stop and the autoservice thread. It is important * that chan is not locked prior to this call * * \retval 0 success * \retval -1 error, or the channel has been hungup */int ast_autoservice_stop(struct ast_channel *chan);/* If built with dahdi optimizations, force a scheduled expiration on the timer fd, at which point we call the callback function / data */int ast_settimeout(struct ast_channel *c, int samples, int (*func)(const void *data), void *data);/*! \brief Transfer a channel (if supported). Returns -1 on error, 0 if not supported and 1 if supported and requested \param chan current channel \param dest destination extension for transfer*/int ast_transfer(struct ast_channel *chan, char *dest);/*! \brief Start masquerading a channel XXX This is a seriously whacked out operation. We're essentially putting the guts of the clone channel into the original channel. Start by killing off the original channel's backend. I'm not sure we're going to keep this function, because while the features are nice, the cost is very high in terms of pure nastiness. XXX \param chan Channel to masquerade*/int ast_do_masquerade(struct ast_channel *chan);/*! \brief Find bridged channel \param chan Current channel*/struct ast_channel *ast_bridged_channel(struct ast_channel *chan);/*! \brief Inherits channel variable from parent to child channel \param parent Parent channel \param child Child channel Scans all channel variables in the parent channel, looking for those that should be copied into the child channel. Variables whose names begin with a single '_' are copied into the child channel with the prefix removed. Variables whose names begin with '__' are copied into the child channel with their names unchanged.*/void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child);/*! \brief adds a list of channel variables to a channel \param chan the channel \param vars a linked list of variables Variable names can be for a regular channel variable or a dialplan function that has the ability to be written to.*/void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars);/*! \brief An opaque 'object' structure use by silence generators on channels. */struct ast_silence_generator;/*! \brief Starts a silence generator on the given channel. \param chan The channel to generate silence on \return An ast_silence_generator pointer, or NULL if an error occurs This function will cause SLINEAR silence to be generated on the supplied channel until it is disabled; if the channel cannot be put into SLINEAR mode then the function will fail. The pointer returned by this function must be preserved and passed to ast_channel_stop_silence_generator when you wish to stop the silence generation. */struct ast_silence_generator *ast_channel_start_silence_generator(struct ast_channel *chan);/*! \brief Stops a previously-started silence generator on the given channel. \param chan The channel to operate on \param state The ast_silence_generator pointer return by a previous call to ast_channel_start_silence_generator. \return nothing This function will stop the operating silence generator and return the channel to its previous write format. */void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state);/*! \brief Check if the channel can run in internal timing mode. \param chan The channel to check \return boolean This function will return 1 if internal timing is enabled and the timing device is available. */int ast_internal_timing_enabled(struct ast_channel *chan);/* Misc. functions below *//*! \brief if fd is a valid descriptor, set *pfd with the descriptor * \return Return 1 (not -1!) if added, 0 otherwise (so we can add the * return value to the index into the array) */static inline int ast_add_fd(struct pollfd *pfd, int fd){ pfd->fd = fd; pfd->events = POLLIN | POLLPRI; return fd >= 0;}/*! \brief Helper function for migrating select to poll */static inline int ast_fdisset(struct pollfd *pfds, int fd, int max, int *start){ int x; int dummy=0; if (fd < 0) return 0; if (!start) start = &dummy; for (x = *start; x<max; x++) if (pfds[x].fd == fd) { if (x == *start) (*start)++; return pfds[x].revents; } return 0;}#ifndef HAVE_TIMERSUBstatic inline void timersub(struct timeval *tvend, struct timeval *tvstart, struct timeval *tvdiff){ tvdiff->tv_sec = tvend->tv_sec - tvstart->tv_sec; tvdiff->tv_usec = tvend->tv_usec - tvstart->tv_usec; if (tvdiff->tv_usec < 0) { tvdiff->tv_sec --; tvdiff->tv_usec += 1000000; }}#endif/*! \brief Waits for activity on a group of channels * \param nfds the maximum number of file descriptors in the sets * \param rfds file descriptors to check for read availability * \param wfds file descriptors to check for write availability * \param efds file descriptors to check for exceptions (OOB data) * \param tvp timeout while waiting for events * This is the same as a standard select(), except it guarantees the * behaviour where the passed struct timeval is updated with how much * time was not slept while waiting for the specified events */static inline int ast_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tvp){#ifdef __linux__ return select(nfds, rfds, wfds, efds, tvp);#else if (tvp) { struct timeval tv, tvstart, tvend, tvlen; int res; tv = *tvp; gettimeofday(&tvstart, NULL); res = select(nfds, rfds, wfds, efds, tvp); gettimeofday(&tvend, NULL); timersub(&tvend, &tvstart, &tvlen); timersub(&tv, &tvlen, tvp); if (tvp->tv_sec < 0 || (tvp->tv_sec == 0 && tvp->tv_usec < 0)) { tvp->tv_sec = 0; tvp->tv_usec = 0; } return res; } else return select(nfds, rfds, wfds, efds, NULL);#endif}/*! \brief Retrieves the current T38 state of a channel */static inline enum ast_t38_state ast_channel_get_t38_state(struct ast_channel *chan){ enum ast_t38_state state = T38_STATE_UNAVAILABLE; int datalen = sizeof(state); ast_channel_queryoption(chan, AST_OPTION_T38_STATE, &state, &datalen, 0); return state;}#define CHECK_BLOCKING(c) do { \ if (ast_test_flag(c, AST_FLAG_BLOCKING)) {\ if (option_debug) \ ast_log(LOG_DEBUG, "Thread %ld Blocking '%s', already blocked by thread %ld in procedure %s\n", (long) pthread_self(), (c)->name, (long) (c)->blocker, (c)->blockproc); \ } else { \ (c)->blocker = pthread_self(); \ (c)->blockproc = __PRETTY_FUNCTION__; \ ast_set_flag(c, AST_FLAG_BLOCKING); \ } } while (0)ast_group_t ast_get_group(const char *s);/*! \brief print call- and pickup groups into buffer */char *ast_print_group(char *buf, int buflen, ast_group_t group);/*! \brief Convert enum channelreloadreason to text string for manager event \param reason Enum channelreloadreason - reason for reload (manager, cli, start etc)*/const char *channelreloadreason2txt(enum channelreloadreason reason);/*! \brief return an ast_variable list of channeltypes */struct ast_variable *ast_channeltype_list(void);/*! \brief return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument \param reason The integer argument, usually taken from AST_CONTROL_ macros \return char pointer explaining the code */const char *ast_channel_reason2str(int reason);/*! \brief channel group info */struct ast_group_info { struct ast_channel *chan; char *category; char *group; AST_LIST_ENTRY(ast_group_info) list; };#if defined(__cplusplus) || defined(c_plusplus)}#endif#endif /* _ASTERISK_CHANNEL_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -