speechd-discuss
[Top][All Lists]
Advanced

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

[PATCH 2/2] remove output_modules_list


From: Andrei Kholodnyi
Subject: [PATCH 2/2] remove output_modules_list
Date: Thu, 11 Nov 2010 22:28:48 +0100

output_modules_list kept ouput module names
and was duplicated with output_modules hash table.
Now everywhere output_modules is used instead
---
 src/server/configuration.c |    1 -
 src/server/output.c        |   33 ++++++++++++++-------------------
 src/server/parse.c         |   19 ++++++++-----------
 src/server/speechd.c       |    1 -
 src/server/speechd.h       |    2 +-
 5 files changed, 23 insertions(+), 33 deletions(-)

diff --git a/src/server/configuration.c b/src/server/configuration.c
index 0bb2092..7612b8c 100644
--- a/src/server/configuration.c
+++ b/src/server/configuration.c
@@ -301,7 +301,6 @@ DOTCONF_CB(cb_AddModule)
     MSG(5,"Module name=%s being inserted into hash table", cur_mod->name);
     assert(cur_mod->name != NULL);
     g_hash_table_insert(output_modules, g_strdup(module_name), cur_mod);
-    output_modules_list=g_list_append(output_modules_list, 
g_strdup(module_name));
 
     g_free(module_dbgfile);
     g_free(module_name);
diff --git a/src/server/output.c b/src/server/output.c
index be3f886..bb7f8ea 100644
--- a/src/server/output.c
+++ b/src/server/output.c
@@ -106,7 +106,8 @@ OutputModule*
 get_output_module(const TSpeechDMessage *message)
 {
   OutputModule *output = NULL;
-  GList *cur_ptr = output_modules_list;
+  GList *gl;
+  int i, len;
 
   if (message->settings.output_module != NULL){
     MSG(5, "Desired output module is %s", message->settings.output_module);
@@ -124,24 +125,18 @@ get_output_module(const TSpeechDMessage *message)
 
   MSG(3, "Couldn't load default output module, trying other modules");
 
-  // Try all other output modules now to see if some of them
-  // is working
-  while(cur_ptr){
-    if (!cur_ptr->data){
-      MSG(2, "bad (NULL) module in output module list");
-      cur_ptr = cur_ptr->next;
-       continue;
-    }
-
-    if (strcmp(cur_ptr->data, "dummy") != 0)
-      output = get_output_module_by_name(cur_ptr->data);
-
-    if ((output != NULL) && (output->working)){
-      MSG(3, "Output module %s seems to be working, using it", cur_ptr->data);
-      return output;
-    }
-
-    cur_ptr    = cur_ptr->next;
+  /* Try all other output modules other than dummy */
+  gl = g_hash_table_get_values(output_modules);
+  len = g_list_length(gl);
+  for (i = 0; i < len; i++) {
+      output = g_list_nth_data(gl, i);
+      if (0 == strcmp(output->name, "dummy"))
+           continue;
+
+      if (output->working) {
+          MSG(3, "Output module %s seems to be working, using it", gl->data);
+          return output;
+      }
   }
 
   // if we get here there are no good modules use the dummy
diff --git a/src/server/parse.c b/src/server/parse.c
index 7431953..8ca9848 100644
--- a/src/server/parse.c
+++ b/src/server/parse.c
@@ -834,17 +834,14 @@ parse_list(const char* buf, const int bytes, const int 
fd, const TSpeechDSock *s
     }else if(TEST_CMD(list_type, "output_modules")){
         GString *result = g_string_new("");
        char *helper;
-       GList *cur_ptr = output_modules_list;
-
-       while(cur_ptr){
-           if (cur_ptr->data != NULL){
-               g_string_append_printf(result, C_OK_MODULES"-%s\r\n", (char*) 
cur_ptr->data);
-           }else{
-                MSG(2, "null entry in output modules list");
-           }
-
-            cur_ptr = cur_ptr->next;
-        }
+       GList *gl = g_hash_table_get_keys(output_modules);
+       int i, len;
+
+       len = g_list_length(gl);
+       for (i = 0; i < len; i++) {
+           g_string_append_printf(result, C_OK_MODULES "-%s\r\n",
+           (char *)g_list_nth_data(gl, i));
+       }
 
        g_string_append(result, OK_MODULES_LIST_SENT);
        helper = result->str;
diff --git a/src/server/speechd.c b/src/server/speechd.c
index 8d36f67..e1a316e 100644
--- a/src/server/speechd.c
+++ b/src/server/speechd.c
@@ -577,7 +577,6 @@ speechd_init()
 
     /* Initialize lists */
     MessagePausedList = NULL;
-    output_modules_list = NULL;
 
     /* Initialize hash tables */
     fd_settings = g_hash_table_new_full(g_int_hash, g_int_equal,
diff --git a/src/server/speechd.h b/src/server/speechd.h
index faeedaa..08fc821 100644
--- a/src/server/speechd.h
+++ b/src/server/speechd.h
@@ -188,7 +188,7 @@ int speaking_sem_id;
 
 /* Table of all configured (and succesfully loaded) output modules */
 GHashTable *output_modules;    
-GList *output_modules_list;
+
 /* Table of settings for each active client (=each active socket)*/
 GHashTable *fd_settings;       
 /* Table of default output modules for different languages */
-- 
1.6.0.4




reply via email to

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