Debian Codegraph @

main/mixmonitor.c

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