Mon Jun 27 16:50:47 2011

Asterisk developer's documentation


app_senddtmf.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief App to send DTMF digits
00022  *
00023  * \author Mark Spencer <markster@digium.com>
00024  * 
00025  * \ingroup applications
00026  */
00027  
00028 #include "asterisk.h"
00029 
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 265453 $")
00031 
00032 #include "asterisk/pbx.h"
00033 #include "asterisk/module.h"
00034 #include "asterisk/app.h"
00035 #include "asterisk/manager.h"
00036 #include "asterisk/channel.h"
00037 
00038 /*** DOCUMENTATION
00039    <application name="SendDTMF" language="en_US">
00040       <synopsis>
00041          Sends arbitrary DTMF digits
00042       </synopsis>
00043       <syntax>
00044          <parameter name="digits" required="true">
00045             <para>List of digits 0-9,*#,abcd</para>
00046          </parameter>
00047          <parameter name="timeout_ms" required="false">
00048             <para>Amount of time to wait in ms between tones. (defaults to .25s)</para>
00049          </parameter>
00050          <parameter name="duration_ms" required="false">
00051             <para>Duration of each digit</para>
00052          </parameter>
00053                         <parameter name="channel" required="false">
00054                                 <para>Channel where digits will be played</para>
00055                         </parameter>
00056       </syntax>
00057       <description>
00058          <para>DTMF digits sent to a channel with half second pause</para>
00059          <para>It will pass all digits or terminate if it encounters an error.</para>
00060       </description>
00061       <see-also>
00062          <ref type="application">Read</ref>
00063       </see-also>
00064    </application>
00065    <manager name="PlayDTMF" language="en_US">
00066       <synopsis>
00067          Play DTMF signal on a specific channel.
00068       </synopsis>
00069       <syntax>
00070          <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
00071          <parameter name="Channel" required="true">
00072             <para>Channel name to send digit to.</para>
00073          </parameter>
00074          <parameter name="Digit" required="true">
00075             <para>The DTMF digit to play.</para>
00076          </parameter>
00077       </syntax>
00078       <description>
00079          <para>Plays a dtmf digit on the specified channel.</para>
00080       </description>
00081    </manager>
00082  ***/
00083 static char *app = "SendDTMF";
00084 
00085 static int senddtmf_exec(struct ast_channel *chan, const char *vdata)
00086 {
00087    int res = 0;
00088    char *data;
00089    int dinterval = 0, duration = 0;
00090    struct ast_channel *dchan;
00091    AST_DECLARE_APP_ARGS(args,
00092       AST_APP_ARG(digits);
00093       AST_APP_ARG(dinterval);
00094       AST_APP_ARG(duration);
00095       AST_APP_ARG(channel);
00096    );
00097 
00098    if (ast_strlen_zero(vdata)) {
00099       ast_log(LOG_WARNING, "SendDTMF requires an argument (digits or *#aAbBcCdD)\n");
00100       return 0;
00101    }
00102 
00103    dchan = chan;
00104 
00105    data = ast_strdupa(vdata);
00106    AST_STANDARD_APP_ARGS(args, data);
00107 
00108    if (!ast_strlen_zero(args.dinterval)) {
00109       ast_app_parse_timelen(args.dinterval, &dinterval, TIMELEN_MILLISECONDS);
00110    }
00111    if (!ast_strlen_zero(args.duration)) {
00112       ast_app_parse_timelen(args.duration, &duration, TIMELEN_MILLISECONDS);
00113    }
00114    if (!ast_strlen_zero(args.channel)) {
00115       dchan = ast_channel_get_by_name(args.channel);
00116    }
00117    if (dchan != chan) {
00118       ast_autoservice_start(chan);
00119    }
00120    res = ast_dtmf_stream(dchan, NULL, args.digits, dinterval <= 0 ? 250 : dinterval, duration);
00121    if (dchan != chan) {
00122       ast_autoservice_stop(chan);
00123       ast_channel_unref(dchan);
00124    }
00125 
00126    return res;
00127 }
00128 
00129 static int manager_play_dtmf(struct mansession *s, const struct message *m)
00130 {
00131    const char *channel = astman_get_header(m, "Channel");
00132    const char *digit = astman_get_header(m, "Digit");
00133    struct ast_channel *chan;
00134 
00135    if (!(chan = ast_channel_get_by_name(channel))) {
00136       astman_send_error(s, m, "Channel not found");
00137       return 0;
00138    }
00139 
00140    if (ast_strlen_zero(digit)) {
00141       astman_send_error(s, m, "No digit specified");
00142       chan = ast_channel_unref(chan);
00143       return 0;
00144    }
00145 
00146    ast_senddigit(chan, *digit, 0);
00147 
00148    chan = ast_channel_unref(chan);
00149 
00150    astman_send_ack(s, m, "DTMF successfully queued");
00151 
00152    return 0;
00153 }
00154 
00155 static int unload_module(void)
00156 {
00157    int res;
00158 
00159    res = ast_unregister_application(app);
00160    res |= ast_manager_unregister("PlayDTMF");
00161 
00162    return res; 
00163 }
00164 
00165 static int load_module(void)
00166 {
00167    int res;
00168 
00169    res = ast_manager_register_xml("PlayDTMF", EVENT_FLAG_CALL, manager_play_dtmf);
00170    res |= ast_register_application_xml(app, senddtmf_exec);
00171 
00172    return res;
00173 }
00174 
00175 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send DTMF digits Application");

Generated on Mon Jun 27 16:50:47 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7