diff options
author | Michael J. Chudobiak <mjc@avtechpulse.com> | 2012-08-13 20:30:19 -0400 |
---|---|---|
committer | Michael J. Chudobiak <mjc@avtechpulse.com> | 2012-08-13 20:30:19 -0400 |
commit | 8abcec2ec0de2cb1344e780775a92ed7cb3b71ec (patch) | |
tree | 684a11b9135f7e7fa0767482b6e60a0209cbe654 | |
parent | a89f9159b155f04daddd51b6cf1a7d021af67ba2 (diff) |
separate main output and error responses
-rw-r--r-- | dummy_functions.c | 2 | ||||
-rw-r--r-- | dummy_functions.h | 2 | ||||
-rw-r--r-- | parser.c | 32 | ||||
-rw-r--r-- | parser.h | 2 | ||||
-rw-r--r-- | response.c | 8 |
5 files changed, 20 insertions, 26 deletions
diff --git a/dummy_functions.c b/dummy_functions.c index 71b4e83..16564e8 100644 --- a/dummy_functions.c +++ b/dummy_functions.c @@ -9,7 +9,7 @@ void GPIB_Set_Execution_Error() {} void Main_update_shift_registers() { } void IO_output_to_comm_bus(char* w, int n) { } //replace with real function void Error_check(void* p) { } -int query_int(char* resp, int n) +int query_int(char** resp, int n) { return 0; } diff --git a/dummy_functions.h b/dummy_functions.h index 9990ec7..d10e62b 100644 --- a/dummy_functions.h +++ b/dummy_functions.h @@ -10,6 +10,6 @@ void GPIB_Set_Execution_Error(); void Main_update_shift_registers(); void IO_output_to_comm_bus(char* w, int n); void Error_check(void*); -int query_int(char* resp, int n); +int query_int(char** resp, int n); #endif @@ -26,7 +26,7 @@ static int Handle_Units(float *mult,char *units, char *base); static int Is_Min_Command(char *text);
static int Is_Max_Command(char *text);
static int Go_syst_err_11(gchar** response, int channel, char *parameter,char *units,int command_type);
-static int Go_syst_errcnt66(gchar* response, int channel, char *parameter,char *units,int command_type);
+static int Go_syst_errcnt66(gchar** response, int channel, char *parameter,char *units,int command_type);
static int Parser_id_word(char *id_me, int *channel, int *with_id_code)
{
@@ -528,7 +528,7 @@ static int Parser_get_unit(char *parameter,char *units) return units_present;
}
-void Parser_main (char *in, gchar** response, int allow_unrequested_responses)
+void Parser_main (char *in, int allow_unrequested_responses, void(*cbfunc)(gpointer, gchar *), gpointer user_data)
{
int in_pos; /* this identifies the single character of in being processed */
int command_depth; /* how many command words have been parsed */
@@ -550,7 +550,6 @@ void Parser_main (char *in, gchar** response, int allow_unrequested_responses) int compound_message; /* this indicates that at least one semicolon has been found, so */
/* the message is a compound one */
-// char response[max_output_length];
int is_query;
int command_type; /* combination of is_query, parameter_found, and units_found */
@@ -684,7 +683,8 @@ void Parser_main (char *in, gchar** response, int allow_unrequested_responses) /* add end of tokens marker (0) */
int error_num=OK;
- response[0]=0;
+ gchar *response = NULL;
+ gchar *error_response = NULL;
if (parameter_found) {
units_found = Parser_get_unit(parameter,units);
@@ -715,18 +715,18 @@ void Parser_main (char *in, gchar** response, int allow_unrequested_responses) switch (routine_num) {
case 0:
- *response = g_strdup_printf("routine_num: %d, channel: %d, parameter: %s, units: %s, command type: %d\n\r",routine_num,channel,parameter,units,command_type);
+ response = g_strdup_printf("routine_num: %d, channel: %d, parameter: %s, units: %s, command type: %d\n\r",routine_num,channel,parameter,units,command_type);
error_num=Unrecognized;
break;
case 11:
- error_num=Go_syst_err_11(response,channel,parameter,units,command_type);
+ error_num=Go_syst_err_11(&response,channel,parameter,units,command_type);
break;
case 32:
case 33:
- error_num=Go_freq_32_33(response,channel,parameter,units,command_type);
+ error_num=Go_freq_32_33(&response,channel,parameter,units,command_type);
break;
case 66:
- error_num=Go_syst_errcnt66(*response,channel,parameter,units,command_type);
+ error_num=Go_syst_errcnt66(&response,channel,parameter,units,command_type);
break;
case 9999:
@@ -735,24 +735,24 @@ void Parser_main (char *in, gchar** response, int allow_unrequested_responses) default:
/* valid but not implemented yet */
- *response = g_strdup_printf("routine_num: %d, channel: %d, parameter: %s, units: %s, command type: %d\n\r",routine_num,channel,parameter,units,command_type);
+ response = g_strdup_printf("routine_num: %d, channel: %d, parameter: %s, units: %s, command type: %d\n\r",routine_num,channel,parameter,units,command_type);
break;
}
}
- // FIXME
if (error_num) {
- g_free (*response);
- *response = NULL;
- queue_error_from_parser(response, error_num);
+ queue_error_from_parser(&error_response, error_num);
if (allow_unrequested_responses) {
- ; // SEND ERROR RESPONSE TO CLIENT NOW!
+ (*cbfunc)(user_data, error_response);
}
} else {
- ; // SEND RESPONSE TO CLIENT NOW!
+ (*cbfunc)(user_data, response);
}
+ g_free (response);
+ g_free (error_response);
+
if (!is_query) {
Main_update_shift_registers(); /* update values in pulse generator circuit */
}
@@ -1024,7 +1024,7 @@ static int Go_syst_err_11(gchar** response, int channel, char *parameter,char *u }
}
-static int Go_syst_errcnt66(gchar* response, int channel, char *parameter,char *units,int command_type)
+static int Go_syst_errcnt66(gchar** response, int channel, char *parameter,char *units,int command_type)
{
switch (command_type) {
case query_simple:
@@ -29,6 +29,6 @@ #define USE_ON_OFF 0 #define NO_ON_OFF 1 -void Parser_main (char *in, gchar** response, int allow_unrequested_responses); +void Parser_main (char *in, int allow_unrequested_responses, void(*cbfunc)(gpointer, gchar *), gpointer user_data); #endif @@ -136,9 +136,6 @@ void responseCb(gpointer instance, GObject *arg1, gpointer user_data) GPollableOutputStream* stream = (GPollableOutputStream*)data->outStream; gchar* str = data->data; - - gchar* out = NULL; - g_strstrip(str); // I2C/LCD test functions - start @@ -148,10 +145,7 @@ void responseCb(gpointer instance, GObject *arg1, gpointer user_data) // I2C/LCD test functions - stop // FIXME - Parser_main may generate multiple responses - Parser_main(str, &out, 1); - - data->cb(stream, out); + Parser_main(str, 1, data->cb, stream); - g_free(out); g_static_mutex_unlock (&mutex); } |