[asterisk-commits] file: branch group/bridging_api r56561 - /team/group/bridging_api/apps/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Feb 23 18:43:23 MST 2007


Author: file
Date: Fri Feb 23 19:43:22 2007
New Revision: 56561

URL: http://svn.digium.com/view/asterisk?view=rev&rev=56561
Log:
Add Dial2 which uses the dialing API to place calls out, and then the new bridging API to bridge them together. Since the bridging API doesn't actually work yet it just implodes.

Added:
    team/group/bridging_api/apps/app_dial2.c   (with props)

Added: team/group/bridging_api/apps/app_dial2.c
URL: http://svn.digium.com/view/asterisk/team/group/bridging_api/apps/app_dial2.c?view=auto&rev=56561
==============================================================================
--- team/group/bridging_api/apps/app_dial2.c (added)
+++ team/group/bridging_api/apps/app_dial2.c Fri Feb 23 19:43:22 2007
@@ -1,0 +1,145 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2007, Digium, Inc.
+ *
+ * Joshua Colp <jcolp at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Dialing and Bridging Application
+ *
+ * \author Joshua Colp <jcolp at digium.com>
+ * 
+ * This is a skeleton for development of an Asterisk application 
+ * \ingroup applications
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "asterisk/file.h"
+#include "asterisk/logger.h"
+#include "asterisk/channel.h"
+#include "asterisk/pbx.h"
+#include "asterisk/module.h"
+#include "asterisk/lock.h"
+#include "asterisk/app.h"
+#include "asterisk/dial.h"
+#include "asterisk/bridging.h"
+
+static char *app = "Dial2";
+static char *synopsis = 
+"Dialing and Bridging Application";
+static char *descrip = "This application is a template to build other applications from.\n"
+ " It shows you the basic structure to create your own Asterisk applications.\n";
+
+static int dial2_exec(struct ast_channel *chan, void *data)
+{
+	int res = 0, have_dial = 0;
+	struct ast_module_user *u;
+	char *parse = NULL, *tmp = NULL, *tech = NULL, *device = NULL;
+	struct ast_dial *dial = NULL;
+	struct ast_bridge *br = NULL;
+	struct ast_channel *answered = NULL;
+
+	if (ast_strlen_zero(data)) {
+		ast_log(LOG_WARNING, "%s requires an argument (Technology/Device)\n", app);
+		return -1;
+	}
+
+	u = ast_module_user_add(chan);
+
+	parse = ast_strdupa(data);
+
+	/* Create a new dialing structure to dial out on */
+	if (!(dial = ast_dial_create())) {
+		ast_log(LOG_WARNING, "Failed to create dialing strcture ;(\n");
+		ast_module_user_remove(u);
+		return 0;
+	}
+
+	/* Parse technology and device */
+	tmp = parse;
+	while ((tmp = strsep(&tmp, "&"))) {
+		device = tmp;
+		tech = strsep(&device, "/");
+		/* If no tech or device... continue on */
+		if (ast_strlen_zero(tech) || ast_strlen_zero(device))
+			continue;
+		have_dial = 1;
+		/* Add to dialing structure */
+		ast_dial_append(dial, tech, device);
+	}
+
+	/* If nobody was dialed... bail out */
+	if (!have_dial) {
+		ast_dial_destroy(dial);
+		ast_module_user_remove(u);
+		return 0;
+	}
+
+	/* Execute dialing and relay progress back */
+	ast_dial_run(dial, chan, 0);
+
+	/* Get answered channel so we can bridge 'em together */
+	answered = ast_dial_answered(dial);
+
+	/* We can safely destroy the dial structure now */
+	ast_dial_destroy(dial);
+
+	/* Confirm we have an answered channel */
+	if (!answered) {
+		ast_module_user_remove(u);
+		return 0;
+	}
+
+	/* Create a new 1TO1 bridge */
+	if (!(br = ast_bridge_create(AST_BRIDGE_CAPABILITY_1TO1))) {
+		ast_hangup(answered);
+		ast_module_user_remove(u);
+		return 0;
+	}
+
+	/* Join the two channels in */
+	ast_bridge_join(br, chan);
+	ast_bridge_join(br, answered);
+
+	/* Wait for the bridge to end */
+
+	/* Destroy the bridge */
+	ast_bridge_destroy(br);
+
+	ast_module_user_remove(u);
+
+	return res;
+}
+
+static int unload_module(void)
+{
+	return ast_unregister_application(app);	
+}
+
+static int load_module(void)
+{
+	return ast_register_application(app, dial2_exec, synopsis, descrip);
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Dialing and Bridging Application");

Propchange: team/group/bridging_api/apps/app_dial2.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/group/bridging_api/apps/app_dial2.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/group/bridging_api/apps/app_dial2.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain



More information about the asterisk-commits mailing list