Asterisk - The Open Source Telephony Project  21.4.1
mixmonitor.c
Go to the documentation of this file.
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 
19 /*! \file
20  *
21  * \brief loadable MixMonitor functionality
22  *
23  * \author Jonathan Rose <jrose@digium.com>
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 
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 
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 }
Main Channel structure associated with a channel.
int ast_start_mixmonitor(struct ast_channel *chan, const char *filename, const char *options)
Start a mixmonitor on a channel with the given parameters.
Definition: mixmonitor.c:74
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
#define SCOPED_WRLOCK(varname, lock)
scoped lock specialization for write locks
Definition: lock.h:599
Utility functions.
#define SCOPED_RDLOCK(varname, lock)
scoped lock specialization for read locks
Definition: lock.h:594
MixMonitor virtual methods table definition.
Definition: mixmonitor.h:58
ast_mutex_t lock
General Asterisk PBX channel definitions.
int ast_stop_mixmonitor(struct ast_channel *chan, const char *mixmon_id)
Stop a mixmonitor on a channel with the given parameters.
Definition: mixmonitor.c:86
Support for logging to various files, console and syslog Configuration in file logger.conf.
int ast_clear_mixmonitor_methods(void)
Clear the MixMonitor virtual methods table. Use this to cleanup function pointers provided by a modul...
Definition: mixmonitor.c:59
loadable MixMonitor functionality
int ast_set_mixmonitor_methods(struct ast_mixmonitor_methods *method_table)
Setup MixMonitor virtual methods table. Use this to provide the MixMonitor functionality from a loada...
Definition: mixmonitor.c:43