SWITCH_DECLARE(void) bridge(CoreSession &session_a, CoreSession &session_b) { switch_input_callback_function_t dtmf_func = NULL; switch_input_args_t args; switch_channel_t *channel_a = NULL, *channel_b = NULL; const char *err = "Channels not ready\n"; if (session_a.allocated && session_a.session && session_b.allocated && session_b.session) { channel_a = switch_core_session_get_channel(session_a.session); channel_b = switch_core_session_get_channel(session_b.session); if (switch_channel_ready(channel_a) && switch_channel_ready(channel_b)) { session_a.begin_allow_threads(); if (!switch_channel_test_flag(channel_a, CF_OUTBOUND) && !switch_channel_media_ready(channel_a)) { switch_channel_pre_answer(channel_a); } if (switch_channel_ready(channel_a) && switch_channel_ready(channel_b)) { args = session_a.get_cb_args(); // get the cb_args data structure for session a dtmf_func = args.input_callback; // get the call back function err = NULL; switch_ivr_multi_threaded_bridge(session_a.session, session_b.session, dtmf_func, args.buf, args.buf); } session_a.end_allow_threads(); } } if (err) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session_a.session), SWITCH_LOG_ERROR, "%s", err); } }
int fs_switch_ivr_originate(switch_core_session_t *session, switch_core_session_t **bleg, char *bridgeto, uint32_t timelimit_sec) /*const switch_state_handler_table_t *table, char * cid_name_override, char * cid_num_override, switch_caller_profile_t *caller_profile_override) */ { switch_channel_t *caller_channel; switch_core_session_t *peer_session; unsigned int timelimit = 60; char *var; switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING; caller_channel = switch_core_session_get_channel(session); assert(caller_channel != NULL); if ((var = switch_channel_get_variable(caller_channel, "call_timeout"))) { timelimit = atoi(var); } if (switch_ivr_originate(session, &peer_session, &cause, bridgeto, timelimit, NULL, NULL, NULL, NULL, SOF_NONE) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Cannot Create Outgoing Channel!\n"); switch_channel_hangup(caller_channel, SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL); return; } else { switch_ivr_multi_threaded_bridge(session, peer_session, NULL, NULL, NULL); switch_core_session_rwunlock(peer_session); } }