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

Generated on Sat Jun 12 16:40:57 2004 for Asterisk by doxygen 1.3.7