[svn-commits] moy: branch moy/mfcr2-1.4 r184833 - /team/moy/mfcr2-1.4/channels/chan_dahdi.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sat Mar 28 14:28:43 CDT 2009


Author: moy
Date: Sat Mar 28 14:28:37 2009
New Revision: 184833

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=184833
Log:
added DADHIAcceptR2Call application

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

Modified: team/moy/mfcr2-1.4/channels/chan_dahdi.c
URL: http://svn.digium.com/svn-view/asterisk/team/moy/mfcr2-1.4/channels/chan_dahdi.c?view=diff&rev=184833&r1=184832&r2=184833
==============================================================================
--- team/moy/mfcr2-1.4/channels/chan_dahdi.c (original)
+++ team/moy/mfcr2-1.4/channels/chan_dahdi.c Sat Mar 28 14:28:37 2009
@@ -3079,6 +3079,126 @@
 #endif
 
 #ifdef HAVE_OPENR2
+static char *dahdi_accept_r2_call_app = "DAHDIAcceptR2Call";
+static char *zap_accept_r2_call_app = "ZapAcceptR2Call";
+
+static char *dahdi_accept_r2_call_synopsis = "Accept an R2 call if its not already accepted (you still need to answer it)";
+static char *zap_accept_r2_call_synopsis = "Accept an R2 call if its not already accepted (you still need to answer it)";
+
+static char *dahdi_accept_r2_call_descrip = 
+"  DAHDIAcceptR2Call(): This application will accept the current MFC/R2 call\n"
+"  You can specify yes or no as argument to accept with or without charge.\n";
+
+static char *zap_accept_r2_call_descrip = 
+"  ZapAcceptR2Call(): This application will accept the current MFC/R2 call\n"
+"  You can specify yes or no as argument to accept with or without charge.\n";
+
+static int dahdi_accept_r2_call_exec(struct ast_channel *chan, void *data)
+{
+	/* data is whether to accept with charge or no charge */
+	openr2_call_mode_t accept_mode;
+	int res, timeout, maxloops;
+	struct ast_frame *f;
+	struct dahdi_pvt *p;
+	char *parse;
+	AST_DECLARE_APP_ARGS(args,
+			AST_APP_ARG(charge);
+	);
+
+	if (ast_strlen_zero(data)) {
+		ast_log(LOG_DEBUG, "No data sent to application!\n");
+		return -1;
+	}
+
+	if (chan->tech != &dahdi_tech) {
+		ast_log(LOG_DEBUG, "Only DAHDI technology accepted!\n");
+		return -1;
+	}
+
+	p = (struct dahdi_pvt *)chan->tech_pvt;
+	if (!p) {
+		ast_log(LOG_DEBUG, "Unable to find technology private!\n");
+		return -1;
+	}
+
+	parse = ast_strdupa(data);
+	AST_STANDARD_APP_ARGS(args, parse);
+
+	if (ast_strlen_zero(args.charge)) {
+		ast_log(LOG_WARNING, "DAHDIAcceptR2Call requires 'yes' or 'no' for the charge parameter\n");
+		return -1;
+	}
+
+	ast_mutex_lock(&p->lock);
+	if (!p->mfcr2 || !p->mfcr2call) {
+		ast_mutex_unlock(&p->lock);
+		ast_log(LOG_DEBUG, "Channel %s does not seems to be an R2 active channel!\n", chan->name);
+		return -1;
+	}
+
+	if (p->mfcr2_call_accepted) {
+		ast_mutex_unlock(&p->lock);
+		ast_log(LOG_DEBUG, "MFC/R2 call already accepted on channel %s!\n", chan->name);
+		return 0;
+	}
+	accept_mode = ast_true(args.charge) ? OR2_CALL_WITH_CHARGE : OR2_CALL_NO_CHARGE;
+	if (openr2_chan_accept_call(p->r2chan, accept_mode)) {
+		ast_mutex_unlock(&p->lock);
+		ast_log(LOG_WARNING, "Failed to accept MFC/R2 call!\n");
+		return -1;
+	}
+	ast_mutex_unlock(&p->lock);
+
+	res = 0;
+	timeout = 100;
+	maxloops = 50; /* wait up to 5 seconds */
+	/* we need to read() until the call is accepted */
+	while (maxloops > 0) {
+		maxloops--;
+		if (ast_check_hangup(chan)) {
+			break;
+		}
+		res = ast_waitfor(chan, timeout);
+		if (res < 0) {
+			ast_log(LOG_DEBUG, "ast_waitfor failed on channel %s, going out ...\n", chan->name);
+			res = -1;
+			break;
+		}
+		if (res == 0) {
+			continue;
+		}
+		f = ast_read(chan);
+		if (!f) {
+			ast_log(LOG_DEBUG, "No frame read on channel %s, going out ...\n", chan->name);
+			res = -1;
+			break;
+		}
+		if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP) {
+			ast_log(LOG_DEBUG, "Got HANGUP frame on channel %s, going out ...\n", chan->name);
+			ast_frfree(f);
+			res = -1;
+			break;
+		}
+		ast_frfree(f);
+		ast_mutex_lock(&p->lock);
+		if (p->mfcr2_call_accepted) {
+			ast_mutex_unlock(&p->lock);
+			ast_log(LOG_DEBUG, "Accepted MFC/R2 call!\n");
+			break;
+		}
+		ast_mutex_unlock(&p->lock);
+	}
+	if (res == -1) {
+		ast_log(LOG_WARNING, "Failed to accept MFC/R2 call!\n");
+	}
+	return res;
+}
+
+static int zap_accept_r2_call_exec(struct ast_channel *chan, void *data)
+{
+	return dahdi_accept_r2_call_exec(chan, data);
+}
+
 static openr2_call_disconnect_cause_t dahdi_ast_cause_to_r2_cause(int cause)
 {
 	openr2_call_disconnect_cause_t r2cause = OR2_CAUSE_NORMAL_CLEARING;
@@ -12094,6 +12214,10 @@
 		}
 	}
 	ast_cli_unregister_multiple(dahdi_mfcr2_cli, sizeof(dahdi_mfcr2_cli) / sizeof(dahdi_mfcr2_cli[0]));
