Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

channel.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- A telephony toolkit for Linux.
00003  *
00004  * General Asterisk channel definitions.
00005  * 
00006  * Copyright (C) 1999-2004, Digium, Inc.
00007  *
00008  * Mark Spencer <markster@digium.com>
00009  *
00010  * This program is free software, distributed under the terms of
00011  * the GNU General Public License
00012  */
00013 
00014 #ifndef _ASTERISK_CHANNEL_H
00015 #define _ASTERISK_CHANNEL_H
00016 
00017 #include <asterisk/frame.h>
00018 #include <asterisk/sched.h>
00019 #include <asterisk/chanvars.h>
00020 #include <unistd.h>
00021 #include <setjmp.h>
00022 #include <sys/poll.h>
00023 
00024 #if defined(__cplusplus) || defined(c_plusplus)
00025 extern "C" {
00026 #endif
00027 
00028 #include <asterisk/lock.h>
00029 
00030 //! Max length of an extension
00031 #define AST_MAX_EXTENSION 80
00032 
00033 #include <asterisk/cdr.h>
00034 #include <asterisk/monitor.h>
00035 
00036 
00037 #define AST_CHANNEL_NAME 80
00038 #define AST_CHANNEL_MAX_STACK 32
00039 
00040 #define MAX_LANGUAGE 20
00041 
00042 
00043 #define AST_MAX_FDS 8
00044 
00045 struct ast_generator {
00046    void *(*alloc)(struct ast_channel *chan, void *params);
00047    void (*release)(struct ast_channel *chan, void *data);
00048    int (*generate)(struct ast_channel *chan, void *data, int len, int samples);
00049 };
00050 
00051 //! Main Channel structure associated with a channel.
00052 /*! 
00053  * This is the side of it mostly used by the pbx and call management.
00054  */
00055 struct ast_channel {
00056    /*! ASCII Description of channel name */
00057    char name[AST_CHANNEL_NAME];     
00058    /*! Language requested */
00059    char language[MAX_LANGUAGE];     
00060    /*! Type of channel */
00061    char *type;          
00062    /*! File descriptor for channel -- Drivers will poll on these file descriptors, so at least one must be non -1.  */
00063    int fds[AST_MAX_FDS];         
00064 
00065    /*! Default music class */
00066    char musicclass[MAX_LANGUAGE];
00067 
00068    /*! Current generator data if there is any */
00069    void *generatordata;
00070    /*! Current active data generator */
00071    struct ast_generator *generator;
00072    /*! Whether or not the generator should be interrupted by write */
00073    int writeinterrupt;
00074 
00075    /*! Who are we bridged to, if we're bridged */
00076    struct ast_channel *bridge;
00077    /*! Who did we call? */
00078    struct ast_channel *dialed;
00079    /*! Who called us? */
00080    struct ast_channel *dialing;
00081    /*! Reverse the dialed link (0 false, 1 true) */
00082    int reversedialed;
00083    /*! Channel that will masquerade as us */
00084    struct ast_channel *masq;     
00085    /*! Who we are masquerading as */
00086    struct ast_channel *masqr;    
00087    /*! Call Detail Record Flags */
00088    int cdrflags;                                
00089    /*! Whether or not we're blocking */
00090    int blocking;           
00091    /*! Whether or not we have been hung up...  Do not set this value
00092        directly, use ast_softhangup */
00093    int _softhangup;           
00094    /*! Non-zero if this is a zombie channel */
00095    int zombie;             
00096    /*! Non-zero, set to actual time when channel is to be hung up */
00097    time_t   whentohangup;
00098    /*! If anyone is blocking, this is them */
00099    pthread_t blocker;         
00100    /*! Lock, can be used to lock a channel for some operations */
00101    ast_mutex_t lock;       
00102    /*! Procedure causing blocking */
00103    const char *blockproc;        
00104 
00105    /*! Current application */
00106    char *appl;          
00107    /*! Data passed to current application */
00108    char *data;          
00109    
00110    /*! Has an exception been detected */
00111    int exception;          
00112    /*! Which fd had an event detected on */
00113    int fdno;            
00114    /*! Schedule context */
00115    struct sched_context *sched;     
00116    /*! For streaming playback, the schedule ID */
00117    int streamid;           
00118    /*! Stream itself. */
00119    struct ast_filestream *stream;      
00120    /*! For streaming playback, the schedule ID */
00121    int vstreamid;          
00122    /*! Stream itself. */
00123    struct ast_filestream *vstream;     
00124    /*! Original writer format */
00125    int oldwriteformat;        
00126    
00127    /*! Timing fd */
00128    int timingfd;
00129    int (*timingfunc)(void *data);
00130    void *timingdata;
00131 
00132    /*! State of line -- Don't write directly, use ast_setstate */
00133    int _state;          
00134    /*! Number of rings so far */
00135    int rings;           
00136    /*! Current level of application */
00137    int stack;
00138 
00139 
00140    /*! Kinds of data this channel can natively handle */
00141    int nativeformats;         
00142    /*! Requested read format */
00143    int readformat;            
00144    /*! Requested write format */
00145    int writeformat;        
00146 
00147    
00148    /*! Malloc'd Dialed Number Identifier */
00149    char *dnid;          
00150    /*! Malloc'd Caller ID */
00151    char *callerid;
00152    /*! Malloc'd ANI */
00153    char *ani;        
00154    /*! Malloc'd RDNIS */
00155    char *rdnis;
00156    /*! Hide callerid from user */
00157    int restrictcid;
00158    /*! Callerid presentation/screening */
00159    int callingpres;
00160 
00161    
00162    /*! Current extension context */
00163    char context[AST_MAX_EXTENSION]; 
00164    /*! Current non-macro context */
00165    char macrocontext[AST_MAX_EXTENSION];  
00166    /*! Current non-macro extension */
00167    char macroexten[AST_MAX_EXTENSION];
00168    /*! Current non-macro priority */
00169    int macropriority;
00170    /*! Current extension number */
00171    char exten[AST_MAX_EXTENSION];      
00172    /* Current extension priority */
00173    int priority;                 
00174    /*! Application information -- see assigned numbers */
00175    void *app[AST_CHANNEL_MAX_STACK];   
00176    /*! Any/all queued DTMF characters */
00177    char dtmfq[AST_MAX_EXTENSION];      
00178    /*! Are DTMF digits being deferred */
00179    int deferdtmf;          
00180    /*! DTMF frame */
00181    struct ast_frame dtmff;       
00182    /*! Private channel implementation details */
00183    struct ast_channel_pvt *pvt;
00184 
00185                   
00186    /*! Jump buffer used for returning from applications */
00187    jmp_buf jmp[AST_CHANNEL_MAX_STACK]; 
00188 
00189    struct ast_pbx *pbx;
00190    /*! Set BEFORE PBX is started to determine AMA flags */
00191    int   amaflags;         
00192    /*! Account code for billing */
00193    char  accountcode[20];     
00194    /*! Call Detail Record */
00195    struct ast_cdr *cdr;       
00196    /*! Whether or not ADSI is detected on CPE */
00197    int   adsicpe;
00198    /*! Where to forward to if asked to dial on this interface */
00199    char call_forward[AST_MAX_EXTENSION];
00200 
00201    /*! Tone zone */
00202    struct tone_zone *zone;
00203 
00204    /* Channel monitoring */
00205    struct ast_channel_monitor *monitor;
00206 
00207    /*! Track the read/written samples for monitor use */
00208    unsigned long insmpl;
00209    unsigned long outsmpl;
00210 
00211    /* Frames in/out counters */
00212    unsigned int fin;
00213    unsigned int fout;
00214 
00215    /* Unique Channel Identifier */
00216    char uniqueid[32];
00217 
00218    /* Why is the channel hanged up */
00219    int hangupcause;
00220    
00221    /* A linked list for variables */
00222    struct ast_var_t *vars; 
00223    AST_LIST_HEAD(varshead,ast_var_t) varshead;
00224 
00225    unsigned int callgroup;
00226    unsigned int pickupgroup;
00227 
00228    /*! channel flags of AST_FLAG_ type */
00229    int flag;
00230    
00231    /*! For easy linking */
00232    struct ast_channel *next;
00233 
00234 };
00235 
00236 #define AST_FLAG_DIGITAL   1  /* if the call is a digital ISDN call */
00237 
00238 static inline int ast_test_flag(struct ast_channel *chan, int mode)
00239 {
00240    return chan->flag & mode;
00241 }
00242 
00243 static inline void ast_set_flag(struct ast_channel *chan, int mode)
00244 {
00245    chan->flag |= mode;
00246 }
00247 
00248 static inline void ast_clear_flag(struct ast_channel *chan, int mode)
00249 {
00250    chan->flag &= ~mode;
00251 }
00252 
00253 static inline void ast_set2_flag(struct ast_channel *chan, int value, int mode)
00254 {
00255    if (value)
00256       ast_set_flag(chan, mode);
00257    else
00258       ast_clear_flag(chan, mode);
00259 }
00260 
00261 static inline void ast_dup_flag(struct ast_channel *dstchan, struct ast_channel *srcchan, int mode)
00262 {
00263    if (ast_test_flag(srcchan, mode))
00264       ast_set_flag(dstchan, mode);
00265    else
00266       ast_clear_flag(dstchan, mode);
00267 }  
00268 
00269 struct ast_bridge_config {
00270    int play_to_caller;
00271    int play_to_callee;
00272    int allowredirect_in;
00273    int allowredirect_out;
00274    int allowdisconnect_in;
00275    int allowdisconnect_out;
00276    long timelimit;
00277    long play_warning;
00278    long warning_freq;
00279    char *warning_sound;
00280    char *end_sound;
00281    char *start_sound;
00282    int firstpass;
00283 };
00284 
00285 struct chanmon;
00286 
00287 #define LOAD_OH(oh) {   \
00288    oh.context = context; \
00289    oh.exten = exten; \
00290    oh.priority = priority; \
00291    oh.callerid = callerid; \
00292    oh.variable = variable; \
00293    oh.account = account; \
00294 } 
00295 
00296 struct outgoing_helper {
00297    char *context;
00298    char *exten;
00299    int priority;
00300    char *callerid;
00301    char *variable;
00302    char *account;
00303 };
00304 
00305 #define AST_CDR_TRANSFER   (1 << 0)
00306 #define AST_CDR_FORWARD    (1 << 1)
00307 #define AST_CDR_CALLWAIT   (1 << 2)
00308 #define AST_CDR_CONFERENCE (1 << 3)
00309 
00310 #define AST_ADSI_UNKNOWN   (0)
00311 #define AST_ADSI_AVAILABLE (1)
00312 #define AST_ADSI_UNAVAILABLE  (2)
00313 #define AST_ADSI_OFFHOOKONLY  (3)
00314 
00315 #define AST_SOFTHANGUP_DEV       (1 << 0) /* Soft hangup by device */
00316 #define AST_SOFTHANGUP_ASYNCGOTO (1 << 1) /* Soft hangup for async goto */
00317 #define AST_SOFTHANGUP_SHUTDOWN     (1 << 2)
00318 #define AST_SOFTHANGUP_TIMEOUT      (1 << 3)
00319 #define AST_SOFTHANGUP_APPUNLOAD (1 << 4)
00320 #define AST_SOFTHANGUP_EXPLICIT     (1 << 5)
00321 
00322 /* Bits 0-15 of state are reserved for the state (up/down) of the line */
00323 /*! Channel is down and available */
00324 #define AST_STATE_DOWN     0     
00325 /*! Channel is down, but reserved */
00326 #define AST_STATE_RESERVED 1     
00327 /*! Channel is off hook */
00328 #define AST_STATE_OFFHOOK  2     
00329 /*! Digits (or equivalent) have been dialed */
00330 #define AST_STATE_DIALING  3     
00331 /*! Line is ringing */
00332 #define AST_STATE_RING     4     
00333 /*! Remote end is ringing */
00334 #define AST_STATE_RINGING  5     
00335 /*! Line is up */
00336 #define AST_STATE_UP    6     
00337 /*! Line is busy */
00338 #define AST_STATE_BUSY     7     
00339 /*! Digits (or equivalent) have been dialed while offhook */
00340 #define AST_STATE_DIALING_OFFHOOK   8
00341 /*! Channel has detected an incoming call and is waiting for ring */
00342 #define AST_STATE_PRERING       9
00343 
00344 /* Bits 16-32 of state are reserved for flags */
00345 /*! Do not transmit voice data */
00346 #define AST_STATE_MUTE     (1 << 16)   
00347 
00348 /*! Device is valid but channel didn't know state */
00349 #define AST_DEVICE_UNKNOWN 0
00350 /*! Device is not used */
00351 #define AST_DEVICE_NOT_INUSE  1
00352 /*! Device is in use */
00353 #define AST_DEVICE_INUSE   2
00354 /*! Device is busy */
00355 #define AST_DEVICE_BUSY    3
00356 /*! Device is invalid */
00357 #define AST_DEVICE_INVALID 4
00358 /*! Device is unavailable */
00359 #define AST_DEVICE_UNAVAILABLE   5
00360 
00361 //! Requests a channel
00362 /*! 
00363  * \param type type of channel to request
00364  * \param format requested channel format
00365  * \param data data to pass to the channel requester
00366  * Request a channel of a given type, with data as optional information used 
00367  * by the low level module
00368  * Returns an ast_channel on success, NULL on failure.
00369  */
00370 struct ast_channel *ast_request(char *type, int format, void *data);
00371 
00372 //! Search the Channels by Name
00373 /*!
00374  * \param device like a dialstring
00375  * Search the Device in active channels by compare the channelname against 
00376  * the devicename. Compared are only the first chars to the first '-' char.
00377  * Returns an AST_DEVICE_UNKNOWN if no channel found or
00378  * AST_DEVICE_INUSE if a channel is found
00379  */
00380 int ast_parse_device_state(char *device);
00381 
00382 //! Asks a channel for device state
00383 /*!
00384  * \param device like a dialstring
00385  * Asks a channel for device state, data is  normaly a number from dialstring
00386  * used by the low level module
00387  * Trys the channel devicestate callback if not supported search in the
00388  * active channels list for the device.
00389  * Returns an AST_DEVICE_??? state -1 on failure
00390  */
00391 int ast_device_state(char *device);
00392 
00393 /*!
00394  * \param type type of channel to request
00395  * \param format requested channel format
00396  * \param data data to pass to the channel requester
00397  * \param timeout maximum amount of time to wait for an answer
00398  * \param why unsuccessful (if unsuceessful)
00399  * Request a channel of a given type, with data as optional information used 
00400  * by the low level module and attempt to place a call on it
00401  * Returns an ast_channel on success or no answer, NULL on failure.  Check the value of chan->_state
00402  * to know if the call was answered or not.
00403  */
00404 struct ast_channel *ast_request_and_dial(char *type, int format, void *data, int timeout, int *reason, char *callerid);
00405 
00406 struct ast_channel *__ast_request_and_dial(char *type, int format, void *data, int timeout, int *reason, char *callerid, struct outgoing_helper *oh);
00407 
00408 //! Registers a channel
00409 /*! 
00410  * \param type type of channel you are registering
00411  * \param description short description of the channel
00412  * \param capabilities a bit mask of the capabilities of the channel
00413  * \param requester a function pointer that properly responds to a call.  See one of the channel drivers for details.
00414  * Called by a channel module to register the kind of channels it supports.
00415  * It supplies a brief type, a longer, but still short description, and a
00416  * routine that creates a channel
00417  * Returns 0 on success, -1 on failure.
00418  */
00419 int ast_channel_register(char *type, char *description, int capabilities, 
00420          struct ast_channel* (*requester)(char *type, int format, void *data));
00421 
00422 /* Same like the upper function but with support for devicestate */
00423 int ast_channel_register_ex(char *type, char *description, int capabilities,
00424       struct ast_channel *(*requester)(char *type, int format, void *data),
00425       int (*devicestate)(void *data));
00426 
00427 //! Unregister a channel class
00428 /*
00429  * \param type the character string that corresponds to the channel you wish to unregister
00430  * Basically just unregisters the channel with the asterisk channel system
00431  * No return value.
00432  */
00433 void ast_channel_unregister(char *type);
00434 
00435 //! Hang up a channel 
00436 /*! 
00437  * \param chan channel to hang up
00438  * This function performs a hard hangup on a channel.  Unlike the soft-hangup, this function
00439  * performs all stream stopping, etc, on the channel that needs to end.
00440  * chan is no longer valid after this call.
00441  * Returns 0 on success, -1 on failure.
00442  */
00443 int ast_hangup(struct ast_channel *chan);
00444 
00445 //! Softly hangup up a channel
00446 /*! 
00447  * \param chan channel to be soft-hung-up
00448  * Call the protocol layer, but don't destroy the channel structure (use this if you are trying to
00449  * safely hangup a channel managed by another thread.
00450  * Returns 0 regardless
00451  */
00452 int ast_softhangup(struct ast_channel *chan, int cause);
00453 int ast_softhangup_nolock(struct ast_channel *chan, int cause);
00454 
00455 //! Check to see if a channel is needing hang up
00456 /*! 
00457  * \param chan channel on which to check for hang up
00458  * This function determines if the channel is being requested to be hung up.
00459  * Returns 0 if not, or 1 if hang up is requested (including time-out).
00460  */
00461 int ast_check_hangup(struct ast_channel *chan);
00462 
00463 //! Set when to hang a channel up
00464 /*! 
00465  * \param chan channel on which to check for hang up
00466  * \param offset offset in seconds from current time of when to hang up
00467  * This function sets the absolute time out on a channel (when to hang up).
00468  */
00469 void ast_channel_setwhentohangup(struct ast_channel *chan, time_t offset);
00470 
00471 //! Answer a ringing call
00472 /*!
00473  * \param chan channel to answer
00474  * This function answers a channel and handles all necessary call
00475  * setup functions.
00476  * Returns 0 on success, -1 on failure
00477  */
00478 int ast_answer(struct ast_channel *chan);
00479 
00480 //! Make a call
00481 /*! 
00482  * \param chan which channel to make the call on
00483  * \param addr destination of the call
00484  * \param timeout time to wait on for connect
00485  * Place a call, take no longer than timeout ms.  Returns -1 on failure, 
00486    0 on not enough time (does not auto matically stop ringing), and  
00487    the number of seconds the connect took otherwise.
00488    Returns 0 on success, -1 on failure
00489    */
00490 int ast_call(struct ast_channel *chan, char *addr, int timeout);
00491 
00492 //! Indicates condition of channel
00493 /*! 
00494  * \param chan channel to change the indication
00495  * \param condition which condition to indicate on the channel
00496  * Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
00497  * Returns 0 on success, -1 on failure
00498  */
00499 int ast_indicate(struct ast_channel *chan, int condition);
00500 
00501 /* Misc stuff */
00502 
00503 //! Wait for input on a channel
00504 /*! 
00505  * \param chan channel to wait on
00506  * \param ms length of time to wait on the channel
00507  * Wait for input on a channel for a given # of milliseconds (<0 for indefinite). 
00508   Returns < 0 on  failure, 0 if nothing ever arrived, and the # of ms remaining otherwise */
00509 int ast_waitfor(struct ast_channel *chan, int ms);
00510 
00511 //! Wait for a specied amount of time, looking for hangups
00512 /*!
00513  * \param chan channel to wait for
00514  * \param ms length of time in milliseconds to sleep
00515  * Waits for a specified amount of time, servicing the channel as required.
00516  * returns -1 on hangup, otherwise 0.
00517  */
00518 int ast_safe_sleep(struct ast_channel *chan, int ms);
00519 
00520 //! Wait for a specied amount of time, looking for hangups and a condition argument
00521 /*!
00522  * \param chan channel to wait for
00523  * \param ms length of time in milliseconds to sleep
00524  * \param cond a function pointer for testing continue condition
00525  * \param data argument to be passed to the condition test function
00526  * Waits for a specified amount of time, servicing the channel as required. If cond
00527  * returns 0, this function returns.
00528  * returns -1 on hangup, otherwise 0.
00529  */
00530 int ast_safe_sleep_conditional(struct ast_channel *chan, int ms, int (*cond)(void*), void *data );
00531 
00532 //! Waits for activity on a group of channels
00533 /*! 
00534  * \param chan an array of pointers to channels
00535  * \param n number of channels that are to be waited upon
00536  * \param fds an array of fds to wait upon
00537  * \param nfds the number of fds to wait upon
00538  * \param exception exception flag
00539  * \param outfd fd that had activity on it
00540  * \param ms how long the wait was
00541  * Big momma function here.  Wait for activity on any of the n channels, or any of the nfds
00542    file descriptors.  Returns the channel with activity, or NULL on error or if an FD
00543    came first.  If the FD came first, it will be returned in outfd, otherwise, outfd
00544    will be -1 */
00545 struct ast_channel *ast_waitfor_nandfds(struct ast_channel **chan, int n, int *fds, int nfds, int *exception, int *outfd, int *ms);
00546 
00547 //! Waits for input on a group of channels
00548 /*! Wait for input on an array of channels for a given # of milliseconds. Return channel
00549    with activity, or NULL if none has activity.  time "ms" is modified in-place, if applicable */
00550 struct ast_channel *ast_waitfor_n(struct ast_channel **chan, int n, int *ms);
00551 
00552 //! Waits for input on an fd
00553 /*! This version works on fd's only.  Be careful with it. */
00554 int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception);
00555 
00556 
00557 //! Reads a frame
00558 /*!
00559  * \param chan channel to read a frame from
00560  * Read a frame.  Returns a frame, or NULL on error.  If it returns NULL, you
00561    best just stop reading frames and assume the channel has been
00562    disconnected. */
00563 struct ast_frame *ast_read(struct ast_channel *chan);
00564 
00565 //! Write a frame to a channel
00566 /*!
00567  * \param chan destination channel of the frame
00568  * \param frame frame that will be written
00569  * This function writes the given frame to the indicated channel.
00570  * It returns 0 on success, -1 on failure.
00571  */
00572 int ast_write(struct ast_channel *chan, struct ast_frame *frame);
00573 
00574 //! Write video frame to a channel
00575 /*!
00576  * \param chan destination channel of the frame
00577  * \param frame frame that will be written
00578  * This function writes the given frame to the indicated channel.
00579  * It returns 1 on success, 0 if not implemented, and -1 on failure.
00580  */
00581 int ast_write_video(struct ast_channel *chan, struct ast_frame *frame);
00582 
00583 /* Send empty audio to prime a channel driver */
00584 int ast_prod(struct ast_channel *chan);
00585 
00586 //! Sets read format on channel chan
00587 /*! 
00588  * \param chan channel to change
00589  * \param format format to change to
00590  * Set read format for channel to whichever component of "format" is best. 
00591  * Returns 0 on success, -1 on failure
00592  */
00593 int ast_set_read_format(struct ast_channel *chan, int format);
00594 
00595 //! Sets write format on channel chan
00596 /*! 
00597  * \param chan channel to change
00598  * \param format new format for writing
00599  * Set write format for channel to whichever compoent of "format" is best. 
00600  * Returns 0 on success, -1 on failure
00601  */
00602 int ast_set_write_format(struct ast_channel *chan, int format);
00603 
00604 //! Sends text to a channel
00605 /*! 
00606  * \param chan channel to act upon
00607  * \param text string of text to send on the channel
00608  * Write text to a display on a channel
00609  * Returns 0 on success, -1 on failure
00610  */
00611 int ast_sendtext(struct ast_channel *chan, char *text);
00612 
00613 //! Receives a text character from a channel
00614 /*! 
00615  * \param chan channel to act upon
00616  * \param timeout timeout in milliseconds (0 for infinite wait)
00617  * Read a char of text from a channel
00618  * Returns 0 on success, -1 on failure
00619  */
00620 
00621 int ast_senddigit(struct ast_channel *chan, char digit);
00622 
00623 int ast_recvchar(struct ast_channel *chan, int timeout);
00624 
00625 //! Browse channels in use
00626 /*! 
00627  * \param prev where you want to start in the channel list
00628  * Browse the channels currently in use 
00629  * Returns the next channel in the list, NULL on end.
00630  * If it returns a channel, that channel *has been locked*!
00631  */
00632 struct ast_channel *ast_channel_walk_locked(struct ast_channel *prev);
00633 
00634 //! Get channel by name (locks channel)
00635 struct ast_channel *ast_get_channel_by_name_locked(char *channame);
00636 
00637 //! Waits for a digit
00638 /*! 
00639  * \param c channel to wait for a digit on
00640  * \param ms how many milliseconds to wait
00641  * Wait for a digit.  Returns <0 on error, 0 on no entry, and the digit on success. */
00642 char ast_waitfordigit(struct ast_channel *c, int ms);
00643 
00644 /* Same as above with audio fd for outputing read audio and ctrlfd to monitor for
00645    reading. Returns 1 if ctrlfd becomes available */
00646 char ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int ctrlfd);
00647 
00648 //! Reads multiple digits
00649 /*! 
00650  * \param c channel to read from
00651  * \param s string to read in to.  Must be at least the size of your length
00652  * \param len how many digits to read (maximum)
00653  * \param timeout how long to timeout between digits
00654  * \param rtimeout timeout to wait on the first digit
00655  * \param enders digits to end the string
00656  * Read in a digit string "s", max length "len", maximum timeout between 
00657    digits "timeout" (-1 for none), terminated by anything in "enders".  Give them rtimeout
00658    for the first digit.  Returns 0 on normal return, or 1 on a timeout.  In the case of
00659    a timeout, any digits that were read before the timeout will still be available in s.  
00660    RETURNS 2 in full version when ctrlfd is available, NOT 1*/
00661 int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders);
00662 int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd);
00663 
00664 /*! Report DTMF on channel 0 */
00665 #define AST_BRIDGE_DTMF_CHANNEL_0      (1 << 0)    
00666 /*! Report DTMF on channel 1 */
00667 #define AST_BRIDGE_DTMF_CHANNEL_1      (1 << 1)    
00668 /*! Return all voice frames on channel 0 */
00669 #define AST_BRIDGE_REC_CHANNEL_0    (1 << 2)    
00670 /*! Return all voice frames on channel 1 */
00671 #define AST_BRIDGE_REC_CHANNEL_1    (1 << 3)    
00672 /*! Ignore all signal frames except NULL */
00673 #define AST_BRIDGE_IGNORE_SIGS         (1 << 4)    
00674 
00675 
00676 //! Makes two channel formats compatible
00677 /*! 
00678  * \param c0 first channel to make compatible
00679  * \param c1 other channel to make compatible
00680  * Set two channels to compatible formats -- call before ast_channel_bridge in general .  Returns 0 on success
00681    and -1 if it could not be done */
00682 int ast_channel_make_compatible(struct ast_channel *c0, struct ast_channel *c1);
00683 
00684 //! Bridge two channels together
00685 /*! 
00686  * \param c0 first channel to bridge
00687  * \param c1 second channel to bridge
00688  * \param flags for the channels
00689  * \param fo destination frame(?)
00690  * \param rc destination channel(?)
00691  * Bridge two channels (c0 and c1) together.  If an important frame occurs, we return that frame in
00692    *rf (remember, it could be NULL) and which channel (0 or 1) in rc */
00693 //int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc);
00694 int ast_channel_bridge(struct ast_channel *c0,struct ast_channel *c1,struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc);
00695 
00696 //! Weird function made for call transfers
00697 /*! 
00698  * \param original channel to make a copy of
00699  * \param clone copy of the original channel
00700  * This is a very strange and freaky function used primarily for transfer.  Suppose that
00701    "original" and "clone" are two channels in random situations.  This function takes
00702    the guts out of "clone" and puts them into the "original" channel, then alerts the
00703    channel driver of the change, asking it to fixup any private information (like the
00704    p->owner pointer) that is affected by the change.  The physical layer of the original
00705    channel is hung up.  */
00706 int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone);
00707 
00708 //! Gives the string form of a given state
00709 /*! 
00710  * \param state state to get the name of
00711  * Give a name to a state 
00712  * Pretty self explanatory.
00713  * Returns the text form of the binary state given
00714  */
00715 char *ast_state2str(int state);
00716 
00717 /* Options: Some low-level drivers may implement "options" allowing fine tuning of the
00718    low level channel.  See frame.h for options.  Note that many channel drivers may support
00719    none or a subset of those features, and you should not count on this if you want your
00720    asterisk application to be portable.  They're mainly useful for tweaking performance */
00721 
00722 //! Sets an option on a channel
00723 /*! 
00724  * \param channel channel to set options on
00725  * \param option option to change
00726  * \param data data specific to option
00727  * \param datalen length of the data
00728  * \param block blocking or not
00729  * Set an option on a channel (see frame.h), optionally blocking awaiting the reply 
00730  * Returns 0 on success and -1 on failure
00731  */
00732 int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block);
00733 
00734 //! Checks the value of an option
00735 /*! 
00736  * Query the value of an option, optionally blocking until a reply is received
00737  * Works similarly to setoption except only reads the options.
00738  */
00739 struct ast_frame *ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block);
00740 
00741 //! Checks for HTML support on a channel
00742 /*! Returns 0 if channel does not support HTML or non-zero if it does */
00743 int ast_channel_supports_html(struct ast_channel *channel);
00744 
00745 //! Sends HTML on given channel
00746 /*! Send HTML or URL on link.  Returns 0 on success or -1 on failure */
00747 int ast_channel_sendhtml(struct ast_channel *channel, int subclass, char *data, int datalen);
00748 
00749 //! Sends a URL on a given link
00750 /*! Send URL on link.  Returns 0 on success or -1 on failure */
00751 int ast_channel_sendurl(struct ast_channel *channel, char *url);
00752 
00753 //! Defers DTMF
00754 /*! Defer DTMF so that you only read things like hangups and audio.  Returns
00755    non-zero if channel was already DTMF-deferred or 0 if channel is just now
00756    being DTMF-deferred */
00757 int ast_channel_defer_dtmf(struct ast_channel *chan);
00758 
00759 //! Undeos a defer
00760 /*! Undo defer.  ast_read will return any dtmf characters that were queued */
00761 void ast_channel_undefer_dtmf(struct ast_channel *chan);
00762 
00763 /*! Initiate system shutdown -- prevents new channels from being allocated.
00764     If "hangup" is non-zero, all existing channels will receive soft
00765      hangups */
00766 void ast_begin_shutdown(int hangup);
00767 
00768 /*! Cancels an existing shutdown and returns to normal operation */
00769 void ast_cancel_shutdown(void);
00770 
00771 /*! Returns number of active/allocated channels */
00772 int ast_active_channels(void);
00773 
00774 /*! Returns non-zero if Asterisk is being shut down */
00775 int ast_shutting_down(void);
00776 
00777 /*! Activate a given generator */
00778 int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params);
00779 
00780 /*! Deactive an active generator */
00781 void ast_deactivate_generator(struct ast_channel *chan);
00782 
00783 void ast_set_callerid(struct ast_channel *chan, char *callerid, int  anitoo);
00784 
00785 /*! Start a tone going */
00786 int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
00787 /*! Stop a tone from playing */
00788 void ast_tonepair_stop(struct ast_channel *chan);
00789 /*! Play a tone pair for a given amount of time */
00790 int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
00791 
00792 /*! Automatically service a channel for us... */
00793 int ast_autoservice_start(struct ast_channel *chan);
00794 
00795 /*! Stop servicing a channel for us...  Returns -1 on error or if channel has been hungup */
00796 int ast_autoservice_stop(struct ast_channel *chan);
00797 
00798 /* If built with zaptel optimizations, force a scheduled expiration on the
00799    timer fd, at which point we call the callback function / data */
00800 int ast_settimeout(struct ast_channel *c, int samples, int (*func)(void *data), void *data);
00801 
00802 /* Transfer a channel (if supported).  Returns -1 on error, 0 if not supported
00803    and 1 if supported and requested */
00804 int ast_transfer(struct ast_channel *chan, char *dest);
00805 
00806 int ast_do_masquerade(struct ast_channel *chan);
00807 
00808 /* Misc. functions below */
00809 
00810 /* Helper function for migrating select to poll */
00811 static inline int ast_fdisset(struct pollfd *pfds, int fd, int max, int *start)
00812 {
00813    int x;
00814    for (x=start ? *start : 0;x<max;x++)
00815       if (pfds[x].fd == fd) {
00816          if (start) {
00817             if (x==*start)
00818                (*start)++;
00819          }
00820          return pfds[x].revents;
00821       }
00822    return 0;
00823 }
00824 
00825 //! Waits for activity on a group of channels
00826 /*! 
00827  * \param nfds the maximum number of file descriptors in the sets
00828  * \param rfds file descriptors to check for read availability
00829  * \param wfds file descriptors to check for write availability
00830  * \param efds file descriptors to check for exceptions (OOB data)
00831  * \param tvp timeout while waiting for events
00832  * This is the same as a standard select(), except it guarantees the
00833  * behaviour where the passed struct timeval is updated with how much
00834  * time was not slept while waiting for the specified events
00835  */
00836 static inline int ast_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tvp)
00837 {
00838 #ifdef __linux__
00839    return select(nfds, rfds, wfds, efds, tvp);
00840 #else
00841    if (tvp) {
00842       struct timeval tv, tvstart, tvend, tvlen;
00843       int res;
00844 
00845       tv = *tvp;
00846       gettimeofday(&tvstart, NULL);
00847       res = select(nfds, rfds, wfds, efds, tvp);
00848       gettimeofday(&tvend, NULL);
00849       timersub(&tvend, &tvstart, &tvlen);
00850       timersub(&tv, &tvlen, tvp);
00851       if (tvp->tv_sec < 0 || (tvp->tv_sec == 0 && tvp->tv_usec < 0)) {
00852          tvp->tv_sec = 0;
00853          tvp->tv_usec = 0;
00854       }
00855       return res;
00856    }
00857    else
00858       return select(nfds, rfds, wfds, efds, NULL);
00859 #endif
00860 }
00861 
00862 #if !defined(ast_strdupa) && defined(__GNUC__)
00863 # define ast_strdupa(s)                         \
00864   (__extension__                             \
00865     ({                                       \
00866       __const char *__old = (s);                \
00867       size_t __len = strlen (__old) + 1;           \
00868       char *__new = (char *) __builtin_alloca (__len);   \
00869       (char *) memcpy (__new, __old, __len);       \
00870     }))
00871 #endif
00872 
00873 #ifdef DO_CRASH
00874 #define CRASH do { fprintf(stderr, "!! Forcing immediate crash a-la abort !!\n"); *((int *)0) = 0; } while(0)
00875 #else
00876 #define CRASH do { } while(0)
00877 #endif
00878 
00879 #define CHECK_BLOCKING(c) {    \
00880                      if ((c)->blocking) {\
00881                         ast_log(LOG_WARNING, "Thread %ld Blocking '%s', already blocked by thread %ld in procedure %s\n", (long) pthread_self(), (c)->name, (long) (c)->blocker, (c)->blockproc); \
00882                         CRASH; \
00883                      } else { \
00884                         (c)->blocker = pthread_self(); \
00885                         (c)->blockproc = __PRETTY_FUNCTION__; \
00886                            c->blocking = -1; \
00887                            } }
00888 
00889 extern unsigned int ast_get_group(char *s);
00890 
00891 #if defined(__cplusplus) || defined(c_plusplus)
00892 }
00893 #endif
00894 
00895 
00896 #endif

Generated on Thu Oct 28 11:32:53 2004 for Asterisk by doxygen1.2.15