]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add megaco_prepare_termination
authorMathieu Rene <mrene@avgs.ca>
Fri, 27 Jul 2012 14:59:37 +0000 (10:59 -0400)
committerMathieu Rene <mrene@avgs.ca>
Fri, 27 Jul 2012 14:59:37 +0000 (10:59 -0400)
src/mod/endpoints/mod_media_gateway/media_gateway.c
src/mod/endpoints/mod_media_gateway/mod_media_gateway.h

index e47055236aa5d36fb2c45dac1553fa6d0cb43615..ee5abe7d2f5d4f90b2272ef29a41d1f5064bee26 100644 (file)
@@ -155,6 +155,48 @@ done:
     return SWITCH_STATUS_SUCCESS;
 }
 
+
+/*
+ * Originate a channel so the target technology gets to run initialization code
+ */
+switch_status_t megaco_prepare_termination(mg_termination_t *term)
+{
+    switch_event_t *var_event = NULL;
+    switch_core_session_t *session = NULL;
+    switch_status_t status = SWITCH_STATUS_SUCCESS;
+    char dialstring[100];
+    switch_call_cause_t cause;
+    switch_channel_t *channel;
+    switch_event_create(&var_event, SWITCH_EVENT_CLONE);
+    
+    if (term->type == MG_TERM_RTP) {
+    } else if (term->type == MG_TERM_TDM) {
+        switch_snprintf(dialstring, sizeof dialstring, "tdm/%s", term->name);
+
+        switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "ftdm_start_only",  "true");
+        switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, kSPAN_NAME,  term->u.tdm.span_name);
+        switch_event_add_header(var_event, SWITCH_STACK_BOTTOM, kCHAN_ID, "%d", term->u.tdm.channel);
+    }
+    
+    /* Set common variables on the channel */
+    switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, SWITCH_PARK_AFTER_BRIDGE_VARIABLE, "true");
+    if (switch_ivr_originate(NULL, &session, &cause, dialstring, 0, NULL, NULL, NULL, NULL, var_event, 0, NULL) != SWITCH_STATUS_SUCCESS) {
+        status = SWITCH_STATUS_FALSE;  
+        goto done;
+    }
+    channel = switch_core_session_get_channel(session);
+    switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+
+done:
+    if (session) {
+        switch_core_session_rwunlock(session);
+    }
+    switch_event_destroy(&var_event);
+
+    return SWITCH_STATUS_SUCCESS;
+}
+
+
 mg_termination_t *megaco_choose_termination(megaco_profile_t *profile, const char *prefix)
 {
     mg_termination_type_t termtype;
index af53052fbb7e581968ce709b59eea0a51643b32a..4ffeaaa4e0c63f97c683d73a5b53c893218d31d4 100644 (file)
@@ -235,6 +235,7 @@ void megaco_release_context(mg_context_t *ctx);
 switch_status_t megaco_context_sub_termination(mg_context_t *ctx, mg_termination_t *term);
 switch_status_t megaco_context_sub_all_termination(mg_context_t *ctx);
 switch_status_t megaco_activate_termination(mg_termination_t *term);
+switch_status_t megaco_prepare_termination(mg_termination_t *term);
 
 mg_termination_t *megaco_choose_termination(megaco_profile_t *profile, const char *prefix);
 mg_termination_t *megaco_find_termination(megaco_profile_t *profile, const char *name);