#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include <math.h>
#include "asterisk.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.
Defines | |
| #define | MAX_AUTOMONS 256 |
Functions | |
| int | ast_autoservice_start (struct ast_channel *chan) |
| int | ast_autoservice_stop (struct ast_channel *chan) |
| AST_MUTEX_DEFINE_STATIC (autolock) | |
| static void * | autoservice_run (void *ign) |
Variables | |
| static struct asent * | aslist = NULL |
| static pthread_t | asthread = AST_PTHREADT_NULL |
Definition in file autoservice.c.
|
|
Definition at line 53 of file autoservice.c. Referenced by autoservice_run(). |
|
|
Automatically service a channel for us... Definition at line 103 of file autoservice.c. References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_pthread_create, AST_PTHREADT_NULL, asthread, autoservice_run(), asent::chan, free, LOG_WARNING, malloc, asent::next, and ast_channel::next. Referenced by ast_dtmf_stream(), ast_get_enum(), ast_get_srv(), ast_get_txt(), ast_osp_lookup(), bridge_playfile(), builtin_atxfer(), builtin_automonitor(), builtin_blindtransfer(), conf_play(), dial_exec_full(), and try_calling(). 00104 {
00105 int res = -1;
00106 struct asent *as;
00107 int needstart;
00108 ast_mutex_lock(&autolock);
00109 needstart = (asthread == AST_PTHREADT_NULL) ? 1 : 0 /* aslist ? 0 : 1 */;
00110 as = aslist;
00111 while(as) {
00112 if (as->chan == chan)
00113 break;
00114 as = as->next;
00115 }
00116 if (!as) {
00117 as = malloc(sizeof(struct asent));
00118 if (as) {
00119 memset(as, 0, sizeof(struct asent));
00120 as->chan = chan;
00121 as->next = aslist;
00122 aslist = as;
00123 res = 0;
00124 if (needstart) {
00125 if (ast_pthread_create(&asthread, NULL, autoservice_run, NULL)) {
00126 ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n");
00127 free(aslist);
00128 aslist = NULL;
00129 res = -1;
00130 } else
00131 pthread_kill(asthread, SIGURG);
00132 }
00133 }
00134 }
00135 ast_mutex_unlock(&autolock);
00136 return res;
00137 }
|
|
|
Stop servicing a channel for us... Returns -1 on error or if channel has been hungup Definition at line 139 of file autoservice.c. References ast_channel::_softhangup, AST_FLAG_BLOCKING, ast_mutex_lock(), ast_mutex_unlock(), AST_PTHREADT_NULL, ast_test_flag, asthread, asent::chan, free, and asent::next. Referenced by ast_dtmf_stream(), ast_get_enum(), ast_get_srv(), ast_get_txt(), ast_osp_lookup(), bridge_playfile(), builtin_atxfer(), builtin_automonitor(), builtin_blindtransfer(), conf_play(), dial_exec_full(), and try_calling(). 00140 {
00141 int res = -1;
00142 struct asent *as, *prev;
00143 ast_mutex_lock(&autolock);
00144 as = aslist;
00145 prev = NULL;
00146 while(as) {
00147 if (as->chan == chan)
00148 break;
00149 prev = as;
00150 as = as->next;
00151 }
00152 if (as) {
00153 if (prev)
00154 prev->next = as->next;
00155 else
00156 aslist = as->next;
00157 free(as);
00158 if (!chan->_softhangup)
00159 res = 0;
00160 }
00161 if (asthread != AST_PTHREADT_NULL)
00162 pthread_kill(asthread, SIGURG);
00163 ast_mutex_unlock(&autolock);
00164 /* Wait for it to un-block */
00165 while(ast_test_flag(chan, AST_FLAG_BLOCKING))
00166 usleep(1000);
00167 return res;
00168 }
|
|
|
|
|
|
Definition at line 65 of file autoservice.c. References ast_channel::_softhangup, ast_frfree(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), AST_PTHREADT_NULL, ast_read(), ast_waitfor_n(), asthread, asent::chan, LOG_WARNING, MAX_AUTOMONS, and asent::next. Referenced by ast_autoservice_start(). 00066 {
00067 struct ast_channel *mons[MAX_AUTOMONS];
00068 int x;
00069 int ms;
00070 struct ast_channel *chan;
00071 struct asent *as;
00072 struct ast_frame *f;
00073 for(;;) {
00074 x = 0;
00075 ast_mutex_lock(&autolock);
00076 as = aslist;
00077 while(as) {
00078 if (!as->chan->_softhangup) {
00079 if (x < MAX_AUTOMONS)
00080 mons[x++] = as->chan;
00081 else
00082 ast_log(LOG_WARNING, "Exceeded maximum number of automatic monitoring events. Fix autoservice.c\n");
00083 }
00084 as = as->next;
00085 }
00086 ast_mutex_unlock(&autolock);
00087
00088 /* if (!aslist)
00089 break; */
00090 ms = 500;
00091 chan = ast_waitfor_n(mons, x, &ms);
00092 if (chan) {
00093 /* Read and ignore anything that occurs */
00094 f = ast_read(chan);
00095 if (f)
00096 ast_frfree(f);
00097 }
00098 }
00099 asthread = AST_PTHREADT_NULL;
00100 return NULL;
00101 }
|
|
|
Definition at line 62 of file autoservice.c. |
|
|
Definition at line 63 of file autoservice.c. Referenced by ast_autoservice_start(), ast_autoservice_stop(), and autoservice_run(). |
1.4.2