#define switch_channel_ready(_channel) switch_channel_test_ready(_channel, SWITCH_FALSE)
#define switch_channel_media_ready(_channel) switch_channel_test_ready(_channel, SWITCH_TRUE)
-
+#define switch_channel_up(_channel) (switch_channel_get_state(_channel) < CS_HANGUP)
+#define switch_channel_down(_channel) (switch_channel_get_state(_channel) >= CS_HANGUP)
SWITCH_DECLARE(void) switch_channel_wait_for_state(switch_channel_t *channel, switch_channel_t *other_channel, switch_channel_state_t want_state);
SWITCH_DECLARE(switch_status_t) switch_channel_wait_for_flag(switch_channel_t *channel,
switch_channel_clear_flag(peer_channel, CF_INNER_BRIDGE);
switch_channel_clear_flag(channel, CF_INNER_BRIDGE);
- if (!switch_channel_get_state(peer_channel) >= CS_HANGUP) {
+ if (!switch_channel_down(peer_channel)) {
switch_core_session_rwunlock(peer_session);
goto end;
}
now = switch_micro_time_now();
elapsed = (unsigned int) ((now - started) / 1000);
- if (switch_channel_get_state(channel) >= CS_HANGUP || switch_test_flag(tech_pvt, TFLAG_BYE)) {
+ if (switch_channel_down(channel) || switch_test_flag(tech_pvt, TFLAG_BYE)) {
goto out;
}
switch_cond_next();
}
- if (switch_channel_get_state(channel) >= CS_HANGUP || switch_test_flag(tech_pvt, TFLAG_BYE)) {
+ if (switch_channel_down(channel) || switch_test_flag(tech_pvt, TFLAG_BYE)) {
goto out;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "using Existing session for %s\n", ldl_session_get_id(dlsession));
- if (switch_channel_get_state(channel) >= CS_HANGUP) {
+ if (switch_channel_down(channel)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Call %s is already over\n", switch_channel_get_name(channel));
status = LDL_STATUS_FALSE;
goto done;
break;
case IAX_EVENT_VOICE:
if (tech_pvt && (tech_pvt->read_frame.datalen = iaxevent->datalen) != 0) {
- if (channel && switch_channel_get_state(channel) <= CS_HANGUP) {
+ if (channel && switch_channel_up(channel)) {
int bytes = 0, frames = 1;
if (!switch_test_flag(tech_pvt, TFLAG_CODEC) || !tech_pvt->read_codec.implementation) {
private_object_t *tech_pvt = switch_core_session_get_private(session);
switch_status_t status = SWITCH_STATUS_SUCCESS;
- if (switch_channel_get_state(channel) >= CS_HANGUP || !tech_pvt) {
+ if (switch_channel_down(channel) || !tech_pvt) {
status = SWITCH_STATUS_FALSE;
goto end;
}
/* ones that do need to lock sofia mutex */
switch_mutex_lock(tech_pvt->sofia_mutex);
- if (switch_channel_get_state(channel) >= CS_HANGUP || !tech_pvt) {
+ if (switch_channel_down(channel) || !tech_pvt) {
status = SWITCH_STATUS_FALSE;
goto end_lock;
}
}
if (session) {
- if (channel && switch_channel_get_state(channel) >= CS_HANGUP) {
+ if (channel && switch_channel_down(channel)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel is already hungup.\n");
goto done;
}
status = switch_ivr_originate(a_session, &tsession, &cause, nhelper->exten, timeout, NULL, NULL, NULL, NULL, NULL, SOF_NONE);
- if ((switch_channel_get_state(channel_a) < CS_HANGUP)) {
+ if ((switch_channel_up(channel_a))) {
if (status != SWITCH_STATUS_SUCCESS || cause != SWITCH_CAUSE_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel! [%s]\n", nhelper->exten);
switch_ivr_park(session, NULL);
/* keep app thread running for lifetime of session */
- if (switch_channel_get_state(switch_core_session_get_channel(session)) >= CS_HANGUP) {
+ if (switch_channel_down(switch_core_session_get_channel(session))) {
while (switch_test_flag(session_element, LFLAG_SESSION_ALIVE)) {
switch_yield(100000);
}
listener_run(NULL, (void *) listener);
}
- if (switch_channel_get_state(channel) >= CS_HANGUP) {
+ if (switch_channel_down(channel)) {
while (switch_test_flag(listener, LFLAG_SESSION)) {
switch_yield(100000);
}
}
}
- if (channel && switch_channel_get_state(channel) >= CS_HANGUP && !switch_test_flag(listener, LFLAG_HANDLE_DISCO)) {
+ if (channel && switch_channel_down(channel) && !switch_test_flag(listener, LFLAG_HANDLE_DISCO)) {
switch_set_flag_locked(listener, LFLAG_HANDLE_DISCO);
if (switch_test_flag(listener, LFLAG_LINGER)) {
char message[128] = "";
saveDepth = JS_SuspendRequest(cx);
for (;;) {
if (((elapsed = (unsigned int) ((switch_micro_time_now() - started) / 1000)) > (switch_time_t) timeout)
- || switch_channel_get_state(channel) >= CS_HANGUP) {
+ || switch_channel_down(channel)) {
*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
break;
}
saveDepth = JS_SuspendRequest(cx);
for (;;) {
if (((elapsed = (unsigned int) ((switch_micro_time_now() - started) / 1000)) > (switch_time_t) timeout)
- || switch_channel_get_state(channel) >= CS_HANGUP) {
+ || switch_channel_down(channel)) {
*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
break;
}
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_NOTICE, "Hangup %s [%s] [%s]\n",
channel->name, state_names[last_state], switch_channel_cause2str(channel->hangup_cause));
- switch_core_media_bug_remove_all(channel->session);
switch_channel_set_variable(channel, "hangup_cause", switch_channel_cause2str(channel->hangup_cause));
switch_channel_presence(channel, "unavailable", switch_channel_cause2str(channel->hangup_cause), NULL);
switch_io_event_hook_video_write_frame_t *ptr;
switch_status_t status = SWITCH_STATUS_FALSE;
- if (switch_channel_get_state(session->channel) >= CS_HANGUP) {
+ if (switch_channel_down(session->channel)) {
return SWITCH_STATUS_FALSE;
}
switch_assert(session != NULL);
- if (switch_channel_get_state(session->channel) >= CS_HANGUP) {
+ if (switch_channel_down(session->channel)) {
return SWITCH_STATUS_FALSE;
}
top:
- if (switch_channel_get_state(session->channel) >= CS_HANGUP) {
+ if (switch_channel_down(session->channel)) {
*frame = NULL;
status = SWITCH_STATUS_FALSE; goto even_more_done;
}
switch_status_t status;
switch_dtmf_t new_dtmf;
- if (switch_channel_get_state(session->channel) >= CS_HANGUP) {
+ if (switch_channel_down(session->channel)) {
return SWITCH_STATUS_FALSE;
}
switch_status_t status = SWITCH_STATUS_FALSE;
switch_dtmf_t new_dtmf;
- if (switch_channel_get_state(session->channel) >= CS_HANGUP) {
+ if (switch_channel_down(session->channel)) {
return SWITCH_STATUS_FALSE;
}
switch_assert(session != NULL);
- if (switch_channel_get_state(session->channel) >= CS_HANGUP) {
+ if (switch_channel_down(session->channel)) {
return SWITCH_STATUS_FALSE;
}
switch_status_t status = SWITCH_STATUS_FALSE;
if (session->rwlock) {
- if (switch_test_flag(session, SSF_DESTROYED) || switch_channel_get_state(session->channel) >= CS_HANGUP) {
+ if (switch_test_flag(session, SSF_DESTROYED) || switch_channel_down(session->channel)) {
status = SWITCH_STATUS_FALSE;
#ifdef SWITCH_DEBUG_RWLOCKS
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "%s Read lock FAIL\n",
const char *this_val;
session = (switch_core_session_t *) val;
if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
- if (switch_channel_get_state(session->channel) < CS_HANGUP &&
+ if (switch_channel_up(session->channel) &&
(this_val = switch_channel_get_variable(session->channel, var_name)) && (!strcmp(this_val, var_val))) {
switch_channel_hangup(session->channel, cause);
}
if ((session = switch_core_hash_find(session_manager.session_table, uuid_str)) != 0) {
/* Acquire a read lock on the session or forget it the channel is dead */
if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
- if (switch_channel_get_state(session->channel) < CS_HANGUP) {
+ if (switch_channel_up(session->channel)) {
status = switch_core_session_receive_message(session, message);
}
switch_core_session_rwunlock(session);
if ((session = switch_core_hash_find(session_manager.session_table, uuid_str)) != 0) {
/* Acquire a read lock on the session or forget it the channel is dead */
if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
- if (switch_channel_get_state(session->channel) < CS_HANGUP) {
+ if (switch_channel_up(session->channel)) {
status = switch_core_session_queue_event(session, event);
}
switch_core_session_rwunlock(session);
switch_assert(session != NULL);
- if (switch_channel_get_state(session->channel) >= CS_HANGUP) {
+ if (switch_channel_down(session->channel)) {
return SWITCH_STATUS_FALSE;
}
/* Acquire a read lock on the session or forget it the channel is dead */
if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
- if (switch_channel_get_state(session->channel) < CS_HANGUP) {
+ if (switch_channel_up(session->channel)) {
if (session->endpoint_interface->io_routines->receive_event) {
status = session->endpoint_interface->io_routines->receive_event(session, *event);
}
{
switch_application_interface_t *application_interface;
- if (switch_channel_get_state(session->channel) >= CS_HANGUP) {
+ if (switch_channel_down(session->channel)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel is hungup, aborting execution of application: %s\n", app);
return SWITCH_STATUS_FALSE;
}
break;
case CS_DONE:
goto done;
- /* HANGUP INIT ROUTING and RESET are all short term so we signal lock during their callbacks */
case CS_HANGUP: /* Deactivate and end the thread */
{
const char *var = switch_channel_get_variable(session->channel, SWITCH_PROCESS_CDR_VARIABLE);
do_extra_handlers = 0;
}
}
+
+ switch_core_media_bug_remove_all(session);
STATE_MACRO(hangup, "HANGUP");
-
- switch_core_media_bug_remove_all(session);
hook_var = switch_channel_get_variable(session->channel, SWITCH_API_HANGUP_HOOK_VARIABLE);
if (switch_true(switch_channel_get_variable(session->channel, SWITCH_SESSION_IN_HANGUP_HOOK_VARIABLE))) {
sth->ready = 1;
- while (switch_channel_ready(channel) && !switch_test_flag(sth->ah, SWITCH_ASR_FLAG_CLOSED)) {
+ while (switch_channel_up(channel) && !switch_test_flag(sth->ah, SWITCH_ASR_FLAG_CLOSED)) {
char *xmlstr = NULL;
switch_thread_cond_wait(sth->cond, sth->mutex);
- if (switch_test_flag(sth->ah, SWITCH_ASR_FLAG_CLOSED))
+ if (switch_channel_down(channel) || switch_test_flag(sth->ah, SWITCH_ASR_FLAG_CLOSED)) {
break;
+ }
if (switch_core_asr_check_results(sth->ah, &flags) == SWITCH_STATUS_SUCCESS) {
switch_event_t *event;
goto end_of_bridge_loop;
}
- if ((b_state = switch_channel_get_state(chan_b)) >= CS_HANGUP) {
+ if ((b_state = switch_channel_down(chan_b))) {
goto end_of_bridge_loop;
}
}
- if (switch_channel_get_state(chan_b) >= CS_HANGUP) {
+ if (switch_channel_down(chan_b)) {
if (originator && switch_channel_ready(chan_a) && !switch_channel_test_flag(chan_a, CF_ANSWERED)) {
switch_channel_hangup(chan_a, switch_channel_get_cause(chan_b));
}
msg.from = __FILE__;
switch_core_session_receive_message(session_a, &msg);
- if (!inner_bridge && switch_channel_get_state(chan_a) < CS_HANGUP) {
+ if (!inner_bridge && switch_channel_up(chan_a)) {
if ((app_name = switch_channel_get_variable(chan_a, SWITCH_EXEC_AFTER_BRIDGE_APP_VARIABLE))) {
switch_caller_extension_t *extension = NULL;
if ((extension = switch_caller_extension_new(session_a, app_name, app_name)) == 0) {
switch_channel_set_variable(channel, SWITCH_BRIDGE_VARIABLE, NULL);
switch_channel_set_variable(other_channel, SWITCH_BRIDGE_VARIABLE, NULL);
- if (switch_channel_get_state(other_channel) < CS_HANGUP) {
+ if (switch_channel_up(other_channel)) {
switch_channel_hangup(other_channel, switch_channel_get_cause(channel));
}
}
switch_channel_t *peer_channel = switch_core_session_get_channel(peer_session);
switch_event_t *event;
- if (switch_channel_get_state(peer_channel) >= CS_HANGUP) {
+ if (switch_channel_down(peer_channel)) {
switch_channel_hangup(caller_channel, switch_channel_get_cause(peer_channel));
return SWITCH_STATUS_FALSE;
}
originator_channel = switch_core_session_get_channel(originator_session);
originatee_channel = switch_core_session_get_channel(originatee_session);
- if (switch_channel_get_state(originator_channel) >= CS_HANGUP) {
+ if (switch_channel_down(originator_channel)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s is hungup refusing to bridge.\n", switch_channel_get_name(originatee_channel));
switch_core_session_rwunlock(originator_session);
switch_core_session_rwunlock(originatee_session);
switch_core_session_exec(collect->session, application_interface, app_data);
- if (switch_channel_get_state(channel) < CS_HANGUP) {
+ if (switch_channel_up(channel)) {
switch_channel_set_flag(channel, CF_WINNER);
}
goto wbreak;
time_t elapsed = switch_epoch_time_now(NULL) - start;
for (i = 0; i < max; i++) {
- if (originate_status[i].peer_channel && switch_channel_get_state(originate_status[i].peer_channel) < CS_HANGUP) {
+ if (originate_status[i].peer_channel && switch_channel_up(originate_status[i].peer_channel)) {
if (originate_status[i].per_channel_progress_timelimit_sec && elapsed > originate_status[i].per_channel_progress_timelimit_sec &&
!(
switch_channel_test_flag(originate_status[i].peer_channel, CF_RING_READY) ||
}
pchannel = switch_core_session_get_channel(originate_status[i].peer_session);
- if (switch_channel_get_state(pchannel) >= CS_HANGUP) {
+ if (switch_channel_down(pchannel)) {
cause_str = switch_channel_cause2str(switch_channel_get_cause(pchannel));
if (switch_stristr(cause_str, fail_on_single_reject_var)) {
ok = 0;