mixmonitor.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2013, Digium, Inc.
  5. *
  6. * Jonathan Rose <jrose@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. /*! \file
  19. *
  20. * \brief loadable MixMonitor functionality
  21. *
  22. * \author Jonathan Rose <jrose@digium.com>
  23. */
  24. /*** MODULEINFO
  25. <support_level>core</support_level>
  26. ***/
  27. #include "asterisk.h"
  28. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  29. #include "asterisk/lock.h"
  30. #include "asterisk/logger.h"
  31. #include "asterisk/mixmonitor.h"
  32. #include "asterisk/utils.h"
  33. #include "asterisk/channel.h"
  34. AST_RWLOCK_DEFINE_STATIC(mixmonitor_lock);
  35. static struct ast_mixmonitor_methods mixmonitor_methods;
  36. static int table_loaded = 0;
  37. int ast_set_mixmonitor_methods(struct ast_mixmonitor_methods *method_table)
  38. {
  39. SCOPED_WRLOCK(lock, &mixmonitor_lock);
  40. if (table_loaded) {
  41. /* If mixmonitor methods have already been provided, reject the new set */
  42. ast_log(LOG_ERROR, "Tried to set mixmonitor methods, but something else has already provided them.\n");
  43. return -1;
  44. }
  45. mixmonitor_methods = *method_table;
  46. table_loaded = 1;
  47. return 0;
  48. }
  49. int ast_clear_mixmonitor_methods(void)
  50. {
  51. SCOPED_WRLOCK(lock, &mixmonitor_lock);
  52. if (!table_loaded) {
  53. ast_log(LOG_ERROR, "Tried to clear mixmonitor methods, but none are currently loaded.\n");
  54. return -1;
  55. }
  56. memset(&mixmonitor_methods, 0, sizeof(mixmonitor_methods));
  57. table_loaded = 0;
  58. return 0;
  59. }
  60. int ast_start_mixmonitor(struct ast_channel *chan, const char *filename, const char *options)
  61. {
  62. SCOPED_RDLOCK(lock, &mixmonitor_lock);
  63. if (!mixmonitor_methods.start) {
  64. ast_log(LOG_ERROR, "No loaded module currently provides MixMonitor starting functionality.\n");
  65. return -1;
  66. }
  67. return mixmonitor_methods.start(chan, filename, options);
  68. }
  69. int ast_stop_mixmonitor(struct ast_channel *chan, const char *mixmon_id)
  70. {
  71. SCOPED_RDLOCK(lock, &mixmonitor_lock);
  72. if (!mixmonitor_methods.stop) {
  73. ast_log(LOG_ERROR, "No loaded module currently provides MixMonitor stopping functionality.\n");
  74. return -1;
  75. }
  76. return mixmonitor_methods.stop(chan, mixmon_id);
  77. }