Wed Jan 8 2020 09:49:40

Asterisk developer's documentation


app_playtones.c
Go to the documentation of this file.
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 /*** MODULEINFO
29  <support_level>core</support_level>
30  ***/
31 
32 #include "asterisk.h"
33 
34 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
35 
36 #include "asterisk/module.h"
37 #include "asterisk/pbx.h"
38 #include "asterisk/channel.h"
39 #include "asterisk/indications.h"
40 
41 static const char playtones_app[] = "PlayTones";
42 static const char stopplaytones_app[] = "StopPlayTones";
43 
44 /*** DOCUMENTATION
45  <application name="PlayTones" language="en_US">
46  <synopsis>
47  Play a tone list.
48  </synopsis>
49  <syntax>
50  <parameter name="arg" required="true">
51  <para>Arg is either the tone name defined in the <filename>indications.conf</filename>
52  configuration file, or a directly specified list of frequencies and durations.</para>
53  </parameter>
54  </syntax>
55  <description>
56  <para>Plays a tone list. Execution will continue with the next step in the dialplan
57  immediately while the tones continue to play.</para>
58  <para>See the sample <filename>indications.conf</filename> for a description of the
59  specification of a tonelist.</para>
60  </description>
61  <see-also>
62  <ref type="application">StopPlayTones</ref>
63  </see-also>
64  </application>
65  <application name="StopPlayTones" language="en_US">
66  <synopsis>
67  Stop playing a tone list.
68  </synopsis>
69  <syntax />
70  <description>
71  <para>Stop playing a tone list, initiated by PlayTones().</para>
72  </description>
73  <see-also>
74  <ref type="application">PlayTones</ref>
75  </see-also>
76  </application>
77  ***/
78 
79 static int handle_playtones(struct ast_channel *chan, const char *data)
80 {
81  struct ast_tone_zone_sound *ts;
82  int res;
83  const char *str = data;
84 
85  if (ast_strlen_zero(str)) {
86  ast_log(LOG_NOTICE,"Nothing to play\n");
87  return -1;
88  }
89 
90  ts = ast_get_indication_tone(chan->zone, str);
91 
92  if (ts) {
93  res = ast_playtones_start(chan, 0, ts->data, 0);
95  } else {
96  res = ast_playtones_start(chan, 0, str, 0);
97  }
98 
99  if (res) {
100  ast_log(LOG_NOTICE, "Unable to start playtones\n");
101  }
102 
103  return res;
104 }
105 
106 static int handle_stopplaytones(struct ast_channel *chan, const char *data)
107 {
108  ast_playtones_stop(chan);
109 
110  return 0;
111 }
112 
113 static int unload_module(void)
114 {
115  int res;
116 
117  res = ast_unregister_application(playtones_app);
118  res |= ast_unregister_application(stopplaytones_app);
119 
120  return res;
121 }
122 
123 static int load_module(void)
124 {
125  int res;
126 
127  res = ast_register_application_xml(playtones_app, handle_playtones);
128  res |= ast_register_application_xml(stopplaytones_app, handle_stopplaytones);
129 
131 }
132 
133 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Playtones Application");
Tone Indication Support.
Main Channel structure associated with a channel.
Definition: channel.h:742
static const char stopplaytones_app[]
Definition: app_playtones.c:42
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
Asterisk main include file. File version handling, generic pbx functions.
struct ast_tone_zone * zone
Definition: channel.h:767
const char * str
Definition: app_jack.c:144
void ast_playtones_stop(struct ast_channel *chan)
Stop playing tones on a channel.
Definition: indications.c:411
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
static int handle_playtones(struct ast_channel *chan, const char *data)
Definition: app_playtones.c:79
static int load_module(void)
General Asterisk PBX channel definitions.
static const char playtones_app[]
Definition: app_playtones.c:41
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
static struct ast_tone_zone_sound * ast_tone_zone_sound_unref(struct ast_tone_zone_sound *ts)
Release a reference to an ast_tone_zone_sound.
Definition: indications.h:226
Core PBX routines and definitions.
Description of a tone.
Definition: indications.h:36
struct ast_tone_zone_sound * ast_get_indication_tone(const struct ast_tone_zone *zone, const char *indication)
Locate a tone zone sound.
Definition: indications.c:473
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
int ast_playtones_start(struct ast_channel *chan, int vol, const char *tonelist, int interruptible)
Start playing a list of tones on a channel.
Definition: indications.c:319
const char * data
Description of a tone.
Definition: indications.h:53
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
static int unload_module(void)
static int handle_stopplaytones(struct ast_channel *chan, const char *data)
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180