From bf79f622861c420ae1124e031d470f2762dea24c Mon Sep 17 00:00:00 2001 From: markster Date: Thu, 9 Dec 2004 19:55:01 +0000 Subject: [PATCH] Make music on hold truly optional (bug #2998) git-svn-id: http://svn.digium.com/svn/asterisk/trunk@4411 f38db490-d61c-443f-a65b-d21fe96a405b --- channel.c | 38 ++++++++++++++++++++++++++++++++++ include/asterisk/musiconhold.h | 4 ++++ res/res_musiconhold.c | 5 +++-- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/channel.c b/channel.c index 39645652f..dca52974a 100755 --- a/channel.c +++ b/channel.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -2959,3 +2960,40 @@ unsigned int ast_get_group(char *s) } return group; } + + +static int (*ast_moh_start_ptr)(struct ast_channel *, char *) = NULL; +static void (*ast_moh_stop_ptr)(struct ast_channel *) = NULL; + + +void ast_install_music_functions(int (*start_ptr)(struct ast_channel *, char *), + void (*stop_ptr)(struct ast_channel *)) +{ + ast_moh_start_ptr = start_ptr; + ast_moh_stop_ptr = stop_ptr; +} + +void ast_uninstall_music_functions(void) +{ + ast_moh_start_ptr = NULL; + ast_moh_stop_ptr = NULL; +} + +/*! Turn on/off music on hold on a given channel */ + +int ast_moh_start(struct ast_channel *chan, char *mclass) +{ + if(ast_moh_start_ptr) + return ast_moh_start_ptr(chan, mclass); + + if (option_verbose > 2) + ast_verbose(VERBOSE_PREFIX_3 "Music class %s requested but no musiconhold loaded.\n", mclass ? mclass : "default"); + + return 0; +} + +void ast_moh_stop(struct ast_channel *chan) +{ + if(ast_moh_stop_ptr) + ast_moh_stop_ptr(chan); +} diff --git a/include/asterisk/musiconhold.h b/include/asterisk/musiconhold.h index ceef76cdf..39c90bd85 100755 --- a/include/asterisk/musiconhold.h +++ b/include/asterisk/musiconhold.h @@ -24,6 +24,10 @@ extern int ast_moh_start(struct ast_channel *chan, char *mclass); /*! Turn off music on hold on a given channel */ extern void ast_moh_stop(struct ast_channel *chan); +extern void ast_install_music_functions(int (*start_ptr)(struct ast_channel *, char *), + void (*stop_ptr)(struct ast_channel *)); +extern void ast_uninstall_music_functions(void); + #if defined(__cplusplus) || defined(c_plusplus) } #endif diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c index e3808da62..53d25f3da 100755 --- a/res/res_musiconhold.c +++ b/res/res_musiconhold.c @@ -588,7 +588,7 @@ static int moh_register(char *classname, char *mode, char *param, char *miscargs return 0; } -int ast_moh_start(struct ast_channel *chan, char *class) +static int local_ast_moh_start(struct ast_channel *chan, char *class) { if (!class || ast_strlen_zero(class)) class = chan->musicclass; @@ -597,7 +597,7 @@ int ast_moh_start(struct ast_channel *chan, char *class) return ast_activate_generator(chan, &mohgen, class); } -void ast_moh_stop(struct ast_channel *chan) +static void local_ast_moh_stop(struct ast_channel *chan) { ast_deactivate_generator(chan); } @@ -659,6 +659,7 @@ int load_module(void) { int res; load_moh_classes(); + ast_install_music_functions(local_ast_moh_start, local_ast_moh_stop); res = ast_register_application(app0, moh0_exec, synopsis0, descrip0); ast_register_atexit(ast_moh_destroy); if (!res)