From 50b044d66f8213077002f2df585203ad5c54a3f1 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Fri, 7 Sep 2012 12:10:16 -0400 Subject: [PATCH] adding api to release all calls/context during Subtract with Context ALL(C=*{S=*}) request processing --- .../mod_media_gateway/media_gateway.c | 16 ++++++++++++++++ .../media_gateway_cmd_handler.c | 2 +- .../mod_media_gateway/media_gateway_stack.h | 2 ++ .../media_gateway_stack_alarms.c | 1 + .../mod_media_gateway/mod_media_gateway.c | 19 +++++++++++++++++++ .../mod_media_gateway/mod_media_gateway.h | 1 + 6 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway.c b/src/mod/endpoints/mod_media_gateway/media_gateway.c index 1a1bba5475..2025ab2443 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway.c @@ -781,6 +781,22 @@ switch_status_t megaco_profile_destroy(megaco_profile_t **profile) return SWITCH_STATUS_SUCCESS; } +switch_status_t mgco_process_mgc_failure(SuId suId) +{ + megaco_profile_t* profile = NULL; + + if(NULL == (profile = megaco_get_profile_by_suId(suId))){ + return SWITCH_STATUS_FALSE; + } + + if(0x01 == profile->peer_active){ + /* MGC failure during active association , release all on-going calls contexts */ + megaco_release_all_calls(profile); + profile->peer_active = 0x00; + } + + return SWITCH_STATUS_SUCCESS; +} switch_status_t mgco_init_ins_service_change(SuId suId) { diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c b/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c index fe99a25b8d..db297c7ff1 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c @@ -1335,7 +1335,7 @@ switch_status_t handle_mg_subtract_cmd(megaco_profile_t* mg_profile, MgMgcoComma switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO," SUB Request for ALL context \n"); - /* TODO */ + megaco_release_all_calls(mg_profile); /* As of now sending +ve response */ goto response; diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_stack.h b/src/mod/endpoints/mod_media_gateway/media_gateway_stack.h index 0b8c5746e1..4b1c80c220 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_stack.h +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_stack.h @@ -247,6 +247,8 @@ switch_status_t mg_activate_ito_timer(megaco_profile_t* profile); void mg_restart_inactivity_timer(megaco_profile_t* profile); +switch_status_t mgco_process_mgc_failure(SuId suId); + /****************************************************************************************************************/ /* MG Stack defines */ diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_stack_alarms.c b/src/mod/endpoints/mod_media_gateway/media_gateway_stack_alarms.c index 6cba35d7c9..4c3e507fd1 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_stack_alarms.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_stack_alarms.c @@ -76,6 +76,7 @@ void handle_mg_alarm(Pst *pst, MgMngmt *usta) { case LMG_EVENT_ALL_MGC_FAILED: { + //mgco_process_mgc_failure(usta->t.usta.alarmInfo.sapId); len = len + sprintf(prBuf+len, "ALL MGC Failed "); break; } diff --git a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.c b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.c index 45f240901d..395254031c 100644 --- a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.c +++ b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.c @@ -230,6 +230,25 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_media_gateway_shutdown) return SWITCH_STATUS_SUCCESS; } +/*****************************************************************************************************************************/ +switch_status_t megaco_release_all_calls(megaco_profile_t* mg_profile) +{ + mg_context_t* ctx = NULL; + uint32_t context_id = 0x00; + + if(NULL == mg_profile) return SWITCH_STATUS_FALSE; + + for (context_id = 0; context_id < MG_MAX_CONTEXTS; context_id++) { + ctx = megaco_get_context(mg_profile, context_id); + if(NULL == ctx) continue; + + megaco_context_sub_all_termination(ctx); + megaco_release_context(ctx); + } + + return SWITCH_STATUS_SUCCESS; +} + /*****************************************************************************************************************************/ switch_status_t megaco_start_all_profiles() { diff --git a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h index 640b22d7e0..004c5153b7 100644 --- a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h +++ b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h @@ -332,6 +332,7 @@ mg_termination_t* megaco_find_termination_by_span_chan(megaco_profile_t *profile switch_status_t megaco_start_all_profiles(void); switch_status_t megaco_profile_start(const char *profilename); switch_status_t megaco_profile_destroy(megaco_profile_t **profile); +switch_status_t megaco_release_all_calls(megaco_profile_t* mg_profile); uint32_t mg_rtp_request_id(megaco_profile_t *profile); void mg_rtp_release_id(megaco_profile_t *profile, uint32_t id);