From e0dc4842aef0aa6151e30bda5fb8803c10d5571c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 10 Jun 2013 19:13:05 -0500 Subject: [PATCH] FS-5498 --- src/include/switch_core.h | 2 ++ src/include/switch_types.h | 1 + src/switch_channel.c | 38 +++++++++++++++++++++++++++----------- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/include/switch_core.h b/src/include/switch_core.h index b67b4865b5..564e0a6f3d 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -91,6 +91,8 @@ typedef struct switch_device_stats_s { uint32_t active; uint32_t held; uint32_t hup; + uint32_t ringing; + uint32_t early; } switch_device_stats_t; diff --git a/src/include/switch_types.h b/src/include/switch_types.h index e9dcbae27c..fec42c077c 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -1115,6 +1115,7 @@ typedef enum { typedef enum { SDS_DOWN, + SDS_RINGING, SDS_ACTIVE, SDS_ACTIVE_MULTI, SDS_HELD, diff --git a/src/switch_channel.c b/src/switch_channel.c index 39cb95068f..a3dd9d9978 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -251,6 +251,7 @@ struct switch_device_state_table { }; static struct switch_device_state_table DEVICE_STATE_CHART[] = { {"DOWN", SDS_DOWN}, + {"RINGING", SDS_RINGING}, {"ACTIVE", SDS_ACTIVE}, {"ACTIVE_MULTI", SDS_ACTIVE_MULTI}, {"HELD", SDS_HELD}, @@ -274,6 +275,8 @@ SWITCH_DECLARE(void) switch_channel_perform_set_callstate(switch_channel_t *chan switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_channel_get_uuid(channel), SWITCH_LOG_DEBUG, "(%s) Callstate Change %s -> %s\n", channel->name, switch_channel_callstate2str(o_callstate), switch_channel_callstate2str(callstate)); + + switch_channel_check_device_state(channel, channel->callstate); if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_CALLSTATE) == SWITCH_STATUS_SUCCESS) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Original-Channel-Call-State", switch_channel_callstate2str(o_callstate)); @@ -1741,7 +1744,6 @@ SWITCH_DECLARE(void) switch_channel_set_flag_value(switch_channel_t *channel, sw const char *brto = switch_channel_get_partner_uuid(channel); switch_channel_set_callstate(channel, CCS_HELD); - switch_channel_check_device_state(channel, CCS_HELD); switch_mutex_lock(channel->profile_mutex); channel->caller_profile->times->last_hold = switch_time_now(); @@ -1900,8 +1902,7 @@ SWITCH_DECLARE(void) switch_channel_clear_flag(switch_channel_t *channel, switch switch_mutex_unlock(channel->flag_mutex); if (ACTIVE) { - switch_channel_set_callstate(channel, CCS_ACTIVE); - switch_channel_check_device_state(channel, CCS_UNHOLD); + switch_channel_set_callstate(channel, CCS_UNHOLD); switch_mutex_lock(channel->profile_mutex); if (channel->caller_profile->times->last_hold) { channel->caller_profile->times->hold_accum += (switch_time_now() - channel->caller_profile->times->last_hold); @@ -4591,7 +4592,13 @@ static void fetch_device_stats(switch_device_record_t *drec) if (np->callstate == CCS_HELD) { drec->stats.held++; } else { - drec->stats.active++; + if (np->callstate == CCS_EARLY) { + drec->stats.early++; + } else if (np->callstate == CCS_RINGING) { + drec->stats.ringing++; + } else { + drec->stats.active++; + } } } else { drec->stats.hup++; @@ -4701,8 +4708,6 @@ static void process_device_hup(switch_channel_t *channel) switch_channel_set_flag(channel, CF_FINAL_DEVICE_LEG); } - switch_channel_check_device_state(channel, CCS_HANGUP); - channel->device_node->parent->refs--; switch_mutex_unlock(globals.device_mutex); @@ -4729,8 +4734,16 @@ static void switch_channel_check_device_state(switch_channel_t *channel, switch_ if (drec->stats.offhook == 0) { drec->state = SDS_HANGUP; } else { - if (drec->stats.active == 0 && drec->stats.held > 0) { - drec->state = SDS_HELD; + if (drec->stats.active == 0) { + if ((drec->stats.ringing + drec->stats.early) > 0) { + drec->state = SDS_RINGING; + } else { + if (drec->stats.held > 0) { + drec->state = SDS_HELD; + } else { + drec->state = SDS_DOWN; + } + } } else if (drec->stats.active == 1) { drec->state = SDS_ACTIVE; } else { @@ -4772,7 +4785,7 @@ static void switch_channel_check_device_state(switch_channel_t *channel, switch_ } switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG1, - "%s device: %s\nState: %s Dev State: %s/%s Total:%u Offhook:%u Active:%u Held:%u Hungup:%u Dur: %u %s\n", + "%s device: %s\nState: %s Dev State: %s/%s Total:%u Offhook:%u Ringing:%u Early:%u Active:%u Held:%u Hungup:%u Dur: %u %s\n", switch_channel_get_name(channel), drec->device_id, switch_channel_callstate2str(callstate), @@ -4780,6 +4793,8 @@ static void switch_channel_check_device_state(switch_channel_t *channel, switch_ switch_channel_device_state2str(drec->state), drec->stats.total, drec->stats.offhook, + drec->stats.ringing, + drec->stats.early, drec->stats.active, drec->stats.held, drec->stats.hup, @@ -4823,6 +4838,7 @@ static void add_uuid(switch_device_record_t *drec, switch_channel_t *channel) node->uuid = switch_core_strdup(drec->pool, switch_core_session_get_uuid(channel->session)); node->parent = drec; + node->callstate = channel->callstate; channel->device_node = node; if (!drec->uuid_list) { @@ -4878,8 +4894,8 @@ SWITCH_DECLARE(const char *) switch_channel_set_device_id(switch_channel_t *chan switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "Setting DEVICE ID to [%s]\n", device_id); - switch_channel_check_device_state(channel, CCS_ACTIVE); - + switch_channel_check_device_state(channel, channel->callstate); + return device_id; }