[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/4] replace int priority with SPDPriority
From: |
Andrei Kholodnyi |
Subject: |
[PATCH 4/4] replace int priority with SPDPriority |
Date: |
Tue, 26 Oct 2010 22:31:06 +0200 |
replace internal int priority with public SPDPriority enum
moved SPDPriority declaration from libspeechd.h to speechd_types.h
to make it available for internal modules
---
include/fdsetconv.h | 2 +-
include/speechd_types.h | 8 ++++
src/api/c/libspeechd.h | 8 ----
src/common/fdsetconv.c | 14 +++---
src/server/configuration.c | 4 +-
src/server/parse.c | 12 +++---
src/server/server.c | 10 ++--
src/server/set.c | 8 ++--
src/server/set.h | 6 +-
src/server/speaking.c | 99 ++++++++++++++++++++++----------------------
src/server/speaking.h | 12 +++---
src/server/speechd.h | 2 +-
12 files changed, 93 insertions(+), 92 deletions(-)
diff --git a/include/fdsetconv.h b/include/fdsetconv.h
index bfe49a4..1d7f250 100644
--- a/include/fdsetconv.h
+++ b/include/fdsetconv.h
@@ -21,6 +21,6 @@ char* ECapLetRecogn2str(SPDCapitalLetters recogn);
SPDCapitalLetters str2ECapLetRecogn(char* str);
-int str2intpriority(char* str);
+SPDPriority str2intpriority(char* str);
#endif
diff --git a/include/speechd_types.h b/include/speechd_types.h
index 5efd9b9..90b0090 100644
--- a/include/speechd_types.h
+++ b/include/speechd_types.h
@@ -64,6 +64,14 @@ typedef enum{
} SPDDataMode;
typedef enum {
+ SPD_IMPORTANT = 1,
+ SPD_MESSAGE = 2,
+ SPD_TEXT = 3,
+ SPD_NOTIFICATION = 4,
+ SPD_PROGRESS = 5
+} SPDPriority;
+
+typedef enum {
SPD_BEGIN = 1,
SPD_END = 2,
SPD_INDEX_MARKS = 4,
diff --git a/src/api/c/libspeechd.h b/src/api/c/libspeechd.h
index 001b32e..89decae 100644
--- a/src/api/c/libspeechd.h
+++ b/src/api/c/libspeechd.h
@@ -51,14 +51,6 @@ extern "C" {
/* --------------------- Public data types ------------------------ */
typedef enum{
- SPD_IMPORTANT = 1,
- SPD_MESSAGE = 2,
- SPD_TEXT = 3,
- SPD_NOTIFICATION = 4,
- SPD_PROGRESS = 5
-}SPDPriority;
-
-typedef enum{
SPD_MODE_SINGLE = 0,
SPD_MODE_THREADED = 1
}SPDConnectionMode;
diff --git a/src/common/fdsetconv.c b/src/common/fdsetconv.c
index 34a03a2..62659ec 100644
--- a/src/common/fdsetconv.c
+++ b/src/common/fdsetconv.c
@@ -154,16 +154,16 @@ str2ECapLetRecogn(char* str)
}
-int
+SPDPriority
str2intpriority(char* str)
{
- int priority;
+ SPDPriority priority;
- if (!strcmp(str, "important")) priority = 1;
- else if (!strcmp(str, "message")) priority = 2;
- else if (!strcmp(str, "text")) priority = 3;
- else if (!strcmp(str, "notification")) priority = 4;
- else if (!strcmp(str, "progress")) priority = 5;
+ if (!strcmp(str, "important")) priority = SPD_IMPORTANT;
+ else if (!strcmp(str, "message")) priority = SPD_MESSAGE;
+ else if (!strcmp(str, "text")) priority = SPD_TEXT;
+ else if (!strcmp(str, "notification")) priority = SPD_NOTIFICATION;
+ else if (!strcmp(str, "progress")) priority = SPD_PROGRESS;
else priority = -1;
return priority;
diff --git a/src/server/configuration.c b/src/server/configuration.c
index c734e01..262dfe8 100644
--- a/src/server/configuration.c
+++ b/src/server/configuration.c
@@ -187,7 +187,7 @@ GLOBAL_FDSET_OPTION_CB_INT(DefaultVolume, volume,
(val>=-100)&&(val<=+100), "Vol
GLOBAL_FDSET_OPTION_CB_INT(DefaultSpelling, spelling_mode, 1, "Invalid
spelling mode")
GLOBAL_FDSET_OPTION_CB_INT(DefaultPauseContext, pause_context, 1, "")
-GLOBAL_FDSET_OPTION_CB_SPECIAL(DefaultPriority, priority, int, str2intpriority)
+GLOBAL_FDSET_OPTION_CB_SPECIAL(DefaultPriority, priority, SPDPriority,
str2intpriority)
GLOBAL_FDSET_OPTION_CB_SPECIAL(DefaultVoiceType, voice, SPDVoiceType,
str2EVoice)
GLOBAL_FDSET_OPTION_CB_SPECIAL(DefaultPunctuationMode, punctuation_mode,
SPDPunctuation, str2EPunctMode)
GLOBAL_FDSET_OPTION_CB_SPECIAL(DefaultCapLetRecognition, cap_let_recogn,
SPDCapitalLetters, str2ECapLetRecogn)
@@ -439,7 +439,7 @@ load_config_options(int *num_options)
void
load_default_global_set_options()
{
- GlobalFDSet.priority = 2;
+ GlobalFDSet.priority = SPD_MESSAGE;
GlobalFDSet.punctuation_mode = SPD_PUNCT_NONE;
GlobalFDSet.spelling_mode = 0;
GlobalFDSet.rate = 0;
diff --git a/src/server/parse.c b/src/server/parse.c
index 9ce3c48..2f26089 100644
--- a/src/server/parse.c
+++ b/src/server/parse.c
@@ -411,18 +411,18 @@ parse_set(const char *buf, const int bytes, const int fd,
const TSpeechDSock *sp
if (TEST_CMD(set_sub, "priority")){
char *priority_s;
- int priority;
+ SPDPriority priority;
NOT_ALLOWED_INSIDE_BLOCK();
/* Setting priority only allowed for "self" */
if (who != 0) return g_strdup(ERR_COULDNT_SET_PRIORITY);
GET_PARAM_STR(priority_s, 3, CONV_DOWN);
- if (TEST_CMD(priority_s, "important")) priority = 1;
- else if (TEST_CMD(priority_s, "message")) priority = 2;
- else if (TEST_CMD(priority_s, "text")) priority = 3;
- else if (TEST_CMD(priority_s, "notification")) priority = 4;
- else if (TEST_CMD(priority_s, "progress")) priority = 5;
+ if (TEST_CMD(priority_s, "important")) priority = SPD_IMPORTANT;
+ else if (TEST_CMD(priority_s, "message")) priority = SPD_MESSAGE;
+ else if (TEST_CMD(priority_s, "text")) priority = SPD_TEXT;
+ else if (TEST_CMD(priority_s, "notification")) priority =
SPD_NOTIFICATION;
+ else if (TEST_CMD(priority_s, "progress")) priority = SPD_PROGRESS;
else{
g_free(priority_s);
return g_strdup(ERR_UNKNOWN_PRIORITY);
diff --git a/src/server/server.c b/src/server/server.c
index c235553..e542ed6 100644
--- a/src/server/server.c
+++ b/src/server/server.c
@@ -156,15 +156,15 @@ queue_message(TSpeechDMessage *new, int fd, int
history_flag,
/* Put the element new to queue according to it's priority. */
check_locked(&element_free_mutex);
switch(settings->priority){
- case 1: MessageQueue->p1 = g_list_append(MessageQueue->p1, new);
+ case SPD_IMPORTANT: MessageQueue->p1 = g_list_append(MessageQueue->p1,
new);
break;
- case 2: MessageQueue->p2 = g_list_append(MessageQueue->p2, new);
+ case SPD_MESSAGE: MessageQueue->p2 = g_list_append(MessageQueue->p2, new);
break;
- case 3: MessageQueue->p3 = g_list_append(MessageQueue->p3, new);
+ case SPD_TEXT: MessageQueue->p3 = g_list_append(MessageQueue->p3, new);
break;
- case 4: MessageQueue->p4 = g_list_append(MessageQueue->p4, new);
+ case SPD_NOTIFICATION: MessageQueue->p4 = g_list_append(MessageQueue->p4,
new);
break;
- case 5: MessageQueue->p5 = g_list_append(MessageQueue->p5, new);
+ case SPD_PROGRESS: MessageQueue->p5 = g_list_append(MessageQueue->p5, new);
//clear last_p5_block if we get new block or no block message
element = g_list_last(last_p5_block);
if (!element || !element->data
diff --git a/src/server/set.c b/src/server/set.c
index 3bf0672..ae511da 100644
--- a/src/server/set.c
+++ b/src/server/set.c
@@ -40,7 +40,7 @@ spd_str_compare(gconstpointer a, gconstpointer b)
}
int
-set_priority_self(int fd, int priority)
+set_priority_self(int fd, SPDPriority priority)
{
int uid;
int ret;
@@ -53,14 +53,14 @@ set_priority_self(int fd, int priority)
}
int
-set_priority_uid(int uid, int priority)
+set_priority_uid(int uid, SPDPriority priority)
{
TFDSetElement *settings;
- if ((priority < 0) || (priority > 5)) return 1;
+ if ((priority < SPD_IMPORTANT) || (priority > SPD_PROGRESS)) return 1;
settings = get_client_settings_by_uid(uid);
if (settings == NULL) return 1;
- set_param_int(&settings->priority, priority);
+ settings->priority = priority;
return 0;
}
diff --git a/src/server/set.h b/src/server/set.h
index e93aa1a..0333ed4 100644
--- a/src/server/set.h
+++ b/src/server/set.h
@@ -33,7 +33,7 @@ TFDSetElement* get_client_settings_by_fd(int fd);
void remove_client_settings_by_uid(int uid);
int get_client_uid_by_fd(int fd);
-int set_priority_uid(int uid, int priority);
+int set_priority_uid(int uid, SPDPriority priority);
int set_language_uid(int uid, char *language);
int set_rate_uid(int uid, int rate);
int set_pitch_uid(int uid, int pitch);
@@ -53,7 +53,7 @@ int set_debug_uid(int uid, int debug);
int set_debug_destination_uid(int uid, char *debug_destination);
-int set_priority_self(int fd, int priority);
+int set_priority_self(int fd, SPDPriority priority);
int set_language_self(int fd, char *language);
int set_rate_self(int fd, int rate);
int set_pitch_self(int fd, int pitch);
@@ -73,7 +73,7 @@ int set_pause_context_self(int fd, int pause_context);
int set_debug_self(int fd, int debug);
int set_debug_destination_self(int fd, char *debug_destination);
-int set_priority_all(int priority);
+int set_priority_all(SPDPriority priority);
int set_language_all(char *language);
int set_rate_all(int rate);
int set_pitch_all(int pitch);
diff --git a/src/server/speaking.c b/src/server/speaking.c
index 87b6b4c..150bbc6 100644
--- a/src/server/speaking.c
+++ b/src/server/speaking.c
@@ -41,7 +41,7 @@
#include "sem_functions.h"
TSpeechDMessage *current_message = NULL;
-static int highest_priority = 0;
+static SPDPriority highest_priority = 0;
int SPEAKING = 0;
int poll_count;
@@ -160,10 +160,10 @@ speak(void* data)
g_list_free1(item);
}
assert(message!=NULL);
- highest_priority = 2;
- stop_priority_older_than(3, message->id);
- stop_priority(4);
- stop_priority(5);
+ highest_priority = SPD_MESSAGE;
+ stop_priority_older_than(SPD_TEXT, message->id);
+ stop_priority(SPD_NOTIFICATION);
+ stop_priority(SPD_PROGRESS);
check_locked(&element_free_mutex);
pthread_mutex_unlock(&element_free_mutex);
speaking_semaphore_post();
@@ -436,11 +436,11 @@ speaking_cancel_all()
{
output_stop();
pthread_mutex_lock(&element_free_mutex);
- stop_priority(1);
- stop_priority(2);
- stop_priority(3);
- stop_priority(4);
- stop_priority(5);
+ stop_priority(SPD_IMPORTANT);
+ stop_priority(SPD_MESSAGE);
+ stop_priority(SPD_TEXT);
+ stop_priority(SPD_NOTIFICATION);
+ stop_priority(SPD_PROGRESS);
pthread_mutex_unlock(&element_free_mutex);
}
@@ -744,7 +744,7 @@ empty_queue_by_time(GList *queue, unsigned int uid)
}
int
-stop_priority(int priority)
+stop_priority(SPDPriority priority)
{
GList *queue;
@@ -762,7 +762,7 @@ stop_priority(int priority)
}
int
-stop_priority_older_than(int priority, unsigned int uid)
+stop_priority_older_than(SPDPriority priority, unsigned int uid)
{
GList *queue;
@@ -843,7 +843,7 @@ set_speak_thread_attributes()
}
void
-stop_priority_except_first(int priority)
+stop_priority_except_first(SPDPriority priority)
{
GList *queue;
GList *gl;
@@ -893,37 +893,38 @@ stop_priority_except_first(int priority)
}
void
-resolve_priorities(int priority)
+resolve_priorities(SPDPriority priority)
{
- if(priority == 1){
- if (SPEAKING && highest_priority != 1)
+ if(priority == SPD_IMPORTANT){
+ if (SPEAKING && highest_priority != SPD_IMPORTANT)
output_stop();
- stop_priority(4);
- stop_priority(5);
+ stop_priority(SPD_NOTIFICATION);
+ stop_priority(SPD_PROGRESS);
}
- if(priority == 2){
- if (SPEAKING && highest_priority != 1 && highest_priority != 2)
+ if(priority == SPD_MESSAGE){
+ if (SPEAKING && highest_priority != SPD_IMPORTANT
+ && highest_priority != SPD_MESSAGE)
output_stop();
- stop_priority(3);
- stop_priority(4);
- stop_priority(5);
+ stop_priority(SPD_TEXT);
+ stop_priority(SPD_NOTIFICATION);
+ stop_priority(SPD_PROGRESS);
}
- if(priority == 3){
- stop_priority_except_first(3);
- stop_priority(4);
- stop_priority(5);
+ if(priority == SPD_TEXT){
+ stop_priority_except_first(SPD_TEXT);
+ stop_priority(SPD_NOTIFICATION);
+ stop_priority(SPD_PROGRESS);
}
- if(priority == 4){
- stop_priority_except_first(4);
- if (SPEAKING && highest_priority != 4)
- stop_priority(4);
+ if(priority == SPD_NOTIFICATION){
+ stop_priority_except_first(SPD_NOTIFICATION);
+ if (SPEAKING && highest_priority != SPD_NOTIFICATION)
+ stop_priority(SPD_NOTIFICATION);
}
- if(priority == 5){
- stop_priority(4);
+ if(priority == SPD_PROGRESS){
+ stop_priority(SPD_NOTIFICATION);
if (SPEAKING){
GList *gl;
check_locked(&element_free_mutex);
@@ -946,12 +947,12 @@ TSpeechDMessage*
get_message_from_queues()
{
GList *gl;
- int prio;
+ SPDPriority prio;
TSpeechDMessage * message;
/* We will descend through priorities to say more important
messages first. */
- for (prio = 1; prio <= 5; prio++) {
+ for (prio = SPD_IMPORTANT; prio <= SPD_PROGRESS; prio++) {
GList *current_queue = speaking_get_queue(prio);
check_locked(&element_free_mutex);
gl = g_list_first(current_queue);
@@ -997,36 +998,36 @@ client_has_messages(int uid){
}
GList*
-speaking_get_queue(int priority)
+speaking_get_queue(SPDPriority priority)
{
GList *queue = NULL;
- assert(priority > 0 && priority <= 5);
+ assert(priority >= SPD_IMPORTANT && priority <= SPD_PROGRESS);
check_locked(&element_free_mutex);
switch(priority){
- case 1: queue = MessageQueue->p1; break;
- case 2: queue = MessageQueue->p2; break;
- case 3: queue = MessageQueue->p3; break;
- case 4: queue = MessageQueue->p4; break;
- case 5: queue = MessageQueue->p5; break;
+ case SPD_IMPORTANT: queue = MessageQueue->p1; break;
+ case SPD_MESSAGE: queue = MessageQueue->p2; break;
+ case SPD_TEXT: queue = MessageQueue->p3; break;
+ case SPD_NOTIFICATION: queue = MessageQueue->p4; break;
+ case SPD_PROGRESS: queue = MessageQueue->p5; break;
}
return queue;
}
void
-speaking_set_queue(int priority, GList *queue)
+speaking_set_queue(SPDPriority priority, GList *queue)
{
- assert(priority > 0 && priority <= 5);
+ assert(priority >= SPD_IMPORTANT && priority <= SPD_PROGRESS);
check_locked(&element_free_mutex);
switch(priority){
- case 1: MessageQueue->p1 = queue; break;
- case 2: MessageQueue->p2 = queue; break;
- case 3: MessageQueue->p3 = queue; break;
- case 4: MessageQueue->p4 = queue; break;
- case 5: MessageQueue->p5 = queue; break;
+ case SPD_IMPORTANT: MessageQueue->p1 = queue; break;
+ case SPD_MESSAGE: MessageQueue->p2 = queue; break;
+ case SPD_TEXT: MessageQueue->p3 = queue; break;
+ case SPD_NOTIFICATION: MessageQueue->p4 = queue; break;
+ case SPD_PROGRESS: MessageQueue->p5 = queue; break;
}
}
diff --git a/src/server/speaking.h b/src/server/speaking.h
index 6951142..ebf6cf1 100644
--- a/src/server/speaking.h
+++ b/src/server/speaking.h
@@ -70,7 +70,7 @@ int is_sb_speaking();
/* Stops speaking and cancels currently spoken message.*/
void stop_speaking_active_module();
-int stop_priority(int priority);
+int stop_priority(SPDPriority priority);
void stop_from_uid(int uid);
@@ -80,12 +80,12 @@ gint message_nto_speak (gconstpointer, gconstpointer);
void set_speak_thread_attributes();
/* Do priority interaction */
-void resolve_priorities(int priority);
+void resolve_priorities(SPDPriority priority);
/* Queue interaction helper functions */
TSpeechDMessage* get_message_from_queues();
-GList* speaking_get_queue(int priority);
-void speaking_set_queue(int priority, GList *queue);
+GList* speaking_get_queue(SPDPriority priority);
+void speaking_set_queue(SPDPriority priority, GList *queue);
gint sortbyuid (gconstpointer a, gconstpointer b);
int client_has_messages(int uid);
@@ -104,8 +104,8 @@ int report_cancel (TSpeechDMessage *msg);
GList* empty_queue(GList *queue);
GList* empty_queue_by_time(GList *queue, unsigned int uid);
-int stop_priority_older_than(int priority, unsigned int uid);
+int stop_priority_older_than(SPDPriority priority, unsigned int uid);
GList* stop_priority_from_uid(GList *queue, const int uid);
-void stop_priority_except_first(int priority);
+void stop_priority_except_first(SPDPriority priority);
#endif /* SPEAKING_H */
diff --git a/src/server/speechd.h b/src/server/speechd.h
index c1fbc83..8aeb7ed 100644
--- a/src/server/speechd.h
+++ b/src/server/speechd.h
@@ -80,7 +80,7 @@ typedef struct{
int paused_while_speaking;
EMessageType type; /* Type of the message (1=text, 2=icon,
3=char, 4=key) */
SPDDataMode ssml_mode; /* SSML mode on (1)/off (0) */
- int priority; /* Priority between 1 and 3 (1 - highest, 3 -
lowest) */
+ SPDPriority priority; /* Priority between 1 and 5 (1 - highest, 5 -
lowest) */
signed int rate; /* Speed of voice from <-100;+100>, 0 is the
default */
signed int pitch; /* Pitch of voice from <-100;+100>, 0 is the
default */
signed int volume; /* Volume of voice from <-100;+100), 0 is the
default */
--
1.6.0.4