]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
rearrange hangup callflow to do more work in the session's own thread
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 25 Mar 2009 20:07:40 +0000 (20:07 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 25 Mar 2009 20:07:40 +0000 (20:07 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12784 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_channel.h
src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c
src/switch_channel.c
src/switch_core_state_machine.c

index cb88143e8c8404d945b31387dcb83b51bec6e424..719748debea6c4d5a9ce5441347d33350cf2f9f6 100644 (file)
@@ -511,6 +511,7 @@ SWITCH_DECLARE(int) switch_channel_test_private_flag(switch_channel_t *channel,
 SWITCH_DECLARE(void) switch_channel_set_app_flag(switch_channel_t *channel, uint32_t flags);
 SWITCH_DECLARE(void) switch_channel_clear_app_flag(switch_channel_t *channel, uint32_t flags);
 SWITCH_DECLARE(int) switch_channel_test_app_flag(switch_channel_t *channel, uint32_t flags);
+SWITCH_DECLARE(void) switch_channel_set_hangup_time(switch_channel_t *channel);
 
 /** @} */
 
index b580da002b0d0f9c9adf73a9e1f2bcd233f504f7..24bb2b28cabaef49857714a4a040f569d9736dd1 100644 (file)
@@ -209,7 +209,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
                        free(buf);
                }
        }
-
+       
        g_template_str = (const char *) switch_core_hash_find(globals.template_hash, globals.default_template);
 
        if ((accountcode = switch_channel_get_variable(channel, "ACCOUNTCODE"))) {
index 4195caec5e75c025161fb9734b5cf22e1301d272..c671f33c6c0c63578c4682421736f9961016b363 100644 (file)
@@ -609,10 +609,12 @@ SWITCH_DECLARE(char *) switch_channel_get_name(switch_channel_t *channel)
 SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_var_check(switch_channel_t *channel, 
                                                                                                                                          const char *varname, const char *value, switch_bool_t var_check)
 {
+       switch_status_t status = SWITCH_STATUS_FALSE;
+       
        switch_assert(channel != NULL);
 
+       switch_mutex_lock(channel->profile_mutex);
        if (channel->variables && !switch_strlen_zero(varname)) {
-               switch_mutex_lock(channel->profile_mutex);
                switch_event_del_header(channel->variables, varname);
                if (!switch_strlen_zero(value)) {
                        int ok = 1;
@@ -626,11 +628,11 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_var_check(switch_cha
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Invalid data (${%s} contains a variable)\n", varname);
                        }
                }
-               switch_mutex_unlock(channel->profile_mutex);
-               return SWITCH_STATUS_SUCCESS;
+               status = SWITCH_STATUS_SUCCESS;
        }
+       switch_mutex_unlock(channel->profile_mutex);
 
-       return SWITCH_STATUS_FALSE;
+       return status;
 }
 
 switch_status_t switch_event_base_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, char *data);
@@ -640,10 +642,12 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_printf(switch_channe
        int ret = 0;
        char *data;
        va_list ap;
+       switch_status_t status = SWITCH_STATUS_FALSE;
+
        switch_assert(channel != NULL);
 
+       switch_mutex_lock(channel->profile_mutex);
        if (channel->variables && !switch_strlen_zero(varname)) {
-               switch_mutex_lock(channel->profile_mutex);
                switch_event_del_header(channel->variables, varname);
 
                va_start(ap, fmt);
@@ -657,11 +661,11 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_printf(switch_channe
 
                switch_event_base_add_header(channel->variables, SWITCH_STACK_BOTTOM, varname, data);
 
-               switch_mutex_unlock(channel->profile_mutex);
-               return SWITCH_STATUS_SUCCESS;
+               status = SWITCH_STATUS_SUCCESS;
        }
+       switch_mutex_unlock(channel->profile_mutex);
 
-       return SWITCH_STATUS_FALSE;
+       return status;
 }
 
 
@@ -1582,6 +1586,16 @@ SWITCH_DECLARE(switch_caller_extension_t *) switch_channel_get_caller_extension(
 }
 
 
+SWITCH_DECLARE(void) switch_channel_set_hangup_time(switch_channel_t *channel)
+{
+       if (channel->caller_profile && channel->caller_profile->times && !channel->caller_profile->times->hungup) {
+               switch_mutex_lock(channel->profile_mutex);
+               channel->caller_profile->times->hungup = switch_micro_time_now();
+               switch_mutex_unlock(channel->profile_mutex);
+       }
+}
+
+
 SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_hangup(switch_channel_t *channel,
                                                                                                                                         const char *file, const char *func, int line, switch_call_cause_t hangup_cause)
 {
@@ -1590,17 +1604,8 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_hangup(switch_chan
        switch_channel_clear_flag(channel, CF_BLOCK_STATE);
        
        if (channel->state < CS_HANGUP) {
-               switch_event_t *event;
                switch_channel_state_t last_state = channel->state;
 
-               if (channel->caller_profile && channel->caller_profile->times && !channel->caller_profile->times->hungup) {
-                       switch_mutex_lock(channel->profile_mutex);
-                       channel->caller_profile->times->hungup = switch_micro_time_now();
-                       switch_mutex_unlock(channel->profile_mutex);
-               }
-               
-               switch_channel_stop_broadcast(channel);
-
                switch_mutex_lock(channel->state_mutex);
                channel->state = CS_HANGUP;
                switch_mutex_unlock(channel->state_mutex);
@@ -1608,21 +1613,9 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_hangup(switch_chan
                channel->hangup_cause = hangup_cause;
                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_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_core_session_kill_channel(channel->session, SWITCH_SIG_KILL);
                switch_core_session_signal_state_change(channel->session);
-
-               switch_channel_set_timestamps(channel);
-
-               if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_HANGUP) == SWITCH_STATUS_SUCCESS) {
-                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Hangup-Cause", switch_channel_cause2str(channel->hangup_cause));
-                       switch_channel_event_set_data(channel, event);
-                       switch_event_fire(&event);
-               }
-
        }
 
        return channel->state;
index f7e52480d94ca2f78b06185a14301020c5c144df..ceae777675d7313f1cec0bb6b1451c8b6aba28a8 100644 (file)
@@ -424,8 +424,19 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
                                {
                                        const char *hook_var;
                                        switch_core_session_t *use_session = NULL;
-                                       
+                                       switch_call_cause_t cause = switch_channel_get_cause(session->channel);
+                                       switch_event_t *event;
+               
+                                       switch_channel_set_hangup_time(session->channel);
+
                                        switch_core_media_bug_remove_all(session);
+                               
+                                       switch_channel_stop_broadcast(session->channel);
+                                       
+                                       switch_channel_set_variable(session->channel, "hangup_cause", switch_channel_cause2str(cause));
+                                       switch_channel_presence(session->channel, "unavailable", switch_channel_cause2str(cause), NULL);
+                                       
+                                       switch_channel_set_timestamps(session->channel);
                                        
                                        STATE_MACRO(hangup, "HANGUP");
 
@@ -462,8 +473,16 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
                                                }
                                                switch_safe_free(stream.data);
                                        }
+
+                                       if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_HANGUP) == SWITCH_STATUS_SUCCESS) {
+                                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Hangup-Cause", switch_channel_cause2str(cause));
+                                               switch_channel_event_set_data(session->channel, event);
+                                               switch_event_fire(&event);
+                                       }
+                               
+                                       switch_channel_set_state(session->channel, CS_REPORTING);
                                }
-                               switch_channel_set_state(session->channel, CS_REPORTING);
+
                                break;
                        case CS_INIT:           /* Basic setup tasks */
                                STATE_MACRO(init, "INIT");