Wed Apr 6 11:29:38 2011

Asterisk developer's documentation


app_playtones.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2009, Digium, Inc.
00005  *
00006  * Russell Bryant <russell@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 /*!
00020  * \file
00021  * \brief Playtones application
00022  *
00023  * \author Russell Bryant <russell@digium.com>
00024  *
00025  * \ingroup applications
00026  */
00027 
00028 #include "asterisk.h"
00029 
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 196072 $")
00031 
00032 #include "asterisk/module.h"
00033 #include "asterisk/pbx.h"
00034 #include "asterisk/channel.h"
00035 #include "asterisk/indications.h"
00036 
00037 static const char playtones_app[] = "PlayTones";
00038 static const char stopplaytones_app[] = "StopPlayTones";
00039 
00040 /*** DOCUMENTATION
00041    <application name="PlayTones" language="en_US">
00042       <synopsis>
00043          Play a tone list.
00044       </synopsis>
00045       <syntax>
00046          <parameter name="arg" required="true">
00047             <para>Arg is either the tone name defined in the <filename>indications.conf</filename>
00048             configuration file, or a directly specified list of frequencies and durations.</para>
00049          </parameter>
00050       </syntax>
00051       <description>
00052          <para>Plays a tone list. Execution will continue with the next step in the dialplan
00053          immediately while the tones continue to play.</para>
00054          <para>See the sample <filename>indications.conf</filename> for a description of the
00055          specification of a tonelist.</para>
00056       </description>
00057       <see-also>
00058          <ref type="application">StopPlayTones</ref>
00059       </see-also>
00060    </application>
00061    <application name="StopPlayTones" language="en_US">
00062       <synopsis>
00063          Stop playing a tone list.
00064       </synopsis>
00065       <syntax />
00066       <description>
00067          <para>Stop playing a tone list, initiated by PlayTones().</para>
00068       </description>
00069       <see-also>
00070          <ref type="application">PlayTones</ref>
00071       </see-also>
00072    </application>
00073  ***/
00074 
00075 static int handle_playtones(struct ast_channel *chan, const char *data)
00076 {
00077    struct ast_tone_zone_sound *ts;
00078    int res;
00079    const char *str = data;
00080 
00081    if (ast_strlen_zero(str)) {
00082       ast_log(LOG_NOTICE,"Nothing to play\n");
00083       return -1;
00084    }
00085 
00086    ts = ast_get_indication_tone(chan->zone, str);
00087 
00088    if (ts) {
00089       res = ast_playtones_start(chan, 0, ts->data, 0);
00090       ts = ast_tone_zone_sound_unref(ts);
00091    } else {
00092       res = ast_playtones_start(chan, 0, str, 0);
00093    }
00094 
00095    if (res) {
00096       ast_log(LOG_NOTICE, "Unable to start playtones\n");
00097    }
00098 
00099    return res;
00100 }
00101 
00102 static int handle_stopplaytones(struct ast_channel *chan, const char *data)
00103 {
00104    ast_playtones_stop(chan);
00105 
00106    return 0;
00107 }
00108 
00109 static int unload_module(void)
00110 {
00111    int res;
00112 
00113    res = ast_unregister_application(playtones_app);
00114    res |= ast_unregister_application(stopplaytones_app);
00115 
00116    return res;
00117 }
00118 
00119 static int load_module(void)
00120 {
00121    int res;
00122 
00123    res = ast_register_application_xml(playtones_app, handle_playtones);
00124    res |= ast_register_application_xml(stopplaytones_app, handle_stopplaytones);
00125 
00126    return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
00127 }
00128 
00129 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Playtones Application");

Generated on Wed Apr 6 11:29:38 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7