Merged revisions 280161 via svnmerge from
[asterisk/asterisk.git] / apps / app_playtones.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2009, Digium, Inc.
5  *
6  * Russell Bryant <russell@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18
19 /*!
20  * \file
21  * \brief Playtones application
22  *
23  * \author Russell Bryant <russell@digium.com>
24  *
25  * \ingroup applications
26  */
27
28 #include "asterisk.h"
29
30 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
31
32 #include "asterisk/module.h"
33 #include "asterisk/pbx.h"
34 #include "asterisk/channel.h"
35 #include "asterisk/indications.h"
36
37 static const char playtones_app[] = "PlayTones";
38 static const char stopplaytones_app[] = "StopPlayTones";
39
40 /*** DOCUMENTATION
41         <application name="PlayTones" language="en_US">
42                 <synopsis>
43                         Play a tone list.
44                 </synopsis>
45                 <syntax>
46                         <parameter name="arg" required="true">
47                                 <para>Arg is either the tone name defined in the <filename>indications.conf</filename>
48                                 configuration file, or a directly specified list of frequencies and durations.</para>
49                         </parameter>
50                 </syntax>
51                 <description>
52                         <para>Plays a tone list. Execution will continue with the next step in the dialplan
53                         immediately while the tones continue to play.</para>
54                         <para>See the sample <filename>indications.conf</filename> for a description of the
55                         specification of a tonelist.</para>
56                 </description>
57                 <see-also>
58                         <ref type="application">StopPlayTones</ref>
59                 </see-also>
60         </application>
61         <application name="StopPlayTones" language="en_US">
62                 <synopsis>
63                         Stop playing a tone list.
64                 </synopsis>
65                 <syntax />
66                 <description>
67                         <para>Stop playing a tone list, initiated by PlayTones().</para>
68                 </description>
69                 <see-also>
70                         <ref type="application">PlayTones</ref>
71                 </see-also>
72         </application>
73  ***/
74
75 static int handle_playtones(struct ast_channel *chan, const char *data)
76 {
77         struct ast_tone_zone_sound *ts;
78         int res;
79         const char *str = data;
80
81         if (ast_strlen_zero(str)) {
82                 ast_log(LOG_NOTICE,"Nothing to play\n");
83                 return -1;
84         }
85
86         ts = ast_get_indication_tone(chan->zone, str);
87
88         if (ts) {
89                 res = ast_playtones_start(chan, 0, ts->data, 0);
90                 ts = ast_tone_zone_sound_unref(ts);
91         } else {
92                 res = ast_playtones_start(chan, 0, str, 0);
93         }
94
95         if (res) {
96                 ast_log(LOG_NOTICE, "Unable to start playtones\n");
97         }
98
99         return res;
100 }
101
102 static int handle_stopplaytones(struct ast_channel *chan, const char *data)
103 {
104         ast_playtones_stop(chan);
105
106         return 0;
107 }
108
109 static int unload_module(void)
110 {
111         int res;
112
113         res = ast_unregister_application(playtones_app);
114         res |= ast_unregister_application(stopplaytones_app);
115
116         return res;
117 }
118
119 static int load_module(void)
120 {
121         int res;
122
123         res = ast_register_application_xml(playtones_app, handle_playtones);
124         res |= ast_register_application_xml(stopplaytones_app, handle_stopplaytones);
125
126         return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
127 }
128
129 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Playtones Application");