]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add interfaces to sqlite db table for quick show api commands (coming soon)
authorMichael Jerris <mike@jerris.com>
Mon, 1 May 2006 19:44:21 +0000 (19:44 +0000)
committerMichael Jerris <mike@jerris.com>
Mon, 1 May 2006 19:44:21 +0000 (19:44 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1313 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_types.h
src/switch_core.c
src/switch_event.c
src/switch_loadable_module.c

index ad4f06ee85ddf84885190aafc0104019619ac4dd..86f84e5a8a89f9dbed5fe64e66a17ad7fefd2914 100644 (file)
@@ -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;
 
index f0a68e0f3cdfb9b42b363a3dabbfa5fe8efb031c..e8652002e9cae6b8da2aa10dfe6c7334edae70d2 100644 (file)
@@ -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) {
index 29fb7a08b0dad0623d8d63e26fe0a1ed7bf21e88..f3cb34e4ac419051936459dcd47cec54b4a72c7c 100644 (file)
@@ -110,6 +110,7 @@ static char *EVENT_NAMES[] = {
        "TALK",
        "NOTALK",
        "SESSION_CRASH",
+       "MODULE_LOAD",
        "ALL"
 };
 
index 325c5e7142c91f7a8c8f576ac069860f33697cd4..13acfed54eb4175de744d428807a553e3d166ffa 100644 (file)
@@ -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);
                }
        }