From 8a292bf0b2fe50e10757e539de62f74f1f9962d1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 4 Jan 2006 01:04:33 +0000 Subject: [PATCH] stupid crap git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@279 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_core.h | 2 +- src/mod/endpoints/mod_exosip/mod_exosip.c | 164 +++++++++++----------- src/switch_core.c | 20 +-- src/switch_loadable_module.c | 5 +- 4 files changed, 96 insertions(+), 95 deletions(-) diff --git a/src/include/switch_core.h b/src/include/switch_core.h index f3ee2c95e0..cc8c2d7fcb 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -78,7 +78,7 @@ SWITCH_DECLARE(switch_status) switch_core_hash_insert(switch_hash *hash, char *k SWITCH_DECLARE(switch_status) switch_core_hash_insert_dup(switch_hash *hash, char *key, void *data); SWITCH_DECLARE(switch_status) switch_core_hash_delete(switch_hash *hash, char *key); SWITCH_DECLARE(void *) switch_core_hash_find(switch_hash *hash, char *key); -SWITCH_DECLARE(void) switch_core_launch_thread(void *(*func)(switch_thread *, void*), void *obj); +SWITCH_DECLARE(void) switch_core_launch_thread(void *(*func)(switch_thread *, void*), void *obj, switch_memory_pool *pool); SWITCH_DECLARE(FILE *) switch_core_data_channel(switch_text_channel channel); SWITCH_DECLARE(void) switch_core_session_launch_thread(switch_core_session *session, void *(*func)(switch_thread *, void *), void *obj); SWITCH_DECLARE(switch_status) switch_core_timer_init(switch_timer *timer, char *timer_name, int interval, int samples, switch_memory_pool *pool); diff --git a/src/mod/endpoints/mod_exosip/mod_exosip.c b/src/mod/endpoints/mod_exosip/mod_exosip.c index 972797c379..4be0b56670 100644 --- a/src/mod/endpoints/mod_exosip/mod_exosip.c +++ b/src/mod/endpoints/mod_exosip/mod_exosip.c @@ -734,18 +734,18 @@ static const switch_loadable_module_interface exosip_module_interface = { /*.application_interface*/ NULL }; - +#if 1 SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void) { if (globals.running) { globals.running = -1; while(globals.running) { - switch_yield(1000); + switch_yield(100000); } } return SWITCH_STATUS_SUCCESS; } - +#endif SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) { /* NOTE: **interface is **_interface because the common lib redefines interface to struct in some situations */ @@ -1240,10 +1240,82 @@ static void log_event(eXosip_event_t *je) -static void *monitor_thread_run(void) +static int config_exosip(int reload) +{ + switch_config cfg; + char *var, *val; + char *cf = "exosip.conf"; + + globals.bytes_per_frame = DEFAULT_BYTES_PER_FRAME; + switch_core_hash_init(&globals.call_hash, module_pool); + + if (!switch_config_open_file(&cfg, cf)) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "open of %s failed\n", cf); + return SWITCH_STATUS_TERM; + } + + globals.rtp_start = 16384; + globals.rtp_end = 32768; + + while (switch_config_next_pair(&cfg, &var, &val)) { + if (!strcasecmp(cfg.category, "settings")) { + if (!strcmp(var, "debug")) { + globals.debug = atoi(val); + } else if (!strcmp(var, "port")) { + globals.port = atoi(val); + } else if (!strcmp(var, "dialplan")) { + set_global_dialplan(val); + } else if (!strcmp(var, "rtp_min_port")) { + globals.rtp_start = atoi(val); + } else if (!strcmp(var, "rtp_max_port")) { + globals.rtp_end = atoi(val); + } else if (!strcmp(var, "codec_ms")) { + globals.codec_ms = atoi(val); + } + } + } + + if (!globals.codec_ms) { + globals.codec_ms = 20; + } + + if (!globals.port) { + globals.port = 5060; + } + + switch_config_close_file(&cfg); + + if (!globals.dialplan) { + set_global_dialplan("default"); + } + + switch_mutex_init(&globals.port_lock, SWITCH_MUTEX_NESTED, module_pool); + + /* Setup the user agent */ + eXosip_set_user_agent("FreeSWITCH"); + + + return 0; + +} + + +SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void) { eXosip_event_t *event = NULL; + config_exosip(0); + + if (eXosip_init ()) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "eXosip_init initialization failed!\n"); + return SWITCH_STATUS_TERM; + } + + if (eXosip_listen_addr (IPPROTO_UDP, NULL, globals.port, AF_INET, 0)) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "eXosip_listen_addr failed!\n"); + return SWITCH_STATUS_TERM; + } + globals.running = 1; while (globals.running > 0) { if (!(event = eXosip_event_wait(0,100))) { @@ -1323,87 +1395,11 @@ static void *monitor_thread_run(void) eXosip_event_free(event); } - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Monitor Thread Exiting\n"); - globals.running = 0; - return NULL; -} - - -static int config_exosip(int reload) -{ - switch_config cfg; - char *var, *val; - char *cf = "exosip.conf"; - - globals.bytes_per_frame = DEFAULT_BYTES_PER_FRAME; - switch_core_hash_init(&globals.call_hash, module_pool); - - if (!switch_config_open_file(&cfg, cf)) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "open of %s failed\n", cf); - return SWITCH_STATUS_TERM; - } - - globals.rtp_start = 16384; - globals.rtp_end = 32768; - - while (switch_config_next_pair(&cfg, &var, &val)) { - if (!strcasecmp(cfg.category, "settings")) { - if (!strcmp(var, "debug")) { - globals.debug = atoi(val); - } else if (!strcmp(var, "port")) { - globals.port = atoi(val); - } else if (!strcmp(var, "dialplan")) { - set_global_dialplan(val); - } else if (!strcmp(var, "rtp_min_port")) { - globals.rtp_start = atoi(val); - } else if (!strcmp(var, "rtp_max_port")) { - globals.rtp_end = atoi(val); - } else if (!strcmp(var, "codec_ms")) { - globals.codec_ms = atoi(val); - } - } - } - - if (!globals.codec_ms) { - globals.codec_ms = 20; - } - - if (!globals.port) { - globals.port = 5060; - } - - switch_config_close_file(&cfg); - - if (!globals.dialplan) { - set_global_dialplan("default"); - } - - if (eXosip_init ()) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "eXosip_init initialization failed!\n"); - return SWITCH_STATUS_GENERR; - } - if (eXosip_listen_addr (IPPROTO_UDP, NULL, globals.port, AF_INET, 0)) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "eXosip_listen_addr failed!\n"); - return SWITCH_STATUS_GENERR; - } - - switch_mutex_init(&globals.port_lock, SWITCH_MUTEX_NESTED, module_pool); - - /* Setup the user agent */ - eXosip_set_user_agent("FreeSWITCH"); - - monitor_thread_run(); - eXosip_quit(); - - return 0; - -} - - -SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void) -{ - config_exosip(0); + globals.running = 0; + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Monitor Thread Exiting\n"); + //switch_sleep(2000000); + return SWITCH_STATUS_TERM; } diff --git a/src/switch_core.c b/src/switch_core.c index ee97640ebb..04ff9f3ac1 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -1594,32 +1594,36 @@ the core to have any clue and keeping switch_loadable_module.c from needing any */ -SWITCH_DECLARE(void) switch_core_launch_thread(switch_thread_start_t func, void *obj) +SWITCH_DECLARE(void) switch_core_launch_thread(switch_thread_start_t func, void *obj, switch_memory_pool *pool) { switch_thread *thread; - switch_threadattr_t *thd_attr; + switch_threadattr_t *thd_attr = NULL; switch_core_thread_session *ts; - switch_memory_pool *pool = NULL; + int mypool; - switch_threadattr_create(&thd_attr, runtime.memory_pool); - switch_threadattr_detach_set(thd_attr, 1); + mypool = pool ? 0 : 1; - if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) { + if (!pool && switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory pool\n"); return; } + switch_threadattr_create(&thd_attr, pool); + switch_threadattr_detach_set(thd_attr, 1); + if (!(ts = switch_core_alloc(pool, sizeof(*ts)))) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory\n"); } else { - ts->pool = pool; + if (mypool) { + ts->pool = pool; + } ts->objs[0] = obj; switch_thread_create(&thread, thd_attr, func, ts, - ts->pool + pool ); } diff --git a/src/switch_loadable_module.c b/src/switch_loadable_module.c index 7586592eb1..d38a129c10 100644 --- a/src/switch_loadable_module.c +++ b/src/switch_loadable_module.c @@ -84,9 +84,10 @@ static void *switch_loadable_module_exec(switch_thread *thread, void *obj) if (ts->pool) { switch_memory_pool *pool = ts->pool; + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Destroying Pool for %s\n", module->interface->module_name); switch_core_destroy_memory_pool(&pool); } - + switch_yield(1000000); return NULL; } @@ -173,7 +174,7 @@ static switch_status switch_loadable_module_load_file(char *filename, switch_mem module->lib = dso; if (module->switch_module_runtime) { - switch_core_launch_thread(switch_loadable_module_exec, module); + switch_core_launch_thread(switch_loadable_module_exec, module, loadable_modules.pool); } *new_module = module;