make modules unbind events and un-reserve subclasses on module unload

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8898 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris committed 2008-07-03 23:54:35 +00:00
1 parent ffb2e317bb
commit 2f94f73921
15 files changed
+98 -28

No files matched your search

@@ -56,11 +56,12 @@ static struct {
int rotate;
int debug;
cdr_leg_t legs;
switch_event_node_t *node;
} globals;
SWITCH_MODULE_LOAD_FUNCTION(mod_cdr_csv_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cdr_csv_shutdown);
SWITCH_MODULE_DEFINITION(mod_cdr_csv, mod_cdr_csv_load, NULL, NULL);
SWITCH_MODULE_DEFINITION(mod_cdr_csv, mod_cdr_csv_load, mod_cdr_csv_shutdown, NULL);
static off_t fd_size(int fd)
{
@@ -363,7 +364,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_cdr_csv_load)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
if (switch_event_bind(modname, SWITCH_EVENT_TRAP, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
if (switch_event_bind_removable(modname, SWITCH_EVENT_TRAP, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL, &globals.node) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
}
@@ -385,6 +386,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cdr_csv_shutdown)
{
globals.shutdown = 1;
switch_event_unbind(&globals.node);
return SWITCH_STATUS_SUCCESS;
}
@@ -54,6 +54,7 @@ static struct {
switch_hash_t *event_hash;
uint8_t event_list[SWITCH_EVENT_ALL + 1];
int running;
switch_event_node_t *node;
} globals;
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_address, globals.address);
@@ -261,6 +262,9 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_event_multicast_shutdown)
globals.udp_socket = NULL;
}
switch_event_unbind(&globals.node);
switch_event_free_subclass(MULTICAST_EVENT);
switch_core_hash_destroy(&globals.event_hash);
return SWITCH_STATUS_SUCCESS;
@@ -106,6 +106,11 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_pref_pass, prefs.password);
static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj);
static void launch_listener_thread(listener_t *listener);
static struct {
switch_event_node_t *node;
} globals;
static switch_status_t socket_logger(const switch_log_node_t *node, switch_log_level_t level)
{
listener_t *l;
@@ -326,6 +331,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_event_socket_shutdown)
break;
}
}
switch_event_unbind(&globals.node);
switch_mutex_lock(listen_list.mutex);
for (l = listen_list.listeners; l; l = l->next) {
@@ -1357,7 +1363,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_socket_runtime)
listen_list.ready = 1;
if (switch_event_bind(modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
if (switch_event_bind_removable(modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL, &globals.node) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
}
@@ -46,6 +46,8 @@ static struct {
sw_discovery discovery;
sw_discovery_publish_id disc_id;
switch_mutex_t *zc_lock;
switch_event_node_t *publish_node;
switch_event_node_t *unpublish_node;
} globals;
@@ -218,12 +220,12 @@ static switch_status_t load_config(void)
return SWITCH_STATUS_MEMERR;
}
} else if (!strcasecmp(var, "publish") && !strcasecmp(val, "yes")) {
if (switch_event_bind(modname, SWITCH_EVENT_PUBLISH, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
if (switch_event_bind_removable(modname, SWITCH_EVENT_PUBLISH, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL, &globals.publish_node) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
}
if (switch_event_bind(modname, SWITCH_EVENT_UNPUBLISH, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
if (switch_event_bind_removable(modname, SWITCH_EVENT_UNPUBLISH, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL, &globals.unpublish_node) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
}
@@ -248,6 +250,12 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_zeroconf_shutdown)
RUNNING = -1;
switch_yield(100000);
}
switch_event_unbind(&globals.publish_node);
switch_event_unbind(&globals.unpublish_node);
switch_event_free_subclass(MY_EVENT_PUBLISH);
switch_event_free_subclass(MY_EVENT_UNPUBLISH);
return SWITCH_STATUS_SUCCESS;
}
@@ -265,10 +273,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_zeroconf_load)
return SWITCH_STATUS_TERM;
}
if (load_config() != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_TERM;
}
if (switch_event_reserve_subclass(MY_EVENT_PUBLISH) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass!\n");
return SWITCH_STATUS_GENERR;
@@ -279,6 +283,10 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_zeroconf_load)
return SWITCH_STATUS_GENERR;
}
if (load_config() != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_TERM;
}
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);