From f6eab64c5c8eb76484f0502eb99c4dbefbbda7ef Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 27 Dec 2010 17:20:33 -0600 Subject: [PATCH] add uuid_buglist to fetch the current media-bugs attached to a given session uuid --- src/include/switch_core.h | 2 + .../applications/mod_commands/mod_commands.c | 47 ++++++++++++++++++- src/switch_core_media_bug.c | 26 ++++++++++ 3 files changed, 73 insertions(+), 2 deletions(-) diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 840a06c204..bcd3c0aee2 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -246,6 +246,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_close(_Inout_ switch_media */ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(_In_ switch_core_session_t *session); +SWITCH_DECLARE(switch_status_t) switch_core_media_bug_enumerate(switch_core_session_t *session, switch_stream_handle_t *stream); + /*! \brief Read a frame from the bug \param bug the bug to read from diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 2deb437948..1c2e3ebfb9 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -2488,6 +2488,48 @@ SWITCH_STANDARD_API(uuid_display_function) return SWITCH_STATUS_SUCCESS; } +#define BUGLIST_SYNTAX "" +SWITCH_STANDARD_API(uuid_buglist_function) +{ + char *mydata = NULL, *argv[2] = { 0 }; + int argc = 0; + + switch_status_t status = SWITCH_STATUS_FALSE; + + if (zstr(cmd)) { + goto error; + } + + mydata = strdup(cmd); + switch_assert(mydata); + + argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); + + if (argc < 1) { + goto error; + } + if (argv[0]) { + switch_core_session_t *lsession = NULL; + + if ((lsession = switch_core_session_locate(argv[0]))) { + status = switch_core_media_bug_enumerate(lsession, stream); + switch_core_session_rwunlock(lsession); + } + goto ok; + } else { + goto error; + } + + error: + stream->write_function(stream, "-USAGE: %s\n", BUGLIST_SYNTAX); + switch_safe_free(mydata); + return SWITCH_STATUS_SUCCESS; + ok: + switch_safe_free(mydata); + + return SWITCH_STATUS_SUCCESS; +} + #define SIMPLIFY_SYNTAX "" SWITCH_STANDARD_API(uuid_simplify_function) { @@ -2541,7 +2583,6 @@ SWITCH_STANDARD_API(uuid_simplify_function) return SWITCH_STATUS_SUCCESS; } - #define JITTERBUFFER_SYNTAX " [0|[:]]" SWITCH_STANDARD_API(uuid_jitterbuffer_function) { @@ -4797,6 +4838,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load) SWITCH_ADD_API(commands_api_interface, "uuid_break", "Break", break_function, BREAK_SYNTAX); SWITCH_ADD_API(commands_api_interface, "uuid_bridge", "uuid_bridge", uuid_bridge_function, ""); SWITCH_ADD_API(commands_api_interface, "uuid_broadcast", "broadcast", uuid_broadcast_function, BROADCAST_SYNTAX); + SWITCH_ADD_API(commands_api_interface, "uuid_buglist", "List media bugs on a session", uuid_buglist_function, BUGLIST_SYNTAX); SWITCH_ADD_API(commands_api_interface, "uuid_chat", "Send a chat message", uuid_chat, UUID_CHAT_SYNTAX); SWITCH_ADD_API(commands_api_interface, "uuid_debug_audio", "debug audio", uuid_debug_audio_function, DEBUG_AUDIO_SYNTAX); SWITCH_ADD_API(commands_api_interface, "uuid_deflect", "Send a deflect", uuid_deflect, UUID_DEFLECT_SYNTAX); @@ -4911,6 +4953,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load) switch_console_set_complete("add uuid_break ::console::list_uuid both"); switch_console_set_complete("add uuid_bridge ::console::list_uuid ::console::list_uuid"); switch_console_set_complete("add uuid_broadcast ::console::list_uuid"); + switch_console_set_complete("add uuid_buglist ::console::list_uuid"); switch_console_set_complete("add uuid_chat ::console::list_uuid"); switch_console_set_complete("add uuid_debug_audio ::console::list_uuid"); switch_console_set_complete("add uuid_deflect ::console::list_uuid"); @@ -4939,7 +4982,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load) switch_console_set_complete("add uuid_phone_event ::console::list_uuid talk"); switch_console_set_complete("add uuid_phone_event ::console::list_uuid hold"); switch_console_set_complete("add uuid_preprocess ::console::list_uuid"); - switch_console_set_complete("add uuid_record ::console::list_uuid"); + switch_console_set_complete("add uuid_record ::console::list_uuid ::[start:stop"); switch_console_set_complete("add uuid_recv_dtmf ::console::list_uuid"); switch_console_set_complete("add uuid_send_dtmf ::console::list_uuid"); switch_console_set_complete("add uuid_session_heartbeat ::console::list_uuid"); diff --git a/src/switch_core_media_bug.c b/src/switch_core_media_bug.c index 7170969be2..21db3a9aff 100644 --- a/src/switch_core_media_bug.c +++ b/src/switch_core_media_bug.c @@ -392,6 +392,32 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_flush_all(switch_core_sess return SWITCH_STATUS_FALSE; } +SWITCH_DECLARE(switch_status_t) switch_core_media_bug_enumerate(switch_core_session_t *session, switch_stream_handle_t *stream) +{ + switch_media_bug_t *bp; + + stream->write_function(stream, "\n"); + + if (session->bugs) { + switch_thread_rwlock_wrlock(session->bug_rwlock); + for (bp = session->bugs; bp; bp = bp->next) { + int thread_locked = (bp->thread_id && bp->thread_id == switch_thread_self()); + stream->write_function(stream, + " \n" + " %s\n" + " %s\n" + " %d\n" + " \n", + bp->function, bp->target, thread_locked); + + } + switch_thread_rwlock_unlock(session->bug_rwlock); + } + + stream->write_function(stream, "\n"); + + return SWITCH_STATUS_SUCCESS; +} SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(switch_core_session_t *session) {