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

Generated on Wed Mar 16 20:08:34 2005 for Asterisk by  doxygen 1.4.0