Sat Mar 10 01:53:59 2012

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 /*** MODULEINFO
00029    <support_level>core</support_level>
00030  ***/
00031  
00032 #include "asterisk.h"
00033 
00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
00035 
00036 #include "asterisk/pbx.h"
00037 #include "asterisk/module.h"
00038 #include "asterisk/app.h"
00039 #include "asterisk/manager.h"
00040 #include "asterisk/channel.h"
00041 
00042 /*** DOCUMENTATION
00043    <application name="SendDTMF" language="en_US">
00044       <synopsis>
00045          Sends arbitrary DTMF digits
00046       </synopsis>
00047       <syntax>
00048          <parameter name="digits" required="true">
00049             <para>List of digits 0-9,*#,abcd</para>
00050          </parameter>
00051          <parameter name="timeout_ms" required="false">
00052             <para>Amount of time to wait in ms between tones. (defaults to .25s)</para>
00053          </parameter>
00054          <parameter name="duration_ms" required="false">
00055             <para>Duration of each digit</para>
00056          </parameter>
00057                         <parameter name="channel" required="false">
00058                                 <para>Channel where digits will be played</para>
00059                         </parameter>
00060       </syntax>
00061       <description>
00062          <para>DTMF digits sent to a channel with half second pause</para>
00063          <para>It will pass all digits or terminate if it encounters an error.</para>
00064       </description>
00065       <see-also>
00066          <ref type="application">Read</ref>
00067       </see-also>
00068    </application>
00069    <manager name="PlayDTMF" language="en_US">
00070       <synopsis>
00071          Play DTMF signal on a specific channel.
00072       </synopsis>
00073       <syntax>
00074          <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
00075          <parameter name="Channel" required="true">
00076             <para>Channel name to send digit to.</para>
00077          </parameter>
00078          <parameter name="Digit" required="true">
00079             <para>The DTMF digit to play.</para>
00080          </parameter>
00081       </syntax>
00082       <description>
00083          <para>Plays a dtmf digit on the specified channel.</para>
00084       </description>
00085    </manager>
00086  ***/
00087 static char *app = "SendDTMF";
00088 
00089 static int senddtmf_exec(struct ast_channel *chan, const char *vdata)
00090 {
00091    int res = 0;
00092    char *data;
00093    int dinterval = 0, duration = 0;
00094    struct ast_channel *dchan;
00095    AST_DECLARE_APP_ARGS(args,
00096       AST_APP_ARG(digits);
00097       AST_APP_ARG(dinterval);
00098       AST_APP_ARG(duration);
00099       AST_APP_ARG(channel);
00100    );
00101 
00102    if (ast_strlen_zero(vdata)) {
00103       ast_log(LOG_WARNING, "SendDTMF requires an argument (digits or *#aAbBcCdD)\n");
00104       return 0;
00105    }
00106 
00107    dchan = chan;
00108 
00109    data = ast_strdupa(vdata);
00110    AST_STANDARD_APP_ARGS(args, data);
00111 
00112    if (!ast_strlen_zero(args.dinterval)) {
00113       ast_app_parse_timelen(args.dinterval, &dinterval, TIMELEN_MILLISECONDS);
00114    }
00115    if (!ast_strlen_zero(args.duration)) {
00116       ast_app_parse_timelen(args.duration, &duration, TIMELEN_MILLISECONDS);
00117    }
00118    if (!ast_strlen_zero(args.channel)) {
00119       dchan = ast_channel_get_by_name(args.channel);
00120    }
00121    if (dchan != chan) {
00122       ast_autoservice_start(chan);
00123    }
00124    res = ast_dtmf_stream(dchan, NULL, args.digits, dinterval <= 0 ? 250 : dinterval, duration);
00125    if (dchan != chan) {
00126       ast_autoservice_stop(chan);
00127       ast_channel_unref(dchan);
00128    }
00129 
00130    return res;
00131 }
00132 
00133 static int manager_play_dtmf(struct mansession *s, const struct message *m)
00134 {
00135    const char *channel = astman_get_header(m, "Channel");
00136    const char *digit = astman_get_header(m, "Digit");
00137    struct ast_channel *chan;
00138 
00139    if (!(chan = ast_channel_get_by_name(channel))) {
00140       astman_send_error(s, m, "Channel not found");
00141       return 0;
00142    }
00143 
00144    if (ast_strlen_zero(digit)) {
00145       astman_send_error(s, m, "No digit specified");
00146       chan = ast_channel_unref(chan);
00147       return 0;
00148    }
00149 
00150    ast_senddigit(chan, *digit, 0);
00151 
00152    chan = ast_channel_unref(chan);
00153 
00154    astman_send_ack(s, m, "DTMF successfully queued");
00155 
00156    return 0;
00157 }
00158 
00159 static int unload_module(void)
00160 {
00161    int res;
00162 
00163    res = ast_unregister_application(app);
00164    res |= ast_manager_unregister("PlayDTMF");
00165 
00166    return res; 
00167 }
00168 
00169 static int load_module(void)
00170 {
00171    int res;
00172 
00173    res = ast_manager_register_xml("PlayDTMF", EVENT_FLAG_CALL, manager_play_dtmf);
00174    res |= ast_register_application_xml(app, senddtmf_exec);
00175 
00176    return res;
00177 }
00178 
00179 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send DTMF digits Application");

Generated on Sat Mar 10 01:53:59 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7