Added event system for TDM termination alarms

This commit is contained in:
root
2012-07-27 21:31:24 -04:00
parent 008bb4942b
commit 2dc5b322dd
8 changed files with 275 additions and 61 deletions
@@ -155,47 +155,38 @@ 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_status_t megaco_prepare_tdm_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_t *event = NULL;
if (switch_event_create(&event, SWITCH_EVENT_TRAP) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to create NOTIFY event\n");
return SWITCH_STATUS_FALSE;
}
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);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "span-name", "%s", term->u.tdm.span_name);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "chan-number", "%d", term->u.tdm.channel);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "condition", "mg-tdm-prepare");
switch_event_fire(&event);
return SWITCH_STATUS_SUCCESS;
}
/* @Kapil Call this function once H.248 link is up */
switch_status_t megaco_check_tdm_termination(mg_termination_t *term)
{
switch_event_t *event = NULL;
if (switch_event_create(&event, SWITCH_EVENT_TRAP) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to create NOTIFY event\n");
return SWITCH_STATUS_FALSE;
}
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "span-name", "%s", term->u.tdm.span_name);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "chan-number", "%d", term->u.tdm.channel);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "condition", "mg-tdm-check");
switch_event_fire(&event);
return SWITCH_STATUS_SUCCESS;
}
mg_termination_t *megaco_choose_termination(megaco_profile_t *profile, const char *prefix)
{
@@ -111,6 +111,8 @@ switch_status_t config_profile(megaco_profile_t *profile, switch_bool_t reload)
profile->physical_terminations = term;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Mapped termination [%s] to freetdm span: %s chan: %d\n", term->name, term->u.tdm.span_name, term->u.tdm.channel);
megaco_prepare_tdm_termination(term);
}
}
}
@@ -56,6 +56,35 @@ static switch_status_t list_profiles(const char *line, const char *cursor, switc
return status;
}
static void mg_event_handler(switch_event_t *event)
{
switch(event->event_id) {
case SWITCH_EVENT_TRAP:
{
const char *span_name = NULL;
const char *chan_number = NULL;
const char *cond = NULL;
cond = switch_event_get_header(event, "condition");
if (zstr(cond)) {
return;
}
span_name = switch_event_get_header(event, "span-name");
chan_number = switch_event_get_header(event, "chan-number");
if (!strcmp(cond, "ftdm-alarm-trap")) {
/* @KAPIL: TDM is in alarm, notify MGC */
} else if (!strcmp(cond, "ftdm-alarm-clear")) {
/* @KAPIL: TDM alarm cleared, notify MGC */
}
}
break;
default:
break;
}
}
SWITCH_MODULE_LOAD_FUNCTION(mod_media_gateway_load)
{
switch_api_interface_t *api_interface;
@@ -82,7 +111,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_media_gateway_load)
switch_console_set_complete("add mg logging ::mg::list_profiles disable");
switch_console_add_complete_func("::mg::list_profiles", list_profiles);
/* Initialize MEGACO Stack */
sng_event.mg.sng_mgco_txn_ind = handle_mgco_txn_ind;
sng_event.mg.sng_mgco_cmd_ind = handle_mgco_cmd_ind;
@@ -96,6 +124,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_media_gateway_load)
/* Log */
sng_event.sm.sng_log = handle_sng_log;
switch_event_bind("mod_media_gateway", SWITCH_EVENT_TRAP, SWITCH_EVENT_SUBCLASS_ANY, mg_event_handler, NULL);
/* initualize MEGACO stack */
return sng_mgco_init(&sng_event);
}
@@ -256,7 +256,8 @@ switch_status_t mg_process_cli_cmd(const char *cmd, switch_stream_handle_t *stre
switch_status_t megaco_context_add_termination(mg_context_t *ctx, mg_termination_t *term);
switch_status_t megaco_context_is_term_present(mg_context_t *ctx, mg_termination_t *term);
switch_status_t megaco_prepare_tdm_termination(mg_termination_t *term);
switch_status_t megaco_check_tdm_termination(mg_termination_t *term);
#endif /* MOD_MEGACO_H */