]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
run execute_on_answer on_media _on_ring apps async
authorAnthony Minessale <anthm@freeswitch.org>
Tue, 30 Nov 2010 17:01:54 +0000 (11:01 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Tue, 30 Nov 2010 17:01:54 +0000 (11:01 -0600)
src/include/switch_core.h
src/switch_channel.c
src/switch_core_session.c
src/switch_ivr_bridge.c

index 231b26f269317d090bca7889c81d150eb2c0412c..33df7e31ddbebb1fd7bc8ee70b40ccfb3599d115 100644 (file)
@@ -882,6 +882,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_exec(_In_ switch_core_sessio
 SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application_get_flags(_In_ switch_core_session_t *session,
                                                                                                                                                                  _In_ const char *app, _In_opt_z_ const char *arg, _Out_opt_ int32_t *flags);
 
+SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application_async(switch_core_session_t *session, const char *app, const char *arg);
+
 SWITCH_DECLARE(switch_status_t) switch_core_session_get_app_flags(const char *app, int32_t *flags);
 
 /*! 
index c63a1aadb9ba254883c4a24c753bb2a330215282..a9c87c5954636ba487b54a38d98833daeabeedea 100644 (file)
@@ -2518,7 +2518,12 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_ring_ready_value(swi
                        if ((arg = strchr(app, ' '))) {
                                *arg++ = '\0';
                        }
-                       switch_core_session_execute_application(channel->session, app, arg);
+
+                       if (switch_core_session_in_thread(channel->session)) {
+                               switch_core_session_execute_application(channel->session, app, arg);
+                       } else {
+                               switch_core_session_execute_application_async(channel->session, app, arg);
+                       }
                }
 
                return SWITCH_STATUS_SUCCESS;
@@ -2571,7 +2576,12 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_pre_answered(switch_
                        if ((arg = strchr(app, ' '))) {
                                *arg++ = '\0';
                        }
-                       switch_core_session_execute_application(channel->session, app, arg);
+
+                       if (switch_core_session_in_thread(channel->session)) {
+                               switch_core_session_execute_application(channel->session, app, arg);
+                       } else {
+                               switch_core_session_execute_application_async(channel->session, app, arg);
+                       }
                }
 
                if ((var = switch_channel_get_variable(channel, SWITCH_PASSTHRU_PTIME_MISMATCH_VARIABLE))) {
@@ -2750,7 +2760,12 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_answered(switch_chan
                        }
                        switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "%s execute on answer: %s(%s)\n", channel->name, app,
                                                          switch_str_nil(arg));
-                       switch_core_session_execute_application(channel->session, app, arg);
+
+                       if (switch_core_session_in_thread(channel->session)) {
+                               switch_core_session_execute_application(channel->session, app, arg);
+                       } else {
+                               switch_core_session_execute_application_async(channel->session, app, arg);
+                       }
                }
        }
 
index aaa47cc696a465584cf6eeebd9eaadc13a320663..a84bfabaf009490f662cf7d7d6569be589cef518 100644 (file)
@@ -855,6 +855,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_queue_event(switch_core_sess
                if (switch_queue_trypush(session->event_queue, *event) == SWITCH_STATUS_SUCCESS) {
                        *event = NULL;
                        status = SWITCH_STATUS_SUCCESS;
+
+                       if (switch_channel_test_flag(session->channel, CF_PROXY_MODE) || switch_channel_test_flag(session->channel, CF_THREAD_SLEEPING)) {
+                               switch_core_session_wake_session_thread(session);
+                       }
                }
        }
 
@@ -1814,6 +1818,28 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_get_app_flags(const char *ap
 
 }
 
+SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application_async(switch_core_session_t *session, const char *app, const char *arg)
+{
+       switch_event_t *execute_event;
+       
+       if (switch_event_create(&execute_event, SWITCH_EVENT_COMMAND) == SWITCH_STATUS_SUCCESS) {
+               switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "call-command", "execute");
+               switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "execute-app-name", app);
+
+               if (arg) {
+                       switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "execute-app-arg", arg);
+               }
+               
+               switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "event-lock", "true");
+               switch_core_session_queue_private_event(session, &execute_event, SWITCH_FALSE);
+               
+               return SWITCH_STATUS_SUCCESS;
+       }
+
+       return SWITCH_STATUS_FALSE;
+}
+
+
 SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application_get_flags(switch_core_session_t *session, const char *app,
                                                                                                                                                                  const char *arg, int32_t *flags)
 {
index 4cae1a67e201095ff31d591a6b763768a483a6f4..4d320d0e5c6181e03043035432ab05eaa9bf54d4 100644 (file)
@@ -348,20 +348,10 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
                if (read_frame_count > DEFAULT_LEAD_FRAMES && switch_channel_media_ack(chan_a)) {
                        
                        if (exec_app) {
-                               switch_event_t *execute_event;
                                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session_a), SWITCH_LOG_DEBUG, "%s Bridge execute app %s(%s)\n", 
                                                                  switch_channel_get_name(chan_a), exec_app, exec_data);
 
-                               if (switch_event_create(&execute_event, SWITCH_EVENT_COMMAND) == SWITCH_STATUS_SUCCESS) {
-                                       switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "call-command", "execute");
-                                       switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "execute-app-name", exec_app);
-                                       if (exec_data) {
-                                               switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "execute-app-arg", exec_data);
-                                       }
-                                       //switch_event_add_header(execute_event, SWITCH_STACK_BOTTOM, "lead-frames", "%d", 5);
-                                       switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "event-lock", "true");
-                                       switch_core_session_queue_private_event(session_a, &execute_event, SWITCH_FALSE);
-                               }
+                               switch_core_session_execute_application_async(session_a, exec_app, exec_data);
                                exec_app = exec_data = NULL;
                        }