static int chanavail_exec(struct ast_channel *chan, void *data)
{
int res=-1;
+ int status;
struct localuser *u;
char info[512], tmp[512], *peers, *tech, *number, *rest, *cur;
struct ast_channel *tempchan;
}
*number = '\0';
number++;
- if ((tempchan = ast_request(tech, chan->nativeformats, number))) {
+ if ((tempchan = ast_request(tech, chan->nativeformats, number, &status))) {
pbx_builtin_setvar_helper(chan, "AVAILCHAN", tempchan->name);
/* Store the originally used channel too */
snprintf(tmp, sizeof(tmp), "%s/%s", tech, number);
pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", tmp);
+ snprintf(tmp, sizeof(tmp), "%d", status);
+ pbx_builtin_setvar_helper(chan, "AVAILSTATUS", tmp);
ast_hangup(tempchan);
tempchan = NULL;
res = 1;
break;
+ } else {
+ snprintf(tmp, sizeof(tmp), "%d", status);
+ pbx_builtin_setvar_helper(chan, "AVAILSTATUS", tmp);
}
cur = rest;
} while (cur);
}
-
if (res < 1) {
pbx_builtin_setvar_helper(chan, "AVAILCHAN", "");
pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", "");
#include <asterisk/callerid.h>
#include <asterisk/utils.h>
#include <asterisk/app.h>
+#include <asterisk/causes.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#define AST_MAX_WATCHERS 256
-static struct ast_channel *wait_for_answer(struct ast_channel *in, struct localuser *outgoing, int *to, int *allowredir_in, int *allowredir_out, int *allowdisconnect_in, int *allowdisconnect_out, int *sentringing, char *status, size_t statussize)
+#define HANDLE_CAUSE(blah, bleh) do { \
+ switch(cause) { \
+ case AST_CAUSE_BUSY: \
+ if (bleh->cdr) \
+ ast_cdr_busy(bleh->cdr); \
+ numbusy++; \
+ case AST_CAUSE_CONGESTION: \
+ case AST_CAUSE_UNREGISTERED: \
+ if (bleh->cdr) \
+ ast_cdr_busy(bleh->cdr); \
+ numcongestion++; \
+ default: \
+ numnochan++; \
+ } \
+} while(0)
+
+
+static struct ast_channel *wait_for_answer(struct ast_channel *in, struct localuser *outgoing, int *to, int *allowredir_in, int *allowredir_out, int *allowdisconnect_in, int *allowdisconnect_out, int *sentringing, char *status, size_t statussize, int busystart, int nochanstart, int congestionstart)
{
struct localuser *o;
int found;
int numlines;
- int numbusy = 0;
- int numcongestion = 0;
- int numnochan = 0;
+ int numbusy = busystart;
+ int numcongestion = congestionstart;
+ int numnochan = nochanstart;
+ int cause;
int orig = *to;
struct ast_frame *f;
struct ast_channel *peer = NULL;
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Now forwarding %s to '%s/%s' (thanks to %s)\n", in->name, tech, stuff, o->chan->name);
/* Setup parameters */
- o->chan = ast_request(tech, in->nativeformats, stuff);
+ o->chan = ast_request(tech, in->nativeformats, stuff, &cause);
if (!o->chan) {
ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s'\n", tech, stuff);
o->stillgoing = 0;
- numnochan++;
+ HANDLE_CAUSE(cause, in);
} else {
if (o->chan->cid.cid_num)
free(o->chan->cid.cid_num);
ast_hangup(o->chan);
o->chan = NULL;
o->stillgoing = 0;
- if (in->cdr)
- ast_cdr_busy(in->cdr);
- numbusy++;
+ HANDLE_CAUSE(AST_CAUSE_BUSY, in);
break;
case AST_CONTROL_CONGESTION:
if (option_verbose > 2)
ast_hangup(o->chan);
o->chan = NULL;
o->stillgoing = 0;
- if (in->cdr)
- ast_cdr_busy(in->cdr);
- numcongestion++;
+ HANDLE_CAUSE(AST_CAUSE_CONGESTION, in);
break;
case AST_CONTROL_RINGING:
if (option_verbose > 2)
int privacy=0;
int announce=0;
int resetcdr=0;
+ int numbusy = 0;
+ int numcongestion = 0;
+ int numnochan = 0;
+ int cause;
char numsubst[AST_MAX_EXTENSION];
char restofit[AST_MAX_EXTENSION];
char *transfer = NULL;
ast_log(LOG_DEBUG, "Dialing by extension %s\n", numsubst);
}
/* Request the peer */
- tmp->chan = ast_request(tech, chan->nativeformats, numsubst);
+ tmp->chan = ast_request(tech, chan->nativeformats, numsubst, &cause);
if (!tmp->chan) {
/* If we can't, just go on to the next call */
ast_log(LOG_NOTICE, "Unable to create channel of type '%s'\n", tech);
- if (chan->cdr)
- ast_cdr_busy(chan->cdr);
- free(tmp);
- cur = rest;
+ HANDLE_CAUSE(cause, chan);
continue;
}
if (!ast_strlen_zero(tmp->chan->call_forward)) {
ast_verbose(VERBOSE_PREFIX_3 "Forwarding %s to '%s/%s' (thanks to %s)\n", chan->name, tech, stuff, tmp->chan->name);
/* Setup parameters */
ast_hangup(tmp->chan);
- tmp->chan = ast_request(tech, chan->nativeformats, stuff);
+ tmp->chan = ast_request(tech, chan->nativeformats, stuff, &cause);
if (!tmp->chan) {
ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s'\n", tech, stuff);
- free(tmp);
- cur = rest;
+ HANDLE_CAUSE(cause, chan);
continue;
}
}
else if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Couldn't call %s\n", numsubst);
ast_hangup(tmp->chan);
- free(tmp);
- cur = rest;
+ tmp->chan = NULL;
continue;
} else
if (option_verbose > 2)
strncpy(status, "CHANUNAVAIL", sizeof(status) - 1);
time(&start_time);
- peer = wait_for_answer(chan, outgoing, &to, &allowredir_in, &allowredir_out, &allowdisconnect_in, &allowdisconnect_out, &sentringing, status, sizeof(status));
+ peer = wait_for_answer(chan, outgoing, &to, &allowredir_in, &allowredir_out, &allowdisconnect_in, &allowdisconnect_out, &sentringing, status, sizeof(status), numbusy, numnochan, numcongestion);
if (!peer) {
if (to)
strncpy(cnf->confno, confno, sizeof(cnf->confno) - 1);
strncpy(cnf->pin, pin, sizeof(cnf->pin) - 1);
cnf->markedusers = 0;
- cnf->chan = ast_request("zap", AST_FORMAT_ULAW, "pseudo");
+ cnf->chan = ast_request("zap", AST_FORMAT_ULAW, "pseudo", NULL);
if (cnf->chan) {
cnf->fd = cnf->chan->fds[0]; /* for use by conf_play() */
} else {
#include <asterisk/config.h>
#include <asterisk/monitor.h>
#include <asterisk/utils.h>
+#include <asterisk/causes.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
char tech[40];
int stillgoing;
int metric;
+ int oldstatus;
int allowredirect_in;
int allowredirect_out;
int ringbackonly;
int penalty; /* Are we a last resort? */
int calls; /* Number of calls serviced by this member */
int dynamic; /* Are we dynamically added? */
+ int status; /* Status of queue member */
time_t lastcall; /* When last successful call was hungup */
struct member *next; /* Next member */
};
new->opos = *pos;
}
+static int has_no_members(struct ast_call_queue *q)
+{
+ struct member *member;
+ int empty = 1;
+ member = q->members;
+ while(empty && member) {
+ switch(member->status) {
+ case AST_CAUSE_NOSUCHDRIVER:
+ case AST_CAUSE_UNREGISTERED:
+ /* Not logged on, etc */
+ break;
+ default:
+ /* Not empty */
+ empty = 0;
+ }
+ member = member->next;
+ }
+ return empty;
+}
+
static int join_queue(char *queuename, struct queue_ent *qe)
{
struct ast_call_queue *q;
if (!strcasecmp(q->name, queuename)) {
/* This is our one */
ast_mutex_lock(&q->lock);
- if ((q->members || q->joinempty) && (!q->maxlen || (q->count < q->maxlen))) {
+ if ((!has_no_members(q) || q->joinempty || !q->head) && (!q->maxlen || (q->count < q->maxlen))) {
/* There's space for us, put us at the right position inside
* the queue.
* Take into account the priority of the calling user */
}
}
+static int update_status(struct ast_call_queue *q, struct member *member, int status)
+{
+ struct member *cur;
+ /* Since a reload could have taken place, we have to traverse the list to
+ be sure it's still valid */
+ ast_mutex_lock(&q->lock);
+ cur = q->members;
+ while(cur) {
+ if (member == cur) {
+ cur->status = status;
+ break;
+ }
+ cur = cur->next;
+ }
+ q->callscompleted++;
+ ast_mutex_unlock(&q->lock);
+ return 0;
+}
+
static int ring_entry(struct queue_ent *qe, struct localuser *tmp)
{
int res;
+ int status;
if (qe->parent->wrapuptime && (time(NULL) - tmp->lastcall < qe->parent->wrapuptime)) {
ast_log(LOG_DEBUG, "Wrapuptime not yet expired for %s/%s\n", tmp->tech, tmp->numsubst);
if (qe->chan->cdr)
return 0;
}
/* Request the peer */
- tmp->chan = ast_request(tmp->tech, qe->chan->nativeformats, tmp->numsubst);
+ tmp->chan = ast_request(tmp->tech, qe->chan->nativeformats, tmp->numsubst, &status);
if (!tmp->chan) { /* If we can't, just go on to the next call */
#if 0
ast_log(LOG_NOTICE, "Unable to create channel of type '%s'\n", cur->tech);
if (qe->chan->cdr)
ast_cdr_busy(qe->chan->cdr);
tmp->stillgoing = 0;
+ update_status(qe->parent, tmp->member, status);
return 0;
- }
+ } else if (status != tmp->oldstatus)
+ update_status(qe->parent, tmp->member, status);
+
tmp->chan->appl = "AppQueue";
tmp->chan->data = "(Outgoing Line)";
tmp->chan->whentohangup = 0;
struct localuser *o;
int found;
int numlines;
+ int status;
int sentringing = 0;
int numbusies = 0;
int numnochan = 0;
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Now forwarding %s to '%s/%s' (thanks to %s)\n", in->name, tech, stuff, o->chan->name);
/* Setup parameters */
- o->chan = ast_request(tech, in->nativeformats, stuff);
+ o->chan = ast_request(tech, in->nativeformats, stuff, &status);
+ if (status != o->oldstatus)
+ update_status(qe->parent, o->member, status);
if (!o->chan) {
ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s'\n", tech, stuff);
o->stillgoing = 0;
}
/* leave the queue if no agents, if enabled */
- if (!(qe->parent->members) && qe->parent->leavewhenempty) {
+ if (has_no_members(qe->parent) && qe->parent->leavewhenempty) {
leave_queue(qe);
break;
}
tmp->member = cur; /* Never directly dereference! Could change on reload */
strncpy(tmp->tech, cur->tech, sizeof(tmp->tech)-1);
strncpy(tmp->numsubst, cur->loc, sizeof(tmp->numsubst)-1);
+ tmp->oldstatus = cur->status;
tmp->lastcall = cur->lastcall;
/* If we're dialing by extension, look at the extension to know what to dial */
if ((newnum = strstr(tmp->numsubst, "BYEXTENSION"))) {
}
}
if (!res) {
+ int makeannouncement = 0;
for (;;) {
/* This is the wait loop for the head caller*/
/* To exit, they may get their call answered; */
break;
}
- /* leave the queue if no agents, if enabled */
- if (!((qe.parent)->members) && (qe.parent)->leavewhenempty) {
- leave_queue(&qe);
- break;
+ if (makeannouncement) {
+ /* Make a position announcement, if enabled */
+ if (qe.parent->announcefrequency && !ringing)
+ say_position(&qe);
}
-
- /* Make a position announcement, if enabled */
- if (qe.parent->announcefrequency && !ringing)
- say_position(&qe);
+ makeannouncement = 1;
/* Try calling all queue members for 'timeout' seconds */
res = try_calling(&qe, options, announceoverride, url, &go_on);
break;
}
+ /* leave the queue if no agents, if enabled */
+ if (has_no_members(qe.parent) && (qe.parent->leavewhenempty)) {
+ res = 0;
+ break;
+ }
+
/* Leave if we have exceeded our queuetimeout */
if (qe.queuetimeout && ( (time(NULL) - qe.start) >= qe.queuetimeout) ) {
res = 0;
ast_mutex_unlock(&qlock);
}
+static char *status2str(int status, char *buf, int buflen)
+{
+ switch(status) {
+ case AST_CAUSE_BUSY:
+ strncpy(buf, "busy", buflen - 1);
+ break;
+ case AST_CAUSE_CONGESTION:
+ strncpy(buf, "congestion", buflen - 1);
+ break;
+ case AST_CAUSE_FAILURE:
+ strncpy(buf, "failure", buflen - 1);
+ break;
+ case AST_CAUSE_UNREGISTERED:
+ strncpy(buf, "unregistered", buflen - 1);
+ break;
+ case AST_CAUSE_NOSUCHDRIVER:
+ strncpy(buf, "nosuchdriver", buflen - 1);
+ break;
+ default:
+ snprintf(buf, buflen, "unknown status %d", status);
+ }
+ return buf;
+}
+
static int __queues_show(int fd, int argc, char **argv, int queue_show)
{
struct ast_call_queue *q;
time_t now;
char max[80] = "";
char calls[80] = "";
+ char tmpbuf[80] = "";
float sl = 0;
time(&now);
max[0] = '\0';
if (mem->dynamic)
strncat(max, " (dynamic)", sizeof(max) - strlen(max) - 1);
+ if (mem->status)
+ snprintf(max + strlen(max), sizeof(max) - strlen(max), " (%s)", status2str(mem->status, tmpbuf, sizeof(tmpbuf)));
if (mem->calls) {
snprintf(calls, sizeof(calls), " has taken %d calls (last was %ld secs ago)",
mem->calls, (long)(time(NULL) - mem->lastcall));
char type[80];
char description[80];
int capabilities;
- struct ast_channel * (*requester)(const char *type, int format, void *data);
+ struct ast_channel * (*requester)(const char *type, int format, void *data, int *cause);
int (*devicestate)(void *data);
struct chanlist *next;
} *backends = NULL;
}
int ast_channel_register(const char *type, const char *description, int capabilities,
- struct ast_channel *(*requester)(const char *type, int format, void *data))
+ struct ast_channel *(*requester)(const char *type, int format, void *data, int *cause))
{
return ast_channel_register_ex(type, description, capabilities, requester, NULL);
}
int ast_channel_register_ex(const char *type, const char *description, int capabilities,
- struct ast_channel *(*requester)(const char *type, int format, void *data),
+ struct ast_channel *(*requester)(const char *type, int format, void *data, int *cause),
int (*devicestate)(void *data))
{
struct chanlist *chan, *last=NULL;
struct ast_channel *__ast_request_and_dial(const char *type, int format, void *data, int timeout, int *outstate, const char *cid_num, const char *cid_name, struct outgoing_helper *oh)
{
int state = 0;
+ int cause = 0;
struct ast_channel *chan;
struct ast_frame *f;
int res = 0;
char *variable;
- chan = ast_request(type, format, data);
+ chan = ast_request(type, format, data, &cause);
if (chan) {
if (oh) {
char *tmp, *var;
ast_frfree(f);
}
} else
- ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, (char *)data);
- } else
+ ast_log(LOG_NOTICE, "Unable to call channel %s/%s\n", type, (char *)data);
+ } else {
ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, (char *)data);
+ switch(cause) {
+ case AST_CAUSE_BUSY:
+ state = AST_CONTROL_BUSY;
+ break;
+ case AST_CAUSE_CONGESTION:
+ state = AST_CONTROL_CONGESTION;
+ break;
+ }
+ }
if (chan) {
/* Final fixups */
if (oh) {
return __ast_request_and_dial(type, format, data, timeout, outstate, cidnum, cidname, NULL);
}
-struct ast_channel *ast_request(const char *type, int format, void *data)
+struct ast_channel *ast_request(const char *type, int format, void *data, int *cause)
{
struct chanlist *chan;
struct ast_channel *c = NULL;
int capabilities;
int fmt;
int res;
+ int foo;
+ if (!cause)
+ cause = &foo;
+ *cause = AST_CAUSE_NOTDEFINED;
if (ast_mutex_lock(&chlock)) {
ast_log(LOG_WARNING, "Unable to lock channel list\n");
return NULL;
}
ast_mutex_unlock(&chlock);
if (chan->requester)
- c = chan->requester(type, capabilities, data);
+ c = chan->requester(type, capabilities, data, cause);
if (c) {
if (c->_state == AST_STATE_DOWN) {
manager_event(EVENT_FLAG_CALL, "Newchannel",
}
chan = chan->next;
}
- if (!chan)
+ if (!chan) {
ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type);
+ *cause = AST_CAUSE_NOSUCHDRIVER;
+ }
ast_mutex_unlock(&chlock);
return c;
}
#include <asterisk/manager.h>
#include <asterisk/features.h>
#include <asterisk/utils.h>
+#include <asterisk/causes.h>
#include <sys/socket.h>
#include <errno.h>
#include <unistd.h>
return res;
}
-static struct ast_channel *agent_request(const char *type, int format, void *data)
+static struct ast_channel *agent_request(const char *type, int format, void *data, int *cause)
{
struct agent_pvt *p;
struct ast_channel *chan = NULL;
chan = agent_new(p, AST_STATE_DOWN);
} else if (!p->owner && !ast_strlen_zero(p->loginchan)) {
/* Adjustable agent */
- p->chan = ast_request("Local", format, p->loginchan);
+ p->chan = ast_request("Local", format, p->loginchan, cause);
if (p->chan)
chan = agent_new(p, AST_STATE_DOWN);
}
} else
ast_log(LOG_DEBUG, "Not creating place holder for '%s' since nobody logged in\n", s);
}
+ if (hasagent)
+ *cause = AST_CAUSE_BUSY;
+ else
+ *cause = AST_CAUSE_UNREGISTERED;
ast_mutex_unlock(&agentlock);
return chan;
}
#include <asterisk/config.h>
#include <asterisk/cli.h>
#include <asterisk/utils.h>
+#include <asterisk/causes.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
return tmp;
}
-static struct ast_channel *alsa_request(const char *type, int format, void *data)
+static struct ast_channel *alsa_request(const char *type, int format, void *data, int *cause)
{
int oldformat = format;
struct ast_channel *tmp=NULL;
ast_mutex_lock(&alsalock);
if (alsa.owner) {
ast_log(LOG_NOTICE, "Already have a call on the ALSA channel\n");
+ *cause = AST_CAUSE_BUSY;
} else {
tmp= alsa_new(&alsa, AST_STATE_DOWN);
if (!tmp) {
#include <asterisk/callerid.h>
#include <asterisk/cli.h>
#include <asterisk/dsp.h>
+#include <asterisk/causes.h>
#ifdef __cplusplus
}
#endif
return 0;
}
}
-static struct ast_channel *oh323_request(const char *type, int format, void *data)
+static struct ast_channel *oh323_request(const char *type, int format, void *data, int *cause)
{
int oldformat;
struct oh323_pvt *pvt;
#include <asterisk/musiconhold.h>
#include <asterisk/features.h>
#include <asterisk/utils.h>
+#include <asterisk/causes.h>
#include <sys/mman.h>
#include <arpa/inet.h>
#include <dirent.h>
}
}
-static struct ast_channel *iax2_request(const char *type, int format, void *data)
+static struct ast_channel *iax2_request(const char *type, int format, void *data, int *cause)
{
int callno;
int res;
/* Populate our address from the given */
if (create_addr(&sin, &capability, &sendani, &maxtime, hostname, NULL, &trunk, ¬ransfer, &usejitterbuf, NULL, 0, NULL, 0, &found, NULL)) {
+ *cause = AST_CAUSE_UNREGISTERED;
return NULL;
}
if (portno) {
callno = find_callno(0, 0, &sin, NEW_FORCE, 1);
if (callno < 1) {
ast_log(LOG_WARNING, "Unable to create call\n");
+ *cause = AST_CAUSE_CONGESTION;
return NULL;
}
ast_mutex_lock(&iaxsl[callno]);
}
-static struct ast_channel *local_request(const char *type, int format, void *data)
+static struct ast_channel *local_request(const char *type, int format, void *data, int *cause)
{
struct local_pvt *p;
struct ast_channel *chan = NULL;
#include <asterisk/app.h>
#include <asterisk/musiconhold.h>
#include <asterisk/utils.h>
+#include <asterisk/causes.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
return 0;
}
-static struct ast_channel *mgcp_request(const char *type, int format, void *data)
+static struct ast_channel *mgcp_request(const char *type, int format, void *data, int *cause)
{
int oldformat;
struct mgcp_subchannel *sub;
sub = find_subchannel(tmp, 0, NULL);
if (!sub) {
ast_log(LOG_WARNING, "Unable to find MGCP endpoint '%s'\n", tmp);
+ *cause = AST_CAUSE_UNREGISTERED;
return NULL;
}
transmit_notify_request(sub,"L/vmwi(-)");
}
}
+ *cause = AST_CAUSE_BUSY;
return NULL;
}
tmpc = mgcp_new(sub->owner ? sub->next : sub, AST_STATE_DOWN);
return tmp;
}
-static struct ast_channel *modem_request(const char *type, int format, void *data)
+static struct ast_channel *modem_request(const char *type, int format, void *data, int *cause)
{
int oldformat;
struct ast_modem_pvt *p;
}
-static struct ast_channel *nbs_request(const char *type, int format, void *data)
+static struct ast_channel *nbs_request(const char *type, int format, void *data, int *cause)
{
int oldformat;
struct nbs_pvt *p;
#include <asterisk/config.h>
#include <asterisk/cli.h>
#include <asterisk/utils.h>
+#include <asterisk/causes.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
return tmp;
}
-static struct ast_channel *oss_request(const char *type, int format, void *data)
+static struct ast_channel *oss_request(const char *type, int format, void *data, int *cause)
{
int oldformat = format;
struct ast_channel *tmp;
}
if (oss.owner) {
ast_log(LOG_NOTICE, "Already have a call on the OSS channel\n");
+ *cause = AST_CAUSE_BUSY;
return NULL;
}
tmp= oss_new(&oss, AST_STATE_DOWN);
#include <asterisk/options.h>
#include <asterisk/utils.h>
#include <asterisk/callerid.h>
+#include <asterisk/causes.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <errno.h>
return tmp;
}
-static struct ast_channel *phone_request(const char *type, int format, void *data)
+static struct ast_channel *phone_request(const char *type, int format, void *data, int *cause)
{
int oldformat;
struct phone_pvt *p;
if (!p->owner) {
tmp = phone_new(p, AST_STATE_DOWN, p->context);
break;
- }
+ } else
+ *cause = AST_CAUSE_BUSY;
}
p = p->next;
}
/*--- sip_request: PBX interface function -build SIP pvt structure ---*/
/* SIP calls initiated by the PBX arrive here */
-static struct ast_channel *sip_request(const char *type, int format, void *data)
+static struct ast_channel *sip_request(const char *type, int format, void *data, int *cause)
{
int oldformat;
struct sip_pvt *p;
p->capability = global_capability;
if (create_addr(p, host)) {
+ *cause = AST_CAUSE_UNREGISTERED;
sip_destroy(p);
return NULL;
}
return 0;
}
-static struct ast_channel *skinny_request(const char *type, int format, void *data)
+static struct ast_channel *skinny_request(const char *type, int format, void *data, int *cause)
{
int oldformat;
struct skinny_subchannel *sub;
return tmp;
}
-static struct ast_channel *vpb_request(const char *type, int format, void *data)
+static struct ast_channel *vpb_request(const char *type, int format, void *data, int *cause)
{
int oldformat;
struct vpb_pvt *p;
}
#endif
-static struct ast_channel *zt_request(const char *type, int format, void *data)
+static struct ast_channel *zt_request(const char *type, int format, void *data, int *cause)
{
int oldformat;
int groupmatch = 0;
}
ast_mutex_unlock(lock);
restart_monitor();
- if (!tmp) {
- if (busy && (channelmatch != CHAN_PSEUDO)) {
- tmp = zt_request("Zap", format, "pseudo");
- if (tmp) {
- char newname[80];
- ast_mutex_lock(&tmp->lock);
- snprintf(newname, sizeof(newname), "Zap/%s-busy-%d", (char *)data, rand());
- ast_change_name(tmp, newname);
- ast_setstate(tmp, AST_STATE_BUSY);
- ast_mutex_unlock(&tmp->lock);
- }
- } else if (busy) {
- ast_log(LOG_WARNING, "Whoa, the pseudo was busy somehow!\n");
- }
- }
+ if (callwait || (!tmp && busy))
+ *cause = AST_CAUSE_BUSY;
return tmp;
}
time_t t;
int i, which=-1;
int numdchans;
+ int cause=0;
struct zt_pvt *crv;
pthread_t threadid;
pthread_attr_t attr;
(tv.tv_usec - lastidle.tv_usec) / 1000) > 1000) {
/* Don't create a new idle call more than once per second */
snprintf(idlen, sizeof(idlen), "%d/%s", pri->pvts[nextidle]->channel, pri->idledial);
- idle = zt_request("Zap", AST_FORMAT_ULAW, idlen);
+ idle = zt_request("Zap", AST_FORMAT_ULAW, idlen, &cause);
if (idle) {
pri->pvts[nextidle]->isidlecall = 1;
if (ast_pthread_create(&p, NULL, do_idle_thread, idle)) {
#define AST_CAUSE_NORMAL AST_CAUSE_NORMAL_CLEARING
#define AST_CAUSE_NOANSWER AST_CAUSE_NO_ANSWER
#define AST_CAUSE_CONGESTION AST_CAUSE_NORMAL_CIRCUIT_CONGESTION
+#define AST_CAUSE_UNREGISTERED AST_CAUSE_NO_ROUTE_DESTINATION
#define AST_CAUSE_NOTDEFINED 0
+#define AST_CAUSE_NOSUCHDRIVER AST_CAUSE_CHAN_NOT_IMPLEMENTED
#endif
* by the low level module
* Returns an ast_channel on success, NULL on failure.
*/
-struct ast_channel *ast_request(const char *type, int format, void *data);
+struct ast_channel *ast_request(const char *type, int format, void *data, int *status);
//! Search the Channels by Name
/*!
* Returns 0 on success, -1 on failure.
*/
int ast_channel_register(const char *type, const char *description, int capabilities,
- struct ast_channel* (*requester)(const char *type, int format, void *data));
+ struct ast_channel* (*requester)(const char *type, int format, void *data, int *cause));
/* Same like the upper function but with support for devicestate */
int ast_channel_register_ex(const char *type, const char *description, int capabilities,
- struct ast_channel *(*requester)(const char *type, int format, void *data),
+ struct ast_channel *(*requester)(const char *type, int format, void *data, int *cause),
int (*devicestate)(void *data));
//! Unregister a channel class