speechd-discuss
[Top][All Lists]
Advanced

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

[PATCH 2/5] modules - Receive and set log level from speechd server


From: Luke Yelavich
Subject: [PATCH 2/5] modules - Receive and set log level from speechd server
Date: Tue, 23 Jun 2009 16:54:37 +1000

From: Luke Yelavich <address@hidden>
To: address@hidden

Receive the log level value sent from the speechd server, and set the
appropriate variable.
---
 ChangeLog                  |    9 +++++++
 src/modules/module_main.c  |    1 +
 src/modules/module_utils.c |   52 ++++++++++++++++++++++++++++++++++++++++++++
 src/modules/module_utils.h |    3 ++
 4 files changed, 65 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2f2af09..a00ce71 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,15 @@
 
        * src/server/output.c (output_send_loglevel_setting): Fix typo.
 
+       * src/modules/module_utils.c:
+         - Add new macro SET_LOGLEVEL_NUM to set the log level variable for
+           speech modules.
+         - Add new function do_loglevel, to retrieve and call the above
+           mentioned macro to set the log level.
+
+       * src/modules/module_main.c (main): Add a call to do_loglevel to set
+       the log level for the module.
+
 2009-06-22  Luke Yelavich <luke.yelavich at canonical.com>
 
        * src/server/output.c: Add output_send_loglevel_setting function
diff --git a/src/modules/module_main.c b/src/modules/module_main.c
index d40fe0b..3c3ca36 100644
--- a/src/modules/module_main.c
+++ b/src/modules/module_main.c
@@ -153,6 +153,7 @@ main(int argc, char *argv[])
         else PROCESS_CMD(LIST VOICES, do_list_voices)
         else PROCESS_CMD(SET, do_set) 
         else PROCESS_CMD(AUDIO, do_audio) 
+        else PROCESS_CMD(LOGLEVEL, do_loglevel)
        else PROCESS_CMD_W_ARGS(DEBUG, do_debug)
         else PROCESS_CMD_NRP(QUIT, do_quit) 
         else{
diff --git a/src/modules/module_utils.c b/src/modules/module_utils.c
index 5eaa3a1..184994b 100644
--- a/src/modules/module_utils.c
+++ b/src/modules/module_utils.c
@@ -301,6 +301,58 @@ do_audio(void)
     return msg;
 }
 
+#define SET_LOGLEVEL_NUM(name, cond) \
+ if(!strcmp(cur_item, #name)){ \
+     number = strtol(cur_value, &tptr, 10); \
+     if(!(cond)){ err = 2; continue; } \
+     if (tptr == cur_value){ err = 2; continue; } \
+     log_level = number; \
+ }
+
+char*
+do_loglevel(void)
+{
+    char *cur_item = NULL;
+    char *cur_value = NULL;
+    char *line = NULL;
+    int ret;
+    size_t n;
+    int number; char *tptr;
+    int err = 0;                /* Error status */
+    char *status;
+    char *msg;
+
+    printf("207 OK RECEIVING LOGLEVEL SETTINGS\n");
+    fflush(stdout);
+
+    while(1){
+        line = NULL; n = 0;
+        ret = getline(&line, &n, stdin);
+        if (ret == -1){ err=1; break; }
+        if (!strcmp(line, ".\n")){
+            xfree(line);
+            break;
+        }
+        if (!err){
+            cur_item = strtok(line, "=");
+            if (cur_item == NULL){ err=1; continue; }
+            cur_value = strtok(NULL, "\n");
+            if (cur_value == NULL){ err=1; continue; }
+
+            SET_LOGLEVEL_NUM(log_level, 1)
+            else err=2;             /* Unknown parameter */
+        }
+        xfree(line);
+    }
+
+    if (err == 1) return strdup("302 ERROR BAD SYNTAX");
+    if (err == 2) return strdup("303 ERROR INVALID PARAMETER OR VALUE");
+
+    msg = g_strdup_printf("203 OK LOG LEVEL SET");
+
+    return msg;
+}
+
 char*
 do_debug(char* cmd_buf)
 {
diff --git a/src/modules/module_utils.h b/src/modules/module_utils.h
index e33865a..3e4e75e 100644
--- a/src/modules/module_utils.h
+++ b/src/modules/module_utils.h
@@ -58,6 +58,8 @@ typedef struct{
   int audio_pulse_min_request;
 }SPDAudioSettings;
 
+int log_level;
+
 AudioID *module_audio_id;
 AudioOutputType module_audio_output_method;
 char* module_audio_pars[10];
@@ -215,6 +217,7 @@ void  do_pause(void);
 char* do_list_voices(void);
 char* do_set(void);
 char* do_audio(void);
+char* do_loglevel(void);
 char* do_debug(char *cmd_buf);
 void do_quit(void);
 
-- 
1.6.3.1




reply via email to

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