[asterisk-commits] moy: branch moy/mfcr2 r182169 - /team/moy/mfcr2/channels/chan_dahdi.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 16 00:19:55 CDT 2009


Author: moy
Date: Mon Mar 16 00:19:52 2009
New Revision: 182169

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=182169
Log:
add changes to allow users to specify the answer mode in the dial plan and fix race condition when setting PBX variable MFCR2_CATEGORY

Modified:
    team/moy/mfcr2/channels/chan_dahdi.c

Modified: team/moy/mfcr2/channels/chan_dahdi.c
URL: http://svn.digium.com/svn-view/asterisk/team/moy/mfcr2/channels/chan_dahdi.c?view=diff&rev=182169&r1=182168&r2=182169
==============================================================================
--- team/moy/mfcr2/channels/chan_dahdi.c (original)
+++ team/moy/mfcr2/channels/chan_dahdi.c Mon Mar 16 00:19:52 2009
@@ -1604,6 +1604,33 @@
 
 static struct ast_channel *dahdi_new(struct dahdi_pvt *, int, int, int, int, int);
 #ifdef HAVE_OPENR2
+
+static int dahdi_r2_answer(struct dahdi_pvt *p)
+{
+	int res = 0;
+	/* openr2 1.1.0 and older does not even define OR2_LIB_INTERFACE
+	* and does not has support for openr2_chan_answer_call_with_mode
+	*  */
+#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1
+	const char *double_answer = pbx_builtin_getvar_helper(p->owner, "MFCR2_DOUBLE_ANSWER");
+	int wants_double_answer = ast_true(double_answer) ? 1 : 0;
+	if (!double_answer) {
+		/* this still can result in double answer if the channel context 
+		* was configured that way */
+		res = openr2_chan_answer_call(p->r2chan);
+	} else if (wants_double_answer) {
+		res = openr2_chan_answer_call_with_mode(p->r2chan, OR2_ANSWER_DOUBLE);
+	} else {
+		res = openr2_chan_answer_call_with_mode(p->r2chan, OR2_ANSWER_SIMPLE);
+	} 
+#else
+	res = openr2_chan_answer_call(p->r2chan);
+#endif
+	return res;
+}
+
+
+
 /* should be called with the ast_channel locked */
 static openr2_calling_party_category_t dahdi_r2_get_channel_category(struct ast_channel *c)
 {
@@ -1747,7 +1774,6 @@
 		c = dahdi_new(p, AST_STATE_RING, 1, SUB_REAL, DAHDI_LAW_ALAW, 0);
 		if (c) {
 			dahdi_r2_update_monitor_count(p->mfcr2, 0);
-			pbx_builtin_setvar_helper(c, "MFCR2_CATEGORY", openr2_proto_get_category_string(p->mfcr2_recvd_category));
 			/* Done here, don't disable reading now since we still need to generate MF tones to accept
 			   the call or reject it and detect the tone off condition of the other end, all of this
 			   will be done in the PBX thread now */
@@ -1792,7 +1818,7 @@
 			openr2_chan_disable_read(r2chan);
 			if (p->mfcr2_answer_pending) {
 				ast_log(LOG_DEBUG, "Answering MFC/R2 call after accepting it on chan %d\n", openr2_chan_get_number(r2chan));
-				openr2_chan_answer_call(r2chan);
+				dahdi_r2_answer(p);
 			}	
 			return;
 		} 
@@ -1802,7 +1828,6 @@
 			/* chan_dahdi will take care of reading from now on in the PBX thread, tell the 
 			   library to forget about it */
 			openr2_chan_disable_read(r2chan);
-			pbx_builtin_setvar_helper(c, "MFCR2_CATEGORY", openr2_proto_get_category_string(p->mfcr2_recvd_category));
 			return;
 		}
 		ast_log(LOG_WARNING, "Unable to create PBX channel in DAHDI channel %d\n", p->channel);
@@ -4778,7 +4803,7 @@
 			}
 		} else {
 			ast_log(LOG_DEBUG, "Answering MFC/R2 call on chan %d\n", p->channel);
-			openr2_chan_answer_call(p->r2chan);
+			dahdi_r2_answer(p);
 		}
 		break;
 #endif
@@ -7493,6 +7518,10 @@
 	/* Assume calls are not idle calls unless we're told differently */
 	i->isidlecall = 0;
 	i->alreadyhungup = 0;
+#endif
+#ifdef HAVE_OPENR2
+	if (i->mfcr2call)
+		pbx_builtin_setvar_helper(tmp, "MFCR2_CATEGORY", openr2_proto_get_category_string(i->mfcr2_recvd_category));
 #endif
 	/* clear the fake event in case we posted one before we had ast_channel */
 	i->fake_event = 0;




More information about the asterisk-commits mailing list