Reporting patch.

This commit is contained in:
robijn
2001-11-29 14:09:13 +00:00
parent 3dc439e2c4
commit 285d29edf3
23 changed files with 534 additions and 477 deletions
+5 -2
View File
@@ -52,8 +52,11 @@ Bind=127.0.0.1
Port=13666 Port=13666
# Listen on this specified port; defaults to 13666. # Listen on this specified port; defaults to 13666.
#Debug=5 #ReportLevel=3
# Sets the debugging level; defaults to 0 (no debugging output). # Sets the reporting level; defaults to 2 (warnings and errors only).
#ReportToSyslog=yes
# Should we report to syslog instead of stderr ? Default: no
WaitTime=5 WaitTime=5
# Sets the default time in seconds to displays a screen. # Sets the default time in seconds to displays a screen.
+2
View File
@@ -66,6 +66,8 @@
/* Define the protocol version */ /* Define the protocol version */
#undef PROTOCOL_VERSION #undef PROTOCOL_VERSION
#undef API_VERSION
#undef SLI_DRV #undef SLI_DRV
#undef SOLARIS #undef SOLARIS
+2
View File
@@ -109,6 +109,8 @@ AC_DEFINE_UNQUOTED(LCDPORT, $LCDPORT)
AC_DEFINE_UNQUOTED(PROTOCOL_VERSION, "0.3") AC_DEFINE_UNQUOTED(PROTOCOL_VERSION, "0.3")
AC_DEFINE_UNQUOTED(API_VERSION, "0.4")
AC_ARG_WITH(loadmax, AC_ARG_WITH(loadmax,
[ --with-loadmax=<load> Max Load Avg at which the backlight will] [ --with-loadmax=<load> Max Load Avg at which the backlight will]
+7 -7
View File
@@ -10,7 +10,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "shared/debug.h" #include "shared/report.h"
#include "client_data.h" #include "client_data.h"
#include "screen.h" #include "screen.h"
@@ -34,14 +34,14 @@ client_data_init (client_data * d)
d->screenlist = NewScreen(); d->screenlist = NewScreen();
if (!d->screenlist) { if (!d->screenlist) {
fprintf (stderr, "client_data_init: Error allocating screenlist\n"); report( RPT_ERR, "client_data_init: Error allocating screenlist");
return -1; return -1;
} }
/* TODO: this section... (client menus) /* TODO: this section... (client menus)
d->menulist = LL_new(); d->menulist = LL_new();
if(!d->menulist) if(!d->menulist)
{ {
fprintf(stderr, "client_data_init: Error allocating menulist\n"); report( RPT_ERR, "client_data_init: Error allocating menulist");
return -1; return -1;
} }
*/ */
@@ -53,7 +53,7 @@ client_data_destroy (client_data * d)
{ {
screen *s; screen *s;
debug ("client_data_destroy\n"); report( RPT_INFO, "client_data_destroy");
if (!d) if (!d)
return -1; return -1;
@@ -69,18 +69,18 @@ client_data_destroy (client_data * d)
free (d->client_keys); free (d->client_keys);
// Clean up the screenlist... // Clean up the screenlist...
debug ("client_data_destroy: Cleaning screenlist\n"); debug( RPT_DEBUG, "client_data_destroy: Cleaning screenlist");
ResetScreenList (d->screenlist); ResetScreenList (d->screenlist);
do { do {
s = NextScreen(d->screenlist); s = NextScreen(d->screenlist);
if (s) { if (s) {
debug ("client_data_destroy: removing screen %s\n", s->id); debug( RPT_DEBUG, "client_data_destroy: removing screen %s", s->id);
// FIXME? This shouldn't be handled here... // FIXME? This shouldn't be handled here...
// Now, remove it from the screenlist... // Now, remove it from the screenlist...
if (screenlist_remove_all (s) < 0) { if (screenlist_remove_all (s) < 0) {
// Not a serious error.. // Not a serious error..
fprintf (stderr, "client_data_destroy: Error dequeueing screen\n"); report( RPT_ERR, "client_data_destroy: Error dequeueing screen");
return 0; return 0;
} }
// Free its memory... // Free its memory...
+64 -69
View File
@@ -1,12 +1,12 @@
/* /*
client_functions.c client_functions.c
This contains definitions for all the functions which clients can run. This contains definitions for all the functions which clients can run.
The functions here are to be called only from parse.c's interpreter. The functions here are to be called only from parse.c's interpreter.
The client's available function set is defined here, as is the syntax The client's available function set is defined here, as is the syntax
for each command. for each command.
*/ */
#include <unistd.h> #include <unistd.h>
@@ -15,9 +15,8 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <syslog.h>
#include "shared/debug.h" #include "shared/report.h"
#include "shared/sockets.h" #include "shared/sockets.h"
#include "drivers/lcd.h" #include "drivers/lcd.h"
@@ -83,7 +82,7 @@ test_func_func (client * c, int argc, char **argv)
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
snprintf (str, sizeof(str), "test_func_func: %i -> %s\n", i, argv[i]); snprintf (str, sizeof(str), "test_func_func: %i -> %s\n", i, argv[i]);
printf (str); report (RPT_INFO, str);
sock_send_string (c->sock, str); sock_send_string (c->sock, str);
} }
return 0; return 0;
@@ -107,7 +106,7 @@ hello_func (client * c, int argc, char **argv)
sock_send_string (c->sock, "huh? extra parameters ignored\n"); sock_send_string (c->sock, "huh? extra parameters ignored\n");
} }
debug ("Hello!\n"); debug(RPT_INFO, "Hello!");
memset(str, '\0', sizeof(str)); memset(str, '\0', sizeof(str));
snprintf (str, sizeof(str), "connect LCDproc %s protocol %s lcd wid %i hgt %i cellwid %i cellhgt %i\n", snprintf (str, sizeof(str), "connect LCDproc %s protocol %s lcd wid %i hgt %i cellwid %i cellhgt %i\n",
@@ -178,9 +177,7 @@ client_set_func (client * c, int argc, char **argv)
} else { } else {
strncpy(str, argv[i], sizeof(str) - 1); strncpy(str, argv[i], sizeof(str) - 1);
debug ("client_set: name=\"%s\"\n", argv[i]); debug(RPT_DEBUG, "client_set: name=\"%s\"", argv[i]);
syslog(LOG_INFO, "client set name to %s", str);
// set the name... // set the name...
if (c->data->name) if (c->data->name)
@@ -229,7 +226,7 @@ client_add_key_func (client * c, int argc, char **argv)
} }
keys = argv[1]; keys = argv[1];
debug ("client_add_key: current client will handle key(s) %s\n", keys); debug(RPT_DEBUG, "client_add_key: current client will handle key(s) %s", keys);
if (!c->data->client_keys) { if (!c->data->client_keys) {
// No keys list, create a new one // No keys list, create a new one
@@ -287,7 +284,7 @@ client_del_key_func (client * c, int argc, char **argv)
} }
keys = argv[1] ; keys = argv[1] ;
debug ("client_del_key: Deleting key(s) %s from client_keys\n", keys); debug(RPT_DEBUG, "client_del_key: Deleting key(s) %s from client_keys", keys);
if (c->data->client_keys) { if (c->data->client_keys) {
// Client has keys, remove keys from the list // Client has keys, remove keys from the list
@@ -350,7 +347,7 @@ screen_add_key_func (client * c, int argc, char **argv)
id = argv[1]; id = argv[1];
keys = argv[2]; keys = argv[2];
debug ("screen_add_key: Adding key(s) %s to screen %s\n", keys, id); debug(RPT_DEBUG, "screen_add_key: Adding key(s) %s to screen %s", keys, id);
// Find the screen // Find the screen
s = screen_find (c, id); s = screen_find (c, id);
@@ -422,7 +419,7 @@ screen_del_key_func (client * c, int argc, char **argv)
id = argv[1] ; id = argv[1] ;
keys = argv[2] ; keys = argv[2] ;
debug ("screen_del_key: Deleting key(s) %s from screen %s\n", keys, id); debug(RPT_DEBUG, "screen_del_key: Deleting key(s) %s from screen %s", keys, id);
// Find the screen // Find the screen
s = screen_find (c, id); s = screen_find (c, id);
@@ -487,7 +484,7 @@ screen_add_func (client * c, int argc, char **argv)
return 0; return 0;
} }
debug ("screen_add: Adding screen %s\n", argv[1]); debug(RPT_DEBUG, "screen_add: Adding screen %s", argv[1]);
memset(scr, '\0', sizeof(scr)); memset(scr, '\0', sizeof(scr));
strncpy(scr, argv[1], sizeof(scr) - 1); strncpy(scr, argv[1], sizeof(scr) - 1);
@@ -496,12 +493,12 @@ screen_add_func (client * c, int argc, char **argv)
if (err == 0) if (err == 0)
sock_send_string(c->sock, "success\n"); sock_send_string(c->sock, "success\n");
else if (err < 0) { else if (err < 0) {
fprintf (stderr, "screen_add_func: Error adding screen\n"); report(RPT_WARNING, "screen_add_func: Error adding screen");
sock_send_string (c->sock, "huh? failed to add screen id#\n"); sock_send_string (c->sock, "huh? failed to add screen id#\n");
} else } else
sock_send_string (c->sock, "huh? You already have a screen with that id#\n"); sock_send_string (c->sock, "huh? You already have a screen with that id#\n");
syslog(LOG_NOTICE, "added a screen (%s) to the display", scr); report(RPT_NOTICE, "added a screen (%s) to the display", scr);
return 0; return 0;
} }
@@ -527,7 +524,7 @@ screen_del_func (client * c, int argc, char **argv)
return 0; return 0;
} }
debug ("screen_del: Deleting screen %s\n", argv[1]); debug (RPT_DEBUG, "screen_del: Deleting screen %s", argv[1]);
// Enforce bounds limits on argv[1] // Enforce bounds limits on argv[1]
memset(scr, '\0', sizeof(scr)); memset(scr, '\0', sizeof(scr));
@@ -537,12 +534,12 @@ screen_del_func (client * c, int argc, char **argv)
if ( err == 0 ) if ( err == 0 )
sock_send_string(c->sock, "success\n"); sock_send_string(c->sock, "success\n");
else if (err < 0) { else if (err < 0) {
fprintf (stderr, "screen_del_func: Error removing screen\n"); report(RPT_WARNING, "screen_del_func: Error removing screen");
sock_send_string(c->sock, "huh? failed to remove screen\n"); sock_send_string(c->sock, "huh? failed to remove screen\n");
} else } else
sock_send_string (c->sock, "huh? You don't have a screen with that id#\n"); sock_send_string (c->sock, "huh? You don't have a screen with that id#\n");
syslog(LOG_NOTICE, "removed a screen (%s) from the display", scr); report(RPT_NOTICE, "removed a screen (%s) from the display", scr);
return 0; return 0;
} }
@@ -589,12 +586,12 @@ screen_set_func (client * c, int argc, char **argv)
p = argv[i]; p = argv[i];
if (*p == '-') if (*p == '-')
p++; p++;
// Handle the "name" parameter // Handle the "name" parameter
if (strcmp (p, "name") == 0) { if (strcmp (p, "name") == 0) {
if (argc > i + 1) { if (argc > i + 1) {
i++; i++;
debug ("screen_set: name=\"%s\"\n", argv[i]); debug (RPT_DEBUG, "screen_set: name=\"%s\"", argv[i]);
// set the name... // set the name...
if (s->name) if (s->name)
@@ -609,7 +606,7 @@ screen_set_func (client * c, int argc, char **argv)
else if (strcmp (p, "priority") == 0) { else if (strcmp (p, "priority") == 0) {
if (argc > i + 1) { if (argc > i + 1) {
i++; i++;
debug ("screen_set: priority=\"%s\"\n", argv[i]); debug (RPT_DEBUG, "screen_set: priority=\"%s\"", argv[i]);
// set the priority... // set the priority...
number = atoi (argv[i]); number = atoi (argv[i]);
@@ -624,7 +621,7 @@ screen_set_func (client * c, int argc, char **argv)
else if (strcmp (p, "duration") == 0) { else if (strcmp (p, "duration") == 0) {
if (argc > i + 1) { if (argc > i + 1) {
i++; i++;
debug ("screen_set: duration=\"%s\"\n", argv[i]); debug (RPT_DEBUG, "screen_set: duration=\"%s\"", argv[i]);
// set the duration... // set the duration...
number = atoi (argv[i]); number = atoi (argv[i]);
@@ -639,7 +636,7 @@ screen_set_func (client * c, int argc, char **argv)
else if (strcmp (p, "heartbeat") == 0) { else if (strcmp (p, "heartbeat") == 0) {
if (argc > i + 1) { if (argc > i + 1) {
i++; i++;
debug ("screen_set: heartbeat=\"%s\"\n", argv[i]); debug (RPT_DEBUG, "screen_set: heartbeat=\"%s\"", argv[i]);
// set the heartbeat type... // set the heartbeat type...
if (0 == strcmp (argv[i], "on")) if (0 == strcmp (argv[i], "on"))
@@ -665,7 +662,7 @@ screen_set_func (client * c, int argc, char **argv)
else if (strcmp (p, "wid") == 0) { else if (strcmp (p, "wid") == 0) {
if (argc > i + 1) { if (argc > i + 1) {
i++; i++;
debug ("screen_set: wid=\"%s\"\n", argv[i]); debug (RPT_DEBUG, "screen_set: wid=\"%s\"", argv[i]);
// set the duration... // set the duration...
number = atoi (argv[i]); number = atoi (argv[i]);
@@ -675,13 +672,13 @@ screen_set_func (client * c, int argc, char **argv)
} else { } else {
sock_send_string (c->sock, "huh? -wid requires a parameter\n"); sock_send_string (c->sock, "huh? -wid requires a parameter\n");
} }
} }
// Handle the "hgt" parameter // Handle the "hgt" parameter
else if (strcmp (p, "hgt") == 0) { else if (strcmp (p, "hgt") == 0) {
if (argc > i + 1) { if (argc > i + 1) {
i++; i++;
debug ("screen_set: hgt=\"%s\"\n", argv[i]); debug (RPT_DEBUG, "screen_set: hgt=\"%s\"", argv[i]);
// set the duration... // set the duration...
number = atoi (argv[i]); number = atoi (argv[i]);
@@ -696,43 +693,42 @@ screen_set_func (client * c, int argc, char **argv)
else if (strcmp (p, "timeout") == 0) { else if (strcmp (p, "timeout") == 0) {
if (argc > i + 1) { if (argc > i + 1) {
i++; i++;
syslog(LOG_NOTICE, "Setting timeout."); debug (RPT_DEBUG, "screen_set: timeout=\"%s\"", argv[i]);
debug ("screen_set: timeout=\"%s\"\n", argv[i]);
// set the duration... // set the duration...
number = atoi (argv[i]); number = atoi (argv[i]);
// Add the timeout value (count of TIME_UNITS) // Add the timeout value (count of TIME_UNITS)
// to struct, TIME_UNIT is 1/8th of a second // to struct, TIME_UNIT is 1/8th of a second
if (number > 0) { if (number > 0) {
s->timeout = number; s->timeout = number;
syslog(LOG_NOTICE, "Timeout set."); report(RPT_NOTICE, "Timeout set.");
} }
sock_send_string(c->sock, "success\n"); sock_send_string(c->sock, "success\n");
} else { } else {
sock_send_string (c->sock, "huh? -timeout requires a parameter\n"); sock_send_string (c->sock, "huh? -timeout requires a parameter\n");
} }
} }
// Handle the backlight parameter // Handle the backlight parameter
else if (strcmp (argv[i], "backlight") == 0) { else if (strcmp (argv[i], "backlight") == 0) {
if (argc > i + 1) { if (argc > i + 1) {
i++; i++;
debug ("screen_set: backlight=\"%s\"\n", argv[i]); debug (RPT_DEBUG, "screen_set: backlight=\"%s\"", argv[i]);
// set the backlight status based on what the client has set // set the backlight status based on what the client has set
switch(c->backlight_state) { switch(c->backlight_state) {
case BACKLIGHT_OPEN: case BACKLIGHT_OPEN:
if (strcmp ("on", argv[i]) == 0) if (strcmp ("on", argv[i]) == 0)
s->backlight_state = BACKLIGHT_ON; s->backlight_state = BACKLIGHT_ON;
if (strcmp ("off", argv[i]) == 0) if (strcmp ("off", argv[i]) == 0)
s->backlight_state = BACKLIGHT_OFF; s->backlight_state = BACKLIGHT_OFF;
if (strcmp ("toggle", argv[i]) == 0) { if (strcmp ("toggle", argv[i]) == 0) {
if (s->backlight_state == BACKLIGHT_ON) if (s->backlight_state == BACKLIGHT_ON)
s->backlight_state = BACKLIGHT_OFF; s->backlight_state = BACKLIGHT_OFF;
else if (s-backlight_state == BACKLIGHT_OFF) else if (s-backlight_state == BACKLIGHT_OFF)
s->backlight_state = BACKLIGHT_ON; s->backlight_state = BACKLIGHT_ON;
} }
if (strcmp ("blink", argv[i]) == 0) if (strcmp ("blink", argv[i]) == 0)
s->backlight_state |= BACKLIGHT_BLINK; s->backlight_state |= BACKLIGHT_BLINK;
@@ -824,7 +820,7 @@ widget_add_func (client * c, int argc, char **argv)
if (err == 0) if (err == 0)
sock_send_string(c->sock, "success\n"); sock_send_string(c->sock, "success\n");
else { else {
fprintf (stderr, "widget_add_func: Error adding widget\n"); report(RPT_WARNING, "widget_add_func: Error adding widget");
sock_send_string(c->sock, "huh? failed\n"); sock_send_string(c->sock, "huh? failed\n");
} }
@@ -866,7 +862,7 @@ widget_del_func (client * c, int argc, char **argv)
sid = argv[1]; sid = argv[1];
wid = argv[2]; wid = argv[2];
debug ("screen_del: Deleting widget %s.%s\n", sid, wid); debug (RPT_DEBUG, "screen_del: Deleting widget %s.%s", sid, wid);
s = screen_find (c, sid); s = screen_find (c, sid);
if (!s) { if (!s) {
@@ -877,7 +873,7 @@ widget_del_func (client * c, int argc, char **argv)
if (err == 0) if (err == 0)
sock_send_string(c->sock, "success\n"); sock_send_string(c->sock, "success\n");
else { else {
fprintf (stderr, "widget_del_func: Error removing widget\n"); report( RPT_WARNING, "widget_del_func: Error removing widget");
sock_send_string(c->sock, "huh? failed\n"); sock_send_string(c->sock, "huh? failed\n");
} }
@@ -942,10 +938,9 @@ widget_set_func (client * c, int argc, char **argv)
// Client Debugging... // Client Debugging...
{ {
int i; int i;
fprintf (stderr, "huh? Invalid widget id (%s)\n", wid); report( RPT_WARNING, "huh? Invalid widget id (%s)", wid);
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
fprintf (stderr, "%s ", argv[i]); report( RPT_WARNING, " %.40s ", argv[i]);
fprintf (stderr, "\n");
} }
return 0; return 0;
} }
@@ -969,10 +964,10 @@ widget_set_func (client * c, int argc, char **argv)
free (w->text); free (w->text);
w->text = strdup (argv[i + 2]); w->text = strdup (argv[i + 2]);
if (!w->text) { if (!w->text) {
fprintf (stderr, "widget_set_func: Error allocating string\n"); report( RPT_WARNING, "widget_set_func: Error allocating string");
return -1; return -1;
} }
debug ("Widget %s set to %s\n", wid, w->text); debug (RPT_DEBUG, "Widget %s set to %s", wid, w->text);
sock_send_string(c->sock, "success\n"); sock_send_string(c->sock, "success\n");
} }
} }
@@ -992,7 +987,7 @@ widget_set_func (client * c, int argc, char **argv)
w->y = y; w->y = y;
w->length = length; w->length = length;
} }
debug ("Widget %s set to %i\n", wid, w->length); debug (RPT_DEBUG, "Widget %s set to %i", wid, w->length);
sock_send_string(c->sock, "success\n"); sock_send_string(c->sock, "success\n");
} }
break; break;
@@ -1011,7 +1006,7 @@ widget_set_func (client * c, int argc, char **argv)
w->y = y; w->y = y;
w->length = length; w->length = length;
} }
debug ("Widget %s set to %i\n", wid, w->length); debug (RPT_DEBUG, "Widget %s set to %i", wid, w->length);
sock_send_string(c->sock, "success\n"); sock_send_string(c->sock, "success\n");
} }
break; break;
@@ -1040,10 +1035,10 @@ widget_set_func (client * c, int argc, char **argv)
free (w->text); free (w->text);
w->text = strdup (argv[i]); w->text = strdup (argv[i]);
if (!w->text) { if (!w->text) {
fprintf (stderr, "widget_set_func: Error allocating string\n"); report( RPT_WARNING, "widget_set_func: Error allocating string");
return -1; return -1;
} }
debug ("Widget %s set to %s\n", wid, w->text); debug (RPT_DEBUG, "Widget %s set to %s", wid, w->text);
sock_send_string(c->sock, "success\n"); sock_send_string(c->sock, "success\n");
} }
break; break;
@@ -1058,17 +1053,17 @@ widget_set_func (client * c, int argc, char **argv)
sock_send_string (c->sock, "huh? Invalid coordinates\n"); sock_send_string (c->sock, "huh? Invalid coordinates\n");
} else { } else {
left = atoi (argv[i]); left = atoi (argv[i]);
//debug("left: %d\n",left); //debug("left: %d",left);
top = atoi (argv[i + 1]); top = atoi (argv[i + 1]);
//debug("top: %d\n",top); //debug("top: %d",top);
right = atoi (argv[i + 2]); right = atoi (argv[i + 2]);
//debug("right: %d\n",right); //debug("right: %d",right);
bottom = atoi (argv[i + 3]); bottom = atoi (argv[i + 3]);
//debug("bottom: %d\n",bottom); //debug("bottom: %d",bottom);
direction = (int) (argv[i + 4][0]); direction = (int) (argv[i + 4][0]);
//debug("dir: %c\n",(char)direction); //debug("dir: %c",(char)direction);
speed = atoi (argv[i + 5]); speed = atoi (argv[i + 5]);
//debug("speed: %d\n",speed); //debug("speed: %d",speed);
// Direction must be v or h // Direction must be v or h
if (((char) direction != 'h') && ((char) direction != 'v')) { if (((char) direction != 'h') && ((char) direction != 'v')) {
sock_send_string (c->sock, "huh? Invalid direction\n"); sock_send_string (c->sock, "huh? Invalid direction\n");
@@ -1084,10 +1079,10 @@ widget_set_func (client * c, int argc, char **argv)
w->text = strdup (argv[i + 6]); w->text = strdup (argv[i + 6]);
if (!w->text) { if (!w->text) {
sock_send_string(c->sock, "huh? out of memory\n"); sock_send_string(c->sock, "huh? out of memory\n");
fprintf (stderr, "widget_set_func: Error allocating string\n"); report( RPT_WARNING, "widget_set_func: Error allocating string");
return -1; return -1;
} }
debug ("Widget %s set to %s\n", wid, w->text); debug (RPT_DEBUG, "Widget %s set to %s", wid, w->text);
sock_send_string(c->sock, "success\n"); sock_send_string(c->sock, "success\n");
} }
} }
@@ -1106,21 +1101,21 @@ widget_set_func (client * c, int argc, char **argv)
sock_send_string (c->sock, "huh? Invalid coordinates\n"); sock_send_string (c->sock, "huh? Invalid coordinates\n");
} else { } else {
left = atoi (argv[i]); left = atoi (argv[i]);
//debug("left: %d\n",left); //debug("left: %d",left);
top = atoi (argv[i + 1]); top = atoi (argv[i + 1]);
//debug("top: %d\n",top); //debug("top: %d",top);
right = atoi (argv[i + 2]); right = atoi (argv[i + 2]);
//debug("right: %d\n",right); //debug("right: %d",right);
bottom = atoi (argv[i + 3]); bottom = atoi (argv[i + 3]);
//debug("bottom: %d\n",bottom); //debug("bottom: %d",bottom);
width = atoi (argv[i + 4]); width = atoi (argv[i + 4]);
//debug("right: %d\n",right); //debug("right: %d",right);
height = atoi (argv[i + 5]); height = atoi (argv[i + 5]);
//debug("bottom: %d\n",bottom); //debug("bottom: %d",bottom);
direction = (int) (argv[i + 6][0]); direction = (int) (argv[i + 6][0]);
//debug("dir: %c\n",(char)direction); //debug("dir: %c",(char)direction);
speed = atoi (argv[i + 7]); speed = atoi (argv[i + 7]);
//debug("speed: %d\n",speed); //debug("speed: %d",speed);
// Direction must be v or h // Direction must be v or h
if (((char) direction != 'h') && ((char) direction != 'v')) { if (((char) direction != 'h') && ((char) direction != 'v')) {
sock_send_string (c->sock, "huh? Invalid direction\n"); sock_send_string (c->sock, "huh? Invalid direction\n");
@@ -1133,7 +1128,7 @@ widget_set_func (client * c, int argc, char **argv)
w->hgt = height; w->hgt = height;
w->length = direction; w->length = direction;
w->speed = speed; w->speed = speed;
debug ("Widget %s set to (%i,%i)-(%i,%i) %ix%i\n", wid, left, top, right, bottom, width, height); debug (RPT_DEBUG, "Widget %s set to (%i,%i)-(%i,%i) %ix%i", wid, left, top, right, bottom, width, height);
sock_send_string(c->sock, "success\n"); sock_send_string(c->sock, "success\n");
} }
} }
@@ -1153,7 +1148,7 @@ widget_set_func (client * c, int argc, char **argv)
w->x = x; w->x = x;
w->y = y; w->y = y;
} }
debug ("Widget %s set to %i\n", wid, w->y); debug (RPT_DEBUG, "Widget %s set to %i", wid, w->y);
sock_send_string(c->sock, "success\n"); sock_send_string(c->sock, "success\n");
} }
break; break;
@@ -1294,9 +1289,9 @@ backlight_func (client * c, int argc, char **argv)
return 0; return 0;
} }
debug ("backlight(%s)\n", argv[1]); debug (RPT_DEBUG, "backlight(%s)", argv[1]);
backlight = (backlight && 1); // only preserves ON/OFF bit backlight = (backlight && 1); // only preserves ON/OFF bit
if (strcmp ("on", argv[1]) == 0) { if (strcmp ("on", argv[1]) == 0) {
@@ -1403,7 +1398,7 @@ output_func (client * c, int argc, char **argv)
// lcd_ptr->output (output_state); // lcd_ptr->output (output_state);
syslog(LOG_NOTICE, "output states changed"); report(RPT_NOTICE, "output states changed");
return 0; return 0;
} }
+28 -29
View File
@@ -15,12 +15,11 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <syslog.h>
#include "sock.h" #include "sock.h"
#include "clients.h" #include "clients.h"
#include "client_data.h" #include "client_data.h"
#include "shared/debug.h" #include "shared/report.h"
#include "render.h" #include "render.h"
LinkedList *clients; LinkedList *clients;
@@ -29,11 +28,11 @@ LinkedList *clients;
int int
client_init () client_init ()
{ {
debug ("client_init()\n"); debug(RPT_INFO, "client_init()");
clients = LL_new (); clients = LL_new ();
if (!clients) { if (!clients) {
fprintf (stderr, "client_init: Unable to create client list\n"); report( RPT_ERR, "client_init: Unable to create client list");
return -1; return -1;
} }
@@ -45,29 +44,29 @@ client_shutdown ()
{ {
client *c; client *c;
debug ("client_shutdown()\n"); debug (RPT_INFO, "client_shutdown()");
// Free all client structures... // Free all client structures...
// Note that the regular list loop doesn't work here, because // Note that the regular list loop doesn't work here, because
// client_destroy() calls LL_Remove() // client_destroy() calls LL_Remove()
for (c = LL_Pop (clients); c; c = LL_Pop (clients)) { for (c = LL_Pop (clients); c; c = LL_Pop (clients)) {
debug ("client_shutdown: ...\n"); debug (RPT_DEBUG, "client_shutdown: ...");
if (c) { if (c) {
debug ("client_shutdown: ... %i ...\n", c->sock); debug (RPT_DEBUG, "client_shutdown: ... %i ...", c->sock);
if (client_destroy (c) != 0) { if (client_destroy (c) != 0) {
fprintf (stderr, "client_shutdown: Error freeing client\n"); report (RPT_ERR, "client_shutdown: Error freeing client");
} else { } else {
debug ("client_shutdown: Freed client...\n"); debug (RPT_DEBUG, "client_shutdown: Freed client...");
} }
} else { } else {
debug ("client_shutdown: No client!\n"); debug (RPT_DEBUG, "client_shutdown: No client!");
} }
} }
// Then, free the list... // Then, free the list...
LL_Destroy (clients); LL_Destroy (clients);
debug ("client_shutdown: done\n"); debug (RPT_DEBUG, "client_shutdown: done");
return 0; return 0;
} }
@@ -81,12 +80,12 @@ client_create (int sock)
{ {
client *c; client *c;
debug ("client_create(%i)\n", sock); debug (RPT_DEBUG, "client_create(%i)", sock);
// Allocate new client... // Allocate new client...
c = malloc (sizeof (client)); c = malloc (sizeof (client));
if (!c) { if (!c) {
fprintf (stderr, "client_create: error allocating new client\n"); report (RPT_ERR, "client_create: error allocating new client");
return NULL; return NULL;
} }
// Init struct members // Init struct members
@@ -100,14 +99,14 @@ client_create (int sock)
// Set up message list... // Set up message list...
c->messages = LL_new (); c->messages = LL_new ();
if (!c->messages) { if (!c->messages) {
fprintf (stderr, "client_create: error allocating message list\n"); report (RPT_ERR, "client_create: error allocating message list");
free (c); free (c);
return NULL; return NULL;
} }
// TODO: allocate and init client data... // TODO: allocate and init client data...
c->data = malloc (sizeof (client_data)); c->data = malloc (sizeof (client_data));
if (!c->data) { if (!c->data) {
fprintf (stderr, "client_create: error allocating client data\n"); report (RPT_ERR, "client_create: error allocating client data");
free (c->messages); free (c->messages);
free (c); free (c);
return NULL; return NULL;
@@ -127,16 +126,16 @@ client_destroy (client * c)
char *str; char *str;
debug ("client_destroy()\n"); debug (RPT_INFO, "client_destroy()");
if (!c) if (!c)
return -1; return -1;
// Eat the rest of the incoming requests... // Eat the rest of the incoming requests...
debug ("client_destroy: get_messages\n"); debug (RPT_DEBUG, "client_destroy: get_messages");
while ((str = client_get_message (c))) { while ((str = client_get_message (c))) {
if (str) { if (str) {
debug ("client_destroy: kill message %s\n", str); debug (RPT_DEBUG, "client_destroy: kill message %s", str);
free (str); free (str);
} }
} }
@@ -145,7 +144,7 @@ client_destroy (client * c)
if (c->sock) { if (c->sock) {
// sock_send_string (c->sock, "bye\n"); // sock_send_string (c->sock, "bye\n");
close(c->sock); close(c->sock);
syslog(LOG_NOTICE, "closed socket for #%d\n", c->sock); report(RPT_NOTICE, "closed socket for #%d", c->sock);
} }
err = LL_Destroy (c->messages); err = LL_Destroy (c->messages);
@@ -171,7 +170,7 @@ client_add_message (client * c, char *message)
char delimiters[] = "\n\r\0"; char delimiters[] = "\n\r\0";
// int len; // int len;
//debug("client_add_message(%s)\n", message); debug(RPT_DEBUG, "client_add_message(%s)", message);
if (!c) if (!c)
return -1; return -1;
@@ -184,17 +183,17 @@ client_add_message (client * c, char *message)
// Copy the string to avoid overwriting the original... // Copy the string to avoid overwriting the original...
dup = strdup (message); dup = strdup (message);
if (!dup) { if (!dup) {
fprintf (stderr, "client_add_message: Error allocating new string\n"); report(RPT_ERR, "client_add_message: Error allocating new string");
return -1; return -1;
} }
// Now split the string into lines and enqueue each one... // Now split the string into lines and enqueue each one...
for (str = strtok (dup, delimiters); str; str = strtok (NULL, delimiters)) { for (str = strtok (dup, delimiters); str; str = strtok (NULL, delimiters)) {
cp = strdup (str); cp = strdup (str);
debug ("client_add_message: %s\n", cp); debug (RPT_DEBUG, "client_add_message: %s", cp);
err += LL_Enqueue (c->messages, (void *) cp); err += LL_Enqueue (c->messages, (void *) cp);
} }
//debug("client_add_message(%s): %i errors\n", message, err); //debug(RPT_DEBUG, "client_add_message(%s): %i errors", message, err);
free (dup); // Fixed memory leak... free (dup); // Fixed memory leak...
// Err is the number of errors encountered... // Err is the number of errors encountered...
@@ -208,14 +207,14 @@ client_get_message (client * c)
{ {
char *str; char *str;
//debug("client_get_message()\n"); debug(RPT_DEBUG, "client_get_message()");
if (!c) if (!c)
return NULL; return NULL;
str = (char *) LL_Dequeue (c->messages); str = (char *) LL_Dequeue (c->messages);
//debug("client_get_message: \"%s\"\n", str); //debug(RPT_DEBUG, "client_get_message: \"%s\"", str);
return str; return str;
} }
@@ -241,19 +240,19 @@ client_find_sock (int sock)
{ {
client *c; client *c;
// debug("client_find_sock(%i)\n", sock); // debug(RPT_INFO, "client_find_sock(%i)", sock);
LL_Rewind (clients); LL_Rewind (clients);
do { do {
c = (client *) LL_Get (clients); c = (client *) LL_Get (clients);
// debug("client_find_sock: ... %i ...\n", c->sock); // debug(RPT_DEBUG, "client_find_sock: ... %i ...", c->sock);
if (c->sock == sock) { if (c->sock == sock) {
// debug("client_find_sock: ..! %i !..\n", c->sock); // debug(RPT_DEBUG, "client_find_sock: ..! %i !..", c->sock);
return c; return c;
} }
} while (LL_Next (clients) == 0); } while (LL_Next (clients) == 0);
debug ("client_find_sock: failed\n"); debug (RPT_ERR, "client_find_sock: failed");
return NULL; return NULL;
} }
+14 -12
View File
@@ -13,6 +13,8 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include "shared/report.h"
typedef struct key { typedef struct key {
char * name; char * name;
@@ -219,7 +221,7 @@ int config_has_key( char *sectionname, char *keyname )
void config_clear() void config_clear()
{ {
printf( "config_clear is unimplemented" ); report( RPT_WARNING, "config_clear is unimplemented" );
} }
@@ -386,7 +388,7 @@ int process_config( section ** current_section, char (*get_next_char)(), char mo
case ST_SECTIONNAME: case ST_SECTIONNAME:
switch( ch ) { switch( ch ) {
case '\n': case '\n':
fprintf( stderr, "Section name incorrectly closed on line %d of %s: %s\n", line_nr, source_descr, sectionname ); report( RPT_WARNING, "Section name incorrectly closed on line %d of %s: %s", line_nr, source_descr, sectionname );
state = ST_INITIAL; state = ST_INITIAL;
break; break;
case '\r': case '\r':
@@ -394,7 +396,7 @@ int process_config( section ** current_section, char (*get_next_char)(), char mo
case ' ': case ' ':
case '"': case '"':
case '[': case '[':
fprintf( stderr, "Section name contains invalid chars on line %d of %s: %s\n", line_nr, source_descr, sectionname ); report( RPT_WARNING, "Section name contains invalid chars on line %d of %s: %s", line_nr, source_descr, sectionname );
state = ST_INVALID_SECTIONNAME; state = ST_INVALID_SECTIONNAME;
break; break;
case ']': case ']':
@@ -404,14 +406,14 @@ int process_config( section ** current_section, char (*get_next_char)(), char mo
state = ST_INITIAL; state = ST_INITIAL;
break; break;
case 0: case 0:
fprintf( stderr, "Section name incorrectly closed on line %d of %s: %s\n", line_nr, source_descr, sectionname ); report( RPT_WARNING, "Section name incorrectly closed on line %d of %s: %s", line_nr, source_descr, sectionname );
break; break;
default: default:
if( sectionname_pos<MAXSECTIONNAMELENGTH ) { if( sectionname_pos<MAXSECTIONNAMELENGTH ) {
sectionname[sectionname_pos++] = ch; sectionname[sectionname_pos++] = ch;
sectionname[sectionname_pos] = 0; sectionname[sectionname_pos] = 0;
} else { } else {
fprintf( stderr, "Section name too long on line %d of %s: %s\n", line_nr, source_descr, sectionname ); report( RPT_WARNING, "Section name too long on line %d of %s: %s", line_nr, source_descr, sectionname );
state = ST_INVALID_SECTIONNAME; state = ST_INVALID_SECTIONNAME;
} }
} }
@@ -431,13 +433,13 @@ int process_config( section ** current_section, char (*get_next_char)(), char mo
case '\r': case '\r':
case '\t': case '\t':
case ' ': case ' ':
fprintf( stderr, "Loose word found on line %d of %s: %s\n", line_nr, source_descr, keyname ); report( RPT_WARNING, "Loose word found on line %d of %s: %s", line_nr, source_descr, keyname );
state = ST_INITIAL; state = ST_INITIAL;
break; break;
case '"': case '"':
case '[': case '[':
case ']': case ']':
fprintf( stderr, "Key name contains invalid characters on line %d of %s: %s\n", line_nr, source_descr, keyname ); report( RPT_WARNING, "Key name contains invalid characters on line %d of %s: %s", line_nr, source_descr, keyname );
state = ST_INVALID_KEYNAME; state = ST_INVALID_KEYNAME;
break; break;
case '=': case '=':
@@ -447,7 +449,7 @@ int process_config( section ** current_section, char (*get_next_char)(), char mo
break; break;
default: default:
if( keyname_pos>=MAXKEYNAMELENGTH ) { if( keyname_pos>=MAXKEYNAMELENGTH ) {
fprintf( stderr, "Key name too long on line %d of %s: %s\n", line_nr, source_descr, keyname ); report( RPT_WARNING, "Key name too long on line %d of %s: %s", line_nr, source_descr, keyname );
state = ST_INVALID_KEYNAME; state = ST_INVALID_KEYNAME;
} else { } else {
keyname[keyname_pos++] = ch; keyname[keyname_pos++] = ch;
@@ -469,7 +471,7 @@ int process_config( section ** current_section, char (*get_next_char)(), char mo
case '#': case '#':
case ';': case ';':
case '=': case '=':
fprintf( stderr, "Value contains invalid characters on line %d of %s, at key: %s\n", line_nr, source_descr, keyname ); report( RPT_WARNING, "Value contains invalid characters on line %d of %s, at key: %s", line_nr, source_descr, keyname );
state = ST_INVALID_VALUE; state = ST_INVALID_VALUE;
break; break;
case '"': case '"':
@@ -482,7 +484,7 @@ int process_config( section ** current_section, char (*get_next_char)(), char mo
case ' ': case ' ':
// Value complete ! // Value complete !
if( ! *current_section ) { if( ! *current_section ) {
fprintf( stderr, "Data before any section on line %d of %s with key: %s\n", line_nr, source_descr, keyname ); report( RPT_WARNING, "Data before any section on line %d of %s with key: %s", line_nr, source_descr, keyname );
} }
else { else {
// Store the value // Store the value
@@ -496,7 +498,7 @@ int process_config( section ** current_section, char (*get_next_char)(), char mo
value[value_pos++] = ch; value[value_pos++] = ch;
value[value_pos] = 0; value[value_pos] = 0;
} else { } else {
fprintf( stderr, "Value key is too long on line %d of %s, at key: %s\n", line_nr, source_descr, keyname ); report( RPT_WARNING, "Value key is too long on line %d of %s, at key: %s", line_nr, source_descr, keyname );
state = ST_INVALID_KEYNAME; state = ST_INVALID_KEYNAME;
} }
} }
@@ -514,7 +516,7 @@ int process_config( section ** current_section, char (*get_next_char)(), char mo
switch( ch ) { switch( ch ) {
case 0: case 0:
case '\n': case '\n':
fprintf( stderr, "String is incorrectly terminated on line %d of %s: %s\n", line_nr, source_descr, keyname ); report( RPT_WARNING, "String is incorrectly terminated on line %d of %s: %s", line_nr, source_descr, keyname );
state = ST_INITIAL; state = ST_INITIAL;
break; break;
case '\\': case '\\':
+7 -8
View File
@@ -11,14 +11,13 @@
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <sys/errno.h> #include <sys/errno.h>
#include <syslog.h>
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
#include "shared/LL.h" #include "shared/LL.h"
#include "shared/debug.h" #include "shared/report.h"
#include "configfile.h" #include "configfile.h"
#include "drivers/lcd.h" #include "drivers/lcd.h"
@@ -40,14 +39,14 @@ load_driver ( char * name, char * filename, char * args )
void (*driver_init)(); void (*driver_init)();
lcd_logical_driver * driver; lcd_logical_driver * driver;
debug ("load_driver(%s,%s,%s)\n", name,filename,args); report( RPT_INFO, "load_driver(%s,%s,%s)", name, filename, args );
// First driver ? // First driver ?
if( !loaded_drivers ) { if( !loaded_drivers ) {
// Create linked list // Create linked list
loaded_drivers = LL_new (); loaded_drivers = LL_new ();
if( !loaded_drivers ) { if( !loaded_drivers ) {
fprintf( stderr, "Error allocating driver list.\n" ); report( RPT_ERR, "Error allocating driver list." );
return -1; return -1;
} }
} }
@@ -56,7 +55,7 @@ load_driver ( char * name, char * filename, char * args )
// Find the driver in the array of driver types // Find the driver in the array of driver types
if ((driver_init = (void *) lcd_find_init(name)) == NULL) { if ((driver_init = (void *) lcd_find_init(name)) == NULL) {
// Driver not found // Driver not found
fprintf( stderr, "invalid driver: %s\n", name); report( RPT_ERR, "invalid driver: %s", name);
return -1; return -1;
} }
@@ -75,7 +74,7 @@ load_driver ( char * name, char * filename, char * args )
res = driver->init( driver, args ); res = driver->init( driver, args );
if( res < 0 ) { if( res < 0 ) {
fprintf( stderr, "res<0\n" ); report( RPT_ERR, "Driver load failed, return code < 0" );
// driver load failed, don't add driver to list // driver load failed, don't add driver to list
return -1; return -1;
} }
@@ -97,10 +96,10 @@ unload_all_drivers ()
{ {
lcd_logical_driver * driver; lcd_logical_driver * driver;
debug ("unload_all_driver()\n"); report( RPT_INFO, "unload_all_driver()");
while( (driver = LL_Pop( loaded_drivers )) != NULL ) { while( (driver = LL_Pop( loaded_drivers )) != NULL ) {
debug ("driver->close %p\n", driver ); debug( RPT_DEBUG, "driver->close %p", driver );
driver->close(); driver->close();
} }
+25 -36
View File
@@ -5,10 +5,10 @@
#include <fcntl.h> #include <fcntl.h>
#include <string.h> #include <string.h>
#include <sys/errno.h> #include <sys/errno.h>
#include <syslog.h>
#include "lcd.h" #include "lcd.h"
#include "debug.h" #include "debug.h"
#include "shared/report.h"
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////////////////////// For Debugging Output ////////////////////////////// ////////////////////// For Debugging Output //////////////////////////////
@@ -22,7 +22,7 @@ static lcd_logical_driver *debug_drv;
int int
debug_init (struct lcd_logical_driver *driver, char *args) debug_init (struct lcd_logical_driver *driver, char *args)
{ {
syslog(LOG_DEBUG, "debug_init"); report (RPT_INFO, "debug_init()");
debug_drv = driver; debug_drv = driver;
@@ -58,10 +58,10 @@ debug_init (struct lcd_logical_driver *driver, char *args)
void void
debug_close () debug_close ()
{ {
syslog(LOG_DEBUG, "debug_close()"); report (RPT_INFO, "debug_close()");
if (debug_drv->framebuf) { if (debug_drv->framebuf) {
printf ("frame buffer: %010X", (int) debug_drv->framebuf); report (RPT_DEBUG, "frame buffer: %010X", (int) debug_drv->framebuf);
free (debug_drv->framebuf); free (debug_drv->framebuf);
} }
@@ -74,7 +74,7 @@ debug_close ()
void void
debug_clear () debug_clear ()
{ {
syslog(LOG_DEBUG, "clear()"); report (RPT_INFO, "clear()");
memset (debug_drv->framebuf, ' ', debug_drv->wid * debug_drv->hgt); memset (debug_drv->framebuf, ' ', debug_drv->wid * debug_drv->hgt);
@@ -86,7 +86,7 @@ debug_clear ()
void void
debug_flush () debug_flush ()
{ {
syslog(LOG_DEBUG, "flush()"); report (RPT_INFO, "flush()");
debug_drv->draw_frame (); debug_drv->draw_frame ();
} }
@@ -100,10 +100,8 @@ debug_string (int x, int y, char string[])
{ {
int i; int i;
char buf[64];
snprintf(buf, sizeof(buf), "string(%i,%i): %s", x, y, string); report(RPT_INFO, "string(%i,%i,%.40s)", x, y, string);
syslog (LOG_DEBUG, buf);
y --; x --; // Convert 1-based coords to 0-based... y --; x --; // Convert 1-based coords to 0-based...
@@ -119,10 +117,7 @@ debug_string (int x, int y, char string[])
void void
debug_chr (int x, int y, char c) debug_chr (int x, int y, char c)
{ {
char buf[64]; report (RPT_DEBUG, "char(%i,%i,%c)", x, y, c);
snprintf(buf, sizeof(buf), "character(%i,%i): %c", x, y, c);
syslog (LOG_DEBUG, buf);
x--; y--; x--; y--;
debug_drv->framebuf[(y * debug_drv->wid) + x] = c; debug_drv->framebuf[(y * debug_drv->wid) + x] = c;
@@ -131,50 +126,44 @@ debug_chr (int x, int y, char c)
int int
debug_contrast (int contrast) debug_contrast (int contrast)
{ {
syslog(LOG_DEBUG, "contrast: %i", contrast); report (RPT_INFO, "contrast(%i)", contrast);
return 0; return 0;
} }
void void
debug_backlight (int on) debug_backlight (int on)
{ {
if (on) report (RPT_INFO, "backlight(%i)", on);
syslog(LOG_DEBUG, "backlight turned on");
else
syslog(LOG_DEBUG, "backlight turned off");
} }
void void
debug_init_vbar () debug_init_vbar ()
{ {
syslog(LOG_DEBUG, "Init vertical bars"); report (LOG_INFO, "init_vbar()");
} }
void void
debug_init_hbar () debug_init_hbar ()
{ {
syslog(LOG_DEBUG, "Init horizontal bars"); report (RPT_INFO, "init_hbar()");
} }
void void
debug_init_num () debug_init_num ()
{ {
syslog(LOG_DEBUG, "Big numbers"); report (RPT_INFO, "init_bignum()");
} }
void void
debug_num (int x, int num) debug_num (int x, int num)
{ {
char buf[64]; report (RPT_INFO, "big number(%i,%i)", x, num);
snprintf(buf, sizeof(buf), "big number(%i): %i", x, num);
syslog (LOG_DEBUG, buf);
} }
void void
debug_set_char (int n, char *dat) debug_set_char (int n, char *dat)
{ {
syslog(LOG_DEBUG, "set character %i", n); report (RPT_INFO, "set_char(%i,data)", n);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -185,7 +174,7 @@ debug_vbar (int x, int len)
{ {
int y; int y;
syslog (LOG_DEBUG, "vbar(%i): len = %i", x, len); report (RPT_INFO, "vbar(%i,%i)", x, len);
for (y = debug_drv->hgt; y > 0 && len > 0; y--) { for (y = debug_drv->hgt; y > 0 && len > 0; y--) {
debug_chr (x, y, '|'); debug_chr (x, y, '|');
@@ -201,7 +190,7 @@ debug_vbar (int x, int len)
void void
debug_hbar (int x, int y, int len) debug_hbar (int x, int y, int len)
{ {
syslog(LOG_DEBUG, "hbar(%i,%i): len = %i", x, y, len); report (RPT_INFO, "hbar(%i,%i,%i)", x, y, len);
for (; x < debug_drv->wid && len > 0; x++) { for (; x < debug_drv->wid && len > 0; x++) {
debug_chr (x, y, '-'); debug_chr (x, y, '-');
@@ -217,13 +206,13 @@ debug_hbar (int x, int y, int len)
void void
debug_icon (int which, char dest) debug_icon (int which, char dest)
{ {
syslog (LOG_DEBUG, "char %i = icon %i", dest, which); report (RPT_INFO, "icon(%i,%i", which, dest);
} }
void void
debug_flush_box (int lft, int top, int rgt, int bot) debug_flush_box (int lft, int top, int rgt, int bot)
{ {
syslog (LOG_DEBUG, "flush_box(%i,%i) - (%i,%i)", lft, top, rgt, bot); report (RPT_INFO, "flush_box(%i,%i,%i,%i)", lft, top, rgt, bot);
debug_flush (); debug_flush ();
} }
@@ -235,25 +224,25 @@ debug_draw_frame (char *dat)
char out[LCD_MAX_WIDTH]; char out[LCD_MAX_WIDTH];
syslog (LOG_DEBUG, "draw_frame()"); report (RPT_INFO, "draw_frame(data)");
if (!dat) if (!dat)
return; return;
// printf("Frame (%ix%i): \n%s\n", debug_drv->wid, debug_drv->hgt, dat); // report (RPT_DEBUG, "Frame (%ix%i): %s", debug_drv->wid, debug_drv->hgt, dat);
for (i = 0; i < debug_drv->wid; i++) { for (i = 0; i < debug_drv->wid; i++) {
out[i] = '-'; out[i] = '-';
} }
out[debug_drv->wid] = 0; out[debug_drv->wid] = 0;
//printf ("+%s+\n", out); //report (RPT_DEBUG, "+%s+", out);
for (i = 0; i < debug_drv->hgt; i++) { for (i = 0; i < debug_drv->hgt; i++) {
for (j = 0; j < debug_drv->wid; j++) { for (j = 0; j < debug_drv->wid; j++) {
out[j] = dat[j + (i * debug_drv->wid)]; out[j] = dat[j + (i * debug_drv->wid)];
} }
out[debug_drv->wid] = 0; out[debug_drv->wid] = 0;
//printf ("|%s|\n", out); //report (RPT_DEBUG, "|%s|", out);
} }
@@ -261,13 +250,13 @@ debug_draw_frame (char *dat)
out[i] = '-'; out[i] = '-';
} }
out[debug_drv->wid] = 0; out[debug_drv->wid] = 0;
//printf ("+%s+\n", out); //report (RPT_DEBUG, "+%s+", out);
} }
char char
debug_getkey () debug_getkey ()
{ {
syslog(LOG_DEBUG, "getkey"); report (RPT_INFO, "getkey()");
return 0; return 0;
} }
+1 -1
View File
@@ -32,7 +32,7 @@
#endif #endif
#include "shared/LL.h" #include "shared/LL.h"
#include "shared/debug.h" #include "shared/report.h"
#include "lcd.h" #include "lcd.h"
+36 -23
View File
@@ -165,7 +165,9 @@
#include "lpt-port.h" #include "lpt-port.h"
#include "lcd.h" #include "lcd.h"
#include "shared/str.h" #include "shared/str.h"
#include <stdio.h> #include "shared/report.h"
#include "configfile.h"
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
@@ -274,6 +276,9 @@ sed1330_init( lcd_logical_driver * driver, char *args )
sed1330 = driver; sed1330 = driver;
debug( RPT_INFO, "SED1330: init(%p,%s)", driver, args );
// TODO: replace DriverName with driver->name when that field exists. // TODO: replace DriverName with driver->name when that field exists.
#define DriverName "sed1330" #define DriverName "sed1330"
@@ -291,13 +296,13 @@ sed1330_init( lcd_logical_driver * driver, char *args )
// READ THE CONFIG FILE // READ THE CONFIG FILE
// Port // Port
port = driver->config_get_int( DriverName, "port", 0, 0x278 ); port = config_get_int( DriverName, "port", 0, 0x278 );
data->port = port; data->port = port;
// Type // Type
s = driver->config_get_string( DriverName, "type", 0, NULL ); s = driver->config_get_string( DriverName, "type", 0, NULL );
if( !s ) { if( !s ) {
printf( "SED1330: you need to specify the display type\n" ); report( RPT_ERR, "SED1330: you need to specify the display type" );
} else if( strcmp( s, "G321D" ) == 0 ) { } else if( strcmp( s, "G321D" ) == 0 ) {
data->type = TYPE_G321D; data->type = TYPE_G321D;
data->graph_width = 320; data->graph_width = 320;
@@ -311,14 +316,17 @@ sed1330_init( lcd_logical_driver * driver, char *args )
data->graph_width = 240; data->graph_width = 240;
data->graph_height = 128; data->graph_height = 128;
} else { } else {
printf( "SED1330: Unknown display type: %s\n", s ); report( RPT_ERR, "SED1330: Unknown display type: %s", s );
return -1; return -1;
} }
driver->wid = data->graph_width / CHARWIDTH; driver->wid = data->graph_width / CHARWIDTH;
driver->hgt = data->graph_height / CHARHEIGHT; driver->hgt = data->graph_height / CHARHEIGHT;
data->bytesperline = (data->graph_width - 1 ) / CHARWIDTH + 1; data->bytesperline = (data->graph_width - 1 ) / CHARWIDTH + 1;
report( RPT_INFO, "SED1330: Using LCD type: %s", s );
report( RPT_INFO, "SED1330: Text size: %dx%d", driver->wid, driver->hgt );
// Keymap // Keymap
for( i=0; i<MAXKEYS; i++ ) { for( i=0; i<MAXKEYS; i++ ) {
char buf[8]; char buf[8];
@@ -327,6 +335,8 @@ sed1330_init( lcd_logical_driver * driver, char *args )
if( s ) { if( s ) {
data->keymap[i] = (char *) malloc( strlen(s)+1 ); data->keymap[i] = (char *) malloc( strlen(s)+1 );
strcpy( data->keymap[i], s ); strcpy( data->keymap[i], s );
report( RPT_INFO, "SED1330: Key %d: \"%s\"", i, s );
} else { } else {
data->keymap[i] = ""; // Pointing to an constant empty string data->keymap[i] = ""; // Pointing to an constant empty string
} }
@@ -360,6 +370,7 @@ sed1330_init( lcd_logical_driver * driver, char *args )
// Arrange for access to port // Arrange for access to port
debug( RPT_DEBUG, "SED1330: getting port access" );
port_access(data->port); port_access(data->port);
port_access(data->port+1); port_access(data->port+1);
port_access(data->port+2); port_access(data->port+2);
@@ -372,7 +383,7 @@ sed1330_init( lcd_logical_driver * driver, char *args )
struct sched_param param; struct sched_param param;
param.sched_priority=1; param.sched_priority=1;
if (( sched_setscheduler(0, SCHED_RR, &param)) == -1) { if (( sched_setscheduler(0, SCHED_RR, &param)) == -1) {
fprintf (stderr, "HD44780_init: failed (%s)\n", strerror (errno)); report( RPT_ERR, "HD44780_init: failed (%s)", strerror (errno));
return -1; return -1;
} }
} }
@@ -404,6 +415,7 @@ sed1330_init( lcd_logical_driver * driver, char *args )
// INITIALIZE THE LCD // INITIALIZE THE LCD
// End reset-state // End reset-state
debug( RPT_DEBUG, "SED1330: initializing LCD" );
port_out( port+2, (nWR) ^ OUTMASK ); // raise ^RD and ^WR port_out( port+2, (nWR) ^ OUTMASK ); // raise ^RD and ^WR
port_out( port+2, (nRESET|nWR) ^ OUTMASK ); // lower RESET port_out( port+2, (nRESET|nWR) ^ OUTMASK ); // lower RESET
uPause( 200 ); uPause( 200 );
@@ -495,7 +507,7 @@ sed1330_command( char command, int datacount, char * data )
int i; int i;
int port = private_data->port; int port = private_data->port;
printf( "sed1330_command %x #data=%d\n", command, datacount ); debug( RPT_INFO, "sed1330_command %x #data=%d", command, datacount );
port_out( port+2, (nRESET|nWR|A0) ^ OUTMASK ); // set A0 to indicate command port_out( port+2, (nRESET|nWR|A0) ^ OUTMASK ); // set A0 to indicate command
port_out( port, command ); // set up data port_out( port, command ); // set up data
@@ -531,7 +543,7 @@ void sed1330_update_cursor()
char disp_en; char disp_en;
char fc; // named after CF register in SED1330 char fc; // named after CF register in SED1330
printf( "sed1330_update_cursor\n" ); debug( RPT_INFO, "sed1330_update_cursor" );
cursor_pos = (data->cursor_y-1) * data->bytesperline + (data->cursor_x-1) + 256 * SCR1_H + SCR1_L; cursor_pos = (data->cursor_y-1) * data->bytesperline + (data->cursor_x-1) + 256 * SCR1_H + SCR1_L;
csrloc[0] = cursor_pos % 256; csrloc[0] = cursor_pos % 256;
@@ -568,7 +580,7 @@ void sed1330_update_cursor()
void void
sed1330_close() sed1330_close()
{ {
printf( "sed1330_close\n" ); debug( RPT_INFO, "sed1330_close" );
//sed1330_command( CMD_DISP_DIS, 0, NULL ); // display off //sed1330_command( CMD_DISP_DIS, 0, NULL ); // display off
//port_out( port+2, (nWR) ^ OUTMASK ); // give LCD reset signal //port_out( port+2, (nWR) ^ OUTMASK ); // give LCD reset signal
@@ -586,7 +598,7 @@ sed1330_clear()
{ {
private_data * data = sed1330->private_data; private_data * data = sed1330->private_data;
printf( "sed1330_clear\n" ); debug( RPT_INFO, "sed1330_clear" );
memset( data->framebuf_text, ' ', data->bytesperline * sed1330->hgt); memset( data->framebuf_text, ' ', data->bytesperline * sed1330->hgt);
memset( data->framebuf_graph, 0, data->bytesperline * data->graph_height ); memset( data->framebuf_graph, 0, data->bytesperline * data->graph_height );
@@ -603,7 +615,8 @@ sed1330_string( int x, int y, char *str )
char * start; char * start;
int len; int len;
printf( "sed1330_string x=%d y=%d s=\"%s\"\n", x, y, str ); debug( RPT_INFO, "sed1330_string x=%d y=%d s=\"%s\"", x, y, str );
if( y > sed1330->hgt ) { if( y > sed1330->hgt ) {
return; // outside framebuf_textfer return; // outside framebuf_textfer
} }
@@ -626,7 +639,7 @@ sed1330_chr( int x, int y, char c )
{ {
private_data * data = sed1330->private_data; private_data * data = sed1330->private_data;
printf( "sed1330_chr x=%d y=%d c='%c'\n", x, y, c ); debug( RPT_INFO, "sed1330_chr x=%d y=%d c='%c'", x, y, c );
if( y > sed1330->hgt || x > sed1330->wid ) { if( y > sed1330->hgt || x > sed1330->wid ) {
return; // outside framebuf_textfer return; // outside framebuf_textfer
@@ -645,7 +658,7 @@ sed1330_flush()
unsigned int pos, start_pos, nr_equal, fblen, len, cursor_pos; unsigned int pos, start_pos, nr_equal, fblen, len, cursor_pos;
char csrloc[2]; char csrloc[2];
printf( "sed1330_flush\n" ); debug( RPT_INFO, "sed1330_flush" );
sed1330_command( CMD_DISP_EN, 1, ((char[1]) {0x16}) ); // cursor off sed1330_command( CMD_DISP_EN, 1, ((char[1]) {0x16}) ); // cursor off
@@ -703,7 +716,7 @@ void sed1330_cursor( int x, int y, char state )
{ {
private_data * data = sed1330->private_data; private_data * data = sed1330->private_data;
printf( "sed1330_cursor x=%d y=%d state='%c'\n", x, y, state ); debug( RPT_INFO, "sed1330_cursor x=%d y=%d state='%c'", x, y, state );
data->cursor_x = x; data->cursor_x = x;
data->cursor_y = y; data->cursor_y = y;
@@ -721,7 +734,7 @@ sed1330_backlight( int on )
{ {
//private_data * data = sed1330->private_data; //private_data * data = sed1330->private_data;
printf( "sed1330_backlight on='%c'\n", on ); debug( RPT_INFO, "sed1330_backlight on='%c'", on );
// unimplemented // unimplemented
} }
@@ -737,7 +750,7 @@ sed1330_rect ( int x1, int y1, int x2, int y2, char pattern )
//private_data * data = sed1330->private_data; //private_data * data = sed1330->private_data;
int x, y; int x, y;
printf( "sed1330_rect x1=%d y1=%d x2=%d y2=%d pattern=%d\n", x1, y1, x2, y2, (int) pattern ); debug( RPT_INFO, "sed1330_rect x1=%d y1=%d x2=%d y2=%d pattern=%d", x1, y1, x2, y2, (int) pattern );
// Swap coordinates if needed // Swap coordinates if needed
if( x1>x2 ) { if( x1>x2 ) {
@@ -771,7 +784,7 @@ sed1330_line ( int x1, int y1, int x2, int y2, char pattern )
//private_data * data = sed1330->private_data; //private_data * data = sed1330->private_data;
int x, y; int x, y;
printf( "sed1330_rect x1=%d y1=%d x2=%d y2=%d pattern=%d\n", x1, y1, x2, y2, (int) pattern ); debug( RPT_INFO, "sed1330_rect x1=%d y1=%d x2=%d y2=%d pattern=%d", x1, y1, x2, y2, (int) pattern );
// Swap coordinates if needed // Swap coordinates if needed
if( x1>x2 ) { if( x1>x2 ) {
@@ -830,7 +843,7 @@ sed1330_set_pixel( int x, int y )
unsigned int bytepos; unsigned int bytepos;
char bitmask; char bitmask;
//printf( "sed1330_set_pixel x=%d y=%d\n", x, y ); //debug( RPT_INFO, "sed1330_set_pixel x=%d y=%d", x, y );
bytepos = y*data->bytesperline + x/PIXELSPERBYTE; bytepos = y*data->bytesperline + x/PIXELSPERBYTE;
bitmask = 0x80 >> (x % PIXELSPERBYTE); bitmask = 0x80 >> (x % PIXELSPERBYTE);
@@ -850,7 +863,7 @@ sed1330_clear_pixel( int x, int y )
int bytepos; int bytepos;
char bitmask; char bitmask;
//printf( "sed1330_clear_pixel x=%d y=%d\n", x, y ); //debug( RPT_INFO, "sed1330_clear_pixel x=%d y=%d", x, y );
bytepos = y*data->bytesperline + x/PIXELSPERBYTE; bytepos = y*data->bytesperline + x/PIXELSPERBYTE;
bitmask = 0x80 >> (x % PIXELSPERBYTE); bitmask = 0x80 >> (x % PIXELSPERBYTE);
@@ -866,7 +879,7 @@ sed1330_vbar( int x, int len )
{ {
private_data * data = sed1330->private_data; private_data * data = sed1330->private_data;
printf( "sed1330_hbar x=%d len=%d\n", x, len ); debug( RPT_INFO, "sed1330_hbar x=%d len=%d", x, len );
sed1330_rect ( (x-1) * CHARWIDTH, data->graph_height-1, x * CHARWIDTH - 1, data->graph_height-1 - ((long) len * CHARHEIGHT / sed1330->cellhgt ), 1 ); sed1330_rect ( (x-1) * CHARWIDTH, data->graph_height-1, x * CHARWIDTH - 1, data->graph_height-1 - ((long) len * CHARHEIGHT / sed1330->cellhgt ), 1 );
} }
@@ -881,7 +894,7 @@ sed1330_hbar( int x, int y, int len )
{ {
//private_data * data = sed1330->private_data; //private_data * data = sed1330->private_data;
printf( "sed1330_hbar x=%d y=%d len=%d\n", x, y, len ); debug( RPT_INFO, "sed1330_hbar x=%d y=%d len=%d", x, y, len );
sed1330_rect ( (x-1) * CHARWIDTH, (y-1) * CHARHEIGHT, x * CHARWIDTH + len, y * CHARHEIGHT - 1, 1 ); sed1330_rect ( (x-1) * CHARWIDTH, (y-1) * CHARHEIGHT, x * CHARWIDTH + len, y * CHARHEIGHT - 1, 1 );
} }
@@ -895,7 +908,7 @@ sed1330_num( int x, int num )
{ {
//private_data * data = sed1330->private_data; //private_data * data = sed1330->private_data;
printf( "sed1330_bignum x=%d num=%d\n", x, num ); debug( RPT_INFO, "sed1330_bignum x=%d num=%d", x, num );
} }
@@ -918,7 +931,7 @@ sed1330_heartbeat( int type )
{ 0xFF, 0xAF, 0x07, 0x07, 0x07, 0x8F, 0xDF, 0xFF, 0x00, 0x00 } { 0xFF, 0xAF, 0x07, 0x07, 0x07, 0x8F, 0xDF, 0xFF, 0x00, 0x00 }
}; };
printf( "sed1330_heartbeat type=%d\n", type ); report( RPT_INFO, "sed1330_heartbeat type=%d", type );
data->framebuf_text[sed1330->wid-1] = ' '; data->framebuf_text[sed1330->wid-1] = ' ';
whichIcon = (! ((timer + 4) & 5)); whichIcon = (! ((timer + 4) & 5));
+6 -7
View File
@@ -66,10 +66,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <syslog.h>
#include "shared/sockets.h" #include "shared/sockets.h"
#include "shared/debug.h" #include "shared/report.h"
#include "drivers/lcd.h" #include "drivers/lcd.h"
@@ -105,7 +104,7 @@ handle_input ()
if ((key = lcd_ptr->getkey ()) == 0) if ((key = lcd_ptr->getkey ()) == 0)
return 0; return 0;
//debug ("handle_input(%c)\n", (char) key); //debug (RPT_DEBUG, "handle_input(%c)", (char) key);
// Sequence: // Sequence:
// Does the current screen want the key? // Does the current screen want the key?
@@ -162,8 +161,8 @@ handle_input ()
int int
server_input (int key) server_input (int key)
{ {
debug ("server_input(%c)\n", (char) key); debug (RPT_INFO, "server_input(%c)", (char) key);
syslog(LOG_DEBUG, "key %d pressed on device", key); report(RPT_INFO, "key %d pressed on device", key);
switch ((char) key) { switch ((char) key) {
case PAUSE_KEY: case PAUSE_KEY:
@@ -181,11 +180,11 @@ server_input (int key)
screenlist_next (); screenlist_next ();
break; break;
case MAIN_MENU_KEY: case MAIN_MENU_KEY:
debug ("got the menu key!\n"); debug (RPT_DEBUG, "got the menu key!");
server_menu (); server_menu ();
break; break;
default: default:
debug ("server_input: Unused key \"%c\" (%i)\n", (char) key, key); debug (RPT_DEBUG, "server_input: Unused key \"%c\" (%i)", (char) key, key);
break; break;
} }
+181 -121
View File
@@ -20,7 +20,6 @@
#include <unistd.h> #include <unistd.h>
#include <pwd.h> #include <pwd.h>
#include <errno.h> #include <errno.h>
#include <syslog.h>
#include <math.h> #include <math.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
@@ -29,7 +28,7 @@
extern char *optarg; extern char *optarg;
extern int optind, optopt, opterr; extern int optind, optopt, opterr;
#include "shared/debug.h" #include "shared/report.h"
#include "drivers.h" #include "drivers.h"
#include "sock.h" #include "sock.h"
@@ -46,7 +45,7 @@ extern int optind, optopt, opterr;
#define MAX_TIMER 0x10000 #define MAX_TIMER 0x10000
#define DEFAULT_DEBUG_LEVEL 1 //#define DEFAULT_DEBUG_LEVEL 1
#define DEFAULT_LCD_PORT LCDPORT #define DEFAULT_LCD_PORT LCDPORT
#define DEFAULT_BIND_ADDR "127.0.0.1" #define DEFAULT_BIND_ADDR "127.0.0.1"
#define DEFAULT_CONFIGFILE "/etc/LCDd.conf" #define DEFAULT_CONFIGFILE "/etc/LCDd.conf"
@@ -56,11 +55,14 @@ extern int optind, optopt, opterr;
#define MAX_DRIVERS 8 #define MAX_DRIVERS 8
#define DEFAULT_DAEMON_MODE 1 #define DEFAULT_DAEMON_MODE 1
#define DEFAULT_ENABLE_SERVER_SCREEN 0 #define DEFAULT_ENABLE_SERVER_SCREEN 0
#define DEFAULT_REPORTTOSYSLOG 0
#define DEFAULT_REPORTLEVEL RPT_WARNING
/* Store some standard defines into vars... */ /* Store some standard defines into vars... */
char *version = VERSION; char *version = VERSION;
char *protocol_version = PROTOCOL_VERSION; char *protocol_version = PROTOCOL_VERSION;
char *api_version = API_VERSION;
char *build_date = __DATE__; char *build_date = __DATE__;
@@ -75,15 +77,22 @@ char *build_date = __DATE__;
/**** Configuration variables ****/ /**** Configuration variables ****/
// All are set to 'unset' values // All variables are set to 'unset' values
int debug_level = -1; #define UNSET_INT -1
int lcd_port = -1; #define UNSET_STR "\01"
char bind_addr[64] = "";
char configfile[256] = "";
char user[64] = "";
int daemon_mode = -1; //int debug_level = UNSET_INT;
int enable_server_screen = -1; int lcd_port = UNSET_INT;
char bind_addr[64] = UNSET_STR;
char configfile[256] = UNSET_STR;
char user[64] = UNSET_STR;
int daemon_mode = UNSET_INT;
int enable_server_screen = UNSET_INT;
static int reportLevel = UNSET_INT;
static int reportToSyslog = UNSET_INT;
static int serverStarted = 0;
// The drivers and their driver parameters // The drivers and their driver parameters
char *drivernames[MAX_DRIVERS]; char *drivernames[MAX_DRIVERS];
@@ -130,7 +139,7 @@ int init_screens();
void do_mainloop(); void do_mainloop();
void lcd_list_drivers(); void lcd_list_drivers();
#define ESSENTIAL(f) {int r; if( ( r=f )!=0 ) return r;} #define ESSENTIAL(f) {int r; if( ( r=(f) )<0 ) { report( RPT_CRIT,"Critical error, abort"); return r;}}
int int
main (int argc, char **argv) main (int argc, char **argv)
@@ -168,12 +177,10 @@ main (int argc, char **argv)
* in the variable declaration... * in the variable declaration...
*/ */
// Open syslog facility // Set the initial reporting parameters
openlog("LCDd", LOG_PID, LOG_DAEMON); report(RPT_NOTICE, "LCDd version %s starting", version );
syslog(LOG_NOTICE, "server version %s starting up (protocol version %s)", report(RPT_INFO, "Built on %s, protocol version %s, API version %s",
version, protocol_version); build_date, protocol_version, api_version );
syslog(LOG_NOTICE, "server built on %s",
build_date);
clear_settings(); clear_settings();
@@ -186,21 +193,26 @@ main (int argc, char **argv)
// Set default values // Set default values
set_default_settings(); set_default_settings();
if (debug_level > 0) // Set reporting values
syslog(LOG_NOTICE, "debug level set to %d", debug_level); ESSENTIAL( set_reporting( reportLevel, (reportToSyslog?RPT_DEST_SYSLOG:RPT_DEST_STDERR) ) );
report( RPT_NOTICE, "Set report level to %d, output to %s", reportLevel, (reportToSyslog?"syslog":"stderr") );
// Startup the server
ESSENTIAL( init_sockets() ); ESSENTIAL( init_sockets() );
ESSENTIAL( init_drivers() ); ESSENTIAL( init_drivers() );
ESSENTIAL( init_screens() ); ESSENTIAL( init_screens() );
ESSENTIAL( drop_privs(user) ); ESSENTIAL( drop_privs(user) );
// Store it for exit_program()
serverStarted = 1;
#ifndef DEBUG #ifndef DEBUG
// Now, go into daemon mode... // Now, go into daemon mode...
if (daemon_mode) { if (daemon_mode) {
syslog(LOG_NOTICE, "server forking to background"); report(RPT_NOTICE, "Server forking to background");
ESSENTIAL( daemonize() ); ESSENTIAL( daemonize() );
} else { } else {
syslog(LOG_NOTICE, "server running in foreground"); report(RPT_NOTICE, "Server running in foreground");
} }
#endif #endif
@@ -216,16 +228,19 @@ clear_settings ()
{ {
int i; int i;
debug_level = -1; //report( RPT_INFO, "clear_settings()" );
lcd_port = -1;
bind_addr[0] = 0;
configfile[0] = 0;
user[0] = 0;
daemon_mode = -1;
enable_server_screen = -1;
backlight = -1;
default_duration = -1; lcd_port = UNSET_INT;
strcpy( bind_addr, UNSET_STR );
strcpy( configfile, UNSET_STR );
strcpy( user, UNSET_STR );
daemon_mode = UNSET_INT;
enable_server_screen = UNSET_INT;
backlight = UNSET_INT;
default_duration = UNSET_INT;
reportToSyslog = UNSET_INT;
reportLevel = UNSET_INT;
for( i=0; i < num_drivers; i++ ) { for( i=0; i < num_drivers; i++ ) {
free( drivernames[i] ); free( drivernames[i] );
@@ -244,10 +259,11 @@ int
process_command_line (int argc, char **argv) process_command_line (int argc, char **argv)
{ {
char c; char c;
char buf[64];
//report( RPT_INFO, "process_command_line()" );
// analyze options here.. // analyze options here..
while ((c = getopt(argc, argv, "a:p:d:hfib:w:c:u:")) > 0) { while ((c = getopt(argc, argv, "a:p:d:hfib:w:c:u:sr:")) > 0) {
// FIXME: Setting of c in this loop clobbers s! // FIXME: Setting of c in this loop clobbers s!
// s is set equivalent to c. // s is set equivalent to c.
switch(c) { switch(c) {
@@ -260,10 +276,10 @@ process_command_line (int argc, char **argv)
strcpy( drivernames[num_drivers], optarg ); strcpy( drivernames[num_drivers], optarg );
strcpy( driverfilenames[num_drivers], optarg ); strcpy( driverfilenames[num_drivers], optarg );
strcpy( driverargs[num_drivers], ""); strcpy( driverargs[num_drivers], "" );
num_drivers ++; num_drivers ++;
} else } else
fprintf(stderr, "too many drivers!"); report( RPT_ERR, "Too many drivers!" );
break; break;
case 'p': case 'p':
lcd_port = atoi(optarg); lcd_port = atoi(optarg);
@@ -299,32 +315,36 @@ process_command_line (int argc, char **argv)
backlight = BACKLIGHT_OPEN; backlight = BACKLIGHT_OPEN;
} }
else if( strcmp( optarg, "" ) != 0 ) { else if( strcmp( optarg, "" ) != 0 ) {
fprintf( stderr, "backlight state should be on, off or open\n" ); report( RPT_ERR, "Backlight state should be on, off or open" );
HelpScreen(); HelpScreen();
} }
break; break;
case 'w': case 'w':
default_duration = atoi(optarg); default_duration = (int) (atof(optarg) * 1e6 / TIME_UNIT);
if ( default_duration < 16 || default_duration > 10000 ) { if ( default_duration * TIME_UNIT < 2e6 ) {
snprintf(buf, sizeof(buf), report( RPT_ERR, "Waittime should be at least 2 (seconds), not %.8s", optarg );
"wait time should be between 16 and 10000 (in 1/8ths of second), not %s\n", optarg);
fprintf(stderr, "%s", buf);
HelpScreen (); HelpScreen ();
}; };
break; break;
case 's':
reportToSyslog = 1;
break;
case 'r':
reportLevel = atoi(optarg);
break;
case '?': case '?':
fprintf(stderr, "unknown option: '%c'\n", optopt); report( RPT_ERR, "Unknown option: '%c'", optopt );
HelpScreen(); HelpScreen();
break; break;
case ':': case ':':
fprintf(stderr, "missing option argument!"); report( RPT_ERR, "Missing option argument!" );
HelpScreen(); HelpScreen();
break; break;
} }
} }
if (optind < argc) if (optind < argc)
fprintf(stderr, "non-option arguments!! BAD..."); report( RPT_ERR, "Non-option arguments on the command line !");
return 0; return 0;
} }
@@ -338,44 +358,46 @@ process_configfile ( char *configfile )
char * s; char * s;
//char buf[64]; //char buf[64];
//report( RPT_INFO, "process_configfile()" );
// Read server settings // Read server settings
config_read_file( configfile ); config_read_file( configfile );
if( debug_level == -1 ) // if( debug_level == UNSET_INT )
debug_level = config_get_int( "server", "debug", 0, -1 ); // debug_level = config_get_int( "server", "debug", 0, UNSET_INT );
if( lcd_port == -1 ) if( lcd_port == UNSET_INT )
lcd_port = config_get_int( "server", "port", 0, -1 ); lcd_port = config_get_int( "server", "port", 0, UNSET_INT );
if( bind_addr[0] == 0 ) if( strcmp( bind_addr, UNSET_STR ) == 0 )
strncpy( bind_addr, config_get_string( "server", "bind", 0, "" ), sizeof(bind_addr)); strncpy( bind_addr, config_get_string( "server", "bind", 0, UNSET_STR ), sizeof(bind_addr));
if( user[0] == 0 ) if( strcmp( user, UNSET_STR ) == 0 )
strncpy( user, config_get_string( "server", "user", 0, "" ), sizeof(user)); strncpy( user, config_get_string( "server", "user", 0, UNSET_STR ), sizeof(user));
if( default_duration == -1 ) { if( default_duration == UNSET_INT ) {
default_duration = (config_get_float( "server", "waittime", 0, 0 ) * 1000000 / TIME_UNIT ); default_duration = (config_get_float( "server", "waittime", 0, 0 ) * 1e6 / TIME_UNIT );
if( default_duration == 0 ) if( default_duration == 0 )
default_duration = -1; default_duration = UNSET_INT;
else if( default_duration < 16 ) { else if( default_duration * TIME_UNIT < 2e6 ) {
fprintf( stderr, "waittime should be at least 2 (seconds)\n" ); report( RPT_ERR, "Waittime should be at least 2 (seconds)" );
return -1; return -1;
} }
} }
if( daemon_mode == -1 ) { if( daemon_mode == UNSET_INT ) {
int fg; int fg;
fg = config_get_bool( "server", "foreground", 0, -1 ); fg = config_get_bool( "server", "foreground", 0, UNSET_INT );
if( fg != -1 ) if( fg != UNSET_INT )
daemon_mode = !fg; daemon_mode = !fg;
} }
if( enable_server_screen == -1 ) if( enable_server_screen == UNSET_INT )
enable_server_screen = config_get_bool( "server", "serverscreen", 0, -1 ); enable_server_screen = config_get_bool( "server", "serverscreen", 0, UNSET_INT );
if( backlight == -1 ) { if( backlight == UNSET_INT ) {
s = config_get_string( "server", "backlight", 0, "" ); s = config_get_string( "server", "backlight", 0, UNSET_STR );
if( strcmp( s, "on" ) == 0 ) { if( strcmp( s, "on" ) == 0 ) {
backlight = BACKLIGHT_ON; backlight = BACKLIGHT_ON;
backlight_state = backlight; backlight_state = backlight;
@@ -387,11 +409,22 @@ process_configfile ( char *configfile )
else if( strcmp( s, "open" ) == 0 ) { else if( strcmp( s, "open" ) == 0 ) {
backlight = BACKLIGHT_OPEN; backlight = BACKLIGHT_OPEN;
} }
else if( strcmp( s, "" ) != 0 ) { else if( strcmp( s, UNSET_STR ) != 0 ) {
fprintf( stderr, "backlight state should be on, off or open\n" ); report( RPT_ERR, "Backlight state should be on, off or open" );
} }
} }
if( reportToSyslog == UNSET_INT ) {
// Is the value set in the config file anyway ?
if( strcmp( config_get_string( "server", "reportToSyslog", 0, "" ), "" ) != 0 ) {
reportToSyslog = config_get_bool( "server", "reportToSyslog", 0, 0 );
}
}
if( reportLevel == UNSET_INT ) {
reportLevel = config_get_int( "server", "reportLevel", 0, UNSET_INT );
}
// Read drivers // Read drivers
// If drivers have been specified on the command line, then do not // If drivers have been specified on the command line, then do not
@@ -435,29 +468,37 @@ process_configfile ( char *configfile )
void void
set_default_settings() set_default_settings()
{ {
//report( RPT_INFO, "set_default_settings()" );
// Set defaults into unfilled variables.... // Set defaults into unfilled variables....
if (debug_level == -1) // if (debug_level == UNSET_INT)
debug_level = DEFAULT_DEBUG_LEVEL; // debug_level = DEFAULT_DEBUG_LEVEL;
if (lcd_port == -1) if (lcd_port == UNSET_INT)
lcd_port = DEFAULT_LCD_PORT; lcd_port = DEFAULT_LCD_PORT;
if (bind_addr[0] == 0) if (strcmp( bind_addr, UNSET_STR ) == 0)
strncpy (bind_addr, DEFAULT_BIND_ADDR, sizeof(bind_addr)); strncpy (bind_addr, DEFAULT_BIND_ADDR, sizeof(bind_addr));
if (configfile[0] == 0) if (strcmp( configfile, UNSET_STR ) == 0)
strncpy (configfile, DEFAULT_CONFIGFILE, sizeof(configfile)); strncpy (configfile, DEFAULT_CONFIGFILE, sizeof(configfile));
if (user[0] == 0) if (strcmp( user, UNSET_STR ) == 0)
strncpy(user, DEFAULT_USER, sizeof(user)); strncpy(user, DEFAULT_USER, sizeof(user));
if (daemon_mode == -1) if (daemon_mode == UNSET_INT)
daemon_mode = DEFAULT_DAEMON_MODE; daemon_mode = DEFAULT_DAEMON_MODE;
if (enable_server_screen == -1) if (enable_server_screen == UNSET_INT)
enable_server_screen = DEFAULT_ENABLE_SERVER_SCREEN; enable_server_screen = DEFAULT_ENABLE_SERVER_SCREEN;
if (default_duration == -1) if (default_duration == UNSET_INT)
default_duration = DEFAULT_SCREEN_DURATION; default_duration = DEFAULT_SCREEN_DURATION;
if (backlight == -1) if (backlight == UNSET_INT)
backlight = BACKLIGHT_OPEN; backlight = BACKLIGHT_OPEN;
if (reportToSyslog == UNSET_INT )
reportToSyslog = DEFAULT_REPORTTOSYSLOG;
if( reportLevel == UNSET_INT )
reportLevel = DEFAULT_REPORTLEVEL;
// Use default driver // Use default driver
if( num_drivers == 0 ) { if( num_drivers == 0 ) {
drivernames[0] = malloc(strlen(DEFAULT_DRIVER)+1); drivernames[0] = malloc(strlen(DEFAULT_DRIVER)+1);
@@ -477,10 +518,12 @@ daemonize()
{ {
int child; int child;
report( RPT_INFO, "daemonize()" );
switch ((child = fork ()) ) { switch ((child = fork ()) ) {
case -1: case -1:
syslog(LOG_ERR, "could not fork"); report(RPT_ERR, "Could not fork");
return 1; return -1;
case 0: // We are the child case 0: // We are the child
break; break;
default: // We are the parent default: // We are the parent
@@ -502,17 +545,18 @@ daemonize()
int int
init_sockets () init_sockets ()
{ {
report( RPT_INFO, "init_sockets()" );
if (sock_create_server (&bind_addr, lcd_port) <= 0) { if (sock_create_server (&bind_addr, lcd_port) <= 0) {
syslog(LOG_ERR, "error opening socket"); report(RPT_ERR, "Error opening socket");
return 1; return -1;
} }
// Now init a bunch of required stuff... // Now init a bunch of required stuff...
if (client_init () < 0) { if (client_init () < 0) {
syslog(LOG_ERR, "error initializing client list"); report(RPT_ERR, "Error initializing client list");
return 1; return -1;
} }
return 0; return 0;
} }
@@ -522,10 +566,11 @@ int
init_drivers() init_drivers()
{ {
int i, res; int i, res;
char buf[64];
int output_loaded = 0; int output_loaded = 0;
report( RPT_INFO, "init_drivers()" );
// FIXME: This sets s equal to a value related to i // FIXME: This sets s equal to a value related to i
// (bitshifted left?) FIX FIX FIX ARGH.... // (bitshifted left?) FIX FIX FIX ARGH....
// //
@@ -550,8 +595,7 @@ init_drivers()
break; break;
} }
} else { } else {
snprintf(buf, sizeof(buf), "Could not load driver %s\n", drivernames[i]); report( RPT_ERR, "Could not load driver %.40s", drivernames[i] );
fprintf(stderr, buf);
} }
} }
@@ -559,6 +603,7 @@ init_drivers()
if ( output_loaded ) { if ( output_loaded ) {
return 0; return 0;
} else { } else {
report( RPT_ERR, "There is no output driver" );
return -1; return -1;
} }
} }
@@ -568,20 +613,16 @@ int drop_privs(char *user)
{ {
struct passwd *pwent; struct passwd *pwent;
report( RPT_INFO, "drop_privs()" );
if (getuid() == 0 || geteuid() == 0) { if (getuid() == 0 || geteuid() == 0) {
if ((pwent = getpwnam(user)) == NULL) { if ((pwent = getpwnam(user)) == NULL) {
if (errno) { report( RPT_ERR, "User %.40s not a valid user!", user );
perror("LCDd: getpwnam"); return -1;
return 1;
} else {
fprintf(stderr, "user %s not a valid user!", user);
return 1;
}
} else { } else {
if (setuid(pwent->pw_uid) < 0) { if (setuid(pwent->pw_uid) < 0) {
fprintf(stderr, "unable to switch to user %s\n", user); report( RPT_ERR, "Unable to switch to user %.40s", user );
perror("LCDd: setuid"); return -1;
return 1;
} }
} }
} }
@@ -592,14 +633,16 @@ int drop_privs(char *user)
int int
init_screens () init_screens ()
{ {
report( RPT_INFO, "init_screens()" );
if (screenlist_init () < 0) { if (screenlist_init () < 0) {
syslog(LOG_ERR, "error initializing screen list"); report(RPT_ERR, "Error initializing screen list");
return 1; return -1;
} }
// Make sure the server screen shows up every once in a while.. // Make sure the server screen shows up every once in a while..
if (server_screen_init () < 0) { if (server_screen_init () < 0) {
syslog(LOG_ERR, "error initializing server screens"); report(RPT_ERR, "Error initializing server screens");
return 1; return -1;
} else if (!enable_server_screen) { } else if (!enable_server_screen) {
server_screen->priority = 256; server_screen->priority = 256;
} }
@@ -612,7 +655,9 @@ do_mainloop ()
{ {
screen *s = NULL; screen *s = NULL;
char *message=NULL; char *message=NULL;
report( RPT_INFO, "do_mainloop()" );
//char buf[64]; //char buf[64];
// FIXME: s should still be null from initialization.... what's happening here?! // FIXME: s should still be null from initialization.... what's happening here?!
@@ -632,7 +677,7 @@ do_mainloop ()
// this is here because s is getting overwritten... // this is here because s is getting overwritten...
//if (s != screenlist_current()) { //if (s != screenlist_current()) {
// syslog(LOG_DEBUG, "internal error! s was found overwritten at main.c:637"); // report(RPT_DEBUG, "internal error! s was found overwritten at main.c:637");
// s = screenlist_current(); // s = screenlist_current();
//} //}
// //
@@ -665,33 +710,33 @@ do_mainloop ()
usleep (TIME_UNIT); usleep (TIME_UNIT);
//Check to see if the screen has a timeout value, if it does //Check to see if the screen has a timeout value, if it does
//decrese it and then check to see if it has excpired. //decrese it and then check to see if it has excpired.
//Remove if expired. //Remove if expired.
if((message = malloc(256)) == NULL) if((message = malloc(256)) == NULL)
syslog(LOG_NOTICE, "Error allocating message string"); report(RPT_ERR, "Error allocating message string");
else { else {
snprintf(message, 256, "Screen->%s has timeout->%d", s->name, s->timeout); snprintf(message, 256, "Screen->%s has timeout->%d", s->name, s->timeout);
syslog(LOG_NOTICE, message); report(RPT_DEBUG, message);
free(message); free(message);
} }
if (s && s->timeout != -1) { if (s && s->timeout != -1) {
--(s->timeout); --(s->timeout);
if((message = malloc(256)) == NULL) if((message = malloc(256)) == NULL)
syslog(LOG_NOTICE, "Error allocating message string"); report(RPT_ERR, "Error allocating message string");
else { else {
snprintf(message, 256, "Timeout matches check, screen %s has timeout->%d", s->name, s->timeout); snprintf(message, 256, "Timeout matches check, screen %s has timeout->%d", s->name, s->timeout);
syslog(LOG_NOTICE, message); report(RPT_DEBUG, message);
free(message); free(message);
} }
if (s->timeout <= 0) { if (s->timeout <= 0) {
screen_remove (s->parent, s->id); screen_remove (s->parent, s->id);
if((message = malloc(256)) == NULL) if((message = malloc(256)) == NULL)
syslog(LOG_NOTICE, "Error allocating message string"); report(RPT_ERR, "Error allocating message string");
else { else {
snprintf(message, 256, "Removing screen %s which has timeout->%d", s->name, s->timeout); snprintf(message, 256, "Removing screen %s which has timeout->%d", s->name, s->timeout);
syslog(LOG_NOTICE, message); report(RPT_DEBUG, message);
free(message); free(message);
} }
} }
@@ -707,28 +752,38 @@ exit_program (int val)
{ {
char buf[64]; char buf[64];
report( RPT_INFO, "exit_program()" );
// TODO: These things shouldn't be so interdependent. The order // TODO: These things shouldn't be so interdependent. The order
// things are shut down in shouldn't matter... // things are shut down in shouldn't matter...
strcpy(buf, "server shutting down on "); strcpy(buf, "Server shutting down on ");
switch(val) { switch(val) {
case 1: strcat(buf, "SIGHUP"); break; case 1: strcat(buf, "SIGHUP"); break;
case 2: strcat(buf, "SIGINT"); break; case 2: strcat(buf, "SIGINT"); break;
case 15: strcat(buf, "SIGTERM"); break; case 15: strcat(buf, "SIGTERM"); break;
default: snprintf(buf, sizeof(buf), "server shutting down on signal %d", val); break; default: snprintf(buf, sizeof(buf), "Server shutting down on signal %d", val); break;
// Other values should not be seen, but just in case.. // Other values should not be seen, but just in case..
} }
syslog(LOG_NOTICE, buf); // send message to syslog report(RPT_NOTICE, buf); // report it
// Set emergency reporting and flush all messages if not done already.
if( reportLevel == UNSET_INT )
reportLevel = DEFAULT_REPORTLEVEL;
if( reportToSyslog == UNSET_INT )
reportLevel = DEFAULT_REPORTLEVEL;
set_reporting( reportLevel, (reportToSyslog?RPT_DEST_SYSLOG:RPT_DEST_STDERR) );
goodbye_screen (); // display goodbye screen on LCD display // Shutdown things if server start was complete
unload_all_drivers (); // release driver memory and file descriptors if( serverStarted ) {
goodbye_screen (); // display goodbye screen on LCD display
client_shutdown (); // shutdown clients (must come first) unload_all_drivers (); // release driver memory and file descriptors
screenlist_shutdown (); // shutdown screens (must come after client_shutdown)
sock_close_all (); // close all open sockets (must come after client_shutdown)
client_shutdown (); // shutdown clients (must come first)
screenlist_shutdown (); // shutdown screens (must come after client_shutdown)
sock_close_all (); // close all open sockets (must come after client_shutdown)
}
exit (0); exit (0);
} }
@@ -737,11 +792,14 @@ exit_program (int val)
void void
HelpScreen () HelpScreen ()
{ {
// Help screen is printed to stdout on purpose. No reason to have
// this in syslog...
report( RPT_INFO, "HelpScreen()" );
printf ("\nLCDd Server Daemon (part of lcdproc), %s\n", version); printf ("\nLCDd Server Daemon (part of lcdproc), %s\n", version);
printf ("Copyright (c) 1999 Scott Scriven, William Ferrell, and misc contributors\n"); printf ("Copyright (c) 1999 Scott Scriven, William Ferrell, and misc contributors\n");
printf ("This program is freely redistributable under the terms of the GNU Public License\n\n"); printf ("This program is freely redistributable under the terms of the GNU Public License\n\n");
printf ("Usage: LCDd [ -hfiw ] [ -c <config> ] [ -d <driver> ] [ -a <addr> ] \\\n\t[ -p <port> ] [ -u <user> ] [ -w <time> ]\n\n"); printf ("Usage: LCDd [ -hfiws ] [ -c <config> ] [ -d <driver> ] [ -a <addr> ] \\\n\t[ -p <port> ] [ -u <user> ] [ -w <time> ] [ -r <level> ]\n\n");
printf ("Available options are:\n"); printf ("Available options are:\n");
printf ("\t-h\t\tDisplay this help screen\n"); printf ("\t-h\t\tDisplay this help screen\n");
@@ -753,10 +811,12 @@ HelpScreen ()
printf ("\t-f\t\tRun in the foreground\n"); printf ("\t-f\t\tRun in the foreground\n");
//printf ("\t-b\t--backlight <mode>\n\t\t\tSet backlight mode (on, off, open)\n"); //printf ("\t-b\t--backlight <mode>\n\t\t\tSet backlight mode (on, off, open)\n");
printf ("\t-i\t\tDisable showing of the main LCDproc server screen\n"); printf ("\t-i\t\tDisable showing of the main LCDproc server screen\n");
printf ("\t-w <waittime>\tTime to pause at each screen (in 1/8s of a second)\n"); printf ("\t-w <waittime>\tTime to pause at each screen (in seconds)\n");
printf ("\t-a <addr>\tNetwork (IP) address to bind to\n"); printf ("\t-a <addr>\tNetwork (IP) address to bind to\n");
printf ("\t-p <port>\tNetwork port to listen for connections on\n"); printf ("\t-p <port>\tNetwork port to listen for connections on\n");
printf ("\t-u <user>\tUser to run as\n"); printf ("\t-u <user>\tUser to run as\n");
printf ("\t-s\t\tOutput messages to syslog\n");
printf ("\t-r <level>\tReport level (default=2)\n");
printf ("\nCurrently available drivers:\n"); printf ("\nCurrently available drivers:\n");
lcd_list_drivers(); lcd_list_drivers();
+3 -3
View File
@@ -7,14 +7,14 @@
So far, all menus are static, and not dynamically generated. I'll So far, all menus are static, and not dynamically generated. I'll
have to find a way to fix this, since many menu items will be dynamic. have to find a way to fix this, since many menu items will be dynamic.
(clients connected, screens available, etc...) (clients connected, screens available, etc...)
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "shared/debug.h" #include "shared/report.h"
#include "drivers/lcd.h" #include "drivers/lcd.h"
@@ -292,7 +292,7 @@ Contrast_func (int input)
void void
server_menu () server_menu ()
{ {
debug ("server_menu()\n"); debug (RPT_DEBUG, "server_menu()");
do_menu (main_menu); do_menu (main_menu);
+13 -11
View File
@@ -6,7 +6,7 @@
It works much like a command line. Only the first token is used to It works much like a command line. Only the first token is used to
determine what function to call. determine what function to call.
*/ */
#include <stdlib.h> #include <stdlib.h>
@@ -15,7 +15,7 @@
#include "shared/LL.h" #include "shared/LL.h"
#include "shared/sockets.h" #include "shared/sockets.h"
#include "shared/debug.h" #include "shared/report.h"
#include "clients.h" #include "clients.h"
#include "client_functions.h" #include "client_functions.h"
#include "parse.h" #include "parse.h"
@@ -42,6 +42,8 @@ parse_all_client_messages ()
int invalid = 0; int invalid = 0;
int quoteindex; int quoteindex;
debug( RPT_DEBUG, "parse_all_client_messages()" );
for (i = 0; i < MAX_ARGUMENTS; i++) { for (i = 0; i < MAX_ARGUMENTS; i++) {
argv[i] = NULL; argv[i] = NULL;
} }
@@ -50,17 +52,17 @@ parse_all_client_messages ()
#define LINE_TERM_CHAR '\0' #define LINE_TERM_CHAR '\0'
#define COMMENT_CHAR '#' #define COMMENT_CHAR '#'
//debug("parse: Rewinding list...\n"); //debug("parse: Rewinding list...");
LL_Rewind (clients); LL_Rewind (clients);
do { do {
// Get the next client... // Get the next client...
//debug("parse: Getting client...\n"); //debug("parse: Getting client...");
c = LL_Get (clients); c = LL_Get (clients);
if (c) { if (c) {
// And parse all its messages... // And parse all its messages...
//debug("parse: Getting messages...\n"); //debug(RPT_DEBUG, "parse: Getting messages...");
for (str = client_get_message (c); str; str = client_get_message (c)) { for (str = client_get_message (c); str; str = client_get_message (c)) {
debug ("parse: ...%s\n", str); debug (RPT_DEBUG, "parse: ...%s", str);
// Now, split up the string... // Now, split up the string...
argc = 0; argc = 0;
i = 0; i = 0;
@@ -70,7 +72,7 @@ parse_all_client_messages ()
continue; // found a comment line - skip it... continue; // found a comment line - skip it...
} }
//fprintf(stderr, "starting string scan...\n"); debug (RPT_DEBUG, "starting string scan...");
do { do {
// bypass initial white space... // bypass initial white space...
@@ -98,7 +100,7 @@ parse_all_client_messages ()
// Handle quoted strings... // Handle quoted strings...
if ((s = strchr(leftquote, *p)) != NULL) { if ((s = strchr(leftquote, *p)) != NULL) {
quoteindex = s - leftquote; quoteindex = s - leftquote;
//fprintf(stderr, "found <%c> at index [%d] = <%c>\n", *p, quoteindex, leftquote[quoteindex]); //debug(RPT_DEBUG, "found <%c> at index [%d] = <%c>", *p, quoteindex, leftquote[quoteindex]);
q = ++p; // past open quote... q = ++p; // past open quote...
while ((rightquote[quoteindex] != *p) && (*p != LINE_TERM_CHAR)) { while ((rightquote[quoteindex] != *p) && (*p != LINE_TERM_CHAR)) {
p++; p++;
@@ -130,11 +132,11 @@ parse_all_client_messages ()
// Not end of line? // Not end of line?
if (*p) { if (*p) {
*p = LINE_TERM_CHAR; *p = LINE_TERM_CHAR;
//fprintf(stderr, "found new token: %s\n", q); //debug(RPT_DEBUG, "found new token: %s", q);
argv[i++] = q; argv[i++] = q;
q = ++p; q = ++p;
} else { } else {
//fprintf(stderr, "found new token: %s\n", q); //debug(RPT_DEBUG, "found new token: %s", q);
argv[i++] = q; argv[i++] = q;
} }
// At the end of this statement, // At the end of this statement,
@@ -146,7 +148,7 @@ parse_all_client_messages ()
argc++; argc++;
} while (*p); } while (*p);
//fprintf(stderr, "exiting string scan...\n"); //debug(RPT_DEBUG, "exiting string scan...");
argv[argc] = NULL; argv[argc] = NULL;
if (argc < 1) if (argc < 1)
+16 -16
View File
@@ -10,7 +10,7 @@
This will probably take a while to do. :( This will probably take a while to do. :(
THIS FILE IS MESSY! Anyone care to rewrite it nicely? Please?? :) THIS FILE IS MESSY! Anyone care to rewrite it nicely? Please?? :)
NOTE: (from David Douthitt) Multiple screen sizes? Multiple simultaneous NOTE: (from David Douthitt) Multiple screen sizes? Multiple simultaneous
screens? Horrors of horrors... next thing you know it'll be making coffee... screens? Horrors of horrors... next thing you know it'll be making coffee...
Better believe it'll take a while to do... Better believe it'll take a while to do...
@@ -20,7 +20,7 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include "shared/debug.h" #include "shared/report.h"
#include "shared/LL.h" #include "shared/LL.h"
#include "drivers/lcd.h" #include "drivers/lcd.h"
@@ -49,12 +49,12 @@ draw_screen (screen * s, int timer)
static screen *old_s = NULL; static screen *old_s = NULL;
int tmp = 0, tmp_state = 0; int tmp = 0, tmp_state = 0;
//debug("Render...\n"); //debug(RPT_DEBUG, "Render...");
//return 0; //return 0;
reset = 1; reset = 1;
//debug("draw_screen: %8x, %i\n", (int)s, timer); //debug(RPT_DEBUG, "draw_screen: %8x, %i", (int)s, timer);
if (!s) if (!s)
return -1; return -1;
@@ -73,7 +73,7 @@ draw_screen (screen * s, int timer)
// lcd_ptr->backlight_brightness, lcd_ptr->backlight_flash ... // lcd_ptr->backlight_brightness, lcd_ptr->backlight_flash ...
// If the screen's backlight_state isn't set (default) then we // If the screen's backlight_state isn't set (default) then we
// inherit the backlight state from the parent client. This allows // inherit the backlight state from the parent client. This allows
// the client to override it's childrens settings. // the client to override it's childrens settings.
if (s->backlight_state == BACKLIGHT_NOTSET) { if (s->backlight_state == BACKLIGHT_NOTSET) {
if (s->parent) tmp_state = s->parent->backlight_state; if (s->parent) tmp_state = s->parent->backlight_state;
@@ -121,7 +121,7 @@ draw_screen (screen * s, int timer)
// Draw a frame... // Draw a frame...
draw_frame (s->widgets, 'v', 0, 0, lcd_ptr->wid, lcd_ptr->hgt, s->wid, s->hgt, (((s->duration / s->hgt) < 1) ? 1 : (s->duration / s->hgt)), timer); draw_frame (s->widgets, 'v', 0, 0, lcd_ptr->wid, lcd_ptr->hgt, s->wid, s->hgt, (((s->duration / s->hgt) < 1) ? 1 : (s->duration / s->hgt)), timer);
//debug("draw_screen done\n"); //debug(RPT_DEBUG, "draw_screen done");
if (heartbeat) { if (heartbeat) {
lcd_ptr->heartbeat(s->heartbeat); lcd_ptr->heartbeat(s->heartbeat);
@@ -143,7 +143,7 @@ draw_screen (screen * s, int timer)
// flush display out, frame and all... // flush display out, frame and all...
lcd_ptr->flush (); lcd_ptr->flush ();
//debug("draw_screen: %8x, %i\n", s, timer); //debug(RPT_DEBUG, "draw_screen: %8x, %i", s, timer);
return 0; return 0;
@@ -213,12 +213,12 @@ draw_frame (LinkedList * list,
} else if (HorizontalScrolling) { } else if (HorizontalScrolling) {
// TODO: Frames don't scroll horizontally yet! // TODO: Frames don't scroll horizontally yet!
} }
//debug("draw_screen: %8x, %i\n", s, timer); //debug(RPT_DEBUG, "draw_screen: %8x, %i", s, timer);
if (!list) if (!list)
return -1; return -1;
//debug("draw_frame: %8x, %i\n", frame, timer); //debug(RPT_DEBUG, "draw_frame: %8x, %i", frame, timer);
#define PositiveX(a) ((a)->x > 0) #define PositiveX(a) ((a)->x > 0)
#define PositiveY(a) ((a)->y > 0) #define PositiveY(a) ((a)->y > 0)
@@ -334,7 +334,7 @@ draw_frame (LinkedList * list,
break; break;
if (w->right < w->left) if (w->right < w->left)
break; break;
//printf("rendering: %s %d\n",w->text,timer); //printf(RPT_DEBUG, "rendering: %s %d",w->text,timer);
screen_width = w->right - w->left + 1; screen_width = w->right - w->left + 1;
switch (w->length) { // actually, direction... switch (w->length) { // actually, direction...
// FIXED: Horz scrollers don't show the // FIXED: Horz scrollers don't show the
@@ -382,7 +382,7 @@ draw_frame (LinkedList * list,
if (offset <= length) { if (offset <= length) {
strncpy (str, &((w->text)[offset]), screen_width); strncpy (str, &((w->text)[offset]), screen_width);
str[screen_width] = '\0'; str[screen_width] = '\0';
//printf("%s : %d\n",str,length-offset); //debug(RPT_DEBUG, "scroller %s : %d", str, length-offset);
} else { } else {
str[0] = '\0'; str[0] = '\0';
} }
@@ -416,15 +416,15 @@ draw_frame (LinkedList * list,
int begin = 0; int begin = 0;
if (!screenlist_action) if (!screenlist_action)
screenlist_action = RENDER_HOLD; screenlist_action = RENDER_HOLD;
//printf("length: %d sw: %d lines req: %d avail lines: %d effLines: %d \n",length,screen_width,lines_required,available_lines,effLines); //debug(RPT_DEBUG, "length: %d sw: %d lines req: %d avail lines: %d effLines: %d ",length,screen_width,lines_required,available_lines,effLines);
if (w->speed > 0) { if (w->speed > 0) {
necessaryTimeUnits = effLines * w->speed; necessaryTimeUnits = effLines * w->speed;
if (((timer / (effLines * w->speed)) % 2) == 0) { if (((timer / (effLines * w->speed)) % 2) == 0) {
//printf("up "); //debug(RPT_DEBUG, "up ");
begin = (timer % (effLines * w->speed)) begin = (timer % (effLines * w->speed))
/ w->speed; / w->speed;
} else { } else {
//printf("down "); //debug(RPT_DEBUG, "down ");
begin = (((timer % (effLines * w->speed)) begin = (((timer % (effLines * w->speed))
- (effLines * w->speed) + 1) / w->speed) - (effLines * w->speed) + 1) / w->speed)
* -1; * -1;
@@ -442,11 +442,11 @@ draw_frame (LinkedList * list,
} else { } else {
begin = 0; begin = 0;
} }
//printf("rendering begin: %d timer: %d effLines: %d\n",begin,timer,effLines); //debug(RPT_DEBUG, "rendering begin: %d timer: %d effLines: %d",begin,timer,effLines);
for (i = begin; i < begin + available_lines; i++) { for (i = begin; i < begin + available_lines; i++) {
strncpy (str, &((w->text)[i * (screen_width)]), screen_width); strncpy (str, &((w->text)[i * (screen_width)]), screen_width);
str[screen_width] = '\0'; str[screen_width] = '\0';
//printf("rendering: '%s' of %s\n", //debug(RPT_DEBUG, "rendering: '%s' of %s",
//str,w->text); //str,w->text);
lcd_ptr->string (w->left, w->top + (i - begin), str); lcd_ptr->string (w->left, w->top + (i - begin), str);
} }
+12 -12
View File
@@ -2,7 +2,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "shared/debug.h" #include "shared/report.h"
#include "drivers/lcd.h" #include "drivers/lcd.h"
@@ -24,7 +24,7 @@ screen_create ()
s = malloc (sizeof (screen)); s = malloc (sizeof (screen));
if (!s) { if (!s) {
fprintf (stderr, "screen_create: Error allocating new screen\n"); report(RPT_ERR, "screen_create: Error allocating new screen");
return NULL; return NULL;
} }
@@ -38,13 +38,13 @@ screen_create ()
s->keys = NULL; s->keys = NULL;
s->parent = NULL; s->parent = NULL;
s->widgets = NULL; s->widgets = NULL;
s->timeout = default_timeout; //ignored unless greater than 0. s->timeout = default_timeout; //ignored unless greater than 0.
s->backlight_state = BACKLIGHT_NOTSET; //Lets the screen do it's own s->backlight_state = BACKLIGHT_NOTSET; //Lets the screen do it's own
//or do what the client says. //or do what the client says.
s->widgets = LL_new (); s->widgets = LL_new ();
if (!s->widgets) { if (!s->widgets) {
fprintf (stderr, "screen_create: Error allocating widget list\n"); report(RPT_ERR, "screen_create: Error allocating widget list");
return NULL; return NULL;
} }
@@ -89,13 +89,13 @@ screen_find (client * c, char *id)
if (!id) if (!id)
return NULL; return NULL;
debug ("client_find_screen(%s)\n", id); debug (RPT_INFO, "client_find_screen(%s)", id);
LL_Rewind (c->data->screenlist); LL_Rewind (c->data->screenlist);
do { do {
s = LL_Get (c->data->screenlist); s = LL_Get (c->data->screenlist);
if ((s) && (0 == strcmp (s->id, id))) { if ((s) && (0 == strcmp (s->id, id))) {
debug ("client_find_screen: Found %s\n", id); debug (RPT_DEBUG, "client_find_screen: Found %s", id);
return s; return s;
} }
} while (LL_Next (c->data->screenlist) == 0); } while (LL_Next (c->data->screenlist) == 0);
@@ -121,7 +121,7 @@ screen_add (client * c, char *id)
s = screen_create (); s = screen_create ();
if (!s) { if (!s) {
fprintf (stderr, "screen_add: Error creating screen\n"); report (RPT_ERR, "screen_add: Error creating screen");
return -1; return -1;
} }
@@ -129,7 +129,7 @@ screen_add (client * c, char *id)
s->id = strdup (id); s->id = strdup (id);
if (!s->id) { if (!s->id) {
fprintf (stderr, "screen_add: Error allocating name\n"); report (RPT_ERR, "screen_add: Error allocating name");
return -1; return -1;
} }
// TODO: Check for errors here? // TODO: Check for errors here?
@@ -137,7 +137,7 @@ screen_add (client * c, char *id)
// Now, add it to the screenlist... // Now, add it to the screenlist...
if (screenlist_add (s) < 0) { if (screenlist_add (s) < 0) {
fprintf (stderr, "screen_add: Error queueing new screen\n"); report (RPT_ERR, "screen_add: Error queueing new screen");
return -1; return -1;
} }
@@ -157,7 +157,7 @@ screen_remove (client * c, char *id)
// Make sure this screen *does* exist... // Make sure this screen *does* exist...
s = screen_find (c, id); s = screen_find (c, id);
if (!s) { if (!s) {
fprintf (stderr, "screen_remove: Error finding screen %s\n", id); report (RPT_ERR, "screen_remove: Error finding screen %s", id);
return 1; return 1;
} }
// TODO: Check for errors here? // TODO: Check for errors here?
@@ -166,7 +166,7 @@ screen_remove (client * c, char *id)
// Now, remove it from the screenlist... // Now, remove it from the screenlist...
if (screenlist_remove_all (s) < 0) { if (screenlist_remove_all (s) < 0) {
// Not a serious error.. // Not a serious error..
fprintf (stderr, "screen_remove: Error dequeueing screen\n"); report (RPT_ERR, "screen_remove: Error dequeueing screen");
return 0; return 0;
} }
+27 -29
View File
@@ -1,10 +1,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <syslog.h>
#include "shared/LL.h" #include "shared/LL.h"
#include "shared/sockets.h" #include "shared/sockets.h"
#include "shared/debug.h" #include "shared/report.h"
#include "screenlist.h" #include "screenlist.h"
#include "screen.h" #include "screen.h"
#include "clients.h" #include "clients.h"
@@ -26,11 +25,11 @@ int compare_addresses (void *one, void *two);
int int
screenlist_init () screenlist_init ()
{ {
debug ("screenlist_init()\n"); report (RPT_INFO, "screenlist_init()");
screenlist = LL_new (); screenlist = LL_new ();
if (!screenlist) { if (!screenlist) {
syslog(LOG_ERR, "screenlist_init: error allocating list"); report(RPT_ERR, "screenlist_init: error allocating list");
return -1; return -1;
} }
@@ -43,7 +42,7 @@ screenlist_init ()
int int
screenlist_shutdown () screenlist_shutdown ()
{ {
debug ("screenlist_shutdown()\n"); report (RPT_INFO, "screenlist_shutdown()");
LL_Destroy (screenlist); LL_Destroy (screenlist);
@@ -53,7 +52,7 @@ screenlist_shutdown ()
int int
screenlist_remove (screen * s) screenlist_remove (screen * s)
{ {
debug ("screenlist_remove()\n"); report (RPT_INFO, "screenlist_remove()");
if (!LL_Remove (screenlist, s)) if (!LL_Remove (screenlist, s))
return -1; return -1;
@@ -66,12 +65,12 @@ screenlist_remove_all (screen * s)
{ {
int i = 0; int i = 0;
debug ("screenlist_remove_all()\n"); report (RPT_INFO, "screenlist_remove_all()");
while (LL_Remove (screenlist, s)) while (LL_Remove (screenlist, s))
i++; i++;
debug ("screenlist_remove_all()... got %i\n", i); debug (RPT_DEBUG, "screenlist_remove_all()... got %i", i);
return i; return i;
} }
@@ -79,7 +78,7 @@ screenlist_remove_all (screen * s)
LinkedList * LinkedList *
screenlist_getlist () screenlist_getlist ()
{ {
debug ("screenlist_getlist()\n"); report (RPT_INFO, "screenlist_getlist()");
return screenlist; return screenlist;
} }
@@ -92,24 +91,25 @@ screenlist_current ()
static screen *old_s = NULL; static screen *old_s = NULL;
client *c; client *c;
//debug("screenlist_current:\n"); debug( RPT_INFO, "screenlist_current:");
//LL_dprint(screenlist); //LL_dprint(screenlist);
s = (screen *) LL_GetFirst (screenlist); s = (screen *) LL_GetFirst (screenlist);
// FIXME: Make sure the screen/client exists! // FIXME: Make sure the screen/client exists!
if (s != old_s) { if (s != old_s) {
debug ("screenlist_current: new screen\n"); //debug (RPT_DEBUG, "screenlist_current: new screen");
timer = 0; timer = 0;
// Tell the client we're done with the current screen // Tell the client we're done with the current screen
if (old_s) { if (old_s) {
//debug("screenlist_current: ignoring old screen\n"); //debug(RPT_DEBUG, "screenlist_current: ignoring old screen");
LL_Rewind (screenlist); LL_Rewind (screenlist);
if (old_s != LL_Find (screenlist, compare_addresses, old_s)) { if (old_s != LL_Find (screenlist, compare_addresses, old_s)) {
debug ("screenlist: Didn't find screen 0x%8x!\n", (int) old_s); report (RPT_WARNING, "screenlist: Didn't find screen 0x%8x!", (int) old_s);
} else { } else {
//debug("screenlist_current: ... sending ignore\n"); //debug(RPT_DEBUG, "screenlist_current: ... sending ignore");
c = old_s->parent; c = old_s->parent;
if (c) // Tell the client we're not listening any more... if (c) // Tell the client we're not listening any more...
{ {
@@ -119,11 +119,11 @@ screenlist_current ()
{ {
; ;
} }
//debug("screenlist_current: ... sent ignore\n"); //debug(RPT_DEBUG, "screenlist_current: ... sent ignore");
} }
} }
if (s) { if (s) {
//debug("screenlist_current: listening to new screen\n"); //debug(RPT_DEBUG, "screenlist_current: listening to new screen");
c = s->parent; c = s->parent;
if (c) // Tell the client we're paying attention... if (c) // Tell the client we're paying attention...
{ {
@@ -138,7 +138,7 @@ screenlist_current ()
old_s = s; old_s = s;
//debug("screenlist_current: return %8x\n", s); //debug(RPT_DEBUG, "screenlist_current: return %8x", s);
return s; return s;
} }
@@ -155,7 +155,7 @@ screenlist_next ()
{ {
screen *s; screen *s;
//debug("Screenlist_next()\n"); //debug(RPT_DEBUG, "Screenlist_next()");
s = screenlist_current (); s = screenlist_current ();
@@ -168,14 +168,14 @@ screenlist_next ()
// Otherwise, reset it to regular operation // Otherwise, reset it to regular operation
screenlist_action = 0; screenlist_action = 0;
//debug("Screenlist_next: calling handler...\n"); //debug(RPT_DEBUG, "Screenlist_next: calling handler...");
// Call the selected queuing function... // Call the selected queuing function...
// TODO: Different queueing modes... // TODO: Different queueing modes...
s = screenlist_next_priority (); s = screenlist_next_priority ();
//s = screenlist_next_roll(); //s = screenlist_next_roll();
//debug("Screenlist_next() done\n"); //debug(RPT_DEBUG, "Screenlist_next() done");
return s; return s;
} }
@@ -207,7 +207,7 @@ screenlist_prev ()
int int
screenlist_add_end (screen * screen) screenlist_add_end (screen * screen)
{ {
debug ("screenlist_add_end()\n"); debug (RPT_DEBUG, "screenlist_add_end()");
return LL_Push (screenlist, (void *) screen); return LL_Push (screenlist, (void *) screen);
} }
@@ -216,7 +216,7 @@ screenlist_add_end (screen * screen)
screen * screen *
screenlist_next_roll () screenlist_next_roll ()
{ {
//debug("screenlist_next_roll()\n"); //debug(RPT_DEBUG, "screenlist_next_roll()");
if (LL_UnRoll (screenlist) != 0) if (LL_UnRoll (screenlist) != 0)
return NULL; return NULL;
@@ -229,7 +229,7 @@ screen *
screenlist_next_priority () screenlist_next_priority ()
{ {
//screen *s, *t; //screen *s, *t;
//debug("screenlist_next_priority\n"); //debug(RPT_DEBUG, "screenlist_next_priority");
if (LL_UnRoll (screenlist) != 0) if (LL_UnRoll (screenlist) != 0)
return NULL; return NULL;
@@ -243,7 +243,7 @@ screenlist_next_priority ()
screen * screen *
screenlist_prev_roll () screenlist_prev_roll ()
{ {
//debug("screenlist_prev_roll()\n"); //debug(RPT_DEBUG, "screenlist_prev_roll()");
if (LL_Roll (screenlist) != 0) if (LL_Roll (screenlist) != 0)
return NULL; return NULL;
@@ -256,7 +256,7 @@ compare_priority (void *one, void *two)
{ {
screen *a, *b; screen *a, *b;
//debug("compare_priority: %8x %8x\n", one, two); //debug(RPT_DEBUG, "compare_priority: %8x %8x", one, two);
if (!one) if (!one)
return 0; return 0;
@@ -266,7 +266,7 @@ compare_priority (void *one, void *two)
a = (screen *) one; a = (screen *) one;
b = (screen *) two; b = (screen *) two;
//debug("compare_priority: done?\n"); //debug(RPT_DEBUG, "compare_priority: done?");
return (a->priority - b->priority); return (a->priority - b->priority);
} }
@@ -274,8 +274,6 @@ compare_priority (void *one, void *two)
int int
compare_addresses (void *one, void *two) compare_addresses (void *one, void *two)
{ {
//printf("compare_addresses: 0x%x == 0x%x ???\n", one, two); //printf(RPT_DEBUG, "compare_addresses: %p == %p ???", one, two);
//if(one == two) printf("Yes!\n");
//else printf("No!\n");
return (one != two); return (one != two);
} }
+12 -12
View File
@@ -6,7 +6,7 @@
#include "config.h" #include "config.h"
#endif #endif
#include "shared/debug.h" #include "shared/report.h"
#include "drivers/lcd.h" #include "drivers/lcd.h"
@@ -36,12 +36,12 @@ server_screen_init ()
{ {
widget *w; widget *w;
debug ("server_screen_init\n"); debug (RPT_DEBUG, "server_screen_init");
server_screen = screen_create (); server_screen = screen_create ();
if (!server_screen) { if (!server_screen) {
fprintf (stderr, "server_screen_init: Error allocating screen\n"); report (RPT_ERR, "server_screen_init: Error allocating screen");
return -1; return -1;
} }
@@ -50,43 +50,43 @@ server_screen_init ()
server_screen->duration = 8; // 1 second, instead of 4... server_screen->duration = 8; // 1 second, instead of 4...
if (widget_add (server_screen, "title", "title", NULL, 1) != 0) { if (widget_add (server_screen, "title", "title", NULL, 1) != 0) {
fprintf (stderr, "server_screen_init: internal error: could not add title widget\n"); report (RPT_ERR, "server_screen_init: internal error: could not add title widget");
} }
if (widget_add (server_screen, "one", "string", NULL, 1) != 0) { if (widget_add (server_screen, "one", "string", NULL, 1) != 0) {
fprintf (stderr, "server_screen_init: internal error: could not add title widget\n"); report (RPT_ERR, "server_screen_init: internal error: could not add title widget");
} }
if (widget_add (server_screen, "two", "string", NULL, 1) != 0) { if (widget_add (server_screen, "two", "string", NULL, 1) != 0) {
fprintf (stderr, "server_screen_init: internal error: could not add title widget\n"); report (RPT_ERR, "server_screen_init: internal error: could not add title widget");
} }
if (widget_add (server_screen, "three", "string", NULL, 1) != 0) { if (widget_add (server_screen, "three", "string", NULL, 1) != 0) {
fprintf (stderr, "server_screen_init: internal error: could not add title widget\n"); report (RPT_ERR, "server_screen_init: internal error: could not add title widget");
} }
// Now, initialize all the widgets... // Now, initialize all the widgets...
if ((w = widget_find (server_screen, "title")) != NULL) { if ((w = widget_find (server_screen, "title")) != NULL) {
WidgetText(w,title); WidgetText(w,title);
} else } else
fprintf (stderr, "server_screen_init: Can't find title\n"); report (RPT_ERR, "server_screen_init: Can't find title");
if ((w = widget_find (server_screen, "one")) != NULL) if ((w = widget_find (server_screen, "one")) != NULL)
WidgetString(w,1,2,one) WidgetString(w,1,2,one)
else else
fprintf (stderr, "server_screen_init: Can't find widget one\n"); report (RPT_ERR, "server_screen_init: Can't find widget one");
if ((w = widget_find (server_screen, "two")) != NULL) if ((w = widget_find (server_screen, "two")) != NULL)
WidgetString(w,1,3,two) WidgetString(w,1,3,two)
else else
fprintf (stderr, "server_screen_init: Can't find widget two\n"); report (RPT_ERR, "server_screen_init: Can't find widget two");
if ((w = widget_find (server_screen, "three")) != NULL) if ((w = widget_find (server_screen, "three")) != NULL)
WidgetString(w,1,4,three) WidgetString(w,1,4,three)
else else
fprintf (stderr, "server_screen_init: Can't find widget three\n"); report (RPT_ERR, "server_screen_init: Can't find widget three");
// And enqueue the screen // And enqueue the screen
screenlist_add (server_screen); screenlist_add (server_screen);
debug ("server_screen_init done\n"); debug (RPT_DEBUG, "server_screen_init done");
return 0; return 0;
} }
+34 -40
View File
@@ -18,8 +18,7 @@
#include "shared/sockets.h" #include "shared/sockets.h"
#include "sock.h" #include "sock.h"
#include "clients.h" #include "clients.h"
#include "shared/debug.h" #include "shared/report.h"
#include "syslog.h"
extern char bind_addr[64]; extern char bind_addr[64];
extern int lcd_port; extern int lcd_port;
@@ -45,36 +44,33 @@ sock_create_inet_socket (char * addr, unsigned int port)
struct sockaddr_in name; struct sockaddr_in name;
int sock, sockopt=1; int sock, sockopt=1;
debug ("sock_create_inet_socket(%i)\n", port); report (RPT_INFO, "sock_create_inet_socket(%i)", port);
/* Create the socket. */ /* Create the socket. */
//debug("Creating Inet Socket\n"); //debug(RPT_DEBUG, "Creating Inet Socket");
sock = socket (PF_INET, SOCK_STREAM, 0); sock = socket (PF_INET, SOCK_STREAM, 0);
if (sock < 0) { if (sock < 0) {
perror ("Error creating socket"); report(RPT_ERR, "Could not create socket");
syslog(LOG_ALERT, "could not create socket");
return -1; return -1;
} }
/* Set the socket so we can re-use it*/ /* Set the socket so we can re-use it*/
if(setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&sockopt,sizeof(sockopt)) < 0) { if(setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&sockopt,sizeof(sockopt)) < 0) {
perror("Error setting socket option SO_REUSEADDR"); report(RPT_ERR, "Error setting socket option SO_REUSEADDR");
syslog(LOG_ALERT, "Error setting socket option SO_REUSEADDR");
return -1; return -1;
} }
/* Give the socket a name. */ /* Give the socket a name. */
//debug("Binding Inet Socket\n"); //debug(RPT_DEBUG, "Binding Inet Socket");
memset (&name, 0, sizeof (name)); memset (&name, 0, sizeof (name));
name.sin_family = AF_INET; name.sin_family = AF_INET;
name.sin_port = htons (port); name.sin_port = htons (port);
inet_aton(addr, &name.sin_addr); inet_aton(addr, &name.sin_addr);
if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0) { if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0) {
perror ("Error binding socket"); report(RPT_ERR, "Could not bind to port %d", port);
syslog(LOG_ALERT, "could not bind to port %d", port);
return -1; return -1;
} else { } else {
syslog(LOG_NOTICE, "listening for queries on port %d", port); report(RPT_NOTICE, "listening for queries on port %d", port);
} }
return sock; return sock;
@@ -87,18 +83,17 @@ sock_create_server (char *bind_addr, int lcd_port)
{ {
int sock; int sock;
debug ("sock_create_server()\n"); report (RPT_INFO, "sock_create_server()");
/* Create the socket and set it up to accept connections. */ /* Create the socket and set it up to accept connections. */
sock = sock_create_inet_socket (bind_addr, lcd_port); sock = sock_create_inet_socket (bind_addr, lcd_port);
if (sock < 0) { if (sock < 0) {
perror ("sock_create_server: Error creating socket"); report (RPT_ERR, "sock_create_server: Error creating socket");
return -1; return -1;
} }
if (listen (sock, 1) < 0) { if (listen (sock, 1) < 0) {
perror ("sock_create_server: Listen error"); report(RPT_ERR, "error in attempting to listen to port");
syslog(LOG_ALERT, "error in attempting to listen to port");
return -1; return -1;
} }
@@ -112,14 +107,14 @@ sock_create_server (char *bind_addr, int lcd_port)
{ {
int val, len, sock; int val, len, sock;
sock = new; sock = new;
len = sizeof(int); len = sizeof(int);
getsockopt(sock, SOL_SOCKET, SO_SNDBUF, &val, &len); getsockopt(sock, SOL_SOCKET, SO_SNDBUF, &val, &len);
printf("SEND buffer: %i bytes\n", val); debug(RPT_DEBUG, "SEND buffer: %i bytes", val);
len = sizeof(int); len = sizeof(int);
getsockopt(sock, SOL_SOCKET, SO_RCVBUF, &val, &len); getsockopt(sock, SOL_SOCKET, SO_RCVBUF, &val, &len);
printf("RECV buffer: %i bytes\n", val); debug(RPT_DEBUG, "RECV buffer: %i bytes", val);
} }
*/ */
@@ -138,7 +133,7 @@ sock_poll_clients ()
struct timeval t; struct timeval t;
client *c; client *c;
//debug("sock_poll_clients()\n"); debug(RPT_INFO, "sock_poll_clients()");
t.tv_sec = 0; t.tv_sec = 0;
t.tv_usec = 0; t.tv_usec = 0;
@@ -147,7 +142,7 @@ sock_poll_clients ()
read_fd_set = active_fd_set; read_fd_set = active_fd_set;
if (select (FD_SETSIZE, &read_fd_set, NULL, NULL, &t) < 0) { if (select (FD_SETSIZE, &read_fd_set, NULL, NULL, &t) < 0) {
perror ("sock_poll_clients: Select error"); report (RPT_ERR, "sock_poll_clients: Select error");
return -1; return -1;
} }
@@ -160,12 +155,10 @@ sock_poll_clients ()
size = sizeof (clientname); size = sizeof (clientname);
new = accept (orig_sock, (struct sockaddr *) &clientname, &size); new = accept (orig_sock, (struct sockaddr *) &clientname, &size);
if (new < 0) { if (new < 0) {
perror ("sock_poll_clients: Accept error"); report (RPT_ERR, "sock_poll_clients: Accept error");
syslog(LOG_WARNING, "error in accepting client");
return -1; return -1;
} }
debug ("sock_poll_clients: connect from host %s, port %hd.\n", inet_ntoa (clientname.sin_addr), ntohs (clientname.sin_port)); report (RPT_INFO, "sock_poll_clients: Connect from host %s:%hd on #%d",
syslog(LOG_NOTICE, "connect from host %s:%hd on #%d",
inet_ntoa (clientname.sin_addr), ntohs (clientname.sin_port), new); inet_ntoa (clientname.sin_addr), ntohs (clientname.sin_port), new);
FD_SET (new, &active_fd_set); FD_SET (new, &active_fd_set);
@@ -173,16 +166,16 @@ sock_poll_clients ()
// TODO: Create new "client" here... (done?) // TODO: Create new "client" here... (done?)
if (client_create (new) == NULL) { if (client_create (new) == NULL) {
fprintf (stderr, "sock_poll_clients: error creating client %i\n", i); report( RPT_ERR, "sock_poll_clients: error creating client %i", i);
return -1; return -1;
} }
} else { } else {
/* Data arriving on an already-connected socket. */ /* Data arriving on an already-connected socket. */
err = 0; err = 0;
do { do {
debug ("sock_poll_clients: reading...\n"); debug (RPT_DEBUG, "sock_poll_clients: reading...");
err = read_from_client (i); err = read_from_client (i);
debug ("sock_poll_clients: ...done\n"); debug (RPT_DEBUG, "sock_poll_clients: ...done");
if (err < 0) { if (err < 0) {
// TODO: Destroy a "client" here... (done?) // TODO: Destroy a "client" here... (done?)
c = client_find_sock (i); c = client_find_sock (i);
@@ -191,10 +184,9 @@ sock_poll_clients ()
client_destroy (c); client_destroy (c);
close (i); close (i);
FD_CLR (i, &active_fd_set); FD_CLR (i, &active_fd_set);
debug ("sock_poll_clients: Closed connection %i\n", i); report (RPT_INFO, "sock_poll_clients: Closed connection %i", i);
syslog(LOG_NOTICE, "closed connection #%i", i);
} else } else
fprintf (stderr, "sock_poll_clients: Can't find client %i\n", i); report (RPT_ERR, "sock_poll_clients: Can't find client %i", i);
} }
} while (err > 0); } while (err > 0);
@@ -211,16 +203,18 @@ read_from_client (int filedes)
int nbytes, i; int nbytes, i;
client *c; client *c;
report(RPT_DEBUG, "read_from_client()" );
//nbytes = read (filedes, buffer, MAXMSG); //nbytes = read (filedes, buffer, MAXMSG);
//debug("read_from_client(%i): reading...\n", filedes); //debug(RPT_DEBUG, "read_from_client(%i): reading...", filedes);
//nbytes = sock_recv (filedes, buffer, MAXMSG); //nbytes = sock_recv (filedes, buffer, MAXMSG);
//debug("read_from_client(%i): ...done\n", filedes); //debug(RPT_DEBUG, "read_from_client(%i): ...done", filedes);
//debug ("read_from_client(%i): %i bytes\n", filedes, nbytes); //debug (RPT_DEBUG, "read_from_client(%i): %i bytes", filedes, nbytes);
errno = 0; errno = 0;
if ((nbytes = sock_recv (filedes, buffer, MAXMSG)) < 0) { if ((nbytes = sock_recv (filedes, buffer, MAXMSG)) < 0) {
if (errno != EAGAIN) if (errno != EAGAIN)
fprintf (stderr, "read_from_client: (fd %d) %s\n", filedes, strerror(errno)); report (RPT_DEBUG, "read_from_client: (fd %d) %s", filedes, strerror(errno));
return 0; return 0;
} else if (nbytes == 0) // EOF } else if (nbytes == 0) // EOF
return -1; return -1;
@@ -240,9 +234,9 @@ read_from_client (int filedes)
if (c) { if (c) {
client_add_message (c, buffer); client_add_message (c, buffer);
} else } else
fprintf (stderr, "read_from_client: Can't find client %i\n", filedes); report (RPT_DEBUG, "read_from_client: Can't find client %i", filedes);
debug ("read_from_client: got message: `%s'\n", buffer); debug (RPT_DEBUG, "read_from_client: got message: `%s'", buffer);
return nbytes; return nbytes;
} }
return nbytes; return nbytes;
@@ -256,7 +250,7 @@ sock_close_all ()
{ {
int fd; int fd;
debug ("sock_close_all()\n"); report (RPT_INFO, "sock_close_all()");
for (fd = 0; fd < FD_SETSIZE; fd++) { for (fd = 0; fd < FD_SETSIZE; fd++) {
// TODO: Destroy a "client" here...? Nope. // TODO: Destroy a "client" here...? Nope.
@@ -274,7 +268,7 @@ sock_close_all ()
//sock_send_string (fd, "bye\n"); //sock_send_string (fd, "bye\n");
close (fd); close (fd);
FD_CLR (fd, &active_fd_set); FD_CLR (fd, &active_fd_set);
debug ("sock_close_all: Closed connection %i\n", fd); debug (RPT_DEBUG, "sock_close_all: Closed connection %i", fd);
} }
} }
+26 -26
View File
@@ -3,7 +3,7 @@
#include <string.h> #include <string.h>
#include "shared/sockets.h" #include "shared/sockets.h"
#include "shared/debug.h" #include "shared/report.h"
#include "screen.h" #include "screen.h"
#include "widget.h" #include "widget.h"
@@ -30,11 +30,11 @@ widget_create ()
{ {
widget *w; widget *w;
debug ("widget_create()\n"); report (RPT_INFO, "widget_create()");
w = malloc (sizeof (widget)); w = malloc (sizeof (widget));
if (!w) { if (!w) {
fprintf (stderr, "widget_create: Error allocating widget\n"); report (RPT_DEBUG, "widget_create: Error allocating widget");
return NULL; return NULL;
} }
@@ -65,14 +65,14 @@ widget_destroy (widget * w)
if (!w) if (!w)
return -1; return -1;
debug ("widget_destroy(%s)\n", w->id); debug (RPT_INFO, "widget_destroy(%s)", w->id);
if (w->id) if (w->id)
free (w->id); free (w->id);
//debug("widget_destroy: id...\n"); //debug(RPT_DEBUG, "widget_destroy: id...");
if (w->text) if (w->text)
free (w->text); free (w->text);
//debug("widget_destroy: text...\n"); //debug(RPT_DEBUG, "widget_destroy: text...");
// TODO: Free kids! // TODO: Free kids!
if (w->kids) { if (w->kids) {
@@ -89,7 +89,7 @@ widget_destroy (widget * w)
} }
free (w); free (w);
//debug("widget_destroy: widget...\n"); //debug(RPT_DEBUG, "widget_destroy: widget...");
return 0; return 0;
} }
@@ -104,7 +104,7 @@ widget_find (screen * s, char *id)
if (!id) if (!id)
return NULL; return NULL;
debug ("widget_find(%s)\n", id); debug (RPT_DEBUG, "widget_find(%s)", id);
return widget_finder (s->widgets, id); return widget_finder (s->widgets, id);
} }
@@ -119,26 +119,26 @@ widget_finder (LinkedList * list, char *id)
if (!id) if (!id)
return NULL; return NULL;
debug ("widget_finder(%s)\n", id); debug (RPT_DEBUG, "widget_finder(%s)", id);
LL_Rewind (list); LL_Rewind (list);
do { do {
//debug("widget_finder: Iteration\n"); //debug(RPT_DEBUG, "widget_finder: Iteration");
w = LL_Get (list); w = LL_Get (list);
if (w) { if (w) {
//debug("widget_finder: ...\n"); //debug(RPT_DEBUG, "widget_finder: ...");
if (0 == strcmp (w->id, id)) { if (0 == strcmp (w->id, id)) {
debug ("widget_finder: Found %s\n", id); debug (RPT_DEBUG, "widget_finder: Found %s", id);
return w; return w;
} }
// Search kids recursively // Search kids recursively
//debug("widget_finder: ...\n"); //debug(RPT_DEBUG, "widget_finder: ...");
if (w->type == WID_FRAME) { if (w->type == WID_FRAME) {
err = widget_finder (w->kids, id); err = widget_finder (w->kids, id);
if (err) if (err)
return err; return err;
} }
//debug("widget_finder: ...\n"); //debug(RPT_DEBUG, "widget_finder: ...");
} }
} while (LL_Next (list) == 0); } while (LL_Next (list) == 0);
@@ -155,7 +155,7 @@ widget_add (screen * s, char *id, char *type, char *in, int sock)
widget *w, *parent; widget *w, *parent;
LinkedList *list; LinkedList *list;
debug ("widget_add(%s, %s, %s)\n", id, type, in); report (RPT_INFO, "widget_add(%s, %s, %s)", id, type, in);
if (!s) if (!s)
return -1; return -1;
@@ -187,7 +187,7 @@ widget_add (screen * s, char *id, char *type, char *in, int sock)
if (parent->type == WID_FRAME) { if (parent->type == WID_FRAME) {
list = parent->kids; list = parent->kids;
if (!list) if (!list)
fprintf (stderr, "widget_add: Parent has no kids\n"); report (RPT_DEBUG, "widget_add: Parent has no kids");
} else { } else {
// no frame to use as parent // no frame to use as parent
sock_send_string (sock, "huh? Not a frame\n"); sock_send_string (sock, "huh? Not a frame\n");
@@ -211,18 +211,18 @@ widget_add (screen * s, char *id, char *type, char *in, int sock)
return 2; return 2;
} }
debug ("widget_add: making widget\n"); debug (RPT_DEBUG, "widget_add: making widget");
// Now, make it... // Now, make it...
w = widget_create (); w = widget_create ();
if (!w) { if (!w) {
fprintf (stderr, "widget_add: Error creating widget\n"); report (RPT_ERR, "widget_add: Error creating widget");
return -1; return -1;
} }
w->id = strdup (id); w->id = strdup (id);
if (!w->id) { if (!w->id) {
fprintf (stderr, "widget_add: Error allocating id\n"); report (RPT_ERR, "widget_add: Error allocating id");
return -1; return -1;
} }
@@ -233,7 +233,7 @@ widget_add (screen * s, char *id, char *type, char *in, int sock)
if (!w->kids) { if (!w->kids) {
w->kids = LL_new (); w->kids = LL_new ();
if (!w->kids) { if (!w->kids) {
fprintf (stderr, "widget_add: error allocating kids for frame\n"); report (RPT_ERR, "widget_add: error allocating kids for frame");
return -1; return -1;
} }
} }
@@ -251,7 +251,7 @@ widget_remove (screen * s, char *id, int sock)
widget *w; widget *w;
LinkedList *list; LinkedList *list;
debug ("widget_remove(%s)\n", id); report (RPT_INFO, "widget_remove(%s)", id);
if (!s) if (!s)
return -1; return -1;
@@ -268,7 +268,7 @@ widget_remove (screen * s, char *id, int sock)
w = widget_find (s, id); w = widget_find (s, id);
if (!w) { if (!w) {
sock_send_string (sock, "huh? You don't have a widget with that id#\n"); sock_send_string (sock, "huh? You don't have a widget with that id#\n");
debug ("widget_remove: Error finding widget %s\n", id); report (RPT_ERR, "widget_remove: Error finding widget %s", id);
return 1; return 1;
} }
@@ -276,7 +276,7 @@ widget_remove (screen * s, char *id, int sock)
// TODO: Make this work with frames... // TODO: Make this work with frames...
// LL_Remove(list, (void *)w); // LL_Remove(list, (void *)w);
// TODO: Check for errors here? // TODO: Check for errors here?
// widget_destroy(w); // widget_destroy(w);
@@ -291,7 +291,7 @@ widget_remover (LinkedList * list, widget * w)
widget *foo, *bar; widget *foo, *bar;
int err; int err;
debug ("widget_remover\n"); debug (RPT_DEBUG, "widget_remover");
if (!list) if (!list)
return 0; return 0;
@@ -309,7 +309,7 @@ widget_remover (LinkedList * list, widget * w)
// If removing a frame, kill all its kids, too... // If removing a frame, kill all its kids, too...
if (foo == w) { if (foo == w) {
if (!foo->kids) { if (!foo->kids) {
fprintf (stderr, "widget_remover: frame has no kids\n"); debug (RPT_DEBUG, "widget_remover: frame has no kids");
} else // Kill the kids... } else // Kill the kids...
{ {
LL_Rewind (foo->kids); LL_Rewind (foo->kids);
@@ -326,7 +326,7 @@ widget_remover (LinkedList * list, widget * w)
} else // Otherwise, search the frame recursively... } else // Otherwise, search the frame recursively...
{ {
if (!foo->kids) { if (!foo->kids) {
fprintf (stderr, "widget_remover: frame has no kids\n"); debug (RPT_DEBUG, "widget_remover: frame has no kids");
} else } else
err = widget_remover (foo->kids, w); err = widget_remover (foo->kids, w);
+1 -1
View File
@@ -1,2 +1,2 @@
noinst_LIBRARIES = libLCDstuff.a noinst_LIBRARIES = libLCDstuff.a
libLCDstuff_a_SOURCES = LL.c LL.h sockets.c sockets.h str.c str.h debug.h libLCDstuff_a_SOURCES = LL.c LL.h sockets.c sockets.h str.c str.h debug.h report.c report.h
+12 -12
View File
@@ -12,7 +12,7 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <fcntl.h> #include <fcntl.h>
#include "debug.h" #include "report.h"
#include "sockets.h" #include "sockets.h"
/************************************************** /**************************************************
@@ -36,7 +36,7 @@ sock_init_sockaddr (sockaddr_in * name, const char *hostname, unsigned short int
name->sin_port = htons (port); name->sin_port = htons (port);
hostinfo = gethostbyname (hostname); hostinfo = gethostbyname (hostname);
if (hostinfo == NULL) { if (hostinfo == NULL) {
fprintf (stderr, "sock_init_sockaddr: Unknown host %s.\n", hostname); report (RPT_ERR, "sock_init_sockaddr: Unknown host %s.", hostname);
return -1; return -1;
} }
name->sin_addr = *(struct in_addr *) hostinfo->h_addr; name->sin_addr = *(struct in_addr *) hostinfo->h_addr;
@@ -53,19 +53,19 @@ sock_connect (char *host, unsigned short int port)
int sock; int sock;
int err = 0; int err = 0;
debug ("sock_connect: Creating socket\n"); report (RPT_DEBUG, "sock_connect: Creating socket");
sock = socket (PF_INET, SOCK_STREAM, 0); sock = socket (PF_INET, SOCK_STREAM, 0);
if (sock < 0) { if (sock < 0) {
perror ("sock_connect: Error creating socket"); report (RPT_ERR, "sock_connect: Error creating socket");
return sock; return sock;
} }
debug ("sock_connect: Created socket (%i)\n", sock); debug (RPT_DEBUG, "sock_connect: Created socket (%i)", sock);
sock_init_sockaddr (&servername, host, port); sock_init_sockaddr (&servername, host, port);
err = connect (sock, (struct sockaddr *) &servername, sizeof (servername)); err = connect (sock, (struct sockaddr *) &servername, sizeof (servername));
if (err < 0) { if (err < 0) {
perror ("sock_connect: connect failed"); report (RPT_ERR, "sock_connect: connect failed");
shutdown (sock, 2); shutdown (sock, 2);
return 0; // Normal exit if server doesn't exist... return 0; // Normal exit if server doesn't exist...
} }
@@ -104,8 +104,8 @@ sock_send_string (int fd, char *string)
int sent = write (fd, string + offset, len - offset); int sent = write (fd, string + offset, len - offset);
if (sent == -1) { if (sent == -1) {
if (errno != EAGAIN) { if (errno != EAGAIN) {
perror ("sock_send_string: socket write error"); report (RPT_ERR, "sock_send_string: socket write error");
printf ("Message was: %s\n", string); report (RPT_DEBUG, "Message was: %s", string);
//shutdown(fd, 2); //shutdown(fd, 2);
return sent; return sent;
} }
@@ -145,7 +145,7 @@ sock_recv_string (int fd, char *dest, size_t maxlen)
} }
return 0; return 0;
} else { } else {
perror ("sock_recv_string: socket read error"); report (RPT_ERR, "sock_recv_string: socket read error");
return err; return err;
} }
} else if (err == 0) { } else if (err == 0) {
@@ -188,7 +188,7 @@ sock_send (int fd, void *src, size_t size)
int sent = write (fd, ((char *) src) + offset, size - offset); int sent = write (fd, ((char *) src) + offset, size - offset);
if (sent == -1) { if (sent == -1) {
if (errno != EAGAIN) { if (errno != EAGAIN) {
perror ("sock_send: socket write error"); report (RPT_ERR, "sock_send: socket write error");
//shutdown(fd, 2); //shutdown(fd, 2);
return sent; return sent;
} }
@@ -217,11 +217,11 @@ sock_recv (int fd, void *dest, size_t maxlen)
err = read (fd, dest, maxlen); err = read (fd, dest, maxlen);
if (err < 0) { if (err < 0) {
//fprintf (stderr,"sock_recv: socket read error\n"); //report (RPT_DEBUG,"sock_recv: socket read error");
//shutdown(fd, 2); //shutdown(fd, 2);
return err; return err;
} }
//debug("sock_recv: Got message \"%s\"\n", (char *)dest); //debug(RPT_DEBUG, "sock_recv: Got message \"%s\"", (char *)dest);
return err; return err;
} }