diff options
author | Michael J. Chudobiak <mjc@avtechpulse.com> | 2012-09-04 09:11:44 -0400 |
---|---|---|
committer | Michael J. Chudobiak <mjc@avtechpulse.com> | 2012-09-04 09:11:44 -0400 |
commit | 39d501c681b65b27e3bfebdb37517637429ea9c9 (patch) | |
tree | fd398af857cd32b65de6df63feaadb54db2a1f2d | |
parent | c8044753779bcf3bf2090e09465e47606db3de6f (diff) |
added message broadcasts
-rw-r--r-- | instr-daemon.c | 80 | ||||
-rw-r--r-- | lcd.c | 2 | ||||
-rw-r--r-- | menus.c | 2 | ||||
-rw-r--r-- | parser.c | 6 |
4 files changed, 23 insertions, 67 deletions
diff --git a/instr-daemon.c b/instr-daemon.c index 01d83c3..24315f7 100644 --- a/instr-daemon.c +++ b/instr-daemon.c @@ -23,74 +23,28 @@ GAsyncQueue** stdinQueue=NULL; GThread **peers; //actual connected peers -//GIOChannel callback for stdin -static gboolean -stdinAvailable (GIOChannel *source, GIOCondition condition, gpointer data) +void send_message(gchar* message) { - static char* buffer=NULL; - static gint64 allocated=0; - - //temporary buffer to read from stdin - char tmp[STDIN_BUF_SIZE]; - memset(tmp,0,STDIN_BUF_SIZE); - - int size = read(0, tmp, STDIN_BUF_SIZE); - if(size<=0) { - return TRUE; + if(NULL == message) { + return; + } + int count=0; + gssize size = strlen(message); + if(!size) { + return; } - //fix for \n or \r sending - if(size ==1) - if(tmp[0] == '\r' || tmp[0] == '\n') { - return TRUE; - } - - //the termination characters - if(!strncmp(tmp, "..", size-1)) { - //final reallocation of the buffer to accomodate the whole string - buffer=realloc(buffer,allocated+1); - if(buffer==NULL) { - g_printerr("realloc FAILED! Exiting!"); - exit(-1); - } - buffer[allocated] = '\0'; - - g_print_debug("Got the buffer: \"%s\", tid: %p\n", buffer, g_thread_self()); - - if (tmp[0] == '.' && tmp[1] == '.') { //fix for single dot sending - int count=0; - - //send the final buffer to the queue - for(count=0; count<maxConn; count++) { - //allocate on the heap and deallocate in response.c, cbClientOutput() - char *toSend = realloc(NULL, allocated+1); - memcpy(toSend, buffer, allocated+1); - - //make sure we send to only valid peers - if(peers[count] != 0) { - g_async_queue_push(stdinQueue[count], toSend); - } - } + //send the final buffer to the queue + for(count=0; count<maxConn; count++) { + //allocate on the heap and deallocate in response.c, cbClientOutput() + char *toSend = realloc(NULL, size+1); + memcpy(toSend, message, size+1); - //free the buffer - free(buffer); - buffer=NULL; - allocated=0; - return TRUE; + //make sure we send to only valid peers + if(peers[count] != 0) { + g_async_queue_push(stdinQueue[count], toSend); } } - - //allocate on the heap. buffer is NULL the first time - buffer=realloc(buffer, allocated+size); - if(buffer==NULL) { - g_printerr("realloc FAILED! Exiting!"); - exit(-1); - } - memcpy(buffer+allocated, tmp, size); - allocated += size; //keep track of allocation - - - return TRUE; } /** pulls an integer position from the vector which contains the @@ -297,7 +251,7 @@ int main(int argc, char **argv) g_printerr("No io channel\n"); exit(-1); } - g_io_add_watch(stdinChannel, G_IO_IN, stdinAvailable, NULL); + int idx=0; //allocate a maxConn queue on the heap @@ -205,7 +205,7 @@ void LCD_write_padded_spaces(int row, int col, char *LCD_string, int width) padded = g_strdup_printf ("%s%*s", LCD_string, width - in_len, ""); } - LCD_write(row, col, padded); + LCD_write(row, col, padded); g_free (padded); } @@ -2461,7 +2461,7 @@ static void Submenu_Service_Encoder(int encoder_change) /* isolate the exponent and non-exponent parts */ gchar *expon = g_strdup (num_string+5); - + num_string[5]=0; /* remove the decimal */ @@ -21,6 +21,8 @@ END DESCRIPTION **********************************************************/ #include <glib/gprintf.h> +extern void send_message(gchar* message); + //STATICS static int query_int (gchar** response, int n); static int query_min_max_float (gchar** response, char *parameter, float min_val, float max_val); @@ -4194,14 +4196,14 @@ static int Go_broadcast_103(gchar** response, int channel, char *parameter,char switch (command_type) { case command_withparam: broadcast_str = g_strdup_printf ("broadcast msg: %s\r\n> ", parameter); - g_printf ("%s", broadcast_str); + send_message(broadcast_str); g_free (broadcast_str); return OK; break; case command_param_units: broadcast_str = g_strdup_printf ("broadcast msg: %s %s\r\n> ", parameter, units); - g_printf ("%s", broadcast_str); + send_message(broadcast_str); g_free (broadcast_str); return OK; break; |