speechd-discuss
[Top][All Lists]
Advanced

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

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


From: Christopher Brannon
Subject: [PATCH] move loading of modules out of the AddModule call back
Date: Sun, 28 Nov 2010 16:41:43 +0000

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

Modified by Christopher Brannon: move all code which manipulates the
list of requested modules into module.c.  Code outside of module.c has
no access to the list.
The list is externally managed by two functions:
module_add_load_request and module_load_requested_modules.
---
 src/server/configuration.c |   37 ++++++++---------------------
 src/server/module.c        |   55 ++++++++++++++++++++++++++++++++++++++++++++
 src/server/module.h        |    4 +++
 src/server/speechd.c       |    4 +++
 4 files changed, 73 insertions(+), 27 deletions(-)

diff --git a/src/server/configuration.c b/src/server/configuration.c
index 6306015..6ebe125 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"
@@ -275,35 +277,16 @@ DOTCONF_CB(cb_CustomLogFile)
 
 DOTCONF_CB(cb_AddModule)
 {
-    char *module_name;
-    char *module_prgname;
-    char *module_cfgfile;
-    char *module_dbgfile;
-
-    OutputModule *cur_mod;
-
-    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);
-
-    g_free(module_dbgfile);
-    g_free(module_name);
+    module_add_load_request(g_strdup(cmd->data.list[0]),
+                           g_strdup(cmd->data.list[1]),
+                           g_strdup(cmd->data.list[2]),
+                           g_strdup_printf("%s/%s.log", SpeechdOptions.log_dir,
+                                           cmd->data.list[0]));
 
     return NULL;
 }
diff --git a/src/server/module.c b/src/server/module.c
index 78cb4c6..7e9d23e 100644
--- a/src/server/module.c
+++ b/src/server/module.c
@@ -339,3 +339,58 @@ output_module_nodebug(OutputModule *module)
     
     return 0;
 }
+
+static GList *requested_modules = NULL;
+
+/*
+ * module_add_load_request - request that a module be loaded.
+ * In other words, add it to the list of modules which will be loaded
+ * by module_load_requested_modules.
+ * Returns: nothing.
+ * Parameters:
+ * module_name: the name of the module.
+ * module_cmd: name of the binary associated with this module.
+ * module_cfgfile: the name of the module's configuration file.
+ * module_dbgfile: name of the file to which the module writes logging
+ * and debugging information.
+ * Note that all parameters are dynamically-allocated strings (char *),
+ * and the caller relinquishes ownership of them when calling this function.
+ */
+void
+module_add_load_request(char *module_name, char *module_cmd,
+                       char *module_cfgfile, char *module_dbgfile) {
+    char **module_params = g_malloc(4 * sizeof(char *));
+    module_params[0] = module_name;
+    module_params[1] = module_cmd;
+    module_params[2] = module_cfgfile;
+    module_params[3] = module_dbgfile;
+    requested_modules = g_list_append(requested_modules, module_params);
+    MSG(5,"Module name=%s being inserted into requested_modules list", 
module_params[0]);
+}
+
+/*
+ * module_load_requested_modules: load all modules requested by calls
+ * to module_add_load_request.
+ * Returns: nothing.
+ * Parameters: none.
+ */
+void
+module_load_requested_modules(void) {
+    while(NULL != requested_modules){
+        OutputModule *new_module;
+        char ** module_params = requested_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);
+        requested_modules = g_list_delete_link(requested_modules, 
requested_modules);
+    }
+}
diff --git a/src/server/module.h b/src/server/module.h
index b7b5813..cd2024d 100644
--- a/src/server/module.h
+++ b/src/server/module.h
@@ -50,5 +50,9 @@ int output_module_debug(OutputModule *module);
 int output_module_nodebug(OutputModule *module);                      
 void destroy_module(OutputModule *module);
 
+void module_add_load_request(char *module_name, char *module_cmd,
+                        char *module_cfgfile, char *module_dbgfile);
+void module_load_requested_modules(void);
+
 #endif
 
diff --git a/src/server/speechd.c b/src/server/speechd.c
index 73dfec9..e0e6c94 100644
--- a/src/server/speechd.c
+++ b/src/server/speechd.c
@@ -685,6 +685,10 @@ speechd_load_configuration(int sig)
       if (dotconf_command_loop(configfile) == 0) DIE("Error reading config 
file\n");
       dotconf_cleanup(configfile);
       MSG(2,"Configuration has been read from \"%s\"", 
SpeechdOptions.conf_file);
+
+      /* We need to load modules here, since this is called both by 
speechd_init
+       * and to handle SIGHUP. */
+      module_load_requested_modules();
     }else{
       MSG(1, "Can't open %s", SpeechdOptions.conf_file);
     }
-- 
1.7.3.2




reply via email to

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