Taking a stab at MODEVENT-47

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13856 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Andrew Thompson 2009-06-19 00:51:53 +00:00
parent 0108797fc7
commit b63e09716a
2 changed files with 26 additions and 14 deletions

View File

@ -914,8 +914,9 @@ int handle_msg(listener_t *listener, erlang_msg *msg, ei_x_buff *buf, ei_x_buff
case ERL_REFERENCE_EXT : case ERL_REFERENCE_EXT :
case ERL_NEW_REFERENCE_EXT : case ERL_NEW_REFERENCE_EXT :
ret = handle_ref_tuple(listener, msg, buf, rbuf); ret = handle_ref_tuple(listener, msg, buf, rbuf);
break;
default : default :
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "WEEEEEEEE %d\n", type); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "WEEEEEEEE %d %d\n", type, type2);
/* some other kind of erlang term */ /* some other kind of erlang term */
ei_x_encode_tuple_header(rbuf, 2); ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "error"); ei_x_encode_atom(rbuf, "error");

View File

@ -476,8 +476,10 @@ static switch_status_t notify_new_session(listener_t *listener, session_elem_t *
return SWITCH_STATUS_MEMERR; return SWITCH_STATUS_MEMERR;
} }
if (!(session = switch_core_session_locate(session_element->uuid_str))) if (!(session = switch_core_session_locate(session_element->uuid_str))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Can't locate session %s\n", session_element->uuid_str);
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
}
channel = switch_core_session_get_channel(session); channel = switch_core_session_get_channel(session);
@ -507,10 +509,9 @@ static switch_status_t notify_new_session(listener_t *listener, session_elem_t *
static switch_status_t check_attached_sessions(listener_t *listener) static switch_status_t check_attached_sessions(listener_t *listener)
{ {
session_elem_t *last,*sp; session_elem_t *last,*sp, *removed;
switch_status_t status = SWITCH_STATUS_SUCCESS; switch_status_t status = SWITCH_STATUS_SUCCESS;
void *pop; void *pop;
int removed = 0;
/* check up on all the attached sessions - /* check up on all the attached sessions -
if they have not yet sent an initial call event to the associated erlang process then do so if they have not yet sent an initial call event to the associated erlang process then do so
if they have pending events in their queues then send them if they have pending events in their queues then send them
@ -520,15 +521,17 @@ static switch_status_t check_attached_sessions(listener_t *listener)
sp = listener->session_list; sp = listener->session_list;
last = NULL; last = NULL;
while(sp) { while(sp) {
removed = 0; removed = NULL;
if (switch_test_flag(sp, LFLAG_WAITING_FOR_PID)) { if (switch_test_flag(sp, LFLAG_WAITING_FOR_PID)) {
break; break;
} }
if (!switch_test_flag(sp, LFLAG_OUTBOUND_INIT)) { if (!switch_test_flag(sp, LFLAG_OUTBOUND_INIT)) {
status = notify_new_session(listener, sp); status = notify_new_session(listener, sp);
if (status != SWITCH_STATUS_SUCCESS) if (status != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Notifying new session failed\n");
break; break;
}
switch_set_flag(sp, LFLAG_OUTBOUND_INIT); switch_set_flag(sp, LFLAG_OUTBOUND_INIT);
} }
/* check event queue for this session */ /* check event queue for this session */
@ -562,7 +565,7 @@ static switch_status_t check_attached_sessions(listener_t *listener)
/* this allows the application threads to exit */ /* this allows the application threads to exit */
switch_clear_flag_locked(sp, LFLAG_SESSION_ALIVE); switch_clear_flag_locked(sp, LFLAG_SESSION_ALIVE);
removed = 1; removed = sp;
ei_x_new_with_version(&ebuf); ei_x_new_with_version(&ebuf);
ei_x_encode_atom(&ebuf, "call_hangup"); ei_x_encode_atom(&ebuf, "call_hangup");
@ -578,9 +581,12 @@ static switch_status_t check_attached_sessions(listener_t *listener)
} }
switch_event_destroy(&pevent); switch_event_destroy(&pevent);
} }
if (!removed)
last = sp;
sp = sp->next; sp = sp->next;
if (removed) {
switch_safe_free(removed)
} else {
last = sp;
}
} }
switch_mutex_unlock(listener->session_mutex); switch_mutex_unlock(listener->session_mutex);
return status; return status;
@ -741,6 +747,7 @@ static void listener_main_loop(listener_t *listener)
#endif #endif
if (handle_msg(listener, &msg, &buf, &rbuf)) { if (handle_msg(listener, &msg, &buf, &rbuf)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "handle_msg requested exit\n");
return; return;
} }
break; break;
@ -755,6 +762,7 @@ static void listener_main_loop(listener_t *listener)
#endif #endif
if (handle_msg(listener, &msg, &buf, &rbuf)) { if (handle_msg(listener, &msg, &buf, &rbuf)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "handle_msg requested exit\n");
return; return;
} }
break; break;
@ -789,6 +797,7 @@ static void listener_main_loop(listener_t *listener)
check_log_queue(listener); check_log_queue(listener);
check_event_queue(listener); check_event_queue(listener);
if (check_attached_sessions(listener) != SWITCH_STATUS_SUCCESS) { if (check_attached_sessions(listener) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "check_attached_sessions requested exit\n");
return; return;
} }
} }
@ -1067,18 +1076,20 @@ static switch_status_t state_handler(switch_core_session_t *session)
session_elem_t *session_elem_create(listener_t* listener, switch_core_session_t *session) session_elem_t *session_elem_create(listener_t* listener, switch_core_session_t *session)
{ {
/* create a session list element */ /* create a session list element */
session_elem_t* session_element = switch_core_session_alloc(session, sizeof(*session_element)); session_elem_t* session_element = malloc(sizeof(*session_element));
switch_channel_t *channel = switch_core_session_get_channel(session); /*switch_channel_t *channel = switch_core_session_get_channel(session);*/
bzero(session_element, sizeof(*session_element));
memcpy(session_element->uuid_str, switch_core_session_get_uuid(session), SWITCH_UUID_FORMATTED_LENGTH); memcpy(session_element->uuid_str, switch_core_session_get_uuid(session), SWITCH_UUID_FORMATTED_LENGTH);
switch_queue_create(&session_element->event_queue, SWITCH_CORE_QUEUE_LEN, switch_core_session_get_pool(session)); switch_queue_create(&session_element->event_queue, SWITCH_CORE_QUEUE_LEN, switch_core_session_get_pool(session));
switch_mutex_init(&session_element->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); switch_mutex_init(&session_element->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
switch_channel_set_private(channel, "_erlang_session_", session_element); /*switch_channel_set_private(channel, "_erlang_session_", session_element);*/
switch_channel_set_private(channel, "_erlang_listener_", listener); /*switch_channel_set_private(channel, "_erlang_listener_", listener);*/
switch_core_event_hook_add_state_change(session, state_handler); /*switch_core_event_hook_add_state_change(session, state_handler);*/
return session_element; return session_element;
} }