summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael J. Chudobiak <mjc@avtechpulse.com>2012-09-04 09:11:44 -0400
committerMichael J. Chudobiak <mjc@avtechpulse.com>2012-09-04 09:11:44 -0400
commit39d501c681b65b27e3bfebdb37517637429ea9c9 (patch)
treefd398af857cd32b65de6df63feaadb54db2a1f2d
parentc8044753779bcf3bf2090e09465e47606db3de6f (diff)
added message broadcasts
-rw-r--r--instr-daemon.c80
-rw-r--r--lcd.c2
-rw-r--r--menus.c2
-rw-r--r--parser.c6
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
diff --git a/lcd.c b/lcd.c
index bedb844..42e7e2a 100644
--- a/lcd.c
+++ b/lcd.c
@@ -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);
}
diff --git a/menus.c b/menus.c
index f7ce069..6407d2b 100644
--- a/menus.c
+++ b/menus.c
@@ -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 */
diff --git a/parser.c b/parser.c
index c1b1fd9..ef1d43a 100644
--- a/parser.c
+++ b/parser.c
@@ -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;