diff options
author | root <root@fedora-arm.domain.avtechpulse.com> | 1999-12-31 19:49:19 -0500 |
---|---|---|
committer | root <root@fedora-arm.domain.avtechpulse.com> | 1999-12-31 19:49:19 -0500 |
commit | 3702b14f594c86af91e063e8b1403e7bfd982bfe (patch) | |
tree | caec2c51f56121cd201141003cfb851f9108303b /response.c | |
parent | dcbb634ee0093999b5316a579728969e8bdb1852 (diff) |
initial parser re-implementation
Diffstat (limited to 'response.c')
-rw-r--r-- | response.c | 101 |
1 files changed, 60 insertions, 41 deletions
@@ -2,6 +2,7 @@ #include "socket-common.h" #include "lcd.h" #include "i2c.h" +#include "parser.h" #include <string.h> #include <stdlib.h> #include <glib.h> @@ -57,14 +58,23 @@ gboolean cbClientInput(gpointer data, gpointer additional) GPollableInputStream* inStream = (GPollableInputStream*)data; GPollableOutputStream* outStream = (GPollableOutputStream*)additional; - - size=g_pollable_input_stream_read_nonblocking(inStream, buffer, 1024, NULL, NULL); - if(size == -1) { + GError* error = NULL; + + if(!g_pollable_input_stream_is_readable(inStream)) { return FALSE; } + size=g_pollable_input_stream_read_nonblocking(inStream, buffer, 1024, NULL, &error); + + if(error && error->message) + { + g_print_debug("Error: %s\n",error->message); + return FALSE; + } + + if(size <= 0) { g_print_debug("Got: %d\n", size); return FALSE; } - //emit a signal which calls the responseCb function + //emit a signal which calls the echoCb function SignalObjectClass myStruct; myStruct.instance = NULL; myStruct.cb = writeOutput; @@ -86,48 +96,57 @@ static gssize writeOutput(GPollableOutputStream* stream, gchar* data, gssize siz //initialize the signals void initSignals(guint *signal) { - *signal = g_signal_new("runEchoService", SIGNAL_OBJECT_TYPE, G_SIGNAL_RUN_FIRST, 0, NULL, NULL, + *signal = g_signal_new("runService", SIGNAL_OBJECT_TYPE, G_SIGNAL_RUN_FIRST, 0, NULL, NULL, g_cclosure_marshal_VOID__POINTER , G_TYPE_NONE, 1, G_TYPE_POINTER); signalObject = g_object_new(SIGNAL_OBJECT_TYPE, NULL); - g_signal_connect (signalObject, "runEchoService", G_CALLBACK (responseCb), NULL); + g_signal_connect (signalObject, "runService", G_CALLBACK (responseCb), NULL); } -//send to client 3 times +//parse message and send to client void responseCb(gpointer instance, GObject *arg1, gpointer user_data) { - static GStaticMutex mutex = G_STATIC_MUTEX_INIT; - g_static_mutex_lock (&mutex); - SignalObjectClass *data = (SignalObjectClass*)arg1; - GPollableOutputStream* stream = (GPollableOutputStream*)data->outStream; - gchar* str = data->data; - gssize len = data->size; - gssize written = 0; - - // remove leading and trailing whitespace - g_strstrip (str); - - // I2C/LCD test function - LCD_display_error_message(str); - - guchar status = 0; // delete me, later - FIXME - // I2C test code - I2C_Write (PCF8574A + Upper_Encoder_Port, 0xff); - status = I2C_Read (PCF8574A + Upper_Encoder_Port); - - // dummy response function - gchar* upper = g_ascii_strup(str, len); - gchar *out_string = g_strdup_printf("%s\n%s\n%s\n%x\n",upper,upper,upper,status); - gssize out_len = strlen (out_string); - - //send response back to client - written = data->cb(stream, out_string, out_len); - if(written == -1) { - g_print_debug("Could not send message to client\n"); - } - - g_free(upper); - g_free(out_string); - - g_static_mutex_unlock (&mutex); + static GStaticMutex mutex = G_STATIC_MUTEX_INIT; + g_static_mutex_lock (&mutex); + SignalObjectClass *data = (SignalObjectClass*)arg1; + GPollableOutputStream* stream = (GPollableOutputStream*)data->outStream; + gchar* str = data->data; + + gssize written = 0; + int errors=OK; + + gchar* out = NULL; + + g_strstrip(str); + + // I2C/LCD test functions - start + guchar status = I2C_Read (PCF8574A + Upper_Encoder_Port); + gchar *lcd_str = g_strdup_printf ("%s %x",str,status); + LCD_display_error_message(lcd_str); + // I2C/LCD test functions - stop + + Parser_main(str, &out, 1, &errors); + + if(errors) { + + } + + if(out==NULL) out=g_strdup(" "); + + if(!strlen(out)) { + strcpy(out, " "); + } + + if(out[strlen(out)-1] != '\n' && out[strlen(out)-1] != '\r') { + strcat(out, "\n"); + } + + written = data->cb(stream, out, strlen(out)); + if (written == -1) { + g_print("Could not send message to client\n"); + } + + g_free(out); + + g_static_mutex_unlock (&mutex); } |