[asterisk-commits] rmudgett: branch group/issue14068 r199780 - /team/group/issue14068/channels/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jun 9 12:31:20 CDT 2009
Author: rmudgett
Date: Tue Jun 9 12:31:08 2009
New Revision: 199780
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=199780
Log:
Eliminate the need to wait for information to be put in an incoming PRI channel.
* Extracted dahdi_pbx_start() out of dahdi_new() so PRI_EVENT_RING can start
the PBX when it is done setting all channel variables on an en-block incoming
call.
* Made overlap and en-block incoming calls set PRI specific channel variables
the same. ANI2 was set differently.
* Added missing ast_channel_unlock() to setting the USERUSERINFO channel
variable in the PRI_EVENT_ANSWER.
Modified:
team/group/issue14068/channels/chan_dahdi.c
Modified: team/group/issue14068/channels/chan_dahdi.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/issue14068/channels/chan_dahdi.c?view=diff&rev=199780&r1=199779&r2=199780
==============================================================================
--- team/group/issue14068/channels/chan_dahdi.c (original)
+++ team/group/issue14068/channels/chan_dahdi.c Tue Jun 9 12:31:08 2009
@@ -7888,6 +7888,38 @@
return res;
}
+/*!
+ * \internal
+ * \brief Start a PBX on the given channel in a new thread.
+ * \since 1.6.3
+ *
+ * \param pvt DAHDI private structure.
+ * \param chan Asterisk channel to start the PBX.
+ *
+ * \retval AST_PBX_SUCCESS on success.
+ * \retval Other on error.
+ */
+static enum ast_pbx_result dahdi_pbx_start(struct dahdi_pvt *pvt, struct ast_channel *chan)
+{
+ enum ast_pbx_result result;
+
+#if defined(HAVE_OPENR2)
+ if (pvt->mfcr2call) {
+ pbx_builtin_setvar_helper(chan, "MFCR2_CATEGORY",
+ openr2_proto_get_category_string(pvt->mfcr2_recvd_category));
+ }
+#endif /* defined(HAVE_OPENR2) */
+
+ result = ast_pbx_start(chan);
+ if (result != AST_PBX_SUCCESS) {
+ ast_log(LOG_WARNING, "Unable to start PBX on %s\n", chan->name);
+ ast_hangup(chan);
+ pvt->owner = NULL;
+ }
+
+ return result;
+}
+
static struct ast_channel *dahdi_new(struct dahdi_pvt *i, int state, int startpbx, int idx, int law, int transfercapability)
{
struct ast_channel *tmp;
@@ -8068,18 +8100,8 @@
for (v = i->vars ; v ; v = v->next)
pbx_builtin_setvar_helper(tmp, v->name, v->value);
- if (startpbx) {
-#ifdef HAVE_OPENR2
- if (i->mfcr2call) {
- pbx_builtin_setvar_helper(tmp, "MFCR2_CATEGORY", openr2_proto_get_category_string(i->mfcr2_recvd_category));
- }
-#endif
- if (ast_pbx_start(tmp)) {
- ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
- ast_hangup(tmp);
- i->owner = NULL;
- return NULL;
- }
+ if (startpbx && dahdi_pbx_start(i, tmp) != AST_PBX_SUCCESS) {
+ return NULL;
}
ast_module_ref(ast_module_info->self);
@@ -13685,7 +13707,10 @@
if (!e->ring.complete
&& (pri->overlapdial & DAHDI_OVERLAPDIAL_INCOMING)
&& ast_matchmore_extension(NULL, pri->pvts[chanpos]->context, pri->pvts[chanpos]->exten, 1, pri->pvts[chanpos]->cid_num)) {
- /* Release the PRI lock while we create the channel */
+ /*
+ * Release the PRI lock while we create the channel
+ * so other threads can send D channel messages.
+ */
ast_mutex_unlock(&pri->lock);
if (crv) {
/* Set bearer and such */
@@ -13696,37 +13721,33 @@
} else {
c = dahdi_new(pri->pvts[chanpos], AST_STATE_RESERVED, 0, SUB_REAL, law, e->ring.ctype);
}
-
- ast_mutex_unlock(&pri->pvts[chanpos]->lock);
-
- if (!ast_strlen_zero(e->ring.callingsubaddr)) {
- pbx_builtin_setvar_helper(c, "CALLINGSUBADDR", e->ring.callingsubaddr);
+ ast_mutex_lock(&pri->lock);
+ if (c) {
+ if (!ast_strlen_zero(e->ring.callingsubaddr)) {
+ pbx_builtin_setvar_helper(c, "CALLINGSUBADDR", e->ring.callingsubaddr);
+ }
+ if (e->ring.ani2 >= 0) {
+ snprintf(ani2str, sizeof(ani2str), "%d", e->ring.ani2);
+ pbx_builtin_setvar_helper(c, "ANI2", ani2str);
+ pri->pvts[chanpos]->cid_ani2 = e->ring.ani2;
+ }
+
+#ifdef SUPPORT_USERUSER
+ if (!ast_strlen_zero(e->ring.useruserinfo)) {
+ pbx_builtin_setvar_helper(c, "USERUSERINFO", e->ring.useruserinfo);
+ }
+#endif
+
+ snprintf(calledtonstr, sizeof(calledtonstr), "%d", e->ring.calledplan);
+ pbx_builtin_setvar_helper(c, "CALLEDTON", calledtonstr);
+ if (e->ring.redirectingreason >= 0) {
+ /* This is now just a status variable. Use REDIRECTING() dialplan function. */
+ pbx_builtin_setvar_helper(c, "PRIREDIRECTREASON", redirectingreason2str(e->ring.redirectingreason));
+ }
+
+ dahdi_pri_handle_subcmds(pri, chanpos, e->e, e->ring.channel,
+ e->ring.subcmds);
}
- if (e->ring.ani2 >= 0) {
- snprintf(ani2str, 5, "%.2d", e->ring.ani2);
- pbx_builtin_setvar_helper(c, "ANI2", ani2str);
- pri->pvts[chanpos]->cid_ani2 = e->ring.ani2;
- }
-
-#ifdef SUPPORT_USERUSER
- if (!ast_strlen_zero(e->ring.useruserinfo)) {
- pbx_builtin_setvar_helper(c, "USERUSERINFO", e->ring.useruserinfo);
- }
-#endif
-
- snprintf(calledtonstr, sizeof(calledtonstr), "%d", e->ring.calledplan);
- pbx_builtin_setvar_helper(c, "CALLEDTON", calledtonstr);
- if (e->ring.redirectingreason >= 0) {
- /* This is now just a status variable. Use REDIRECTING() dialplan function. */
- pbx_builtin_setvar_helper(c, "PRIREDIRECTREASON", redirectingreason2str(e->ring.redirectingreason));
- }
-
- ast_mutex_lock(&pri->pvts[chanpos]->lock);
- ast_mutex_lock(&pri->lock);
-
- dahdi_pri_handle_subcmds(pri, chanpos, e->e, e->ring.channel,
- e->ring.subcmds);
-
if (c && !ast_pthread_create_detached(&threadid, NULL, ss_thread, c)) {
ast_verb(3, "Accepting overlap call from '%s' to '%s' on channel %d/%d, span %d\n",
plancallingnum, S_OR(pri->pvts[chanpos]->exten, "<unspecified>"),
@@ -13742,16 +13763,19 @@
}
}
} else {
+ /*
+ * Release the PRI lock while we create the channel
+ * so other threads can send D channel messages.
+ */
ast_mutex_unlock(&pri->lock);
- /* Release PRI lock while we create the channel */
- c = dahdi_new(pri->pvts[chanpos], AST_STATE_RING, 1, SUB_REAL, law, e->ring.ctype);
+ c = dahdi_new(pri->pvts[chanpos], AST_STATE_RING, 0, SUB_REAL, law, e->ring.ctype);
+ ast_mutex_lock(&pri->lock);
if (c) {
- char calledtonstr[10];
-
- ast_mutex_unlock(&pri->pvts[chanpos]->lock);
-
+ if (!ast_strlen_zero(e->ring.callingsubaddr)) {
+ pbx_builtin_setvar_helper(c, "CALLINGSUBADDR", e->ring.callingsubaddr);
+ }
if (e->ring.ani2 >= 0) {
- snprintf(ani2str, 5, "%d", e->ring.ani2);
+ snprintf(ani2str, sizeof(ani2str), "%d", e->ring.ani2);
pbx_builtin_setvar_helper(c, "ANI2", ani2str);
pri->pvts[chanpos]->cid_ani2 = e->ring.ani2;
}
@@ -13770,21 +13794,16 @@
snprintf(calledtonstr, sizeof(calledtonstr), "%d", e->ring.calledplan);
pbx_builtin_setvar_helper(c, "CALLEDTON", calledtonstr);
- ast_mutex_lock(&pri->pvts[chanpos]->lock);
- ast_mutex_lock(&pri->lock);
-
dahdi_pri_handle_subcmds(pri, chanpos, e->e, e->ring.channel,
e->ring.subcmds);
-
+ }
+ if (c && !dahdi_pbx_start(pri->pvts[chanpos], c)) {
ast_verb(3, "Accepting call from '%s' to '%s' on channel %d/%d, span %d\n",
plancallingnum, pri->pvts[chanpos]->exten,
pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset, pri->span);
dahdi_enable_ec(pri->pvts[chanpos]);
} else {
-
- ast_mutex_lock(&pri->lock);
-
ast_log(LOG_WARNING, "Unable to start PBX on channel %d/%d, span %d\n",
pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset, pri->span);
pri_hangup(pri->pri, e->ring.call, PRI_CAUSE_SWITCH_CONGESTION);
@@ -14035,6 +14054,7 @@
if (owner) {
pbx_builtin_setvar_helper(owner, "USERUSERINFO",
e->answer.useruserinfo);
+ ast_channel_unlock(owner);
}
}
#endif
More information about the asterisk-commits
mailing list