[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/2] add history_add_message and move GList *message_history to h
From: |
Andrei Kholodnyi |
Subject: |
[PATCH 1/2] add history_add_message and move GList *message_history to history.c |
Date: |
Thu, 11 Nov 2010 22:28:47 +0100 |
GList *message_history was declared in speechd.h
move it to history.c since it is related to history functionality and make it
static
convert a chunk of code where message_history was used into separate function
and move it to history.c
replace "if/else" statement in it with "if(error) return" statement
---
src/server/history.c | 31 +++++++++++++++++++++++++++++++
src/server/history.h | 1 +
src/server/server.c | 24 +++---------------------
src/server/speechd.c | 1 -
src/server/speechd.h | 4 ----
5 files changed, 35 insertions(+), 26 deletions(-)
diff --git a/src/server/history.c b/src/server/history.c
index 7edc2ad..c2a244b 100644
--- a/src/server/history.c
+++ b/src/server/history.c
@@ -33,6 +33,9 @@
#include "history.h"
+/* List of messages in history */
+static GList *message_history;
+
/* Compares TSpeechDMessage data structure elements
with given ID */
gint
@@ -304,6 +307,34 @@ history_say_id(int fd, int id)
return g_strdup(OK_MESSAGE_QUEUED);
}
+int history_add_message(TSpeechDMessage * msg)
+{
+ TSpeechDMessage * hist_msg;
+
+ /* We will make an exact copy of the message for inclusion into
history. */
+ hist_msg = (TSpeechDMessage*) spd_message_copy(msg);
+
+ if(hist_msg == NULL){
+ if(SPEECHD_DEBUG) FATAL("Can't include message into history\n");
+ return -1;
+ }
+
+ /* Do the necessary expiration of old messages*/
+ if (g_list_length(message_history) >=
SpeechdOptions.max_history_messages){
+ GList *gl;
+ MSG(5, "Discarding older history message, limit reached");
+ gl = g_list_first(message_history);
+ if (gl != NULL){
+ message_history = g_list_remove_link(message_history, gl);
+ if (gl->data != NULL)
+ mem_free_message(gl->data);
+ }
+ }
+ /* Save the message into history */
+ message_history = g_list_append(message_history, hist_msg);
+ return 0;
+}
+
GList*
get_messages_by_client(int uid){
GList *list = NULL;
diff --git a/src/server/history.h b/src/server/history.h
index 4703a03..0ab3243 100644
--- a/src/server/history.h
+++ b/src/server/history.h
@@ -41,6 +41,7 @@ char* history_cursor_backward(int fd);
char* history_say_id(int fd, int id);
char* history_get_client_id(int fd);
char* history_get_message(int uid);
+int history_add_message(TSpeechDMessage * msg);
/* Internal functions */
GList* get_messages_by_client(int uid);
diff --git a/src/server/server.c b/src/server/server.c
index 3dab413..38d2a71 100644
--- a/src/server/server.c
+++ b/src/server/server.c
@@ -30,6 +30,7 @@
#include "set.h"
#include "speaking.h"
#include "sem_functions.h"
+#include "history.h"
int last_message_id = 0;
@@ -68,7 +69,7 @@ queue_message(TSpeechDMessage *new, int fd, int history_flag,
SPDMessageType type, int reparted)
{
TFDSetElement *settings;
- TSpeechDMessage *hist_msg, *message_copy;
+ TSpeechDMessage *message_copy;
int id;
GList *element;
@@ -128,27 +129,8 @@ queue_message(TSpeechDMessage *new, int fd, int
history_flag,
the message before we woud copy it) */
// if (history_flag){
if (0){
- /* We will make an exact copy of the message for inclusion into
history. */
- hist_msg = (TSpeechDMessage*) spd_message_copy(new);
-
pthread_mutex_lock(&element_free_mutex);
- if(hist_msg != NULL){
- /* Do the necessary expiration of old messages*/
- if (g_list_length(message_history) >=
SpeechdOptions.max_history_messages){
- GList *gl;
- MSG(5, "Discarding older history message, limit reached");
- gl = g_list_first(message_history);
- if (gl != NULL){
- message_history = g_list_remove_link(message_history, gl);
- if (gl->data != NULL)
- mem_free_message(gl->data);
- }
- }
- /* Save the message into history */
- message_history = g_list_append(message_history, hist_msg);
- }else{
- if(SPEECHD_DEBUG) FATAL("Can't include message into history\n");
- }
+ history_add_message(new);
pthread_mutex_unlock(&element_free_mutex);
}
diff --git a/src/server/speechd.c b/src/server/speechd.c
index b4cce8a..8d36f67 100644
--- a/src/server/speechd.c
+++ b/src/server/speechd.c
@@ -577,7 +577,6 @@ speechd_init()
/* Initialize lists */
MessagePausedList = NULL;
- message_history = NULL;
output_modules_list = NULL;
/* Initialize hash tables */
diff --git a/src/server/speechd.h b/src/server/speechd.h
index 078e701..faeedaa 100644
--- a/src/server/speechd.h
+++ b/src/server/speechd.h
@@ -200,10 +200,6 @@ GHashTable *fd_uid;
TSpeechDQueue *MessageQueue;
/* List of messages from paused clients waiting for resume */
GList *MessagePausedList;
-/* List of settings related to history */
-GList *history_settings;
-/* List of messages in history */
-GList *message_history;
/* List of different entries of client-specific configuration */
GList *client_specific_settings;
--
1.6.0.4