app_playtones.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. * \file
  20. * \brief Playtones application
  21. *
  22. * \author Russell Bryant <russell@digium.com>
  23. *
  24. * \ingroup applications
  25. */
  26. /*** MODULEINFO
  27. <support_level>core</support_level>
  28. ***/
  29. #include "asterisk.h"
  30. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  31. #include "asterisk/module.h"
  32. #include "asterisk/pbx.h"
  33. #include "asterisk/channel.h"
  34. #include "asterisk/indications.h"
  35. static const char playtones_app[] = "PlayTones";
  36. static const char stopplaytones_app[] = "StopPlayTones";
  37. /*** DOCUMENTATION
  38. <application name="PlayTones" language="en_US">
  39. <synopsis>
  40. Play a tone list.
  41. </synopsis>
  42. <syntax>
  43. <parameter name="arg" required="true">
  44. <para>Arg is either the tone name defined in the <filename>indications.conf</filename>
  45. configuration file, or a directly specified list of frequencies and durations.</para>
  46. </parameter>
  47. </syntax>
  48. <description>
  49. <para>Plays a tone list. Execution will continue with the next step in the dialplan
  50. immediately while the tones continue to play.</para>
  51. <para>See the sample <filename>indications.conf</filename> for a description of the
  52. specification of a tonelist.</para>
  53. </description>
  54. <see-also>
  55. <ref type="application">StopPlayTones</ref>
  56. </see-also>
  57. </application>
  58. <application name="StopPlayTones" language="en_US">
  59. <synopsis>
  60. Stop playing a tone list.
  61. </synopsis>
  62. <syntax />
  63. <description>
  64. <para>Stop playing a tone list, initiated by PlayTones().</para>
  65. </description>
  66. <see-also>
  67. <ref type="application">PlayTones</ref>
  68. </see-also>
  69. </application>
  70. ***/
  71. static int handle_playtones(struct ast_channel *chan, const char *data)
  72. {
  73. struct ast_tone_zone_sound *ts;
  74. int res;
  75. const char *str = data;
  76. if (ast_strlen_zero(str)) {
  77. ast_log(LOG_NOTICE,"Nothing to play\n");
  78. return -1;
  79. }
  80. ts = ast_get_indication_tone(ast_channel_zone(chan), str);
  81. if (ts) {
  82. res = ast_playtones_start(chan, 0, ts->data, 0);
  83. ts = ast_tone_zone_sound_unref(ts);
  84. } else {
  85. res = ast_playtones_start(chan, 0, str, 0);
  86. }
  87. if (res) {
  88. ast_log(LOG_NOTICE, "Unable to start playtones\n");
  89. }
  90. return res;
  91. }
  92. static int handle_stopplaytones(struct ast_channel *chan, const char *data)
  93. {
  94. ast_playtones_stop(chan);
  95. return 0;
  96. }
  97. static int unload_module(void)
  98. {
  99. int res;
  100. res = ast_unregister_application(playtones_app);
  101. res |= ast_unregister_application(stopplaytones_app);
  102. return res;
  103. }
  104. static int load_module(void)
  105. {
  106. int res;
  107. res = ast_register_application_xml(playtones_app, handle_playtones);
  108. res |= ast_register_application_xml(stopplaytones_app, handle_stopplaytones);
  109. return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
  110. }
  111. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Playtones Application");