Fri Jul 24 00:40:53 2009

Asterisk developer's documentation


channel.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2006, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  * \brief General Asterisk PBX channel definitions.
00021  * \par See also:
00022  *  \arg \ref Def_Channel
00023  *  \arg \ref channel_drivers
00024  */
00025 
00026 /*! \page Def_Channel Asterisk Channels
00027    \par What is a Channel?
00028    A phone call through Asterisk consists of an incoming
00029    connection and an outbound connection. Each call comes
00030    in through a channel driver that supports one technology,
00031    like SIP, DAHDI, IAX2 etc.
00032    \par
00033    Each channel driver, technology, has it's own private
00034    channel or dialog structure, that is technology-dependent.
00035    Each private structure is "owned" by a generic Asterisk
00036    channel structure, defined in channel.h and handled by
00037    channel.c .
00038    \par Call scenario
00039    This happens when an incoming call arrives to Asterisk
00040    -# Call arrives on a channel driver interface
00041    -# Channel driver creates a PBX channel and starts a
00042       pbx thread on the channel
00043    -# The dial plan is executed
00044    -# At this point at least two things can happen:
00045       -# The call is answered by Asterisk and
00046          Asterisk plays a media stream or reads media
00047       -# The dial plan forces Asterisk to create an outbound
00048          call somewhere with the dial (see \ref app_dial.c)
00049          application
00050    .
00051 
00052    \par Bridging channels
00053    If Asterisk dials out this happens:
00054    -# Dial creates an outbound PBX channel and asks one of the
00055       channel drivers to create a call
00056    -# When the call is answered, Asterisk bridges the media streams
00057       so the caller on the first channel can speak with the callee
00058       on the second, outbound channel
00059    -# In some cases where we have the same technology on both
00060       channels and compatible codecs, a native bridge is used.
00061       In a native bridge, the channel driver handles forwarding
00062       of incoming audio to the outbound stream internally, without
00063       sending audio frames through the PBX.
00064    -# In SIP, theres an "external native bridge" where Asterisk
00065       redirects the endpoint, so audio flows directly between the
00066       caller's phone and the callee's phone. Signalling stays in
00067       Asterisk in order to be able to provide a proper CDR record
00068       for the call.
00069 
00070 
00071    \par Masquerading channels
00072    In some cases, a channel can masquerade itself into another
00073    channel. This happens frequently in call transfers, where
00074    a new channel takes over a channel that is already involved
00075    in a call. The new channel sneaks in and takes over the bridge
00076    and the old channel, now a zombie, is hung up.
00077 
00078    \par Reference
00079    \arg channel.c - generic functions
00080    \arg channel.h - declarations of functions, flags and structures
00081    \arg translate.h - Transcoding support functions
00082    \arg \ref channel_drivers - Implemented channel drivers
00083    \arg \ref Def_Frame Asterisk Multimedia Frames
00084    \arg \ref Def_Bridge
00085 
00086 */
00087 /*! \page Def_Bridge Asterisk Channel Bridges
00088 
00089    In Asterisk, there's several media bridges.
00090 
00091    The Core bridge handles two channels (a "phone call") and bridge
00092    them together.
00093 
00094    The conference bridge (meetme) handles several channels simultaneously
00095    with the support of an external timer (DAHDI timer). This is used
00096    not only by the Conference application (meetme) but also by the
00097    page application and the SLA system introduced in 1.4.
00098    The conference bridge does not handle video.
00099 
00100    When two channels of the same type connect, the channel driver
00101    or the media subsystem used by the channel driver (i.e. RTP)
00102    can create a native bridge without sending media through the
00103    core.
00104 
00105    Native briding can be disabled by a number of reasons,
00106    like DTMF being needed by the core or codecs being incompatible
00107    so a transcoding module is needed.
00108 
00109 References:
00110    \li \see ast_channel_early_bridge()
00111    \li \see ast_channel_bridge()
00112    \li \see app_meetme.c
00113    \li \ref AstRTPbridge
00114    \li \see ast_rtp_bridge()
00115    \li \ref Def_Channel
00116 */
00117 
00118 /*! \page AstFileDesc File descriptors
00119    Asterisk File descriptors are connected to each channel (see \ref Def_Channel)
00120    in the \ref ast_channel structure.
00121 */
00122 
00123 #ifndef _ASTERISK_CHANNEL_H
00124 #define _ASTERISK_CHANNEL_H
00125 
00126 #include "asterisk/abstract_jb.h"
00127 
00128 #include "asterisk/poll-compat.h"
00129 
00130 #if defined(__cplusplus) || defined(c_plusplus)
00131 extern "C" {
00132 #endif
00133 
00134 #define AST_MAX_EXTENSION  80 /*!< Max length of an extension */
00135 #define AST_MAX_CONTEXT    80 /*!< Max length of a context */
00136 #define AST_CHANNEL_NAME   80 /*!< Max length of an ast_channel name */
00137 #define MAX_LANGUAGE    20 /*!< Max length of the language setting */
00138 #define MAX_MUSICCLASS     80 /*!< Max length of the music class setting */
00139 
00140 #include "asterisk/frame.h"
00141 #include "asterisk/sched.h"
00142 #include "asterisk/chanvars.h"
00143 #include "asterisk/config.h"
00144 #include "asterisk/lock.h"
00145 #include "asterisk/cdr.h"
00146 #include "asterisk/utils.h"
00147 #include "asterisk/linkedlists.h"
00148 #include "asterisk/stringfields.h"
00149 #include "asterisk/datastore.h"
00150 
00151 #define DATASTORE_INHERIT_FOREVER   INT_MAX
00152 
00153 #define AST_MAX_FDS     10
00154 /*
00155  * We have AST_MAX_FDS file descriptors in a channel.
00156  * Some of them have a fixed use:
00157  */
00158 #define AST_ALERT_FD (AST_MAX_FDS-1)      /*!< used for alertpipe */
00159 #define AST_TIMING_FD   (AST_MAX_FDS-2)      /*!< used for timingfd */
00160 #define AST_AGENT_FD (AST_MAX_FDS-3)      /*!< used by agents for pass through */
00161 #define AST_GENERATOR_FD   (AST_MAX_FDS-4)   /*!< used by generator */
00162 
00163 enum ast_bridge_result {
00164    AST_BRIDGE_COMPLETE = 0,
00165    AST_BRIDGE_FAILED = -1,
00166    AST_BRIDGE_FAILED_NOWARN = -2,
00167    AST_BRIDGE_RETRY = -3,
00168 };
00169 
00170 typedef unsigned long long ast_group_t;
00171 
00172 /*! \todo Add an explanation of an Asterisk generator
00173 */
00174 struct ast_generator {
00175    void *(*alloc)(struct ast_channel *chan, void *params);
00176    void (*release)(struct ast_channel *chan, void *data);
00177    /*! This function gets called with the channel unlocked, but is called in
00178     *  the context of the channel thread so we know the channel is not going
00179     *  to disappear.  This callback is responsible for locking the channel as
00180     *  necessary. */
00181    int (*generate)(struct ast_channel *chan, void *data, int len, int samples);
00182    /*! This gets called when DTMF_END frames are read from the channel */
00183    void (*digit)(struct ast_channel *chan, char digit);
00184 };
00185 
00186 /*! \brief Structure for all kinds of caller ID identifications.
00187  * \note All string fields here are malloc'ed, so they need to be
00188  * freed when the structure is deleted.
00189  * Also, NULL and "" must be considered equivalent.
00190  *
00191  * SIP and IAX2 has utf8 encoded Unicode caller ID names.
00192  * In some cases, we also have an alternative (RPID) E.164 number that can be used
00193  * as caller ID on numeric E.164 phone networks (DAHDI or SIP/IAX2 to pstn gateway).
00194  *
00195  * \todo Implement settings for transliteration between UTF8 caller ID names in
00196  *       to Ascii Caller ID's (DAHDI). Östen Åsklund might be transliterated into
00197  *  Osten Asklund or Oesten Aasklund depending upon language and person...
00198  *  We need automatic routines for incoming calls and static settings for
00199  *     our own accounts.
00200  */
00201 struct ast_callerid {
00202    char *cid_dnid;      /*!< Malloc'd Dialed Number Identifier */
00203    char *cid_num;    /*!< Malloc'd Caller Number */
00204    char *cid_name;      /*!< Malloc'd Caller Name (ASCII) */
00205    char *cid_ani;    /*!< Malloc'd ANI */
00206    char *cid_rdnis;  /*!< Malloc'd RDNIS */
00207    int cid_pres;     /*!< Callerid presentation/screening */
00208    int cid_ani2;     /*!< Callerid ANI 2 (Info digits) */
00209    int cid_ton;      /*!< Callerid Type of Number */
00210    int cid_tns;      /*!< Callerid Transit Network Select */
00211 };
00212 
00213 /*! \brief
00214    Structure to describe a channel "technology", ie a channel driver
00215    See for examples:
00216    \arg chan_iax2.c - The Inter-Asterisk exchange protocol
00217    \arg chan_sip.c - The SIP channel driver
00218    \arg chan_dahdi.c - PSTN connectivity (TDM, PRI, T1/E1, FXO, FXS)
00219 
00220    If you develop your own channel driver, this is where you
00221    tell the PBX at registration of your driver what properties
00222    this driver supports and where different callbacks are
00223    implemented.
00224 */
00225 struct ast_channel_tech {
00226    const char * const type;
00227    const char * const description;
00228 
00229    int capabilities;    /*!< Bitmap of formats this channel can handle */
00230 
00231    int properties;         /*!< Technology Properties */
00232 
00233    /*! \brief Requester - to set up call data structures (pvt's) */
00234    struct ast_channel *(* const requester)(const char *type, int format, void *data, int *cause);
00235 
00236    int (* const devicestate)(void *data); /*!< Devicestate call back */
00237 
00238    /*!
00239     * \brief Start sending a literal DTMF digit
00240     *
00241     * \note The channel is not locked when this function gets called.
00242     */
00243    int (* const send_digit_begin)(struct ast_channel *chan, char digit);
00244 
00245    /*!
00246     * \brief Stop sending a literal DTMF digit
00247     *
00248     * \note The channel is not locked when this function gets called.
00249     */
00250    int (* const send_digit_end)(struct ast_channel *chan, char digit, unsigned int duration);
00251 
00252    /*! \brief Call a given phone number (address, etc), but don't
00253       take longer than timeout seconds to do so.  */
00254    int (* const call)(struct ast_channel *chan, char *addr, int timeout);
00255 
00256    /*! \brief Hangup (and possibly destroy) the channel */
00257    int (* const hangup)(struct ast_channel *chan);
00258 
00259    /*! \brief Answer the channel */
00260    int (* const answer)(struct ast_channel *chan);
00261 
00262    /*! \brief Read a frame, in standard format (see frame.h) */
00263    struct ast_frame * (* const read)(struct ast_channel *chan);
00264 
00265    /*! \brief Write a frame, in standard format (see frame.h) */
00266    int (* const write)(struct ast_channel *chan, struct ast_frame *frame);
00267 
00268    /*! \brief Display or transmit text */
00269    int (* const send_text)(struct ast_channel *chan, const char *text);
00270 
00271    /*! \brief Display or send an image */
00272    int (* const send_image)(struct ast_channel *chan, struct ast_frame *frame);
00273 
00274    /*! \brief Send HTML data */
00275    int (* const send_html)(struct ast_channel *chan, int subclass, const char *data, int len);
00276 
00277    /*! \brief Handle an exception, reading a frame */
00278    struct ast_frame * (* const exception)(struct ast_channel *chan);
00279 
00280    /*! \brief Bridge two channels of the same type together */
00281    enum ast_bridge_result (* const bridge)(struct ast_channel *c0, struct ast_channel *c1, int flags,
00282                   struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
00283 
00284    /*! \brief Bridge two channels of the same type together (early) */
00285    enum ast_bridge_result (* const early_bridge)(struct ast_channel *c0, struct ast_channel *c1);
00286 
00287    /*! \brief Indicate a particular condition (e.g. AST_CONTROL_BUSY or AST_CONTROL_RINGING or AST_CONTROL_CONGESTION */
00288    int (* const indicate)(struct ast_channel *c, int condition, const void *data, size_t datalen);
00289 
00290    /*! \brief Fix up a channel:  If a channel is consumed, this is called.  Basically update any ->owner links */
00291    int (* const fixup)(struct ast_channel *oldchan, struct ast_channel *newchan);
00292 
00293    /*! \brief Set a given option */
00294    int (* const setoption)(struct ast_channel *chan, int option, void *data, int datalen);
00295 
00296    /*! \brief Query a given option */
00297    int (* const queryoption)(struct ast_channel *chan, int option, void *data, int *datalen);
00298 
00299    /*! \brief Blind transfer other side (see app_transfer.c and ast_transfer() */
00300    int (* const transfer)(struct ast_channel *chan, const char *newdest);
00301 
00302    /*! \brief Write a frame, in standard format */
00303    int (* const write_video)(struct ast_channel *chan, struct ast_frame *frame);
00304 
00305    /*! \brief Write a text frame, in standard format */
00306    int (* const write_text)(struct ast_channel *chan, struct ast_frame *frame);
00307 
00308    /*! \brief Find bridged channel */
00309    struct ast_channel *(* const bridged_channel)(struct ast_channel *chan, struct ast_channel *bridge);
00310 
00311    /*! \brief Provide additional read items for CHANNEL() dialplan function */
00312    int (* func_channel_read)(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);
00313 
00314    /*! \brief Provide additional write items for CHANNEL() dialplan function */
00315    int (* func_channel_write)(struct ast_channel *chan, const char *function, char *data, const char *value);
00316 
00317    /*! \brief Retrieve base channel (agent and local) */
00318    struct ast_channel* (* get_base_channel)(struct ast_channel *chan);
00319 
00320    /*! \brief Set base channel (agent and local) */
00321    int (* set_base_channel)(struct ast_channel *chan, struct ast_channel *base);
00322 
00323    /*! \brief Get the unique identifier for the PVT, i.e. SIP call-ID for SIP */
00324    const char * (* get_pvt_uniqueid)(struct ast_channel *chan);
00325 };
00326 
00327 struct ast_epoll_data;
00328 
00329 /*!
00330  * The high bit of the frame count is used as a debug marker, so
00331  * increments of the counters must be done with care.
00332  * Please use c->fin = FRAMECOUNT_INC(c->fin) and the same for c->fout.
00333  */
00334 #define  DEBUGCHAN_FLAG  0x80000000
00335 
00336 /* XXX not ideal to evaluate x twice... */
00337 #define  FRAMECOUNT_INC(x) ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) )
00338 
00339 /*!
00340  * The current value of the debug flags is stored in the two
00341  * variables global_fin and global_fout (declared in main/channel.c)
00342  */
00343 extern unsigned long global_fin, global_fout;
00344 
00345 enum ast_channel_adsicpe {
00346    AST_ADSI_UNKNOWN,
00347    AST_ADSI_AVAILABLE,
00348    AST_ADSI_UNAVAILABLE,
00349    AST_ADSI_OFFHOOKONLY,
00350 };
00351 
00352 /*!
00353  * \brief ast_channel states
00354  *
00355  * \note Bits 0-15 of state are reserved for the state (up/down) of the line
00356  *       Bits 16-32 of state are reserved for flags
00357  */
00358 enum ast_channel_state {
00359    AST_STATE_DOWN,         /*!< Channel is down and available */
00360    AST_STATE_RESERVED,     /*!< Channel is down, but reserved */
00361    AST_STATE_OFFHOOK,      /*!< Channel is off hook */
00362    AST_STATE_DIALING,      /*!< Digits (or equivalent) have been dialed */
00363    AST_STATE_RING,         /*!< Line is ringing */
00364    AST_STATE_RINGING,      /*!< Remote end is ringing */
00365    AST_STATE_UP,        /*!< Line is up */
00366    AST_STATE_BUSY,         /*!< Line is busy */
00367    AST_STATE_DIALING_OFFHOOK, /*!< Digits (or equivalent) have been dialed while offhook */
00368    AST_STATE_PRERING,      /*!< Channel has detected an incoming call and is waiting for ring */
00369 
00370    AST_STATE_MUTE = (1 << 16),   /*!< Do not transmit voice data */
00371 };
00372 
00373 /*!
00374  * \brief Possible T38 states on channels
00375  */
00376 enum ast_t38_state {
00377    T38_STATE_UNAVAILABLE,  /*!< T38 is unavailable on this channel or disabled by configuration */
00378    T38_STATE_UNKNOWN,   /*!< The channel supports T38 but the current status is unknown */
00379    T38_STATE_NEGOTIATING,  /*!< T38 is being negotiated */
00380    T38_STATE_REJECTED,  /*!< Remote side has rejected our offer */
00381    T38_STATE_NEGOTIATED,   /*!< T38 established */
00382 };
00383 
00384 /*! \brief Main Channel structure associated with a channel.
00385  * This is the side of it mostly used by the pbx and call management.
00386  *
00387  * \note XXX It is important to remember to increment .cleancount each time
00388  *       this structure is changed. XXX
00389  *
00390  * \note When adding fields to this structure, it is important to add the field
00391  *       'in position' with like-aligned fields, so as to keep the compiler from
00392  *       having to add padding to align fields. The structure's fields are sorted
00393  *       in this order: pointers, structures, long, int/enum, short, char. This
00394  *       is especially important on 64-bit architectures, where mixing 4-byte
00395  *       and 8-byte fields causes 4 bytes of padding to be added before many
00396  *       8-byte fields.
00397  */
00398 
00399 struct ast_channel {
00400    const struct ast_channel_tech *tech;      /*!< Technology (point to channel driver) */
00401    void *tech_pvt;               /*!< Private data used by the technology driver */
00402    void *music_state;            /*!< Music State*/
00403    void *generatordata;          /*!< Current generator data if there is any */
00404    struct ast_generator *generator;    /*!< Current active data generator */
00405    struct ast_channel *_bridge;        /*!< Who are we bridged to, if we're bridged.
00406                           Who is proxying for us, if we are proxied (i.e. chan_agent).
00407                           Do not access directly, use ast_bridged_channel(chan) */
00408    struct ast_channel *masq;        /*!< Channel that will masquerade as us */
00409    struct ast_channel *masqr;       /*!< Who we are masquerading as */
00410    const char *blockproc;           /*!< Procedure causing blocking */
00411    const char *appl;          /*!< Current application */
00412    const char *data;          /*!< Data passed to current application */
00413    struct sched_context *sched;        /*!< Schedule context */
00414    struct ast_filestream *stream;         /*!< Stream itself. */
00415    struct ast_filestream *vstream;        /*!< Video Stream itself. */
00416    int (*timingfunc)(const void *data);
00417    void *timingdata;
00418    struct ast_pbx *pbx;          /*!< PBX private structure for this channel */
00419    struct ast_trans_pvt *writetrans;      /*!< Write translation path */
00420    struct ast_trans_pvt *readtrans;    /*!< Read translation path */
00421    struct ast_audiohook_list *audiohooks;
00422    struct ast_cdr *cdr;          /*!< Call Detail Record */
00423    struct tone_zone *zone;       /*!< Tone zone as set in indications.conf or
00424                           in the CHANNEL dialplan function */
00425    struct ast_channel_monitor *monitor;      /*!< Channel monitoring */
00426 #ifdef HAVE_EPOLL
00427    struct ast_epoll_data *epfd_data[AST_MAX_FDS];
00428 #endif
00429 
00430    AST_DECLARE_STRING_FIELDS(
00431       AST_STRING_FIELD(name);       /*!< ASCII unique channel name */
00432       AST_STRING_FIELD(language);      /*!< Language requested for voice prompts */
00433       AST_STRING_FIELD(musicclass);    /*!< Default music class */
00434       AST_STRING_FIELD(accountcode);      /*!< Account code for billing */
00435       AST_STRING_FIELD(call_forward);     /*!< Where to forward to if asked to dial on this interface */
00436       AST_STRING_FIELD(uniqueid);      /*!< Unique Channel Identifier */
00437       AST_STRING_FIELD(parkinglot);    /*! Default parking lot, if empty, default parking lot  */
00438       AST_STRING_FIELD(dialcontext);      /*!< Dial: Extension context that we were called from */
00439    );
00440 
00441    struct timeval whentohangup;              /*!< Non-zero, set to actual time when channel is to be hung up */
00442    pthread_t blocker;            /*!< If anyone is blocking, this is them */
00443    ast_mutex_t lock_dont_use;       /*!< Lock a channel for some operations. See ast_channel_lock() */
00444    struct ast_callerid cid;         /*!< Caller ID, name, presentation etc */
00445    struct ast_frame dtmff;          /*!< DTMF frame */
00446    struct varshead varshead;        /*!< A linked list for channel variables. See \ref AstChanVar */
00447    ast_group_t callgroup;           /*!< Call group for call pickups */
00448    ast_group_t pickupgroup;         /*!< Pickup group - which calls groups can be picked up? */
00449    AST_LIST_HEAD_NOLOCK(, ast_frame) readq;
00450    AST_LIST_ENTRY(ast_channel) chan_list;    /*!< For easy linking */
00451    struct ast_jb jb;          /*!< The jitterbuffer state */
00452    struct timeval dtmf_tv;          /*!< The time that an in process digit began, or the last digit ended */
00453    AST_LIST_HEAD_NOLOCK(datastores, ast_datastore) datastores; /*!< Data stores on the channel */
00454 
00455    unsigned long insmpl;            /*!< Track the read/written samples for monitor use */
00456    unsigned long outsmpl;           /*!< Track the read/written samples for monitor use */
00457 
00458    int fds[AST_MAX_FDS];            /*!< File descriptors for channel -- Drivers will poll on
00459                           these file descriptors, so at least one must be non -1.
00460                           See \arg \ref AstFileDesc */
00461    int cdrflags;              /*!< Call Detail Record Flags */
00462    int _softhangup;           /*!< Whether or not we have been hung up...  Do not set this value
00463                           directly, use ast_softhangup() */
00464    int fdno;               /*!< Which fd had an event detected on */
00465    int streamid;              /*!< For streaming playback, the schedule ID */
00466    int vstreamid;             /*!< For streaming video playback, the schedule ID */
00467    int oldwriteformat;           /*!< Original writer format */
00468    int timingfd;              /*!< Timing fd */
00469    enum ast_channel_state _state;         /*!< State of line -- Don't write directly, use ast_setstate() */
00470    int rings;              /*!< Number of rings so far */
00471    int priority;              /*!< Dialplan: Current extension priority */
00472    int macropriority;            /*!< Macro: Current non-macro priority. See app_macro.c */
00473    int amaflags;              /*!< Set BEFORE PBX is started to determine AMA flags */
00474    enum ast_channel_adsicpe adsicpe;      /*!< Whether or not ADSI is detected on CPE */
00475    unsigned int fin;          /*!< Frames in counters. The high bit is a debug mask, so
00476                           the counter is only in the remaining bits */
00477    unsigned int fout;            /*!< Frames out counters. The high bit is a debug mask, so
00478                           the counter is only in the remaining bits */
00479    int hangupcause;           /*!< Why is the channel hanged up. See causes.h */
00480    unsigned int flags;           /*!< channel flags of AST_FLAG_ type */
00481    int alertpipe[2];
00482    int nativeformats;            /*!< Kinds of data this channel can natively handle */
00483    int readformat;               /*!< Requested read format */
00484    int writeformat;           /*!< Requested write format */
00485    int rawreadformat;            /*!< Raw read format */
00486    int rawwriteformat;           /*!< Raw write format */
00487    unsigned int emulate_dtmf_duration;    /*!< Number of ms left to emulate DTMF for */
00488 #ifdef HAVE_EPOLL
00489    int epfd;
00490 #endif
00491    int visible_indication;                         /*!< Indication currently playing on the channel */
00492 
00493    unsigned short transfercapability;     /*!< ISDN Transfer Capbility - AST_FLAG_DIGITAL is not enough */
00494 
00495    union {
00496       char unused_old_dtmfq[AST_MAX_EXTENSION];       /*!< (deprecated, use readq instead) Any/all queued DTMF characters */
00497       struct {
00498          struct ast_timer *timer;            /*!< timer object that provided timingfd */
00499       };
00500    };
00501 
00502    char context[AST_MAX_CONTEXT];         /*!< Dialplan: Current extension context */
00503    char exten[AST_MAX_EXTENSION];         /*!< Dialplan: Current extension number */
00504    char macrocontext[AST_MAX_CONTEXT];    /*!< Macro: Current non-macro context. See app_macro.c */
00505    char macroexten[AST_MAX_EXTENSION];    /*!< Macro: Current non-macro extension. See app_macro.c */
00506    char emulate_dtmf_digit;         /*!< Digit being emulated */
00507 };
00508 
00509 /*! \brief ast_channel_tech Properties */
00510 enum {
00511    /*! \brief Channels have this property if they can accept input with jitter;
00512     *         i.e. most VoIP channels */
00513    AST_CHAN_TP_WANTSJITTER = (1 << 0),
00514    /*! \brief Channels have this property if they can create jitter;
00515     *         i.e. most VoIP channels */
00516    AST_CHAN_TP_CREATESJITTER = (1 << 1),
00517 };
00518 
00519 /*! \brief ast_channel flags */
00520 enum {
00521    /*! Queue incoming dtmf, to be released when this flag is turned off */
00522    AST_FLAG_DEFER_DTMF =    (1 << 1),
00523    /*! write should be interrupt generator */
00524    AST_FLAG_WRITE_INT =     (1 << 2),
00525    /*! a thread is blocking on this channel */
00526    AST_FLAG_BLOCKING =      (1 << 3),
00527    /*! This is a zombie channel */
00528    AST_FLAG_ZOMBIE =        (1 << 4),
00529    /*! There is an exception pending */
00530    AST_FLAG_EXCEPTION =     (1 << 5),
00531    /*! Listening to moh XXX anthm promises me this will disappear XXX */
00532    AST_FLAG_MOH =           (1 << 6),
00533    /*! This channel is spying on another channel */
00534    AST_FLAG_SPYING =        (1 << 7),
00535    /*! This channel is in a native bridge */
00536    AST_FLAG_NBRIDGE =       (1 << 8),
00537    /*! the channel is in an auto-incrementing dialplan processor,
00538     *  so when ->priority is set, it will get incremented before
00539     *  finding the next priority to run */
00540    AST_FLAG_IN_AUTOLOOP =   (1 << 9),
00541    /*! This is an outgoing call */
00542    AST_FLAG_OUTGOING =      (1 << 10),
00543    /*! A DTMF_BEGIN frame has been read from this channel, but not yet an END */
00544    AST_FLAG_IN_DTMF =       (1 << 12),
00545    /*! A DTMF_END was received when not IN_DTMF, so the length of the digit is
00546     *  currently being emulated */
00547    AST_FLAG_EMULATE_DTMF =  (1 << 13),
00548    /*! This is set to tell the channel not to generate DTMF begin frames, and
00549     *  to instead only generate END frames. */
00550    AST_FLAG_END_DTMF_ONLY = (1 << 14),
00551    /*! Flag to show channels that this call is hangup due to the fact that the call
00552        was indeed anwered, but in another channel */
00553    AST_FLAG_ANSWERED_ELSEWHERE = (1 << 15),
00554    /*! This flag indicates that on a masquerade, an active stream should not
00555     *  be carried over */
00556    AST_FLAG_MASQ_NOSTREAM = (1 << 16),
00557    /*! This flag indicates that the hangup exten was run when the bridge terminated,
00558     *  a message aimed at preventing a subsequent hangup exten being run at the pbx_run
00559     *  level */
00560    AST_FLAG_BRIDGE_HANGUP_RUN = (1 << 17),
00561    /*! This flag indicates that the hangup exten should NOT be run when the
00562     *  bridge terminates, this will allow the hangup in the pbx loop to be run instead.
00563     *  */
00564    AST_FLAG_BRIDGE_HANGUP_DONT = (1 << 18),
00565 };
00566 
00567 /*! \brief ast_bridge_config flags */
00568 enum {
00569    AST_FEATURE_PLAY_WARNING = (1 << 0),
00570    AST_FEATURE_REDIRECT =     (1 << 1),
00571    AST_FEATURE_DISCONNECT =   (1 << 2),
00572    AST_FEATURE_ATXFER =       (1 << 3),
00573    AST_FEATURE_AUTOMON =      (1 << 4),
00574    AST_FEATURE_PARKCALL =     (1 << 5),
00575    AST_FEATURE_AUTOMIXMON =   (1 << 6),
00576    AST_FEATURE_NO_H_EXTEN =   (1 << 7),
00577    AST_FEATURE_WARNING_ACTIVE = (1 << 8),
00578 };
00579 
00580 /*! \brief bridge configuration */
00581 struct ast_bridge_config {
00582    struct ast_flags features_caller;
00583    struct ast_flags features_callee;
00584    struct timeval start_time;
00585    struct timeval nexteventts;
00586    long feature_timer;
00587    long timelimit;
00588    long play_warning;
00589    long warning_freq;
00590    const char *warning_sound;
00591    const char *end_sound;
00592    const char *start_sound;
00593    int firstpass;
00594    unsigned int flags;
00595    void (* end_bridge_callback)(void *);   /*!< A callback that is called after a bridge attempt */
00596    void *end_bridge_callback_data;         /*!< Data passed to the callback */
00597    /*! If the end_bridge_callback_data refers to a channel which no longer is going to
00598     * exist when the end_bridge_callback is called, then it needs to be fixed up properly
00599     */
00600    void (*end_bridge_callback_data_fixup)(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator);
00601 };
00602 
00603 struct chanmon;
00604 
00605 struct outgoing_helper {
00606    const char *context;
00607    const char *exten;
00608    int priority;
00609    const char *cid_num;
00610    const char *cid_name;
00611    const char *account;
00612    struct ast_variable *vars;
00613    struct ast_channel *parent_channel;
00614 };
00615 
00616 enum {
00617    AST_CDR_TRANSFER =   (1 << 0),
00618    AST_CDR_FORWARD =    (1 << 1),
00619    AST_CDR_CALLWAIT =   (1 << 2),
00620    AST_CDR_CONFERENCE = (1 << 3),
00621 };
00622 
00623 enum {
00624    /*! Soft hangup by device */
00625    AST_SOFTHANGUP_DEV =       (1 << 0),
00626    /*! Soft hangup for async goto */
00627    AST_SOFTHANGUP_ASYNCGOTO = (1 << 1),
00628    AST_SOFTHANGUP_SHUTDOWN =  (1 << 2),
00629    AST_SOFTHANGUP_TIMEOUT =   (1 << 3),
00630    AST_SOFTHANGUP_APPUNLOAD = (1 << 4),
00631    AST_SOFTHANGUP_EXPLICIT =  (1 << 5),
00632    AST_SOFTHANGUP_UNBRIDGE =  (1 << 6),
00633 };
00634 
00635 
00636 /*! \brief Channel reload reasons for manager events at load or reload of configuration */
00637 enum channelreloadreason {
00638    CHANNEL_MODULE_LOAD,
00639    CHANNEL_MODULE_RELOAD,
00640    CHANNEL_CLI_RELOAD,
00641    CHANNEL_MANAGER_RELOAD,
00642 };
00643 
00644 /*!
00645  * \note None of the datastore API calls lock the ast_channel they are using.
00646  *       So, the channel should be locked before calling the functions that
00647  *       take a channel argument.
00648  */
00649 
00650 /*!
00651  * \brief Create a channel data store object
00652  * \deprecated You should use the ast_datastore_alloc() generic function instead.
00653  * \version 1.6.1 deprecated
00654  */
00655 struct ast_datastore *ast_channel_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
00656    __attribute__((deprecated));
00657 
00658 /*!
00659  * \brief Free a channel data store object
00660  * \deprecated You should use the ast_datastore_free() generic function instead.
00661  * \version 1.6.1 deprecated
00662  */
00663 int ast_channel_datastore_free(struct ast_datastore *datastore)
00664    __attribute__((deprecated));
00665 
00666 /*! \brief Inherit datastores from a parent to a child. */
00667 int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to);
00668 
00669 /*!
00670  * \brief Add a datastore to a channel
00671  *
00672  * \note The channel should be locked before calling this function.
00673  *
00674  * \retval 0 success
00675  * \retval non-zero failure
00676  */
00677 
00678 int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore);
00679 
00680 /*!
00681  * \brief Remove a datastore from a channel
00682  *
00683  * \note The channel should be locked before calling this function.
00684  *
00685  * \retval 0 success
00686  * \retval non-zero failure
00687  */
00688 int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore);
00689 
00690 /*!
00691  * \brief Find a datastore on a channel
00692  *
00693  * \note The channel should be locked before calling this function.
00694  *
00695  * \note The datastore returned from this function must not be used if the
00696  *       reference to the channel is released.
00697  *
00698  * \retval pointer to the datastore if found
00699  * \retval NULL if not found
00700  */
00701 struct ast_datastore *ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid);
00702 
00703 /*! \brief Change the state of a channel */
00704 int ast_setstate(struct ast_channel *chan, enum ast_channel_state);
00705 
00706 /*!
00707  * \brief Create a channel structure
00708  *
00709  * \retval NULL failure
00710  * \retval non-NULL successfully allocated channel
00711  *
00712  * \note By default, new channels are set to the "s" extension
00713  *       and "default" context.
00714  */
00715 struct ast_channel *ast_channel_alloc(int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const int amaflag, const char *name_fmt, ...) __attribute__((format(printf, 9, 10)));
00716 
00717 /*!
00718  * \brief Queue an outgoing frame
00719  *
00720  * \note The channel does not need to be locked before calling this function.
00721  */
00722 int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f);
00723 
00724 /*!
00725  * \brief Queue an outgoing frame to the head of the frame queue
00726  *
00727  * \param chan the channel to queue the frame on
00728  * \param f the frame to queue.  Note that this frame will be duplicated by
00729  *        this function.  It is the responsibility of the caller to handle
00730  *        freeing the memory associated with the frame being passed if
00731  *        necessary.
00732  *
00733  * \retval 0 success
00734  * \retval non-zero failure
00735  */
00736 int ast_queue_frame_head(struct ast_channel *chan, struct ast_frame *f);
00737 
00738 /*!
00739  * \brief Queue a hangup frame
00740  *
00741  * \note The channel does not need to be locked before calling this function.
00742  */
00743 int ast_queue_hangup(struct ast_channel *chan);
00744 
00745 /*!
00746  * \brief Queue a hangup frame with hangupcause set
00747  *
00748  * \note The channel does not need to be locked before calling this function.
00749  * \param[in] chan channel to queue frame onto
00750  * \param[in] cause the hangup cause
00751  * \return 0 on success, -1 on error
00752  * \since 1.6.1
00753  */
00754 int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause);
00755 
00756 /*!
00757  * \brief Queue a control frame with payload
00758  *
00759  * \param chan channel to queue frame onto
00760  * \param control type of control frame
00761  *
00762  * \note The channel does not need to be locked before calling this function.
00763  *
00764  * \retval zero on success
00765  * \retval non-zero on failure
00766  */
00767 int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control);
00768 
00769 /*!
00770  * \brief Queue a control frame with payload
00771  *
00772  * \param chan channel to queue frame onto
00773  * \param control type of control frame
00774  * \param data pointer to payload data to be included in frame
00775  * \param datalen number of bytes of payload data
00776  *
00777  * \retval 0 success
00778  * \retval non-zero failure
00779  *
00780  * The supplied payload data is copied into the frame, so the caller's copy
00781  * is not modified nor freed, and the resulting frame will retain a copy of
00782  * the data even if the caller frees their local copy.
00783  *
00784  * \note This method should be treated as a 'network transport'; in other
00785  * words, your frames may be transferred across an IAX2 channel to another
00786  * system, which may be a different endianness than yours. Because of this,
00787  * you should ensure that either your frames will never be expected to work
00788  * across systems, or that you always put your payload data into 'network byte
00789  * order' before calling this function.
00790  *
00791  * \note The channel does not need to be locked before calling this function.
00792  */
00793 int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control,
00794             const void *data, size_t datalen);
00795 
00796 /*!
00797  * \brief Change channel name
00798  *
00799  * \note The channel must be locked before calling this function.
00800  */
00801 void ast_change_name(struct ast_channel *chan, char *newname);
00802 
00803 /*! \brief Free a channel structure */
00804 void  ast_channel_free(struct ast_channel *);
00805 
00806 /*!
00807  * \brief Requests a channel
00808  *
00809  * \param type type of channel to request
00810  * \param format requested channel format (codec)
00811  * \param data data to pass to the channel requester
00812  * \param status status
00813  *
00814  * Request a channel of a given type, with data as optional information used
00815  * by the low level module
00816  *
00817  * \retval NULL failure
00818  * \retval non-NULL channel on success
00819  */
00820 struct ast_channel *ast_request(const char *type, int format, void *data, int *status);
00821 
00822 /*!
00823  * \brief Request a channel of a given type, with data as optional information used
00824  *        by the low level module and attempt to place a call on it
00825  *
00826  * \param type type of channel to request
00827  * \param format requested channel format
00828  * \param data data to pass to the channel requester
00829  * \param timeout maximum amount of time to wait for an answer
00830  * \param reason why unsuccessful (if unsuccessful)
00831  * \param cid_num Caller-ID Number
00832  * \param cid_name Caller-ID Name (ascii)
00833  *
00834  * \return Returns an ast_channel on success or no answer, NULL on failure.  Check the value of chan->_state
00835  * to know if the call was answered or not.
00836  */
00837 struct ast_channel *ast_request_and_dial(const char *type, int format, void *data,
00838    int timeout, int *reason, const char *cid_num, const char *cid_name);
00839 
00840 /*!
00841  * \brief Request a channel of a given type, with data as optional information used
00842  * by the low level module and attempt to place a call on it
00843  * \param type type of channel to request
00844  * \param format requested channel format
00845  * \param data data to pass to the channel requester
00846  * \param timeout maximum amount of time to wait for an answer
00847  * \param reason why unsuccessful (if unsuccessful)
00848  * \param cid_num Caller-ID Number
00849  * \param cid_name Caller-ID Name (ascii)
00850  * \param oh Outgoing helper
00851  * \return Returns an ast_channel on success or no answer, NULL on failure.  Check the value of chan->_state
00852  * to know if the call was answered or not.
00853  */
00854 struct ast_channel *__ast_request_and_dial(const char *type, int format, void *data,
00855    int timeout, int *reason, const char *cid_num, const char *cid_name, struct outgoing_helper *oh);
00856 
00857 /*!\brief Register a channel technology (a new channel driver)
00858  * Called by a channel module to register the kind of channels it supports.
00859  * \param tech Structure defining channel technology or "type"
00860  * \return Returns 0 on success, -1 on failure.
00861  */
00862 int ast_channel_register(const struct ast_channel_tech *tech);
00863 
00864 /*! \brief Unregister a channel technology
00865  * \param tech Structure defining channel technology or "type" that was previously registered
00866  * \return No return value.
00867  */
00868 void ast_channel_unregister(const struct ast_channel_tech *tech);
00869 
00870 /*! \brief Get a channel technology structure by name
00871  * \param name name of technology to find
00872  * \return a pointer to the structure, or NULL if no matching technology found
00873  */
00874 const struct ast_channel_tech *ast_get_channel_tech(const char *name);
00875 
00876 #ifdef CHANNEL_TRACE
00877 /*! \brief Update the context backtrace if tracing is enabled
00878  * \return Returns 0 on success, -1 on failure
00879  */
00880 int ast_channel_trace_update(struct ast_channel *chan);
00881 
00882 /*! \brief Enable context tracing in the channel
00883  * \return Returns 0 on success, -1 on failure
00884  */
00885 int ast_channel_trace_enable(struct ast_channel *chan);
00886 
00887 /*! \brief Disable context tracing in the channel.
00888  * \note Does not remove current trace entries
00889  * \return Returns 0 on success, -1 on failure
00890  */
00891 int ast_channel_trace_disable(struct ast_channel *chan);
00892 
00893 /*! \brief Whether or not context tracing is enabled
00894  * \return Returns -1 when the trace is enabled. 0 if not.
00895  */
00896 int ast_channel_trace_is_enabled(struct ast_channel *chan);
00897 
00898 /*! \brief Put the channel backtrace in a string
00899  * \return Returns the amount of lines in the backtrace. -1 on error.
00900  */
00901 int ast_channel_trace_serialize(struct ast_channel *chan, struct ast_str **out);
00902 #endif
00903 
00904 /*! \brief Hang up a channel
00905  * \note This function performs a hard hangup on a channel.  Unlike the soft-hangup, this function
00906  * performs all stream stopping, etc, on the channel that needs to end.
00907  * chan is no longer valid after this call.
00908  * \param chan channel to hang up
00909  * \return Returns 0 on success, -1 on failure.
00910  */
00911 int ast_hangup(struct ast_channel *chan);
00912 
00913 /*!
00914  * \brief Softly hangup up a channel
00915  *
00916  * \param chan channel to be soft-hung-up
00917  * \param cause   Ast hangupcause for hangup
00918  *
00919  * Call the protocol layer, but don't destroy the channel structure
00920  * (use this if you are trying to
00921  * safely hangup a channel managed by another thread.
00922  *
00923  * \note The channel passed to this function does not need to be locked.
00924  *
00925  * \return Returns 0 regardless
00926  */
00927 int ast_softhangup(struct ast_channel *chan, int cause);
00928 
00929 /*! \brief Softly hangup up a channel (no channel lock)
00930  * \param chan channel to be soft-hung-up
00931  * \param cause   Ast hangupcause for hangup (see cause.h) */
00932 int ast_softhangup_nolock(struct ast_channel *chan, int cause);
00933 
00934 /*! \brief Check to see if a channel is needing hang up
00935  * \param chan channel on which to check for hang up
00936  * This function determines if the channel is being requested to be hung up.
00937  * \return Returns 0 if not, or 1 if hang up is requested (including time-out).
00938  */
00939 int ast_check_hangup(struct ast_channel *chan);
00940 
00941 /*!
00942  * \brief Compare a offset with the settings of when to hang a channel up
00943  * \param chan channel on which to check for hang up
00944  * \param offset offset in seconds from current time
00945  * \return 1, 0, or -1
00946  * This function compares a offset from current time with the absolute time
00947  * out on a channel (when to hang up). If the absolute time out on a channel
00948  * is earlier than current time plus the offset, it returns 1, if the two
00949  * time values are equal, it return 0, otherwise, it return -1.
00950  * \sa ast_channel_cmpwhentohangup_tv()
00951  * \version 1.6.1 deprecated function (only had seconds precision)
00952  */
00953 int ast_channel_cmpwhentohangup(struct ast_channel *chan, time_t offset) __attribute__((deprecated));
00954 
00955 /*!
00956  * \brief Compare a offset with the settings of when to hang a channel up
00957  * \param chan channel on which to check for hangup
00958  * \param offset offset in seconds and microseconds from current time
00959  * \return 1, 0, or -1
00960  * This function compares a offset from current time with the absolute time
00961  * out on a channel (when to hang up). If the absolute time out on a channel
00962  * is earlier than current time plus the offset, it returns 1, if the two
00963  * time values are equal, it return 0, otherwise, it return -1.
00964  * \since 1.6.1
00965  */
00966 int ast_channel_cmpwhentohangup_tv(struct ast_channel *chan, struct timeval offset);
00967 
00968 /*! \brief Set when to hang a channel up
00969  *
00970  * \param chan channel on which to check for hang up
00971  * \param offset offset in seconds relative to the current time of when to hang up
00972  *
00973  * This function sets the absolute time out on a channel (when to hang up).
00974  *
00975  * \note This function does not require that the channel is locked before
00976  *       calling it.
00977  *
00978  * \return Nothing
00979  * \sa ast_channel_setwhentohangup_tv()
00980  * \version 1.6.1 deprecated function (only had seconds precision)
00981  */
00982 void ast_channel_setwhentohangup(struct ast_channel *chan, time_t offset) __attribute__((deprecated));
00983 
00984 /*! \brief Set when to hang a channel up
00985  *
00986  * \param chan channel on which to check for hang up
00987  * \param offset offset in seconds and useconds relative to the current time of when to hang up
00988  *
00989  * This function sets the absolute time out on a channel (when to hang up).
00990  *
00991  * \note This function does not require that the channel is locked before
00992  * calling it.
00993  *
00994  * \return Nothing
00995  * \since 1.6.1
00996  */
00997 void ast_channel_setwhentohangup_tv(struct ast_channel *chan, struct timeval offset);
00998 
00999 /*!
01000  * \brief Answer a channel
01001  *
01002  * \param chan channel to answer
01003  *
01004  * This function answers a channel and handles all necessary call
01005  * setup functions.
01006  *
01007  * \note The channel passed does not need to be locked, but is locked
01008  * by the function when needed.
01009  *
01010  * \note This function will wait up to 500 milliseconds for media to
01011  * arrive on the channel before returning to the caller, so that the
01012  * caller can properly assume the channel is 'ready' for media flow.
01013  *
01014  * \retval 0 on success
01015  * \retval non-zero on failure
01016  */
01017 int ast_answer(struct ast_channel *chan);
01018 
01019 /*!
01020  * \brief Answer a channel
01021  *
01022  * \param chan channel to answer
01023  * \param cdr_answer flag to control whether any associated CDR should be marked as 'answered'
01024  *
01025  * This function answers a channel and handles all necessary call
01026  * setup functions.
01027  *
01028  * \note The channel passed does not need to be locked, but is locked
01029  * by the function when needed.
01030  *
01031  * \note Unlike ast_answer(), this function will not wait for media
01032  * flow to begin. The caller should be careful before sending media
01033  * to the channel before incoming media arrives, as the outgoing
01034  * media may be lost.
01035  *
01036  * \retval 0 on success
01037  * \retval non-zero on failure
01038  */
01039 int ast_raw_answer(struct ast_channel *chan, int cdr_answer);
01040 
01041 /*!
01042  * \brief Answer a channel, with a selectable delay before returning
01043  *
01044  * \param chan channel to answer
01045  * \param delay maximum amount of time to wait for incoming media
01046  * \param cdr_answer flag to control whether any associated CDR should be marked as 'answered'
01047  *
01048  * This function answers a channel and handles all necessary call
01049  * setup functions.
01050  *
01051  * \note The channel passed does not need to be locked, but is locked
01052  * by the function when needed.
01053  *
01054  * \note This function will wait up to 'delay' milliseconds for media to
01055  * arrive on the channel before returning to the caller, so that the
01056  * caller can properly assume the channel is 'ready' for media flow. If
01057  * 'delay' is less than 500, the function will wait up to 500 milliseconds.
01058  *
01059  * \retval 0 on success
01060  * \retval non-zero on failure
01061  */
01062 int __ast_answer(struct ast_channel *chan, unsigned int delay, int cdr_answer);
01063 
01064 /*! \brief Make a call
01065  * \param chan which channel to make the call on
01066  * \param addr destination of the call
01067  * \param timeout time to wait on for connect
01068  * Place a call, take no longer than timeout ms.
01069    \return Returns -1 on failure, 0 on not enough time
01070    (does not automatically stop ringing), and
01071    the number of seconds the connect took otherwise.
01072    */
01073 int ast_call(struct ast_channel *chan, char *addr, int timeout);
01074 
01075 /*! \brief Indicates condition of channel
01076  * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
01077  * \param chan channel to change the indication
01078  * \param condition which condition to indicate on the channel
01079  * \return Returns 0 on success, -1 on failure
01080  */
01081 int ast_indicate(struct ast_channel *chan, int condition);
01082 
01083 /*! \brief Indicates condition of channel, with payload
01084  * \note Indicate a condition such as AST_CONTROL_HOLD with payload being music on hold class
01085  * \param chan channel to change the indication
01086  * \param condition which condition to indicate on the channel
01087  * \param data pointer to payload data
01088  * \param datalen size of payload data
01089  * \return Returns 0 on success, -1 on failure
01090  */
01091 int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen);
01092 
01093 /* Misc stuff ------------------------------------------------ */
01094 
01095 /*! \brief Wait for input on a channel
01096  * \param chan channel to wait on
01097  * \param ms length of time to wait on the channel
01098  * Wait for input on a channel for a given # of milliseconds (<0 for indefinite).
01099   \return Returns < 0 on  failure, 0 if nothing ever arrived, and the # of ms remaining otherwise */
01100 int ast_waitfor(struct ast_channel *chan, int ms);
01101 
01102 /*! \brief Wait for a specified amount of time, looking for hangups
01103  * \param chan channel to wait for
01104  * \param ms length of time in milliseconds to sleep
01105  * Waits for a specified amount of time, servicing the channel as required.
01106  * \return returns -1 on hangup, otherwise 0.
01107  */
01108 int ast_safe_sleep(struct ast_channel *chan, int ms);
01109 
01110 /*! \brief Wait for a specified amount of time, looking for hangups and a condition argument
01111  * \param chan channel to wait for
01112  * \param ms length of time in milliseconds to sleep
01113  * \param cond a function pointer for testing continue condition
01114  * \param data argument to be passed to the condition test function
01115  * \return returns -1 on hangup, otherwise 0.
01116  * Waits for a specified amount of time, servicing the channel as required. If cond
01117  * returns 0, this function returns.
01118  */
01119 int ast_safe_sleep_conditional(struct ast_channel *chan, int ms, int (*cond)(void*), void *data );
01120 
01121 /*! \brief Waits for activity on a group of channels
01122  * \param chan an array of pointers to channels
01123  * \param n number of channels that are to be waited upon
01124  * \param fds an array of fds to wait upon
01125  * \param nfds the number of fds to wait upon
01126  * \param exception exception flag
01127  * \param outfd fd that had activity on it
01128  * \param ms how long the wait was
01129  * Big momma function here.  Wait for activity on any of the n channels, or any of the nfds
01130    file descriptors.
01131    \return Returns the channel with activity, or NULL on error or if an FD
01132    came first.  If the FD came first, it will be returned in outfd, otherwise, outfd
01133    will be -1 */
01134 struct ast_channel *ast_waitfor_nandfds(struct ast_channel **chan, int n,
01135    int *fds, int nfds, int *exception, int *outfd, int *ms);
01136 
01137 /*! \brief Waits for input on a group of channels
01138    Wait for input on an array of channels for a given # of milliseconds.
01139    \return Return channel with activity, or NULL if none has activity.
01140    \param chan an array of pointers to channels
01141    \param n number of channels that are to be waited upon
01142    \param ms time "ms" is modified in-place, if applicable */
01143 struct ast_channel *ast_waitfor_n(struct ast_channel **chan, int n, int *ms);
01144 
01145 /*! \brief Waits for input on an fd
01146    This version works on fd's only.  Be careful with it. */
01147 int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception);
01148 
01149 
01150 /*! \brief Reads a frame
01151  * \param chan channel to read a frame from
01152  * \return Returns a frame, or NULL on error.  If it returns NULL, you
01153    best just stop reading frames and assume the channel has been
01154    disconnected. */
01155 struct ast_frame *ast_read(struct ast_channel *chan);
01156 
01157 /*! \brief Reads a frame, returning AST_FRAME_NULL frame if audio.
01158    \param chan channel to read a frame from
01159    \return  Returns a frame, or NULL on error.  If it returns NULL, you
01160       best just stop reading frames and assume the channel has been
01161       disconnected.
01162    \note Audio is replaced with AST_FRAME_NULL to avoid
01163    transcode when the resulting audio is not necessary. */
01164 struct ast_frame *ast_read_noaudio(struct ast_channel *chan);
01165 
01166 /*! \brief Write a frame to a channel
01167  * This function writes the given frame to the indicated channel.
01168  * \param chan destination channel of the frame
01169  * \param frame frame that will be written
01170  * \return It returns 0 on success, -1 on failure.
01171  */
01172 int ast_write(struct ast_channel *chan, struct ast_frame *frame);
01173 
01174 /*! \brief Write video frame to a channel
01175  * This function writes the given frame to the indicated channel.
01176  * \param chan destination channel of the frame
01177  * \param frame frame that will be written
01178  * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
01179  */
01180 int ast_write_video(struct ast_channel *chan, struct ast_frame *frame);
01181 
01182 /*! \brief Write text frame to a channel
01183  * This function writes the given frame to the indicated channel.
01184  * \param chan destination channel of the frame
01185  * \param frame frame that will be written
01186  * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
01187  */
01188 int ast_write_text(struct ast_channel *chan, struct ast_frame *frame);
01189 
01190 /*! \brief Send empty audio to prime a channel driver */
01191 int ast_prod(struct ast_channel *chan);
01192 
01193 /*! \brief Sets read format on channel chan
01194  * Set read format for channel to whichever component of "format" is best.
01195  * \param chan channel to change
01196  * \param format format to change to
01197  * \return Returns 0 on success, -1 on failure
01198  */
01199 int ast_set_read_format(struct ast_channel *chan, int format);
01200 
01201 /*! \brief Sets write format on channel chan
01202  * Set write format for channel to whichever component of "format" is best.
01203  * \param chan channel to change
01204  * \param format new format for writing
01205  * \return Returns 0 on success, -1 on failure
01206  */
01207 int ast_set_write_format(struct ast_channel *chan, int format);
01208 
01209 /*!
01210  * \brief Sends text to a channel
01211  *
01212  * \param chan channel to act upon
01213  * \param text string of text to send on the channel
01214  *
01215  * Write text to a display on a channel
01216  *
01217  * \note The channel does not need to be locked before calling this function.
01218  *
01219  * \retval 0 on success
01220  * \retval -1 on failure
01221  */
01222 int ast_sendtext(struct ast_channel *chan, const char *text);
01223 
01224 /*! \brief Receives a text character from a channel
01225  * \param chan channel to act upon
01226  * \param timeout timeout in milliseconds (0 for infinite wait)
01227  * Read a char of text from a channel
01228  * Returns 0 on success, -1 on failure
01229  */
01230 int ast_recvchar(struct ast_channel *chan, int timeout);
01231 
01232 /*! \brief Send a DTMF digit to a channel
01233  * Send a DTMF digit to a channel.
01234  * \param chan channel to act upon
01235  * \param digit the DTMF digit to send, encoded in ASCII
01236  * \param duration the duration of the digit ending in ms
01237  * \return Returns 0 on success, -1 on failure
01238  */
01239 int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration);
01240 
01241 /*! \brief Send a DTMF digit to a channel
01242  * Send a DTMF digit to a channel.
01243  * \param chan channel to act upon
01244  * \param digit the DTMF digit to send, encoded in ASCII
01245  * \return Returns 0 on success, -1 on failure
01246  */
01247 int ast_senddigit_begin(struct ast_channel *chan, char digit);
01248 
01249 /*! \brief Send a DTMF digit to a channel
01250 
01251  * Send a DTMF digit to a channel.
01252  * \param chan channel to act upon
01253  * \param digit the DTMF digit to send, encoded in ASCII
01254  * \param duration the duration of the digit ending in ms
01255  * \return Returns 0 on success, -1 on failure
01256  */
01257 int ast_senddigit_end(struct ast_channel *chan, char digit, unsigned int duration);
01258 
01259 /*! \brief Receives a text string from a channel
01260  * Read a string of text from a channel
01261  * \param chan channel to act upon
01262  * \param timeout timeout in milliseconds (0 for infinite wait)
01263  * \return the received text, or NULL to signify failure.
01264  */
01265 char *ast_recvtext(struct ast_channel *chan, int timeout);
01266 
01267 /*! \brief Browse channels in use
01268  * Browse the channels currently in use
01269  * \param prev where you want to start in the channel list
01270  * \return Returns the next channel in the list, NULL on end.
01271  *    If it returns a channel, that channel *has been locked*!
01272  */
01273 struct ast_channel *ast_channel_walk_locked(const struct ast_channel *prev);
01274 
01275 /*! \brief Get channel by name or uniqueid (locks channel) */
01276 struct ast_channel *ast_get_channel_by_name_locked(const char *chan);
01277 
01278 /*! \brief Get channel by name or uniqueid prefix (locks channel) */
01279 struct ast_channel *ast_get_channel_by_name_prefix_locked(const char *name, const int namelen);
01280 
01281 /*! \brief Get channel by name or uniqueid prefix (locks channel) */
01282 struct ast_channel *ast_walk_channel_by_name_prefix_locked(const struct ast_channel *chan, const char *name, const int namelen);
01283 
01284 /*! \brief Get channel by exten (and optionally context) and lock it */
01285 struct ast_channel *ast_get_channel_by_exten_locked(const char *exten, const char *context);
01286 
01287 /*! \brief Get next channel by exten (and optionally context) and lock it */
01288 struct ast_channel *ast_walk_channel_by_exten_locked(const struct ast_channel *chan, const char *exten,
01289                        const char *context);
01290 
01291 /*! ! \brief Waits for a digit
01292  * \param c channel to wait for a digit on
01293  * \param ms how many milliseconds to wait
01294  * \return Returns <0 on error, 0 on no entry, and the digit on success. */
01295 int ast_waitfordigit(struct ast_channel *c, int ms);
01296 
01297 /*! \brief Wait for a digit
01298  Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading.
01299  * \param c channel to wait for a digit on
01300  * \param ms how many milliseconds to wait
01301  * \param audiofd audio file descriptor to write to if audio frames are received
01302  * \param ctrlfd control file descriptor to monitor for reading
01303  * \return Returns 1 if ctrlfd becomes available */
01304 int ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int ctrlfd);
01305 
01306 /*! Reads multiple digits
01307  * \param c channel to read from
01308  * \param s string to read in to.  Must be at least the size of your length
01309  * \param len how many digits to read (maximum)
01310  * \param timeout how long to timeout between digits
01311  * \param rtimeout timeout to wait on the first digit
01312  * \param enders digits to end the string
01313  * Read in a digit string "s", max length "len", maximum timeout between
01314    digits "timeout" (-1 for none), terminated by anything in "enders".  Give them rtimeout
01315    for the first digit.  Returns 0 on normal return, or 1 on a timeout.  In the case of
01316    a timeout, any digits that were read before the timeout will still be available in s.
01317    RETURNS 2 in full version when ctrlfd is available, NOT 1*/
01318 int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders);
01319 int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd);
01320 
01321 /*! \brief Report DTMF on channel 0 */
01322 #define AST_BRIDGE_DTMF_CHANNEL_0      (1 << 0)
01323 /*! \brief Report DTMF on channel 1 */
01324 #define AST_BRIDGE_DTMF_CHANNEL_1      (1 << 1)
01325 /*! \brief Return all voice frames on channel 0 */
01326 #define AST_BRIDGE_REC_CHANNEL_0    (1 << 2)
01327 /*! \brief Return all voice frames on channel 1 */
01328 #define AST_BRIDGE_REC_CHANNEL_1    (1 << 3)
01329 /*! \brief Ignore all signal frames except NULL */
01330 #define AST_BRIDGE_IGNORE_SIGS         (1 << 4)
01331 
01332 
01333 /*! \brief Makes two channel formats compatible
01334  * \param c0 first channel to make compatible
01335  * \param c1 other channel to make compatible
01336  * Set two channels to compatible formats -- call before ast_channel_bridge in general .
01337  * \return Returns 0 on success and -1 if it could not be done */
01338 int ast_channel_make_compatible(struct ast_channel *c0, struct ast_channel *c1);
01339 
01340 /*! Bridge two channels together (early)
01341  * \param c0 first channel to bridge
01342  * \param c1 second channel to bridge
01343  * Bridge two channels (c0 and c1) together early. This implies either side may not be answered yet.
01344  * \return Returns 0 on success and -1 if it could not be done */
01345 int ast_channel_early_bridge(struct ast_channel *c0, struct ast_channel *c1);
01346 
01347 /*! Bridge two channels together
01348  * \param c0 first channel to bridge
01349  * \param c1 second channel to bridge
01350  * \param config config for the channels
01351  * \param fo destination frame(?)
01352  * \param rc destination channel(?)
01353  * Bridge two channels (c0 and c1) together.  If an important frame occurs, we return that frame in
01354    *rf (remember, it could be NULL) and which channel (0 or 1) in rc */
01355 /* int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc); */
01356 int ast_channel_bridge(struct ast_channel *c0,struct ast_channel *c1,
01357    struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc);
01358 
01359 /*!
01360  * \brief Weird function made for call transfers
01361  *
01362  * \param original channel to make a copy of
01363  * \param clone copy of the original channel
01364  *
01365  * This is a very strange and freaky function used primarily for transfer.  Suppose that
01366  * "original" and "clone" are two channels in random situations.  This function takes
01367  * the guts out of "clone" and puts them into the "original" channel, then alerts the
01368  * channel driver of the change, asking it to fixup any private information (like the
01369  * p->owner pointer) that is affected by the change.  The physical layer of the original
01370  * channel is hung up.
01371  *
01372  * \note Neither channel passed here needs to be locked before calling this function.
01373  */
01374 int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone);
01375 
01376 /*! Gives the string form of a given cause code */
01377 /*!
01378  * \param state cause to get the description of
01379  * Give a name to a cause code
01380  * Returns the text form of the binary cause code given
01381  */
01382 const char *ast_cause2str(int state) attribute_pure;
01383 
01384 /*! Convert the string form of a cause code to a number */
01385 /*!
01386  * \param name string form of the cause
01387  * Returns the cause code
01388  */
01389 int ast_str2cause(const char *name) attribute_pure;
01390 
01391 /*! Gives the string form of a given channel state */
01392 /*!
01393  * \param ast_channel_state state to get the name of
01394  * Give a name to a state
01395  * Returns the text form of the binary state given
01396  */
01397 const char *ast_state2str(enum ast_channel_state);
01398 
01399 /*! Gives the string form of a given transfer capability */
01400 /*!
01401  * \param transfercapability transfercapabilty to get the name of
01402  * Give a name to a transfercapbility
01403  * See above
01404  * Returns the text form of the binary transfer capability
01405  */
01406 char *ast_transfercapability2str(int transfercapability) attribute_const;
01407 
01408 /* Options: Some low-level drivers may implement "options" allowing fine tuning of the
01409    low level channel.  See frame.h for options.  Note that many channel drivers may support
01410    none or a subset of those features, and you should not count on this if you want your
01411    asterisk application to be portable.  They're mainly useful for tweaking performance */
01412 
01413 /*! Sets an option on a channel */
01414 /*!
01415  * \param channel channel to set options on
01416  * \param option option to change
01417  * \param data data specific to option
01418  * \param datalen length of the data
01419  * \param block blocking or not
01420  * Set an option on a channel (see frame.h), optionally blocking awaiting the reply
01421  * Returns 0 on success and -1 on failure
01422  */
01423 int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block);
01424 
01425 /*! Pick the best codec  */
01426 /* Choose the best codec...  Uhhh...   Yah. */
01427 int ast_best_codec(int fmts);
01428 
01429 
01430 /*! Checks the value of an option */
01431 /*!
01432  * Query the value of an option
01433  * Works similarly to setoption except only reads the options.
01434  */
01435 int ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block);
01436 
01437 /*! Checks for HTML support on a channel */
01438 /*! Returns 0 if channel does not support HTML or non-zero if it does */
01439 int ast_channel_supports_html(struct ast_channel *channel);
01440 
01441 /*! Sends HTML on given channel */
01442 /*! Send HTML or URL on link.  Returns 0 on success or -1 on failure */
01443 int ast_channel_sendhtml(struct ast_channel *channel, int subclass, const char *data, int datalen);
01444 
01445 /*! Sends a URL on a given link */
01446 /*! Send URL on link.  Returns 0 on success or -1 on failure */
01447 int ast_channel_sendurl(struct ast_channel *channel, const char *url);
01448 
01449 /*! Defers DTMF */
01450 /*! Defer DTMF so that you only read things like hangups and audio.  Returns
01451    non-zero if channel was already DTMF-deferred or 0 if channel is just now
01452    being DTMF-deferred */
01453 int ast_channel_defer_dtmf(struct ast_channel *chan);
01454 
01455 /*! Undo defer.  ast_read will return any dtmf characters that were queued */
01456 void ast_channel_undefer_dtmf(struct ast_channel *chan);
01457 
01458 /*! Initiate system shutdown -- prevents new channels from being allocated.
01459     If "hangup" is non-zero, all existing channels will receive soft
01460      hangups */
01461 void ast_begin_shutdown(int hangup);
01462 
01463 /*! Cancels an existing shutdown and returns to normal operation */
01464 void ast_cancel_shutdown(void);
01465 
01466 /*! Returns number of active/allocated channels */
01467 int ast_active_channels(void);
01468 
01469 /*! Returns non-zero if Asterisk is being shut down */
01470 int ast_shutting_down(void);
01471 
01472 /*! Activate a given generator */
01473 int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params);
01474 
01475 /*! Deactivate an active generator */
01476 void ast_deactivate_generator(struct ast_channel *chan);
01477 
01478 /*!
01479  * \brief Set caller ID number, name and ANI
01480  *
01481  * \note The channel does not need to be locked before calling this function.
01482  */
01483 void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani);
01484 
01485 /*! Set the file descriptor on the channel */
01486 void ast_channel_set_fd(struct ast_channel *chan, int which, int fd);
01487 
01488 /*! Add a channel to an optimized waitfor */
01489 void ast_poll_channel_add(struct ast_channel *chan0, struct ast_channel *chan1);
01490 
01491 /*! Delete a channel from an optimized waitfor */
01492 void ast_poll_channel_del(struct ast_channel *chan0, struct ast_channel *chan1);
01493 
01494 /*! Start a tone going */
01495 int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
01496 /*! Stop a tone from playing */
01497 void ast_tonepair_stop(struct ast_channel *chan);
01498 /*! Play a tone pair for a given amount of time */
01499 int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
01500 
01501 /*!
01502  * \brief Automatically service a channel for us...
01503  *
01504  * \retval 0 success
01505  * \retval -1 failure, or the channel is already being autoserviced
01506  */
01507 int ast_autoservice_start(struct ast_channel *chan);
01508 
01509 /*!
01510  * \brief Stop servicing a channel for us...
01511  *
01512  * \note if chan is locked prior to calling ast_autoservice_stop, it
01513  * is likely that there will be a deadlock between the thread that calls
01514  * ast_autoservice_stop and the autoservice thread. It is important
01515  * that chan is not locked prior to this call
01516  *
01517  * \retval 0 success
01518  * \retval -1 error, or the channel has been hungup
01519  */
01520 int ast_autoservice_stop(struct ast_channel *chan);
01521 
01522 /*!
01523  * \brief Enable or disable timer ticks for a channel
01524  *
01525  * \param rate number of timer ticks per second
01526  *
01527  * If timers are supported, force a scheduled expiration on the
01528  * timer fd, at which point we call the callback function / data
01529  *
01530  * Call this function with a rate of 0 to turn off the timer ticks
01531  *
01532  * \version 1.6.1 changed samples parameter to rate, accomodates new timing methods
01533  */
01534 int ast_settimeout(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data);
01535 
01536 /*!   \brief Transfer a channel (if supported).  Returns -1 on error, 0 if not supported
01537    and 1 if supported and requested
01538    \param chan current channel
01539    \param dest destination extension for transfer
01540 */
01541 int ast_transfer(struct ast_channel *chan, char *dest);
01542 
01543 /*!   \brief  Start masquerading a channel
01544    XXX This is a seriously whacked out operation.  We're essentially putting the guts of
01545            the clone channel into the original channel.  Start by killing off the original
01546            channel's backend.   I'm not sure we're going to keep this function, because
01547            while the features are nice, the cost is very high in terms of pure nastiness. XXX
01548    \param chan    Channel to masquerade
01549 */
01550 int ast_do_masquerade(struct ast_channel *chan);
01551 
01552 /*!   \brief Find bridged channel
01553    \param chan Current channel
01554 */
01555 struct ast_channel *ast_bridged_channel(struct ast_channel *chan);
01556 
01557 /*!
01558   \brief Inherits channel variable from parent to child channel
01559   \param parent Parent channel
01560   \param child Child channel
01561 
01562   Scans all channel variables in the parent channel, looking for those
01563   that should be copied into the child channel.
01564   Variables whose names begin with a single '_' are copied into the
01565   child channel with the prefix removed.
01566   Variables whose names begin with '__' are copied into the child
01567   channel with their names unchanged.
01568 */
01569 void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child);
01570 
01571 /*!
01572   \brief adds a list of channel variables to a channel
01573   \param chan the channel
01574   \param vars a linked list of variables
01575 
01576   Variable names can be for a regular channel variable or a dialplan function
01577   that has the ability to be written to.
01578 */
01579 void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars);
01580 
01581 /*!
01582   \brief An opaque 'object' structure use by silence generators on channels.
01583  */
01584 struct ast_silence_generator;
01585 
01586 /*!
01587   \brief Starts a silence generator on the given channel.
01588   \param chan The channel to generate silence on
01589   \return An ast_silence_generator pointer, or NULL if an error occurs
01590 
01591   This function will cause SLINEAR silence to be generated on the supplied
01592   channel until it is disabled; if the channel cannot be put into SLINEAR
01593   mode then the function will fail.
01594 
01595   The pointer returned by this function must be preserved and passed to
01596   ast_channel_stop_silence_generator when you wish to stop the silence
01597   generation.
01598  */
01599 struct ast_silence_generator *ast_channel_start_silence_generator(struct ast_channel *chan);
01600 
01601 /*!
01602   \brief Stops a previously-started silence generator on the given channel.
01603   \param chan The channel to operate on
01604   \param state The ast_silence_generator pointer return by a previous call to
01605   ast_channel_start_silence_generator.
01606   \return nothing
01607 
01608   This function will stop the operating silence generator and return the channel
01609   to its previous write format.
01610  */
01611 void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state);
01612 
01613 /*!
01614   \brief Check if the channel can run in internal timing mode.
01615   \param chan The channel to check
01616   \return boolean
01617 
01618   This function will return 1 if internal timing is enabled and the timing
01619   device is available.
01620  */
01621 int ast_internal_timing_enabled(struct ast_channel *chan);
01622 
01623 /* Misc. functions below */
01624 
01625 /*! \brief if fd is a valid descriptor, set *pfd with the descriptor
01626  * \return Return 1 (not -1!) if added, 0 otherwise (so we can add the
01627  * return value to the index into the array)
01628  */
01629 static inline int ast_add_fd(struct pollfd *pfd, int fd)
01630 {
01631    pfd->fd = fd;
01632    pfd->events = POLLIN | POLLPRI;
01633    return fd >= 0;
01634 }
01635 
01636 /*! \brief Helper function for migrating select to poll */
01637 static inline int ast_fdisset(struct pollfd *pfds, int fd, int maximum, int *start)
01638 {
01639    int x;
01640    int dummy = 0;
01641 
01642    if (fd < 0)
01643       return 0;
01644    if (!start)
01645       start = &dummy;
01646    for (x = *start; x < maximum; x++)
01647       if (pfds[x].fd == fd) {
01648          if (x == *start)
01649             (*start)++;
01650          return pfds[x].revents;
01651       }
01652    return 0;
01653 }
01654 
01655 #ifndef HAVE_TIMERSUB
01656 static inline void timersub(struct timeval *tvend, struct timeval *tvstart, struct timeval *tvdiff)
01657 {
01658    tvdiff->tv_sec = tvend->tv_sec - tvstart->tv_sec;
01659    tvdiff->tv_usec = tvend->tv_usec - tvstart->tv_usec;
01660    if (tvdiff->tv_usec < 0) {
01661       tvdiff->tv_sec --;
01662       tvdiff->tv_usec += 1000000;
01663    }
01664 
01665 }
01666 #endif
01667 
01668 /*! \brief Waits for activity on a group of channels
01669  * \param nfds the maximum number of file descriptors in the sets
01670  * \param rfds file descriptors to check for read availability
01671  * \param wfds file descriptors to check for write availability
01672  * \param efds file descriptors to check for exceptions (OOB data)
01673  * \param tvp timeout while waiting for events
01674  * This is the same as a standard select(), except it guarantees the
01675  * behaviour where the passed struct timeval is updated with how much
01676  * time was not slept while waiting for the specified events
01677  */
01678 static inline int ast_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tvp)
01679 {
01680 #ifdef __linux__
01681    return select(nfds, rfds, wfds, efds, tvp);
01682 #else
01683    if (tvp) {
01684       struct timeval tv, tvstart, tvend, tvlen;
01685       int res;
01686 
01687       tv = *tvp;
01688       gettimeofday(&tvstart, NULL);
01689       res = select(nfds, rfds, wfds, efds, tvp);
01690       gettimeofday(&tvend, NULL);
01691       timersub(&tvend, &tvstart, &tvlen);
01692       timersub(&tv, &tvlen, tvp);
01693       if (tvp->tv_sec < 0 || (tvp->tv_sec == 0 && tvp->tv_usec < 0)) {
01694          tvp->tv_sec = 0;
01695          tvp->tv_usec = 0;
01696       }
01697       return res;
01698    }
01699    else
01700       return select(nfds, rfds, wfds, efds, NULL);
01701 #endif
01702 }
01703 
01704 /*! \brief Retrieves the current T38 state of a channel */
01705 static inline enum ast_t38_state ast_channel_get_t38_state(struct ast_channel *chan)
01706 {
01707    enum ast_t38_state state = T38_STATE_UNAVAILABLE;
01708    int datalen = sizeof(state);
01709 
01710    ast_channel_queryoption(chan, AST_OPTION_T38_STATE, &state, &datalen, 0);
01711 
01712    return state;
01713 }
01714 
01715 #define CHECK_BLOCKING(c) do {    \
01716    if (ast_test_flag(c, AST_FLAG_BLOCKING)) {\
01717       if (option_debug) \
01718          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); \
01719    } else { \
01720       (c)->blocker = pthread_self(); \
01721       (c)->blockproc = __PRETTY_FUNCTION__; \
01722       ast_set_flag(c, AST_FLAG_BLOCKING); \
01723    } } while (0)
01724 
01725 ast_group_t ast_get_group(const char *s);
01726 
01727 /*! \brief print call- and pickup groups into buffer */
01728 char *ast_print_group(char *buf, int buflen, ast_group_t group);
01729 
01730 /*! \brief Convert enum channelreloadreason to text string for manager event
01731    \param reason  Enum channelreloadreason - reason for reload (manager, cli, start etc)
01732 */
01733 const char *channelreloadreason2txt(enum channelreloadreason reason);
01734 
01735 /*! \brief return an ast_variable list of channeltypes */
01736 struct ast_variable *ast_channeltype_list(void);
01737 
01738 /*!
01739   \brief return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument
01740   \param reason  The integer argument, usually taken from AST_CONTROL_ macros
01741   \return char pointer explaining the code
01742  */
01743 const char *ast_channel_reason2str(int reason);
01744 
01745 /*! \brief channel group info
01746  */
01747 struct ast_group_info {
01748    struct ast_channel *chan;
01749    char *category;
01750    char *group;
01751    AST_LIST_ENTRY(ast_group_info) list;
01752 };
01753 
01754 
01755 #if defined(__cplusplus) || defined(c_plusplus)
01756 }
01757 #endif
01758 
01759 #endif /* _ASTERISK_CHANNEL_H */

Generated on Fri Jul 24 00:40:53 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7