From b6545379d6f66c1c86d080f0253d3d0f413e8b2e Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 1 May 2006 19:44:21 +0000 Subject: [PATCH] add interfaces to sqlite db table for quick show api commands (coming soon) git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1313 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_types.h | 1 + src/switch_core.c | 16 +++++++++++++- src/switch_event.c | 1 + src/switch_loadable_module.c | 43 ++++++++++++++++++++++++++++++++++-- 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index ad4f06ee85..86f84e5a8a 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -540,6 +540,7 @@ typedef enum { SWITCH_EVENT_TALK, SWITCH_EVENT_NOTALK, SWITCH_EVENT_SESSION_CRASH, + SWITCH_EVENT_MODULE_LOAD, SWITCH_EVENT_ALL } switch_event_types_t; diff --git a/src/switch_core.c b/src/switch_core.c index f0a68e0f3c..e8652002e9 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -2683,11 +2683,18 @@ static void core_event_handler(switch_event_t *event) sql = buf; break; case SWITCH_EVENT_SHUTDOWN: - snprintf(buf, sizeof(buf), "delete from channels"); + snprintf(buf, sizeof(buf), "delete from channels;delete from interfaces;delete from calls"); sql = buf; break; case SWITCH_EVENT_LOG: return; + case SWITCH_EVENT_MODULE_LOAD: + snprintf(buf, sizeof(buf), "insert into interfaces (type,name) values('%s','%s')", + switch_event_get_header(event, "type"), + switch_event_get_header(event, "name") + ); + sql = buf; + break; default: //buf[0] = '\0'; //switch_event_serialize(event, buf, sizeof(buf), NULL); @@ -2795,12 +2802,19 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(char *console) " callee_chan_name VARCHAR(255),\n" " callee_uuid VARCHAR(255)\n" ");\n"; + char create_interfaces_sql[] = + "CREATE TABLE interfaces (\n" + " type VARCHAR(255),\n" + " name VARCHAR(255)\n" + ");\n"; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Opening DB\n"); switch_core_db_exec(runtime.db, "drop table channels", NULL, NULL, NULL); switch_core_db_exec(runtime.db, "drop table calls", NULL, NULL, NULL); + switch_core_db_exec(runtime.db, "drop table interfaces", NULL, NULL, NULL); switch_core_db_exec(runtime.db, create_channels_sql, NULL, NULL, NULL); switch_core_db_exec(runtime.db, create_calls_sql, NULL, NULL, NULL); + switch_core_db_exec(runtime.db, create_interfaces_sql, NULL, NULL, NULL); if (switch_event_bind("core_db", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL) != SWITCH_STATUS_SUCCESS) { diff --git a/src/switch_event.c b/src/switch_event.c index 29fb7a08b0..f3cb34e4ac 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -110,6 +110,7 @@ static char *EVENT_NAMES[] = { "TALK", "NOTALK", "SESSION_CRASH", + "MODULE_LOAD", "ALL" }; diff --git a/src/switch_loadable_module.c b/src/switch_loadable_module.c index 325c5e7142..13acfed54e 100644 --- a/src/switch_loadable_module.c +++ b/src/switch_loadable_module.c @@ -89,7 +89,7 @@ static void *switch_loadable_module_exec(switch_thread_t *thread, void *obj) static switch_status_t switch_loadable_module_process(char *key, switch_loadable_module_t *new_module) { - + switch_event_t *event; switch_core_hash_insert(loadable_modules.module_hash, key, new_module); @@ -113,7 +113,11 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable ptr->interface_name, impl->samples_per_second, impl->microseconds_per_frame / 1000); } - + if (switch_event_create(&event, SWITCH_EVENT_MODULE_LOAD) == SWITCH_STATUS_SUCCESS) { + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "type", "codec"); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "name", "%s", ptr->interface_name); + switch_event_fire(&event); + } switch_core_hash_insert(loadable_modules.codec_hash, (char *) ptr->iananame, (void *) ptr); } } @@ -123,6 +127,11 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable for (ptr = new_module->module_interface->dialplan_interface; ptr; ptr = ptr->next) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding Dialplan '%s'\n", ptr->interface_name); + if (switch_event_create(&event, SWITCH_EVENT_MODULE_LOAD) == SWITCH_STATUS_SUCCESS) { + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "type", "dialplan"); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "name", "%s", ptr->interface_name); + switch_event_fire(&event); + } switch_core_hash_insert(loadable_modules.dialplan_hash, (char *) ptr->interface_name, (void *) ptr); } } @@ -132,6 +141,11 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable for (ptr = new_module->module_interface->timer_interface; ptr; ptr = ptr->next) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding Timer '%s'\n", ptr->interface_name); + if (switch_event_create(&event, SWITCH_EVENT_MODULE_LOAD) == SWITCH_STATUS_SUCCESS) { + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "type", "timer"); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "name", "%s", ptr->interface_name); + switch_event_fire(&event); + } switch_core_hash_insert(loadable_modules.timer_hash, (char *) ptr->interface_name, (void *) ptr); } } @@ -141,6 +155,11 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable for (ptr = new_module->module_interface->application_interface; ptr; ptr = ptr->next) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding Application '%s'\n", ptr->interface_name); + if (switch_event_create(&event, SWITCH_EVENT_MODULE_LOAD) == SWITCH_STATUS_SUCCESS) { + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "type", "application"); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "name", "%s", ptr->interface_name); + switch_event_fire(&event); + } switch_core_hash_insert(loadable_modules.application_hash, (char *) ptr->interface_name, (void *) ptr); } @@ -151,6 +170,11 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable for (ptr = new_module->module_interface->api_interface; ptr; ptr = ptr->next) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding API Function '%s'\n", ptr->interface_name); + if (switch_event_create(&event, SWITCH_EVENT_MODULE_LOAD) == SWITCH_STATUS_SUCCESS) { + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "type", "api"); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "name", "%s", ptr->interface_name); + switch_event_fire(&event); + } switch_core_hash_insert(loadable_modules.api_hash, (char *) ptr->interface_name, (void *) ptr); } } @@ -162,6 +186,11 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable int i; for (i = 0; ptr->extens[i]; i++) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding File Format '%s'\n", ptr->extens[i]); + if (switch_event_create(&event, SWITCH_EVENT_MODULE_LOAD) == SWITCH_STATUS_SUCCESS) { + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "type", "file"); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "name", "%s", ptr->interface_name); + switch_event_fire(&event); + } switch_core_hash_insert(loadable_modules.file_hash, (char *) ptr->extens[i], (void *) ptr); } } @@ -172,6 +201,11 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable for (ptr = new_module->module_interface->speech_interface; ptr; ptr = ptr->next) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding Speech interface '%s'\n", ptr->interface_name); + if (switch_event_create(&event, SWITCH_EVENT_MODULE_LOAD) == SWITCH_STATUS_SUCCESS) { + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "type", "speech"); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "name", "%s", ptr->interface_name); + switch_event_fire(&event); + } switch_core_hash_insert(loadable_modules.speech_hash, (char *) ptr->interface_name, (void *) ptr); } } @@ -181,6 +215,11 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable for (ptr = new_module->module_interface->directory_interface; ptr; ptr = ptr->next) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding Directory interface '%s'\n", ptr->interface_name); + if (switch_event_create(&event, SWITCH_EVENT_MODULE_LOAD) == SWITCH_STATUS_SUCCESS) { + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "type", "directory"); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "name", "%s", ptr->interface_name); + switch_event_fire(&event); + } switch_core_hash_insert(loadable_modules.directory_hash, (char *) ptr->interface_name, (void *) ptr); } }