From f1ee225cb1cad4088680c061b0a0b13073cf4f60 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 8 Jul 2011 12:52:12 -0500 Subject: [PATCH] push out signal data into its own queue system --- src/include/private/switch_core_pvt.h | 1 + src/include/switch_core.h | 4 +++ src/include/switch_ivr.h | 2 +- src/mod/endpoints/mod_sofia/mod_sofia.h | 2 +- src/mod/endpoints/mod_sofia/sofia.c | 18 ++++++------ src/switch_channel.c | 6 ++-- src/switch_core_session.c | 37 +++++++++++++++++++++++++ src/switch_ivr.c | 25 +++++++++++++++++ 8 files changed, 80 insertions(+), 15 deletions(-) diff --git a/src/include/private/switch_core_pvt.h b/src/include/private/switch_core_pvt.h index 8c1ac3707c..3b530b3940 100644 --- a/src/include/private/switch_core_pvt.h +++ b/src/include/private/switch_core_pvt.h @@ -145,6 +145,7 @@ struct switch_core_session { void *private_info; switch_queue_t *event_queue; switch_queue_t *message_queue; + switch_queue_t *signal_data_queue; switch_queue_t *private_event_queue; switch_queue_t *private_event_queue_pri; switch_thread_rwlock_t *bug_rwlock; diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 9e16346199..61d89bfcd0 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -835,6 +835,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_queue_message(_In_ switch_co SWITCH_DECLARE(void) switch_core_session_free_message(switch_core_session_message_t **message); + +SWITCH_DECLARE(switch_status_t) switch_core_session_queue_signal_data(switch_core_session_t *session, void *signal_data); +SWITCH_DECLARE(switch_status_t) switch_core_session_dequeue_signal_data(switch_core_session_t *session, void **signal_data); + /*! \brief pass an indication message on a session \param session the session to pass the message across diff --git a/src/include/switch_ivr.h b/src/include/switch_ivr.h index 288751d850..37940daf90 100644 --- a/src/include/switch_ivr.h +++ b/src/include/switch_ivr.h @@ -110,7 +110,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_parse_event(_In_ switch_core_session_ SWITCH_DECLARE(switch_status_t) switch_ivr_parse_all_events(switch_core_session_t *session); SWITCH_DECLARE(switch_status_t) switch_ivr_parse_next_event(switch_core_session_t *session); SWITCH_DECLARE(switch_status_t) switch_ivr_parse_all_messages(switch_core_session_t *session); - +SWITCH_DECLARE(switch_status_t) switch_ivr_parse_all_signal_data(switch_core_session_t *session); /*! \brief Wait for time to pass for a specified number of milliseconds \param session the session to wait for. diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index e31b54f192..9b1adcf2e5 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -316,7 +316,7 @@ typedef enum { TFLAG_MAX } TFLAGS; -#define SOFIA_MAX_MSG_QUEUE 25 +#define SOFIA_MAX_MSG_QUEUE 250 #define SOFIA_MSG_QUEUE_SIZE 50 struct mod_sofia_globals { diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 0661c2e4c6..41cd10872b 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -1226,6 +1226,7 @@ void sofia_event_callback(nua_event_t event, memset(de, 0, sizeof(*de)); nua_save_event(nua, de->event); de->nh = nua_handle_ref(nh); + de->nh = nh; de->data = nua_event_data(de->event); de->sip = sip_object(de->data->e_msg); de->profile = profile; @@ -1244,21 +1245,20 @@ void sofia_event_callback(nua_event_t event, } if (sofia_private && sofia_private != &mod_sofia_globals.destroy_private && sofia_private != &mod_sofia_globals.keep_private) { - switch_core_session_message_t *msg; switch_core_session_t *session; if (!zstr(sofia_private->uuid)) { if ((session = switch_core_session_locate(sofia_private->uuid))) { - msg = switch_core_session_alloc(session, sizeof(*msg)); - msg->message_id = SWITCH_MESSAGE_INDICATE_SIGNAL_DATA; - msg->from = __FILE__; - msg->numeric_arg = status; - msg->pointer_arg = de; if (switch_core_session_running(session)) { - switch_core_session_queue_message(session, msg); + switch_core_session_queue_signal_data(session, de); } else { - switch_core_session_receive_message(session, msg); + switch_core_session_message_t msg = { 0 }; + msg.message_id = SWITCH_MESSAGE_INDICATE_SIGNAL_DATA; + msg.from = __FILE__; + msg.pointer_arg = de; + + switch_core_session_receive_message(session, &msg); } switch_core_session_rwunlock(session); return; @@ -1266,6 +1266,7 @@ void sofia_event_callback(nua_event_t event, } } + sofia_queue_message(de); } @@ -5017,7 +5018,6 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, NUTAG_ANSWER_SENT_REF(answer_sent), SIPTAG_REPLACES_STR_REF(replaces_str), SOATAG_LOCAL_SDP_STR_REF(l_sdp), SOATAG_REMOTE_SDP_STR_REF(r_sdp), TAG_END()); - if (session) { channel = switch_core_session_get_channel(session); tech_pvt = switch_core_session_get_private(session); diff --git a/src/switch_channel.c b/src/switch_channel.c index d8abf7706e..68d07a9548 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -1728,10 +1728,8 @@ SWITCH_DECLARE(int) switch_channel_test_ready(switch_channel_t *channel, switch_ ret++; } - if (ret) { - if (!switch_channel_test_flag(channel, CF_LEG_HOLDING) && switch_core_session_in_thread(channel->session)) { - switch_ivr_parse_all_events(channel->session); - } + if (ret && switch_core_session_in_thread(channel->session)) { + switch_ivr_parse_all_signal_data(channel->session); } return ret; diff --git a/src/switch_core_session.c b/src/switch_core_session.c index 5e344026d6..038dda1b83 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -841,6 +841,42 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_flush_message(switch_core_se return SWITCH_STATUS_SUCCESS; } +SWITCH_DECLARE(switch_status_t) switch_core_session_queue_signal_data(switch_core_session_t *session, void *signal_data) +{ + switch_status_t status = SWITCH_STATUS_FALSE; + + switch_assert(session != NULL); + + if (session->signal_data_queue) { + if (switch_queue_trypush(session->signal_data_queue, signal_data) == SWITCH_STATUS_SUCCESS) { + status = SWITCH_STATUS_SUCCESS; + } + + switch_core_session_kill_channel(session, SWITCH_SIG_BREAK); + + if (switch_channel_test_flag(session->channel, CF_PROXY_MODE) || switch_channel_test_flag(session->channel, CF_THREAD_SLEEPING)) { + switch_core_session_wake_session_thread(session); + } + } + + return status; +} + +SWITCH_DECLARE(switch_status_t) switch_core_session_dequeue_signal_data(switch_core_session_t *session, void **signal_data) +{ + switch_status_t status = SWITCH_STATUS_FALSE; + void *pop; + + switch_assert(session != NULL); + + if (session->signal_data_queue && switch_queue_size(session->signal_data_queue)) { + if ((status = (switch_status_t) switch_queue_trypop(session->signal_data_queue, &pop)) == SWITCH_STATUS_SUCCESS) { + *signal_data = pop; + } + } + + return status; +} SWITCH_DECLARE(switch_status_t) switch_core_session_receive_event(switch_core_session_t *session, switch_event_t **event) { @@ -1713,6 +1749,7 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_uuid(switch_ switch_thread_rwlock_create(&session->rwlock, session->pool); switch_thread_rwlock_create(&session->io_rwlock, session->pool); switch_queue_create(&session->message_queue, SWITCH_MESSAGE_QUEUE_LEN, session->pool); + switch_queue_create(&session->signal_data_queue, SWITCH_MESSAGE_QUEUE_LEN, session->pool); switch_queue_create(&session->event_queue, SWITCH_EVENT_QUEUE_LEN, session->pool); switch_queue_create(&session->private_event_queue, SWITCH_EVENT_QUEUE_LEN, session->pool); switch_queue_create(&session->private_event_queue_pri, SWITCH_EVENT_QUEUE_LEN, session->pool); diff --git a/src/switch_ivr.c b/src/switch_ivr.c index e292b2c4b4..967e86626e 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -674,6 +674,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_parse_all_messages(switch_core_sessio switch_channel_t *channel = switch_core_session_get_channel(session); int i = 0; + switch_ivr_parse_all_signal_data(session); + while (switch_core_session_dequeue_message(session, &message) == SWITCH_STATUS_SUCCESS) { i++; @@ -708,6 +710,29 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_parse_all_messages(switch_core_sessio return i ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE; } + +SWITCH_DECLARE(switch_status_t) switch_ivr_parse_all_signal_data(switch_core_session_t *session) +{ + void *data; + switch_core_session_message_t msg = { 0 }; + int i = 0; + + msg.message_id = SWITCH_MESSAGE_INDICATE_SIGNAL_DATA; + msg.from = __FILE__; + + while (switch_core_session_dequeue_signal_data(session, &data) == SWITCH_STATUS_SUCCESS) { + i++; + + msg.pointer_arg = data; + switch_core_session_receive_message(session, &msg); + + data = NULL; + + } + + return i ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE; +} + SWITCH_DECLARE(switch_status_t) switch_ivr_parse_all_events(switch_core_session_t *session) { int x = 0;