speechd-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/2] move loading of modules out of the AddModule call back


From: Andrei Kholodnyi
Subject: [PATCH 1/2] move loading of modules out of the AddModule call back
Date: Fri, 26 Nov 2010 23:21:17 +0100

From: Trevor Saunders <address@hidden>
To: address@hidden

We know use the AddModule call back to create a list of modules we want
to try and load.  Then after parsing the config file we try to load all
the modules.

Modified-by: Andrei Kholodnyi <Andrei.Kholodnyi at gmail.com>
in AddModule cb create a list of AddModule char entries instead
of OutputModules, since it will be created my load_output_module

add function get_added_modules to return such a list
---
 src/server/configuration.c |   44 +++++++++++++++++++-------------------------
 src/server/configuration.h |    3 +++
 src/server/speechd.c       |   23 ++++++++++++++++++++++-
 3 files changed, 44 insertions(+), 26 deletions(-)

diff --git a/src/server/configuration.c b/src/server/configuration.c
index 6306015..7bf5dbf 100644
--- a/src/server/configuration.c
+++ b/src/server/configuration.c
@@ -26,6 +26,8 @@
 #include <config.h>
 #endif
 
+#include <glib.h>
+
 #include <dotconf.h>
 
 #include "speechd.h"
@@ -33,6 +35,7 @@
 #include <fdsetconv.h>
 
 static TFDSetClientSpecific *cl_spec_section;
+static GList *added_modules;
 
 /* So that gcc doesn't comply about casts to char* */
 
@@ -275,35 +278,22 @@ DOTCONF_CB(cb_CustomLogFile)
 
 DOTCONF_CB(cb_AddModule)
 {
-    char *module_name;
-    char *module_prgname;
-    char *module_cfgfile;
-    char *module_dbgfile;
-
-    OutputModule *cur_mod;
+    char **module_params;
 
-    if (cmd->data.list[0] != NULL) module_name = g_strdup(cmd->data.list[0]);
-    else FATAL("No output module name specified in configuration under 
AddModule");
-
-    module_prgname = cmd->data.list[1];
-    module_cfgfile = cmd->data.list[2];
-   
-    module_dbgfile = g_strdup_printf("%s/%s.log", SpeechdOptions.log_dir,
-                                    module_name);
-
-    cur_mod = load_output_module(module_name, module_prgname, module_cfgfile,
-                                module_dbgfile);
-    if (cur_mod == NULL){
-        MSG(3, "Couldn't load specified output module");
-        return NULL;
+    if (cmd->data.list[0] == NULL) {
+       MSG(3, "No output module name specified in configuration under 
AddModule");
+       return NULL;
     }
 
-    assert(cur_mod->name != NULL);
-    output_modules = g_list_append(output_modules, cur_mod);
-    MSG(5,"Module name=%s being inserted into modules list", cur_mod->name);
+    module_params = g_malloc(4 * sizeof(char *));
+    module_params[0] = g_strdup(cmd->data.list[0]);
+    module_params[1] = g_strdup(cmd->data.list[1]);
+    module_params[2] = g_strdup(cmd->data.list[2]);
+    module_params[3] = g_strdup_printf("%s/%s.log", SpeechdOptions.log_dir,
+                                       module_params[0]);
 
-    g_free(module_dbgfile);
-    g_free(module_name);
+    added_modules = g_list_append(added_modules, module_params);
+    MSG(5,"Module name=%s being inserted into added_modules list", 
module_params[0]);
 
     return NULL;
 }
@@ -484,3 +474,7 @@ load_default_global_set_options()
     logfile = stderr;
     custom_logfile = NULL;    
 }
+
+GList * get_added_modules(void) {
+    return added_modules;
+}
\ No newline at end of file
diff --git a/src/server/configuration.h b/src/server/configuration.h
index 84f6989..7c7a2f1 100644
--- a/src/server/configuration.h
+++ b/src/server/configuration.h
@@ -27,6 +27,7 @@
 
 #include <stdlib.h>
 #include <dotconf.h>
+#include <glib.h>
 
 #define SPEECHD_DEFAULT_PORT 6560
 
@@ -43,4 +44,6 @@ add_config_option(configoption_t *options, int 
*num_config_options, char *name,
 
 void load_default_global_set_options();
 
+GList * get_added_modules(void);
+
 #endif
diff --git a/src/server/speechd.c b/src/server/speechd.c
index 73dfec9..a605d0a 100644
--- a/src/server/speechd.c
+++ b/src/server/speechd.c
@@ -563,7 +563,8 @@ void
 speechd_init()
 {
     int ret;
-    
+    GList *modules;
+
     SpeechdStatus.max_uid = 0;
     SpeechdStatus.max_gid = 0;
 
@@ -640,6 +641,26 @@ speechd_init()
 
     logging_init();
 
+    modules = get_added_modules();
+
+    while(NULL != modules){
+        OutputModule *new_module;
+        char ** module_params = modules->data;
+
+        new_module = load_output_module(module_params[0], module_params[1],
+                                        module_params[2], module_params[3]);
+
+        if(new_module != NULL)
+            output_modules = g_list_append(output_modules, new_module);
+
+        g_free(module_params[0]);
+        g_free(module_params[1]);
+        g_free(module_params[2]);
+        g_free(module_params[3]);
+        g_free(module_params);
+        modules = g_list_delete_link(modules, modules);
+    }
+
     /* Check for output modules */
     if (g_list_length(output_modules) == 0){
         DIE("No speech output modules were loaded - aborting...");
-- 
1.6.0.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]