[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/2] add an initial module detection algorithm
From: |
Andrei Kholodnyi |
Subject: |
[PATCH 2/2] add an initial module detection algorithm |
Date: |
Fri, 26 Nov 2010 23:21:18 +0100 |
From: Trevor Saunders <address@hidden>
To: address@hidden
we simply walk through the list of files in MODULEBINDIR, and use the
files name to get the paths for that module.
Modified-by: Andrei Kholodnyi <Andrei.Kholodnyi at gmail.com>
move module detect function in module.c
in detect function create a list of char entries instead of
OutputModule list, since it will be created my load_output_module
put added_modules from conf and detected modules in one list and load them
comment all AddModule directives in the conf file, instead of removing them
---
config/speechd.conf | 6 +++---
src/server/module.c | 34 +++++++++++++++++++++++++++++++++-
src/server/module.h | 3 +++
src/server/speechd.c | 3 ++-
4 files changed, 41 insertions(+), 5 deletions(-)
diff --git a/config/speechd.conf b/config/speechd.conf
index a230785..3b19569 100644
--- a/config/speechd.conf
+++ b/config/speechd.conf
@@ -206,8 +206,8 @@ DefaultVolume 100
# - configuration is the path to the config file of this module,
# either relative (to etc/speech-dispatcher/modules/) or absolute
-AddModule "espeak" "sd_espeak" "espeak.conf"
-AddModule "festival" "sd_festival" "festival.conf"
+#AddModule "espeak" "sd_espeak" "espeak.conf"
+#AddModule "festival" "sd_festival" "festival.conf"
#AddModule "flite" "sd_flite" "flite.conf"
#AddModule "ivona" "sd_ivona" "ivona.conf"
#AddModule "pico" "sd_pico" "pico.conf"
@@ -222,7 +222,7 @@ AddModule "festival" "sd_festival" "festival.conf"
# DO NOT REMOVE the following line unless you have
# a specific reason -- this is the fallback output module
# that is only used when no other modules are in use
-AddModule "dummy" "sd_dummy" ""
+#AddModule "dummy" "sd_dummy" ""
# The output module testing doesn't actually connect to anything. It
# outputs the requested commands to standard output and reads
diff --git a/src/server/module.c b/src/server/module.c
index 78cb4c6..912d976 100644
--- a/src/server/module.c
+++ b/src/server/module.c
@@ -29,10 +29,13 @@
#include <sys/wait.h>
#include <sys/stat.h>
#include <stdio.h>
+#include <dirent.h>
+#include <glib.h>
+
#include "speechd.h"
#include <spd_utils.h>
#include "output.h"
-
+#include "module.h"
void
destroy_module(OutputModule *module)
@@ -43,6 +46,35 @@ destroy_module(OutputModule *module)
g_free(module);
}
+GList * detect_output_modules(char *dirname)
+{
+ DIR *module_dir = opendir(dirname);
+ struct dirent *entry;
+ char **module_params;
+ GList *detected_modules = NULL;
+
+ if(module_dir == NULL){
+ MSG(3, "couldn't open directory %s because of error %s\n", dirname,
strerror(errno));
+ return NULL;
+ }
+
+ while(NULL != (entry = readdir(module_dir))){
+ module_params = g_malloc(4 * sizeof(char *));
+
+ module_params[0] = g_strdup(entry->d_name+3);
+ module_params[1] = g_strdup(entry->d_name);
+ module_params[2] = g_strdup_printf("%s.conf", module_params[0]);
+ module_params[3] = g_strdup_printf("%s/%s.log", SpeechdOptions.log_dir,
+ module_params[0]);
+
+ detected_modules = g_list_append(detected_modules, module_params);
+ MSG(5,"Module name=%s being inserted into detected_modules list",
module_params[0]);
+ }
+
+ closedir(module_dir);
+ return (detected_modules);
+}
+
OutputModule*
load_output_module(char* mod_name, char* mod_prog, char* mod_cfgfile, char*
mod_dbgfile)
{
diff --git a/src/server/module.h b/src/server/module.h
index b7b5813..48110f3 100644
--- a/src/server/module.h
+++ b/src/server/module.h
@@ -28,6 +28,8 @@
#include <stdlib.h>
#include <glib.h>
+#include <speechd_types.h>
+
typedef struct{
char* name;
char* filename;
@@ -42,6 +44,7 @@ typedef struct{
SPDVoice **voices;
}OutputModule;
+GList * detect_output_modules(char *dirname);
OutputModule* load_output_module(char* mod_name, char* mod_prog,
char* mod_cfgfile, char * mod_dbgfile);
int unload_output_module(OutputModule *module);
diff --git a/src/server/speechd.c b/src/server/speechd.c
index a605d0a..5d16af5 100644
--- a/src/server/speechd.c
+++ b/src/server/speechd.c
@@ -641,7 +641,8 @@ speechd_init()
logging_init();
- modules = get_added_modules();
+ modules = detect_output_modules(MODULEBINDIR);
+ modules = g_list_concat(modules, get_added_modules());
while(NULL != modules){
OutputModule *new_module;
--
1.6.0.4