#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"
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_LIST_HEAD_STATIC (aslist, asent) |
static void * | autoservice_run (void *ign) |
Variables | |
static pthread_t | asthread = AST_PTHREADT_NULL |
Definition in file autoservice.c.
#define MAX_AUTOMONS 256 |
int ast_autoservice_start | ( | struct ast_channel * | chan | ) |
Automatically service a channel for us...
0 | success | |
-1 | failure, or the channel is already being autoserviced |
Definition at line 96 of file autoservice.c.
Referenced by _macro_exec(), ast_dtmf_stream(), ast_get_enum(), ast_get_srv(), ast_get_txt(), bridge_playfile(), builtin_atxfer(), builtin_automonitor(), builtin_blindtransfer(), conf_play(), feature_exec_app(), osplookup_exec(), sla_station_exec(), and try_calling().
00097 { 00098 int res = -1; 00099 struct asent *as; 00100 AST_LIST_LOCK(&aslist); 00101 00102 /* Check if the channel already has autoservice */ 00103 AST_LIST_TRAVERSE(&aslist, as, list) { 00104 if (as->chan == chan) 00105 break; 00106 } 00107 00108 /* If not, start autoservice on channel */ 00109 if (!as && (as = ast_calloc(1, sizeof(*as)))) { 00110 as->chan = chan; 00111 AST_LIST_INSERT_HEAD(&aslist, as, list); 00112 res = 0; 00113 if (asthread == AST_PTHREADT_NULL) { /* need start the thread */ 00114 if (ast_pthread_create_background(&asthread, NULL, autoservice_run, NULL)) { 00115 ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n"); 00116 /* There will only be a single member in the list at this point, 00117 the one we just added. */ 00118 AST_LIST_REMOVE(&aslist, as, list); 00119 free(as); 00120 res = -1; 00121 } else 00122 pthread_kill(asthread, SIGURG); 00123 } 00124 } 00125 AST_LIST_UNLOCK(&aslist); 00126 return res; 00127 }
int ast_autoservice_stop | ( | struct ast_channel * | chan | ) |
Stop servicing a channel for us...
0 | success | |
-1 | error, or the channel has been hungup |
Definition at line 129 of file autoservice.c.
Referenced by _macro_exec(), ast_dtmf_stream(), ast_get_enum(), ast_get_srv(), ast_get_txt(), bridge_playfile(), builtin_atxfer(), builtin_automonitor(), conf_play(), feature_exec_app(), finishup(), osplookup_exec(), sla_station_exec(), and try_calling().
00130 { 00131 int res = -1; 00132 struct asent *as; 00133 00134 AST_LIST_LOCK(&aslist); 00135 AST_LIST_TRAVERSE_SAFE_BEGIN(&aslist, as, list) { 00136 if (as->chan == chan) { 00137 AST_LIST_REMOVE_CURRENT(&aslist, list); 00138 free(as); 00139 if (!chan->_softhangup) 00140 res = 0; 00141 break; 00142 } 00143 } 00144 AST_LIST_TRAVERSE_SAFE_END 00145 00146 if (asthread != AST_PTHREADT_NULL) 00147 pthread_kill(asthread, SIGURG); 00148 AST_LIST_UNLOCK(&aslist); 00149 00150 /* Wait for it to un-block */ 00151 while(ast_test_flag(chan, AST_FLAG_BLOCKING)) 00152 usleep(1000); 00153 return res; 00154 }
static AST_LIST_HEAD_STATIC | ( | aslist | , | |
asent | ||||
) | [static] |
static void* autoservice_run | ( | void * | ign | ) | [static] |
Definition at line 64 of file autoservice.c.
References ast_channel::_softhangup, ast_frfree(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_read(), ast_waitfor_n(), asthread, asent::chan, f, 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_LIST_LOCK(&aslist); 00074 AST_LIST_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_LIST_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 }
pthread_t asthread = AST_PTHREADT_NULL [static] |
Definition at line 62 of file autoservice.c.
Referenced by ast_autoservice_start(), ast_autoservice_stop(), and autoservice_run().