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

Generated on Thu Apr 16 06:27:11 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6