diff --git a/src/include/switch_channel.h b/src/include/switch_channel.h index 595014edc8..7fe43ab1f0 100644 --- a/src/include/switch_channel.h +++ b/src/include/switch_channel.h @@ -44,6 +44,12 @@ extern "C" { #include +typedef struct { + switch_time_t created; + switch_time_t answered; + switch_time_t hungup; +} switch_channel_timetable_t; + /** * @defgroup switch_channel Channel Functions * @ingroup FREESWITCH @@ -67,6 +73,13 @@ SWITCH_DECLARE(switch_channel_state) switch_channel_get_state(switch_channel *ch */ SWITCH_DECLARE(switch_channel_state) switch_channel_set_state(switch_channel *channel, switch_channel_state state); +/*! + \brief View the timetable of a channel + \param channel channel to retrieve timetable from + \returns a pointer to the channel's timetable (created, answered, etc..) +*/ +SWITCH_DECLARE(switch_channel_timetable_t *) switch_channel_get_timetable(switch_channel *channel); + /*! \brief Allocate a new channel \param channel NULL pointer to allocate channel to diff --git a/src/switch_channel.c b/src/switch_channel.c index 86086dd3b2..b68670d37d 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -32,7 +32,6 @@ #include struct switch_channel { - time_t initiated; char *name; switch_buffer *dtmf_buffer; switch_mutex_t *dtmf_mutex; @@ -46,6 +45,7 @@ struct switch_channel { const struct switch_state_handler_table *state_handlers[SWITCH_MAX_STATE_HANDLERS]; int state_handler_index; switch_hash *variables; + switch_channel_timetable_t times; void *private; int freq; int bits; @@ -54,7 +54,10 @@ struct switch_channel { int kbps; }; - +SWITCH_DECLARE(switch_channel_timetable_t *) switch_channel_get_timetable(switch_channel *channel) +{ + return &channel->times; +} SWITCH_DECLARE(switch_status) switch_channel_alloc(switch_channel **channel, switch_memory_pool *pool) { @@ -67,7 +70,7 @@ SWITCH_DECLARE(switch_status) switch_channel_alloc(switch_channel **channel, swi switch_core_hash_init(&(*channel)->variables, pool); switch_buffer_create(pool, &(*channel)->dtmf_buffer, 128); switch_mutex_init(&(*channel)->dtmf_mutex, SWITCH_MUTEX_NESTED, pool); - + (*channel)->times.created = switch_time_now(); return SWITCH_STATUS_SUCCESS; } @@ -549,6 +552,7 @@ SWITCH_DECLARE(switch_status) switch_channel_hangup(switch_channel *channel) { assert(channel != NULL); if (channel->state < CS_HANGUP) { + channel->times.hungup = switch_time_now(); channel->state = CS_HANGUP; switch_core_session_signal_state_change(channel->session); } @@ -563,6 +567,7 @@ SWITCH_DECLARE(switch_status) switch_channel_answer(switch_channel *channel) if (switch_core_session_answer_channel(channel->session) == SWITCH_STATUS_SUCCESS) { switch_event *event; + channel->times.answered = switch_time_now(); switch_channel_set_flag(channel, CF_ANSWERED); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Answer %s!\n", channel->name); if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_ANSWER) == SWITCH_STATUS_SUCCESS) {