Make mod_event_multicast re-read its config on RELOADXML (partially)

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13872 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Andrew Thompson 2009-06-19 19:24:23 +00:00
parent 163f5da3d8
commit 886f2c5548

View File

@ -39,6 +39,7 @@
/* magic byte sequence */
static unsigned char MAGIC[] = {226, 132, 177, 197, 152, 198, 142, 211, 172, 197, 158, 208, 169, 208, 135, 197, 166, 207, 154, 196, 166};
static char *MARKER = "1";
static switch_mutex_t *MUTEX = NULL;
SWITCH_MODULE_LOAD_FUNCTION(mod_event_multicast_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_event_multicast_shutdown);
@ -78,24 +79,17 @@ static switch_status_t load_config(void)
char *next, *cur;
uint32_t count = 0;
uint8_t custom = 0;
switch_ssize_t hlen = -1;
gethostname(globals.hostname, sizeof(globals.hostname));
globals.host_hash = switch_hashfunc_default(globals.hostname, &hlen);
globals.key_count = 0;
globals.ttl = 1;
globals.psk = NULL;
globals.key_count = 0;
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf);
return SWITCH_STATUS_TERM;
}
if (switch_event_reserve_subclass(MULTICAST_EVENT) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass!\n");
return SWITCH_STATUS_GENERR;
}
if ((settings = switch_xml_child(cfg, "settings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
@ -180,6 +174,21 @@ static void event_handler(switch_event_t *event)
return;
}
if (event->event_id == SWITCH_EVENT_RELOADXML) {
switch_mutex_lock(MUTEX);
switch_core_hash_destroy(&globals.event_hash);
globals.event_hash = NULL;
switch_core_hash_init(&globals.event_hash, module_pool);
bzero(globals.event_list, SWITCH_EVENT_ALL);
if (load_config() != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Failed to reload config file\n");
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Event Multicast Reloaded\n");
}
switch_mutex_unlock(MUTEX);
}
switch_mutex_lock(MUTEX);
if (globals.event_list[(uint8_t) SWITCH_EVENT_ALL]) {
send = 1;
} else if ((globals.event_list[(uint8_t) event->event_id])) {
@ -187,6 +196,7 @@ static void event_handler(switch_event_t *event)
send = 1;
}
}
switch_mutex_unlock(MUTEX);
if (send) {
char *packet;
@ -254,12 +264,19 @@ static void event_handler(switch_event_t *event)
SWITCH_MODULE_LOAD_FUNCTION(mod_event_multicast_load)
{
switch_ssize_t hlen = -1;
memset(&globals, 0, sizeof(globals));
switch_mutex_init(&MUTEX, SWITCH_MUTEX_NESTED, pool);
module_pool = pool;
switch_core_hash_init(&globals.event_hash, module_pool);
gethostname(globals.hostname, sizeof(globals.hostname));
globals.host_hash = switch_hashfunc_default(globals.hostname, &hlen);
globals.key_count = 0;
if (load_config() != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Configure\n");
return SWITCH_STATUS_TERM;
@ -302,6 +319,10 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_event_multicast_load)
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
if (switch_event_reserve_subclass(MULTICAST_EVENT) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass!\n");
return SWITCH_STATUS_GENERR;
}
if (switch_event_bind(modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");