Make CALLTYPE available

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1776 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Spencer
2003-11-21 18:38:42 +00:00
parent dc17a4c1c8
commit bfb27d0836
3 changed files with 112 additions and 39 deletions

View File

@@ -2511,7 +2511,7 @@ static int zt_ring_phone(struct zt_pvt *p)
static void *ss_thread(void *data); static void *ss_thread(void *data);
static struct ast_channel *zt_new(struct zt_pvt *, int, int, int, int); static struct ast_channel *zt_new(struct zt_pvt *, int, int, int, int, int);
static int attempt_transfer(struct zt_pvt *p) static int attempt_transfer(struct zt_pvt *p)
{ {
@@ -3018,7 +3018,7 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
(ast->_state == AST_STATE_RING)) { (ast->_state == AST_STATE_RING)) {
if (!alloc_sub(p, SUB_THREEWAY)) { if (!alloc_sub(p, SUB_THREEWAY)) {
/* Make new channel */ /* Make new channel */
chan = zt_new(p, AST_STATE_RESERVED, 0, SUB_THREEWAY, 0); chan = zt_new(p, AST_STATE_RESERVED, 0, SUB_THREEWAY, 0, 0);
/* Swap things around between the three-way and real call */ /* Swap things around between the three-way and real call */
swap_subs(p, SUB_THREEWAY, SUB_REAL); swap_subs(p, SUB_THREEWAY, SUB_REAL);
/* Disable echo canceller for better dialing */ /* Disable echo canceller for better dialing */
@@ -3727,7 +3727,34 @@ static int zt_indicate(struct ast_channel *chan, int condition)
return res; return res;
} }
static struct ast_channel *zt_new(struct zt_pvt *i, int state, int startpbx, int index, int law) #ifdef ZAPATA_PRI
static void set_calltype(struct ast_channel *chan, int ctype)
{
char *s = "UNKNOWN";
switch(ctype) {
case PRI_TRANS_CAP_SPEECH:
s = "SPEECH";
break;
case PRI_TRANS_CAP_DIGITAL:
s = "DIGITAL";
break;
case PRI_TRANS_CAP_RESTRICTED_DIGITAL:
s = "RESTRICTED_DIGITAL";
break;
case PRI_TRANS_CAP_3_1K_AUDIO:
s = "31KAUDIO";
break;
case PRI_TRANS_CAP_7K_AUDIO:
s = "7KAUDIO";
break;
case PRI_TRANS_CAP_VIDEO:
s = "VIDEO";
break;
}
pbx_builtin_setvar_helper(chan, "CALLTYPE", s);
}
#endif
static struct ast_channel *zt_new(struct zt_pvt *i, int state, int startpbx, int index, int law, int ctype)
{ {
struct ast_channel *tmp; struct ast_channel *tmp;
int deflaw; int deflaw;
@@ -3853,6 +3880,7 @@ static struct ast_channel *zt_new(struct zt_pvt *i, int state, int startpbx, int
tmp->restrictcid = i->restrictcid; tmp->restrictcid = i->restrictcid;
tmp->callingpres = i->callingpres; tmp->callingpres = i->callingpres;
#ifdef ZAPATA_PRI #ifdef ZAPATA_PRI
set_calltype(tmp, ctype);
/* Assume calls are not idle calls unless we're told differently */ /* Assume calls are not idle calls unless we're told differently */
i->isidlecall = 0; i->isidlecall = 0;
i->alreadyhungup = 0; i->alreadyhungup = 0;
@@ -4560,7 +4588,7 @@ static int handle_init_event(struct zt_pvt *i, int event)
zt_enable_ec(i); zt_enable_ec(i);
/* The channel is immediately up. Start right away */ /* The channel is immediately up. Start right away */
res = tone_zone_play_tone(i->subs[SUB_REAL].zfd, ZT_TONE_RINGTONE); res = tone_zone_play_tone(i->subs[SUB_REAL].zfd, ZT_TONE_RINGTONE);
chan = zt_new(i, AST_STATE_RING, 1, SUB_REAL, 0); chan = zt_new(i, AST_STATE_RING, 1, SUB_REAL, 0, 0);
if (!chan) { if (!chan) {
ast_log(LOG_WARNING, "Unable to start PBX on channel %d\n", i->channel); ast_log(LOG_WARNING, "Unable to start PBX on channel %d\n", i->channel);
res = tone_zone_play_tone(i->subs[SUB_REAL].zfd, ZT_TONE_CONGESTION); res = tone_zone_play_tone(i->subs[SUB_REAL].zfd, ZT_TONE_CONGESTION);
@@ -4569,7 +4597,7 @@ static int handle_init_event(struct zt_pvt *i, int event)
} }
} else { } else {
/* Check for callerid, digits, etc */ /* Check for callerid, digits, etc */
chan = zt_new(i, AST_STATE_RESERVED, 0, SUB_REAL, 0); chan = zt_new(i, AST_STATE_RESERVED, 0, SUB_REAL, 0, 0);
if (chan) { if (chan) {
if (has_voicemail(i)) if (has_voicemail(i))
#ifdef ZT_TONE_STUTTER #ifdef ZT_TONE_STUTTER
@@ -4611,7 +4639,7 @@ static int handle_init_event(struct zt_pvt *i, int event)
case SIG_SF_FEATB: case SIG_SF_FEATB:
case SIG_SF: case SIG_SF:
/* Check for callerid, digits, etc */ /* Check for callerid, digits, etc */
chan = zt_new(i, AST_STATE_RING, 0, SUB_REAL, 0); chan = zt_new(i, AST_STATE_RING, 0, SUB_REAL, 0, 0);
if (pthread_create(&threadid, &attr, ss_thread, chan)) { if (pthread_create(&threadid, &attr, ss_thread, chan)) {
ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel); ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
res = tone_zone_play_tone(i->subs[SUB_REAL].zfd, ZT_TONE_CONGESTION); res = tone_zone_play_tone(i->subs[SUB_REAL].zfd, ZT_TONE_CONGESTION);
@@ -5527,7 +5555,7 @@ static struct ast_channel *zt_request(char *type, int format, void *data)
} }
} }
p->outgoing = 1; p->outgoing = 1;
tmp = zt_new(p, AST_STATE_RESERVED, 0, p->owner ? SUB_CALLWAIT : SUB_REAL, 0); tmp = zt_new(p, AST_STATE_RESERVED, 0, p->owner ? SUB_CALLWAIT : SUB_REAL, 0, 0);
/* Make special notes */ /* Make special notes */
if (res > 1) { if (res > 1) {
if (opt == 'c') { if (opt == 'c') {
@@ -6061,7 +6089,7 @@ static void *pri_dchannel(void *vpri)
/* Get the use_callingpres state */ /* Get the use_callingpres state */
pri->pvt[chan]->callingpres = e->ring.callingpres; pri->pvt[chan]->callingpres = e->ring.callingpres;
/* Start PBX */ /* Start PBX */
c = zt_new(pri->pvt[chan], AST_STATE_RING, 1, SUB_REAL, law); c = zt_new(pri->pvt[chan], AST_STATE_RING, 1, SUB_REAL, law, e->ring.ctype);
if (c) { if (c) {
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Accepting call from '%s' to '%s' on channel %d, span %d\n", ast_verbose(VERBOSE_PREFIX_3 "Accepting call from '%s' to '%s' on channel %d, span %d\n",

52
pbx.c
View File

@@ -2342,8 +2342,7 @@ static char *complete_show_application(char *line, char *word,
static int handle_show_application(int fd, int argc, char *argv[]) static int handle_show_application(int fd, int argc, char *argv[])
{ {
struct ast_app *a; struct ast_app *a;
int n, app, no_registered_app = 1; int app, no_registered_app = 1;
char *buf;
if (argc < 3) return RESULT_SHOWUSAGE; if (argc < 3) return RESULT_SHOWUSAGE;
@@ -2360,19 +2359,46 @@ static int handle_show_application(int fd, int argc, char *argv[])
* to 'show application' command ... */ * to 'show application' command ... */
for (app = 2; app < argc; app++) { for (app = 2; app < argc; app++) {
if (!strcasecmp(a->name, argv[app])) { if (!strcasecmp(a->name, argv[app])) {
/* Maximum number of characters added by terminal coloring is 22 */
char infotitle[64 + AST_MAX_APP + 22], syntitle[40], destitle[40];
char info[64 + AST_MAX_APP], *synopsis = NULL, *description = NULL;
int synopsis_size, description_size;
no_registered_app = 0; no_registered_app = 0;
/* ... one of our applications, show info ...*/ if (a->synopsis)
n = asprintf(&buf, synopsis_size = strlen(a->synopsis) + 23;
"\n -= Info about application '%s' =- \n\n" else
"[Synopsis]:\n %s\n\n" synopsis_size = strlen("Not available") + 23;
"[Description]:\n%s\n", synopsis = alloca(synopsis_size);
a->name,
a->synopsis ? a->synopsis : "Not available", if (a->description)
a->description ? a-> description : "Not available"); description_size = strlen(a->description) + 23;
if (n >= 0) { else
ast_cli(fd, buf); description_size = strlen("Not available") + 23;
free(buf); description = alloca(description_size);
if (synopsis && description) {
snprintf(info, 64 + AST_MAX_APP, "\n -= Info about application '%s' =- \n\n", a->name);
term_color(infotitle, info, COLOR_MAGENTA, 0, 64 + AST_MAX_APP + 22);
term_color(syntitle, "[Synopsis]:\n", COLOR_MAGENTA, 0, 40);
term_color(destitle, "[Description]:\n", COLOR_MAGENTA, 0, 40);
term_color(synopsis,
a->synopsis ? a->synopsis : "Not available",
COLOR_CYAN, 0, synopsis_size);
term_color(description,
a->description ? a->description : "Not available",
COLOR_CYAN, 0, description_size);
ast_cli(fd,"%s%s%s\n\n%s%s\n", infotitle, syntitle, synopsis, destitle, description);
} else {
/* ... one of our applications, show info ...*/
ast_cli(fd,"\n -= Info about application '%s' =- \n\n"
"[Synopsis]:\n %s\n\n"
"[Description]:\n%s\n",
a->name,
a->synopsis ? a->synopsis : "Not available",
a->description ? a->description : "Not available");
} }
} }
} }

55
sched.c
View File

@@ -21,6 +21,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
#include <pthread.h>
#include <asterisk/sched.h> #include <asterisk/sched.h>
#include <asterisk/logger.h> #include <asterisk/logger.h>
#include <asterisk/channel.h> #include <asterisk/channel.h>
@@ -39,6 +41,7 @@ struct sched {
}; };
struct sched_context { struct sched_context {
ast_mutex_t lock;
/* Number of events processed */ /* Number of events processed */
int eventcnt; int eventcnt;
@@ -60,6 +63,7 @@ struct sched_context *sched_context_create(void)
struct sched_context *tmp; struct sched_context *tmp;
tmp = malloc(sizeof(struct sched_context)); tmp = malloc(sizeof(struct sched_context));
if (tmp) { if (tmp) {
ast_mutex_init(&tmp->lock);
tmp->eventcnt = 1; tmp->eventcnt = 1;
tmp->schedcnt = 0; tmp->schedcnt = 0;
tmp->schedq = NULL; tmp->schedq = NULL;
@@ -74,6 +78,7 @@ struct sched_context *sched_context_create(void)
void sched_context_destroy(struct sched_context *con) void sched_context_destroy(struct sched_context *con)
{ {
struct sched *s, *sl; struct sched *s, *sl;
ast_mutex_lock(&con->lock);
#ifdef SCHED_MAX_CACHE #ifdef SCHED_MAX_CACHE
/* Eliminate the cache */ /* Eliminate the cache */
s = con->schedc; s = con->schedc;
@@ -91,6 +96,7 @@ void sched_context_destroy(struct sched_context *con)
free(sl); free(sl);
} }
/* And the context */ /* And the context */
ast_mutex_unlock(&con->lock);
free(con); free(con);
} }
@@ -138,16 +144,19 @@ int ast_sched_wait(struct sched_context *con)
struct timeval tv; struct timeval tv;
int ms; int ms;
DEBUG(ast_log(LOG_DEBUG, "ast_sched_wait()\n")); DEBUG(ast_log(LOG_DEBUG, "ast_sched_wait()\n"));
if (!con->schedq) ast_mutex_lock(&con->lock);
return -1; if (!con->schedq) {
if (gettimeofday(&tv, NULL) < 0) { ms = -1;
} else if (gettimeofday(&tv, NULL) < 0) {
/* This should never happen */ /* This should never happen */
return 0;
};
ms = (con->schedq->when.tv_sec - tv.tv_sec) * 1000;
ms += (con->schedq->when.tv_usec - tv.tv_usec) / 1000;
if (ms < 0)
ms = 0; ms = 0;
} else {
ms = (con->schedq->when.tv_sec - tv.tv_sec) * 1000;
ms += (con->schedq->when.tv_usec - tv.tv_usec) / 1000;
if (ms < 0)
ms = 0;
}
ast_mutex_unlock(&con->lock);
return ms; return ms;
} }
@@ -223,11 +232,13 @@ int ast_sched_add(struct sched_context *con, int when, ast_sched_cb callback, vo
* Schedule callback(data) to happen when ms into the future * Schedule callback(data) to happen when ms into the future
*/ */
struct sched *tmp; struct sched *tmp;
int res = -1;
DEBUG(ast_log(LOG_DEBUG, "ast_sched_add()\n")); DEBUG(ast_log(LOG_DEBUG, "ast_sched_add()\n"));
if (!when) { if (!when) {
ast_log(LOG_NOTICE, "Scheduled event in 0 ms?\n"); ast_log(LOG_NOTICE, "Scheduled event in 0 ms?\n");
return -1; return -1;
} }
ast_mutex_lock(&con->lock);
if ((tmp = sched_alloc(con))) { if ((tmp = sched_alloc(con))) {
tmp->id = con->eventcnt++; tmp->id = con->eventcnt++;
tmp->callback = callback; tmp->callback = callback;
@@ -237,12 +248,13 @@ int ast_sched_add(struct sched_context *con, int when, ast_sched_cb callback, vo
tmp->when.tv_usec = 0; tmp->when.tv_usec = 0;
if (sched_settime(&tmp->when, when)) { if (sched_settime(&tmp->when, when)) {
sched_release(con, tmp); sched_release(con, tmp);
return -1; } else {
} else
schedule(con, tmp); schedule(con, tmp);
} else res = tmp->id;
return -1; }
return tmp->id; }
ast_mutex_lock(&con->lock);
return res;
} }
int ast_sched_del(struct sched_context *con, int id) int ast_sched_del(struct sched_context *con, int id)
@@ -255,6 +267,7 @@ int ast_sched_del(struct sched_context *con, int id)
*/ */
struct sched *last=NULL, *s; struct sched *last=NULL, *s;
DEBUG(ast_log(LOG_DEBUG, "ast_sched_del()\n")); DEBUG(ast_log(LOG_DEBUG, "ast_sched_del()\n"));
ast_mutex_lock(&con->lock);
s = con->schedq; s = con->schedq;
while(s) { while(s) {
if (s->id == id) { if (s->id == id) {
@@ -264,16 +277,20 @@ int ast_sched_del(struct sched_context *con, int id)
con->schedq = s->next; con->schedq = s->next;
con->schedcnt--; con->schedcnt--;
sched_release(con, s); sched_release(con, s);
return 0; break;
} }
last = s; last = s;
s = s->next; s = s->next;
} }
ast_log(LOG_NOTICE, "Attempted to delete non-existant schedule entry %d!\n", id); ast_mutex_unlock(&con->lock);
if (!s) {
ast_log(LOG_NOTICE, "Attempted to delete non-existant schedule entry %d!\n", id);
#ifdef DO_CRASH #ifdef DO_CRASH
CRASH; CRASH;
#endif #endif
return -1; return -1;
} else
return 0;
} }
void ast_sched_dump(struct sched_context *con) void ast_sched_dump(struct sched_context *con)
@@ -327,13 +344,14 @@ int ast_sched_runq(struct sched_context *con)
int x=0; int x=0;
DEBUG(ast_log(LOG_DEBUG, "ast_sched_runq()\n")); DEBUG(ast_log(LOG_DEBUG, "ast_sched_runq()\n"));
ast_mutex_lock(&con->lock);
for(;;) { for(;;) {
if (!con->schedq) if (!con->schedq)
break; break;
if (gettimeofday(&tv, NULL)) { if (gettimeofday(&tv, NULL)) {
/* This should never happen */ /* This should never happen */
ast_log(LOG_NOTICE, "gettimeofday() failed!\n"); ast_log(LOG_NOTICE, "gettimeofday() failed!\n");
return 0; break;
} }
/* We only care about millisecond accuracy anyway, so this will /* We only care about millisecond accuracy anyway, so this will
help us get more than one event at one time if they are very help us get more than one event at one time if they are very
@@ -369,5 +387,6 @@ int ast_sched_runq(struct sched_context *con)
} else } else
break; break;
} }
ast_mutex_unlock(&con->lock);
return x; return x;
} }