[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/3] move loading of modules out of the AddModule call back
From: |
Trevor Saunders |
Subject: |
[PATCH 2/3] move loading of modules out of the AddModule call back |
Date: |
Thu, 18 Nov 2010 06:40:12 -0500 |
We know use the AddModule call back to create a list of modules we wnat
to try and load. Then after parsing the config file we try to load all
the modules.
---
src/server/configuration.c | 32 ++++++++++++--------------------
src/server/configuration.h | 6 ++++++
src/server/module.c | 15 ++++-----------
src/server/speechd.c | 21 ++++++++++++++++++++-
4 files changed, 42 insertions(+), 32 deletions(-)
diff --git a/src/server/configuration.c b/src/server/configuration.c
index 6306015..6b260c0 100644
--- a/src/server/configuration.c
+++ b/src/server/configuration.c
@@ -275,35 +275,27 @@ DOTCONF_CB(cb_CustomLogFile)
DOTCONF_CB(cb_AddModule)
{
+ OutputModule *module = g_malloc(sizeof(OutputModule));
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){
+ module->name = g_strdup(cmd->data.list[0]);
+ }else{
+ 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->filename = g_strdup_printf("%s/%s", MODULEBINDIR,
cmd->data.list[1]);
+ module->configfilename = g_strdup_printf("%s/modules/%s",
SpeechdOptions.conf_dir, cmd->data.list[2]);
+ module->debugfilename = g_strdup_printf("%s/%s.log",
SpeechdOptions.log_dir,
+ module->name);
- g_free(module_dbgfile);
- g_free(module_name);
+ loadable_modules = g_list_append(loadable_modules, module);
+ MSG(5,"Module name=%s being inserted into modules list", module->name);
return NULL;
}
diff --git a/src/server/configuration.h b/src/server/configuration.h
index 84f6989..862fa11 100644
--- a/src/server/configuration.h
+++ b/src/server/configuration.h
@@ -28,8 +28,12 @@
#include <stdlib.h>
#include <dotconf.h>
+#include"speechd.h"
+
#define SPEECHD_DEFAULT_PORT 6560
+extern GList *loadable_modules;
+
/* Loading options from DotConf */
configoption_t *spd_options;
int spd_num_options;
@@ -43,4 +47,6 @@ add_config_option(configoption_t *options, int
*num_config_options, char *name,
void load_default_global_set_options();
+GList *detect_modules(void);
+
#endif
diff --git a/src/server/module.c b/src/server/module.c
index 78cb4c6..5e8f516 100644
--- a/src/server/module.c
+++ b/src/server/module.c
@@ -62,18 +62,11 @@ load_output_module(char* mod_name, char* mod_prog, char*
mod_cfgfile, char* mod_
module = (OutputModule*) g_malloc(sizeof(OutputModule));
- module->name = (char*) g_strdup(mod_name);
- module->filename = (char*) spd_get_path(mod_prog, MODULEBINDIR);
+ module->name = g_strdup(mod_name);
+ module->filename = g_strdup(mod_prog);
+ module->configfilename = g_strdup(mod_cfgfile);
+ module->debugfilename = g_strdup(mod_dbgfile);
- module_conf_dir = g_strdup_printf("%s/modules/",
- SpeechdOptions.conf_dir);
-
- module->configfilename = (char*) spd_get_path(mod_cfgfile,
module_conf_dir);
- g_free(module_conf_dir);
-
- if (mod_dbgfile != NULL) module->debugfilename = g_strdup(mod_dbgfile);
- else module->debugfilename = NULL;
-
if (!strcmp(mod_name, "testing")){
module->pipe_in[1] = 1; /* redirect to stdin */
module->pipe_out[0] = 0; /* redirect to stdout */
diff --git a/src/server/speechd.c b/src/server/speechd.c
index 73dfec9..95cf570 100644
--- a/src/server/speechd.c
+++ b/src/server/speechd.c
@@ -49,7 +49,10 @@
#include <i18n.h>
/* list of output modules */
-GList *output_modules;
+GList *output_modules = NULL;
+
+/* list of moduels to load */
+GList *loadable_modules = NULL;
/* Manipulating pid files */
int create_pid_file();
@@ -689,6 +692,22 @@ speechd_load_configuration(int sig)
MSG(1, "Can't open %s", SpeechdOptions.conf_file);
}
+ while(NULL != loadable_modules){
+ OutputModule *new_module = NULL, *to_load = loadable_modules->data;
+
+ new_module = load_output_module(to_load->name, to_load->filename,
to_load->configfilename, to_load->debugfilename);
+
+ if(new_module != NULL)
+ output_modules = g_list_append(output_modules, new_module);
+
+ g_free(to_load->name);
+ g_free(to_load->filename);
+ g_free(to_load->configfilename);
+ g_free(to_load->debugfilename);
+ g_free(to_load);
+ loadable_modules = g_list_delete_link(loadable_modules,
loadable_modules);
+ }
+
free_config_options(spd_options, &spd_num_options);
}
--
1.7.2.3
- rfc module autodetection patch set, Trevor Saunders, 2010/11/18
- [PATCH 1/3] output_modules should be declared in a c file not a header, Trevor Saunders, 2010/11/18
- [PATCH 2/3] move loading of modules out of the AddModule call back,
Trevor Saunders <=
- [PATCH 2/3] move loading of modules out of the AddModule call back, Andrei Kholodnyi, 2010/11/18
- [PATCH 2/3] move loading of modules out of the AddModule call back, Christopher Brannon, 2010/11/19
- [PATCH 2/3] move loading of modules out of the AddModule call back, Andrei . Kholodnyi, 2010/11/19
- [PATCH 2/3] move loading of modules out of the AddModule call back, Andrei Kholodnyi, 2010/11/26
- [PATCH 2/3] move loading of modules out of the AddModule call back, Christopher Brannon, 2010/11/27
- [PATCH 2/3] move loading of modules out of the AddModule call back, Christopher Brannon, 2010/11/28
- [PATCH 2/3] move loading of modules out of the AddModule call back, Andrei Kholodnyi, 2010/11/28
[PATCH 3/3] add an initial module detection algorithm, Trevor Saunders, 2010/11/18
rfc module autodetection patch set, Christopher Brannon, 2010/11/18