Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

channel_pvt.h File Reference

#include <asterisk/channel.h>

Go to the source code of this file.

Data Structures

struct  ast_channel_pvt

Functions

ast_channelast_channel_alloc (int needalertpipe)
 Create a channel structure.
int ast_queue_frame (struct ast_channel *chan, struct ast_frame *f)
int ast_queue_hangup (struct ast_channel *chan)
int ast_queue_control (struct ast_channel *chan, int control)
int ast_setstate (struct ast_channel *chan, int state)
void ast_change_name (struct ast_channel *chan, char *newname)
void ast_channel_free (struct ast_channel *)
 Free a channel structure.


Function Documentation

void ast_change_name struct ast_channel chan,
char *  newname
 

Definition at line 2143 of file channel.c.

References EVENT_FLAG_CALL, manager_event(), ast_channel::name, and ast_channel::uniqueid.

02144 { 02145 char tmp[256]; 02146 strncpy(tmp, chan->name, sizeof(tmp) - 1); 02147 strncpy(chan->name, newname, sizeof(chan->name) - 1); 02148 manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", tmp, chan->name, chan->uniqueid); 02149 }

struct ast_channel* ast_channel_alloc int  needalertpipe  ) 
 

Create a channel structure.

Returns NULL on failure to allocate Definition at line 274 of file channel.c.

References ast_default_accountcode, ast_default_amaflags, AST_LIST_HEAD_INIT, AST_LIST_INSERT_HEAD, ast_log(), AST_MAX_FDS, ast_mutex_lock, ast_mutex_unlock, AST_STATE_DOWN, ast_var_assign(), channels, defaultlanguage, free, LOG_WARNING, malloc, and sched_context_create().

Referenced by ast_async_goto(), and ast_pbx_outgoing_exten().