+	if (*dahdi_chan_mode == CHAN_DAHDI_PLUS_ZAP_MODE) {
+		ast_unregister_application(dahdi_accept_r2_call_app);
+	}
+	ast_unregister_application(zap_accept_r2_call_app);
 #endif
 	ast_cli_unregister_multiple(dahdi_cli, sizeof(dahdi_cli) / sizeof(struct ast_cli_entry));
 	local_astman_unregister("DialOffHook");
@@ -13053,7 +13177,7 @@
 #ifdef HAVE_ZAPTEL
 	int load_from_zapata_conf = 1;
 #else
-	int load_from_zapata_conf = (dahdi_chan_mode == CHAN_ZAP_MODE);
+	int load_from_zapata_conf = (*dahdi_chan_mode == CHAN_ZAP_MODE);
 #endif
 
 	if (load_from_zapata_conf) {
@@ -13223,6 +13347,12 @@
 #endif
 #ifdef HAVE_OPENR2
 	init_mfcr2_globals();
+	if (*dahdi_chan_mode == CHAN_DAHDI_PLUS_ZAP_MODE) {
+		ast_register_application(dahdi_accept_r2_call_app, dahdi_accept_r2_call_exec,
+			dahdi_accept_r2_call_synopsis, dahdi_accept_r2_call_descrip);
+	}
+	ast_register_application(zap_accept_r2_call_app, zap_accept_r2_call_exec,
+		zap_accept_r2_call_synopsis, zap_accept_r2_call_descrip);
 #endif
 	if ((res = setup_dahdi(0))) {
 		return AST_MODULE_LOAD_DECLINE;




More information about the svn-commits mailing list