![]() |
Home page |
Mailing list |
Docs
Asterisk developer's documentation :: Codename Pineapple
autoservice.c File Reference
Definition in file autoservice.c.
#include "asterisk.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include "asterisk/pbx.h"
#include "asterisk/frame.h"
#include "asterisk/sched.h"
#include "asterisk/options.h"
#include "asterisk/channel.h"
#include "asterisk/logger.h"
#include "asterisk/file.h"
#include "asterisk/translate.h"
#include "asterisk/manager.h"
#include "asterisk/chanvars.h"
#include "asterisk/linkedlists.h"
#include "asterisk/indications.h"
#include "asterisk/lock.h"
#include "asterisk/utils.h"
Include dependency graph for autoservice.c:

Go to the source code of this file.
Data Structures | |
| struct | asent |
Defines | |
| #define | MAX_AUTOMONS 256 |
Functions | |
| int | ast_autoservice_start (struct ast_channel *chan) |
| Automatically service a channel for us... | |
| int | ast_autoservice_stop (struct ast_channel *chan) |
| Stop servicing a channel for us... | |
| static | AST_RWLIST_HEAD_STATIC (aslist, asent) |
| static void * | autoservice_run (void *ign) |
Variables | |
| static pthread_t | asthread = AST_PTHREADT_NULL |
|
|
Definition at line 53 of file autoservice.c. Referenced by autoservice_run(). |
|
|
Automatically service a channel for us...
Definition at line 96 of file autoservice.c. References ast_calloc, ast_log(), ast_pthread_create_background, AST_PTHREADT_NULL, AST_RWLIST_INSERT_HEAD, AST_RWLIST_REMOVE, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, asthread, autoservice_run(), asent::chan, free, and LOG_WARNING. Referenced by ast_dtmf_stream(), ast_get_enum(), ast_get_srv(), ast_get_txt(), bridge_playfile(), builtin_atxfer(), builtin_automonitor(), builtin_blindtransfer(), and feature_exec_app(). 00097 { 00098 int res = -1; 00099 struct asent *as; 00100 00101 AST_RWLIST_WRLOCK(&aslist); 00102 00103 /* Check if the channel already has autoservice */ 00104 AST_RWLIST_TRAVERSE(&aslist, as, list) { 00105 if (as->chan == chan) 00106 break; 00107 } 00108 00109 /* If not, start autoservice on channel */ 00110 if (!as && (as = ast_calloc(1, sizeof(*as)))) { 00111 as->chan = chan; 00112 AST_RWLIST_INSERT_HEAD(&aslist, as, list); 00113 res = 0; 00114 if (asthread == AST_PTHREADT_NULL) { /* need start the thread */ 00115 if (ast_pthread_create_background(&asthread, NULL, autoservice_run, NULL)) { 00116 ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n"); 00117 /* There will only be a single member in the list at this point, 00118 the one we just added. */ 00119 AST_RWLIST_REMOVE(&aslist, as, list); 00120 free(as); 00121 res = -1; 00122 } else 00123 pthread_kill(asthread, SIGURG); 00124 } 00125 } 00126 AST_RWLIST_UNLOCK(&aslist); 00127 return res; 00128 }
|
|
|
Stop servicing a channel for us...
Definition at line 130 of file autoservice.c. References ast_channel::_softhangup, AST_FLAG_BLOCKING, AST_PTHREADT_NULL, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_test_flag, asthread, asent::chan, and free. Referenced by ast_get_srv(), bridge_playfile(), builtin_atxfer(), builtin_automonitor(), feature_exec_app(), and finishup(). 00131 { 00132 int res = -1; 00133 struct asent *as; 00134 00135 AST_RWLIST_WRLOCK(&aslist); 00136 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&aslist, as, list) { 00137 if (as->chan == chan) { 00138 AST_RWLIST_REMOVE_CURRENT(&aslist, list); 00139 free(as); 00140 if (!chan->_softhangup) 00141 res = 0; 00142 break; 00143 } 00144 } 00145 AST_RWLIST_TRAVERSE_SAFE_END 00146 00147 if (asthread != AST_PTHREADT_NULL) 00148 pthread_kill(asthread, SIGURG); 00149 AST_RWLIST_UNLOCK(&aslist); 00150 00151 /* Wait for it to un-block */ 00152 while (ast_test_flag(chan, AST_FLAG_BLOCKING)) 00153 usleep(1000); 00154 return res; 00155 }
|
|
||||||||||||
|
|
|
|
Definition at line 64 of file autoservice.c. References ast_channel::_softhangup, ast_frfree(), ast_log(), ast_read(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_waitfor_n(), asent::chan, LOG_WARNING, and MAX_AUTOMONS. Referenced by ast_autoservice_start(). 00065 { 00066 00067 for (;;) { 00068 struct ast_channel *mons[MAX_AUTOMONS]; 00069 struct ast_channel *chan; 00070 struct asent *as; 00071 int x = 0, ms = 500; 00072 00073 AST_RWLIST_RDLOCK(&aslist); 00074 AST_RWLIST_TRAVERSE(&aslist, as, list) { 00075 if (!as->chan->_softhangup) { 00076 if (x < MAX_AUTOMONS) 00077 mons[x++] = as->chan; 00078 else 00079 ast_log(LOG_WARNING, "Exceeded maximum number of automatic monitoring events. Fix autoservice.c\n"); 00080 } 00081 } 00082 AST_RWLIST_UNLOCK(&aslist); 00083 00084 chan = ast_waitfor_n(mons, x, &ms); 00085 if (chan) { 00086 /* Read and ignore anything that occurs */ 00087 struct ast_frame *f = ast_read(chan); 00088 if (f) 00089 ast_frfree(f); 00090 } 00091 } 00092 asthread = AST_PTHREADT_NULL; 00093 return NULL; 00094 }
|
|
|
Definition at line 62 of file autoservice.c. Referenced by ast_autoservice_start(), and ast_autoservice_stop(). |