[commit] r5072 - freeswitch/trunk/src/mod/endpoints/mod_sofia
Author: anthm Date: Wed May 2 19:32:45 2007 New Revision: 5072 Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Log: update Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c ============================================================================== --- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c (original) +++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c Wed May 2 19:32:45 2007 @@ -950,7 +950,7 @@ const void *vvar; int c = 0; int ac = 0; - const char *line = "======================================================================================="; + const char *line = "================================================================================================="; if (argc > 0) { @@ -1045,14 +1045,16 @@ if (strcmp(vvar, profile->name)) { ac++; - stream->write_function(stream, "%25s\t%s\t %32s\t%s\n", vvar, " alias", profile->name, "LOADED"); + stream->write_function(stream, "%25s\t%s\t %32s\t%s\n", vvar, " alias", profile->name, "ALIASED"); } else { - stream->write_function(stream, "%25s\t%s\t %32s\t%s\n", profile->name, "profile", profile->url, "LOADED"); + stream->write_function(stream, "%25s\t%s\t %32s\t%s\n", profile->name, "profile", profile->url, + sofia_test_pflag(profile, PFLAG_RUNNING) ? "RUNNING" : "DOWN"); c++; for (gp = profile->gateways; gp; gp = gp->next) { assert(gp->state < REG_STATE_LAST); stream->write_function(stream, "%25s\t%s\t %32s\t%s\n", gp->name, "gateway", gp->register_to, sofia_state_names[gp->state]); + } } @@ -1061,7 +1063,7 @@ } switch_mutex_unlock(mod_sofia_globals.hash_mutex); stream->write_function(stream, "%s\n", line); - stream->write_function(stream, "%d profiles %d aliases\n", c, ac); + stream->write_function(stream, "%d profile%s %d alias%s\n", c, c == 1 ? "" : "s", ac, ac == 1 ? "" : "es"); return SWITCH_STATUS_SUCCESS; } @@ -1105,9 +1107,15 @@ sofia_clear_pflag_locked(profile, PFLAG_RUNNING); stream->write_function(stream, "stopping: %s", profile->name); } else if (!strcasecmp(argv[1], "restart")) { - sofia_set_pflag_locked(profile, PFLAG_RESPAWN); - sofia_clear_pflag_locked(profile, PFLAG_RUNNING); - stream->write_function(stream, "restarting: %s", profile->name); + int rsec = 30; + + if (time(NULL) - profile->started < rsec) { + stream->write_function(stream, "Profile %s must be up for at least %d seconds to restart\n", rsec, profile->name); + } else { + sofia_set_pflag_locked(profile, PFLAG_RESPAWN); + sofia_clear_pflag_locked(profile, PFLAG_RUNNING); + stream->write_function(stream, "restarting: %s", profile->name); + } } if (profile) { Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h ============================================================================== --- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (original) +++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h Wed May 2 19:32:45 2007 @@ -240,6 +240,7 @@ switch_thread_rwlock_t *rwlock; switch_mutex_t *flag_mutex; uint32_t inuse; + time_t started; #ifdef SWITCH_HAVE_ODBC char *odbc_dsn; char *odbc_user; Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c ============================================================================== --- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (original) +++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c Wed May 2 19:32:45 2007 @@ -262,6 +262,13 @@ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Creating agent for %s\n", profile->name); + if (!sofia_glue_init_sql(profile)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open SQL Database [%s]!\n", profile->name); + sofia_glue_del_profile(profile); + goto end; + } + + profile->nua = nua_create(profile->s_root, /* Event loop */ sofia_event_callback, /* Callback for processing events */ profile, /* Additional data to pass to callback */ @@ -269,6 +276,7 @@ if (!profile->nua) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Creating SIP UA for profile: %s\n", profile->name); + sofia_glue_del_profile(profile); goto end; } @@ -313,10 +321,6 @@ } - if (!sofia_glue_init_sql(profile)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open SQL Database!\n"); - goto end; - } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "activated db for %s\n", profile->name); @@ -343,8 +347,11 @@ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Starting thread for %s\n", profile->name); - + profile->started = time(NULL); + switch_yield(1000000); + sofia_set_pflag_locked(profile, PFLAG_RUNNING); + while (mod_sofia_globals.running == 1 && sofia_test_pflag(profile, PFLAG_RUNNING)) { if (++ireg_loops >= IREG_SECONDS) { sofia_reg_check_expire(profile, time(NULL)); @@ -363,8 +370,12 @@ switch_yield(500000); } + + //sofia_reg_check_expire(profile, 0); //sofia_reg_check_gateway(profile, 0); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock %s\n", profile->name); switch_thread_rwlock_wrlock(profile->rwlock); sofia_reg_unregister(profile); nua_shutdown(profile->nua); @@ -393,6 +404,7 @@ sofia_glue_del_profile(profile); switch_thread_rwlock_unlock(profile->rwlock); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write unlock %s\n", profile->name); if (sofia_test_pflag(profile, PFLAG_RESPAWN)) { config_sofia(1, profile->name); @@ -402,6 +414,7 @@ end: + switch_mutex_lock(mod_sofia_globals.mutex); mod_sofia_globals.threads--; Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c ============================================================================== --- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (original) +++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Wed May 2 19:32:45 2007 @@ -1426,10 +1426,14 @@ switch_mutex_lock(mod_sofia_globals.hash_mutex); if ((profile = (sofia_profile_t *) switch_core_hash_find(mod_sofia_globals.profile_hash, key))) { if (!sofia_test_pflag(profile, PFLAG_RUNNING)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Profile %s is not running\n", profile->name); profile = NULL; } else if (switch_thread_rwlock_tryrdlock(profile->rwlock) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Profile %s is locked\n", profile->name); profile = NULL; } + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Profile %s is not in the hash\n", profile->name); } switch_mutex_unlock(mod_sofia_globals.hash_mutex); @@ -1545,7 +1549,7 @@ } #endif - return 1; + return profile->master_odbc ? 1 : 0; } void sofia_glue_sql_close(sofia_profile_t *profile)
participants (1)
-
Freeswitch SVN