00275 { 00276 struct ast_channel *tmp; 00277 struct ast_channel_pvt *pvt; 00278 int x; 00279 int flags; 00280 struct varshead *headp; 00281 00282 00283 /* If shutting down, don't allocate any new channels */ 00284 if (shutting_down) 00285 return NULL; 00286 ast_mutex_lock(&chlock); 00287 tmp = malloc(sizeof(struct ast_channel)); 00288 if (tmp) { 00289 memset(tmp, 0, sizeof(struct ast_channel)); 00290 pvt = malloc(sizeof(struct ast_channel_pvt)); 00291 if (pvt) { 00292 memset(pvt, 0, sizeof(struct ast_channel_pvt)); 00293 tmp->sched = sched_context_create(); 00294 if (tmp->sched) { 00295 for (x=0;x<AST_MAX_FDS - 1;x++) 00296 tmp->fds[x] = -1; 00297 #ifdef ZAPTEL_OPTIMIZATIONS 00298 tmp->timingfd = open("/dev/zap/timer", O_RDWR); 00299 if (tmp->timingfd > -1) { 00300 /* Check if timing interface supports new 00301 ping/pong scheme */ 00302 flags = 1; 00303 if (!ioctl(tmp->timingfd, ZT_TIMERPONG, &flags)) 00304 needqueue = 0; 00305 } 00306 #else 00307 tmp->timingfd = -1; 00308 #endif 00309 if (needqueue && 00310 pipe(pvt->alertpipe)) { 00311 ast_log(LOG_WARNING, "Alert pipe creation failed!\n"); 00312 free(pvt); 00313 free(tmp); 00314 tmp = NULL; 00315 pvt = NULL; 00316 } else { 00317 if (needqueue) { 00318 flags = fcntl(pvt->alertpipe[0], F_GETFL); 00319 fcntl(pvt->alertpipe[0], F_SETFL, flags | O_NONBLOCK); 00320 flags = fcntl(pvt->alertpipe[1], F_GETFL); 00321 fcntl(pvt->alertpipe[1], F_SETFL, flags | O_NONBLOCK); 00322 } else 00323 /* Make sure we've got it done right if they don't */ 00324 pvt->alertpipe[0] = pvt->alertpipe[1] = -1; 00325 /* Always watch the alertpipe */ 00326 tmp->fds[AST_MAX_FDS-1] = pvt->alertpipe[0]; 00327 /* And timing pipe */ 00328 tmp->fds[AST_MAX_FDS-2] = tmp->timingfd; 00329 strncpy(tmp->name, "**Unknown**", sizeof(tmp->name)-1); 00330 tmp->pvt = pvt; 00331 /* Initial state */ 00332 tmp->_state = AST_STATE_DOWN; 00333 tmp->stack = -1; 00334 tmp->streamid = -1; 00335 tmp->appl = NULL; 00336 tmp->data = NULL; 00337 tmp->fin = 0; 00338 tmp->fout = 0; 00339 snprintf(tmp->uniqueid, sizeof(tmp->uniqueid), "%li.%d", (long)time(NULL), uniqueint++); 00340 headp=&tmp->varshead; 00341 ast_mutex_init(&tmp->lock); 00342 AST_LIST_HEAD_INIT(headp); 00343 tmp->vars=ast_var_assign("tempvar","tempval"); 00344 AST_LIST_INSERT_HEAD(headp,tmp->vars,entries); 00345 strncpy(tmp->context, "default", sizeof(tmp->context)-1); 00346 strncpy(tmp->language, defaultlanguage, sizeof(tmp->language)-1); 00347 strncpy(tmp->exten, "s", sizeof(tmp->exten)-1); 00348 tmp->priority=1; 00349 tmp->amaflags = ast_default_amaflags; 00350 strncpy(tmp->accountcode, ast_default_accountcode, sizeof(tmp->accountcode)-1); 00351 tmp->next = channels; 00352 channels= tmp; 00353 } 00354 } else { 00355 ast_log(LOG_WARNING, "Unable to create schedule context\n"); 00356 free(tmp); 00357 tmp = NULL; 00358 } 00359 } else { 00360 ast_log(LOG_WARNING, "Out of memory\n"); 00361 free(tmp); 00362 tmp = NULL; 00363 } 00364 } else 00365 ast_log(LOG_WARNING, "Out of memory\n"); 00366 ast_mutex_unlock(&chlock); 00367 return tmp; 00368 }

void ast_channel_free struct ast_channel  ) 
 

Free a channel structure.

Definition at line 555 of file channel.c.

References ast_channel_pvt::alertpipe, ast_channel::ani, AST_CHANNEL_NAME, ast_device_state_changed(), ast_frfree(), AST_LIST_EMPTY, AST_LIST_FIRST, AST_LIST_REMOVE_HEAD, ast_log(), ast_mutex_destroy, ast_mutex_lock, ast_mutex_unlock, ast_translator_free_path(), ast_var_delete(), ast_channel::callerid, channels, ast_channel::dnid, free, ast_channel::lock, LOG_WARNING, ast_channel::monitor, ast_channel::name, ast_frame::next, ast_channel::next, ast_channel::pbx, ast_channel_pvt::pvt, ast_channel::pvt, ast_channel::rdnis, ast_channel_pvt::readq, ast_channel_pvt::readtrans, ast_channel_monitor::stop, ast_channel::timingfd, and ast_channel_pvt::writetrans.

Referenced by ast_do_masquerade(), and ast_hangup().

00556 { 00557 struct ast_channel *last=NULL, *cur; 00558 int fd; 00559 struct ast_var_t *vardata; 00560 struct ast_frame *f, *fp; 00561 struct varshead *headp; 00562 char name[AST_CHANNEL_NAME]; 00563 00564 headp=&chan->varshead; 00565 00566 ast_mutex_lock(&chlock); 00567 cur = channels; 00568 while(cur) { 00569 if (cur == chan) { 00570 if (last) 00571 last->next = cur->next; 00572 else 00573 channels = cur->next; 00574 break; 00575 } 00576 last = cur; 00577 cur = cur->next; 00578 } 00579 if (!cur) 00580 ast_log(LOG_WARNING, "Unable to find channel in list\n"); 00581 else { 00582 /* Lock and unlock the channel just to be sure nobody 00583 has it locked still */ 00584 ast_mutex_lock(&cur->lock); 00585 ast_mutex_unlock(&cur->lock); 00586 } 00587 if (chan->pvt->pvt) 00588 ast_log(LOG_WARNING, "Channel '%s' may not have been hung up properly\n", chan->name); 00589 00590 strncpy(name, chan->name, sizeof(name)-1); 00591 00592 /* Stop monitoring */ 00593 if (chan->monitor) { 00594 chan->monitor->stop( chan, 0 ); 00595 } 00596 00597 /* Free translatosr */ 00598 if (chan->pvt->readtrans) 00599 ast_translator_free_path(chan->pvt->readtrans); 00600 if (chan->pvt->writetrans) 00601 ast_translator_free_path(chan->pvt->writetrans); 00602 if (chan->pbx) 00603 ast_log(LOG_WARNING, "PBX may not have been terminated properly on '%s'\n", chan->name); 00604 if (chan->dnid) 00605 free(chan->dnid); 00606 if (chan->callerid) 00607 free(chan->callerid); 00608 if (chan->ani) 00609 free(chan->ani); 00610 if (chan->rdnis) 00611 free(chan->rdnis); 00612 ast_mutex_destroy(&chan->lock); 00613 /* Close pipes if appropriate */ 00614 if ((fd = chan->pvt->alertpipe[0]) > -1) 00615 close(fd); 00616 if ((fd = chan->pvt->alertpipe[1]) > -1) 00617 close(fd); 00618 if ((fd = chan->timingfd) > -1) 00619 close(fd); 00620 f = chan->pvt->readq; 00621 chan->pvt->readq = NULL; 00622 while(f) { 00623 fp = f; 00624 f = f->next; 00625 ast_frfree(fp); 00626 } 00627 00628 /* loop over the variables list, freeing all data and deleting list items */ 00629 /* no need to lock the list, as the channel is already locked */ 00630 00631 while (!AST_LIST_EMPTY(headp)) { /* List Deletion. */ 00632 vardata = AST_LIST_FIRST(headp); 00633 AST_LIST_REMOVE_HEAD(headp, entries); 00634 // printf("deleting var %s=%s\n",ast_var_name(vardata),ast_var_value(vardata)); 00635 ast_var_delete(vardata); 00636 } 00637 00638 00639 free(chan->pvt); 00640 chan->pvt = NULL; 00641 free(chan); 00642 ast_mutex_unlock(&chlock); 00643 00644 ast_device_state_changed(name); 00645 }

int ast_queue_control struct ast_channel chan,
int  control
 

Definition at line 428 of file channel.c.

References AST_FRAME_CONTROL, ast_queue_frame(), and ast_frame::subclass.

00429 { 00430 struct ast_frame f = { AST_FRAME_CONTROL, }; 00431 f.subclass = control; 00432 return ast_queue_frame(chan, &f); 00433 }

int ast_queue_frame struct ast_channel chan,
struct ast_frame f
 

Queue an outgoing frame Definition at line 370 of file channel.c.

References ast_channel_pvt::alertpipe, AST_FRAME_VOICE, ast_frdup(), ast_frfree(), ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_channel::blocker, ast_channel::blocking, CRASH, ast_frame::frametype, ast_channel::lock, LOG_DEBUG, LOG_WARNING, ast_channel::name, ast_frame::next, ast_channel::pvt, ast_channel_pvt::readq, and ast_channel::timingfd.

Referenced by ast_channel_masquerade(), ast_dsp_process(), ast_queue_control(), ast_queue_hangup(), and ast_softhangup_nolock().

00371 { 00372 struct ast_frame *f; 00373 struct ast_frame *prev, *cur; 00374 int blah = 1; 00375 int qlen = 0; 00376 /* Build us a copy and free the original one */ 00377 f = ast_frdup(fin); 00378 if (!f) { 00379 ast_log(LOG_WARNING, "Unable to duplicate frame\n"); 00380 return -1; 00381 } 00382 ast_mutex_lock(&chan->lock); 00383 prev = NULL; 00384 cur = chan->pvt->readq; 00385 while(cur) { 00386 prev = cur; 00387 cur = cur->next; 00388 qlen++; 00389 } 00390 /* Allow up to 96 voice frames outstanding, and up to 128 total frames */ 00391 if (((fin->frametype == AST_FRAME_VOICE) && (qlen > 96)) || (qlen > 128)) { 00392 if (fin->frametype != AST_FRAME_VOICE) { 00393 ast_log(LOG_WARNING, "Exceptionally long queue length queuing to %s\n", chan->name); 00394 CRASH; 00395 } else { 00396 ast_log(LOG_DEBUG, "Dropping voice to exceptionally long queue on %s\n", chan->name); 00397 ast_frfree(f); 00398 ast_mutex_unlock(&chan->lock); 00399 return 0; 00400 } 00401 } 00402 if (prev) 00403 prev->next = f; 00404 else 00405 chan->pvt->readq = f; 00406 if (chan->pvt->alertpipe[1] > -1) { 00407 if (write(chan->pvt->alertpipe[1], &blah, sizeof(blah)) != sizeof(blah)) 00408 ast_log(LOG_WARNING, "Unable to write to alert pipe on %s, frametype/subclass %d/%d (qlen = %d): %s!\n", 00409 chan->name, f->frametype, f->subclass, qlen, strerror(errno)); 00410 #ifdef ZAPTEL_OPTIMIZATIONS 00411 } else if (chan->timingfd > -1) { 00412 ioctl(chan->timingfd, ZT_TIMERPING, &blah); 00413 #endif 00414 } else if (chan->blocking) { 00415 pthread_kill(chan->blocker, SIGURG); 00416 } 00417 ast_mutex_unlock(&chan->lock); 00418 return 0; 00419 }

int ast_queue_hangup struct ast_channel chan  ) 
 

Definition at line 421 of file channel.c.

References ast_channel::_softhangup, AST_CONTROL_HANGUP, AST_FRAME_CONTROL, ast_queue_frame(), and AST_SOFTHANGUP_DEV.

00422 { 00423 struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP }; 00424 chan->_softhangup |= AST_SOFTHANGUP_DEV; 00425 return ast_queue_frame(chan, &f); 00426 }

int ast_setstate struct ast_channel chan,
int  state
 

Change the state of a channel Definition at line 2388 of file channel.c.

References ast_channel::_state, ast_device_state_changed(), ast_state2str(), AST_STATE_DOWN, ast_channel::callerid, EVENT_FLAG_CALL, manager_event(), ast_channel::name, and ast_channel::uniqueid.

Referenced by ast_answer(), ast_async_goto(), and ast_read().

02389 { 02390 if (chan->_state != state) { 02391 int oldstate = chan->_state; 02392 chan->_state = state; 02393 if (oldstate == AST_STATE_DOWN) { 02394 ast_device_state_changed(chan->name); 02395 manager_event(EVENT_FLAG_CALL, "Newchannel", 02396 "Channel: %s\r\n" 02397 "State: %s\r\n" 02398 "Callerid: %s\r\n" 02399 "Uniqueid: %s\r\n", 02400 chan->name, ast_state2str(chan->_state), chan->callerid ? chan->callerid : "<unknown>", chan->uniqueid); 02401 } else { 02402 manager_event(EVENT_FLAG_CALL, "Newstate", 02403 "Channel: %s\r\n" 02404 "State: %s\r\n" 02405 "Callerid: %s\r\n" 02406 "Uniqueid: %s\r\n", 02407 chan->name, ast_state2str(chan->_state), chan->callerid ? chan->callerid : "<unknown>", chan->uniqueid); 02408 } 02409 } 02410 return 0; 02411 }


Generated on Tue Aug 17 16:13:55 2004 for Asterisk by doxygen 1.3.8