From b6bd80718624b0153f4d1d560885c843e870afd1 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Thu, 23 Aug 2012 18:15:07 -0400 Subject: [PATCH] adding "peer_active" flag to check before send any message to megaco stack --- .../endpoints/mod_media_gateway/media_gateway.c | 3 +++ .../mod_media_gateway/media_gateway_cmd_handler.c | 14 ++++++++++++++ .../mod_media_gateway/mod_media_gateway.h | 3 +++ 3 files changed, 20 insertions(+) diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway.c b/src/mod/endpoints/mod_media_gateway/media_gateway.c index 54a8fbe3fb..8105b8b158 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway.c @@ -637,6 +637,7 @@ switch_status_t megaco_profile_start(const char *profilename) profile->name = switch_core_strdup(pool, profilename); profile->next_context_id++; profile->inact_tmr = 0x00; + profile->peer_active = 0x00; profile->inact_tmr_task_id = 0x00; switch_thread_rwlock_create(&profile->rwlock, pool); @@ -708,6 +709,8 @@ switch_status_t mgco_init_ins_service_change(SuId suId) return SWITCH_STATUS_FALSE; } + profile->peer_active = 0x01; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "mgco_init_ins_service_change : Initiating terminations service change for profile: %s\n", profile->name); 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 e45fc1cda8..9c078bec5a 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 @@ -2479,6 +2479,14 @@ U32 get_txn_id(){ return outgoing_txn_id; } /*****************************************************************************************************************************/ +switch_status_t mg_is_peer_active(megaco_profile_t* profile) +{ + if((profile) && (0x01 == profile->peer_active)){ + return SWITCH_STATUS_SUCCESS; + } + return SWITCH_STATUS_FALSE; +} +/*****************************************************************************************************************************/ switch_status_t mg_send_term_service_change(char *span_name, char *chan_number, mg_term_states_e term_state) { mg_termination_t* term = NULL; @@ -2493,6 +2501,12 @@ switch_status_t mg_send_term_service_change(char *span_name, char *chan_number, return SWITCH_STATUS_FALSE; } + if(SWITCH_STATUS_FALSE == mg_is_peer_active(term->profile)) + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "profile: %s peer not yet enabled..\n", term->profile->name); + return SWITCH_STATUS_FALSE; + } + switch(term_state) { case MG_TERM_SERVICE_STATE_IN_SERVICE: 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 a3d8c2fc04..ce44617e28 100644 --- a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h +++ b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h @@ -205,6 +205,7 @@ struct megaco_profile_s { char* peer_list[MG_MAX_PEERS]; /* MGC Peer ID LIST */ char* codec_prefs; int inact_tmr; /* inactivity timer value */ + int peer_active; /* inactivity timer value */ uint32_t inact_tmr_task_id; /* FS timer scheduler task-id */ switch_thread_rwlock_t *contexts_rwlock; @@ -221,6 +222,8 @@ struct megaco_profile_s { switch_thread_rwlock_t *terminations_rwlock; }; + + static inline const char *megaco_codec_str(megaco_codec_t codec) { switch (codec) {