Reporting cleaned up and levels made more consistent.
This commit is contained in:
+35
-52
@@ -29,12 +29,12 @@ Client * client_create (int sock)
|
||||
{
|
||||
Client *c;
|
||||
|
||||
debug (RPT_DEBUG, "new_client(%i)", sock);
|
||||
debug (RPT_DEBUG, "%s( sock=%i )", __FUNCTION__, sock);
|
||||
|
||||
/* Allocate new client...*/
|
||||
c = malloc (sizeof (Client));
|
||||
if (!c) {
|
||||
report (RPT_ERR, "client_create: Error allocating");
|
||||
report (RPT_ERR, "%s: Error allocating", __FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
/* Init struct members*/
|
||||
@@ -46,7 +46,7 @@ Client * client_create (int sock)
|
||||
/*Set up message list...*/
|
||||
c->messages = LL_new ();
|
||||
if (!c->messages) {
|
||||
report (RPT_ERR, "client_create: Error allocating");
|
||||
report (RPT_ERR, "%s: Error allocating", __FUNCTION__);
|
||||
free (c);
|
||||
return NULL;
|
||||
}
|
||||
@@ -58,7 +58,7 @@ Client * client_create (int sock)
|
||||
c->screenlist = LL_new();
|
||||
|
||||
if (!c->screenlist) {
|
||||
report( RPT_ERR, "client_create: Error allocating");
|
||||
report( RPT_ERR, "%s: Error allocating", __FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
return c;
|
||||
@@ -67,18 +67,25 @@ Client * client_create (int sock)
|
||||
int
|
||||
client_destroy (Client * c)
|
||||
{
|
||||
//int err;
|
||||
Screen *s;
|
||||
|
||||
debug (RPT_INFO, "client_destroy()");
|
||||
char * str;
|
||||
|
||||
if (!c)
|
||||
return -1;
|
||||
|
||||
client_close_sock (c);
|
||||
debug (RPT_DEBUG, "%s( c=[%d] )", __FUNCTION__, c->sock );
|
||||
|
||||
/* Close the socket */
|
||||
close (c->sock);
|
||||
|
||||
/* Eat messages */
|
||||
while ((str = client_get_message (c))) {
|
||||
free (str);
|
||||
}
|
||||
LL_Destroy( c->messages );
|
||||
|
||||
/* Clean up the screenlist...*/
|
||||
debug( RPT_DEBUG, "client_data_destroy: Cleaning screenlist");
|
||||
debug( RPT_DEBUG, "%s: Cleaning screenlist", __FUNCTION__);
|
||||
|
||||
for( s=LL_GetFirst (c->screenlist); s; s=LL_GetNext(c->screenlist) ) {
|
||||
/* Free its memory...*/
|
||||
@@ -93,6 +100,7 @@ client_destroy (Client * c)
|
||||
if (c->menu) {
|
||||
menuscreen_inform_item_destruction (c->menu);
|
||||
menu_remove_item (c->menu->parent, c->menu);
|
||||
menuscreen_inform_item_modified (c->menu->parent);
|
||||
menuitem_destroy (c->menu);
|
||||
}
|
||||
|
||||
@@ -109,34 +117,10 @@ client_destroy (Client * c)
|
||||
/* Remove structure */
|
||||
free (c);
|
||||
|
||||
debug( RPT_DEBUG, "%s: Client data removed", __FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void client_close_sock (Client * c)
|
||||
{
|
||||
char *str;
|
||||
|
||||
if (c->sock == EOF )
|
||||
return;
|
||||
|
||||
/*Eat the rest of the incoming requests...*/
|
||||
debug (RPT_DEBUG, "client_destroy: get_messages");
|
||||
while ((str = client_get_message (c))) {
|
||||
if (str) {
|
||||
debug (RPT_DEBUG, "client_destroy: kill message %s", str);
|
||||
free (str);
|
||||
}
|
||||
}
|
||||
|
||||
/*close socket...*/
|
||||
if (c->sock) {
|
||||
/*sock_send_string (c->sock, "bye\n");*/
|
||||
close(c->sock);
|
||||
report(RPT_NOTICE, "closed socket for #%d", c->sock);
|
||||
}
|
||||
c->sock = EOF;
|
||||
}
|
||||
|
||||
/*Add and remove messages from the client's queue...*/
|
||||
int
|
||||
client_add_message (Client * c, char *message)
|
||||
@@ -145,38 +129,31 @@ client_add_message (Client * c, char *message)
|
||||
char *dup;
|
||||
char *str, *cp;
|
||||
char delimiters[] = "\n\r\0";
|
||||
/* int len;*/
|
||||
|
||||
debug(RPT_DEBUG, "client_add_message(%s)", message);
|
||||
debug(RPT_DEBUG, "%s( c=[%d], message=\"%s\" )", __FUNCTION__, c->sock, message);
|
||||
|
||||
if (!c)
|
||||
return -1;
|
||||
if (!message)
|
||||
return -1;
|
||||
|
||||
/* len = strlen(message);
|
||||
* if(len < 1) return 0;
|
||||
*/
|
||||
|
||||
/* Copy the string to avoid overwriting the original...*/
|
||||
dup = strdup (message);
|
||||
if (!dup) {
|
||||
report(RPT_ERR, "client_add_message: Error allocating");
|
||||
report(RPT_ERR, "%s: Error allocating", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
/* Now split the string into lines and enqueue each one...*/
|
||||
for (str = strtok (dup, delimiters); str; str = strtok (NULL, delimiters)) {
|
||||
cp = strdup (str);
|
||||
debug (RPT_DEBUG, "client_add_message: %s", cp);
|
||||
debug (RPT_DEBUG, "%s: Queued message: \"%s\"", __FUNCTION__, cp);
|
||||
err += LL_Enqueue (c->messages, (void *) cp);
|
||||
}
|
||||
|
||||
/*debug(RPT_DEBUG, "client_add_message(%s): %i errors", message, err);*/
|
||||
free (dup); /* Fixed memory leak...*/
|
||||
free (dup);
|
||||
|
||||
/* Err is the number of errors encountered...*/
|
||||
return err;
|
||||
|
||||
}
|
||||
|
||||
/* Woo-hoo! A simple function. :)*/
|
||||
@@ -185,15 +162,13 @@ client_get_message (Client * c)
|
||||
{
|
||||
char *str;
|
||||
|
||||
debug(RPT_DEBUG, "client_get_message()");
|
||||
debug(RPT_DEBUG, "%s( c=[%d] )", __FUNCTION__, c->sock);
|
||||
|
||||
if (!c)
|
||||
return NULL;
|
||||
|
||||
str = (char *) LL_Dequeue (c->messages);
|
||||
|
||||
/*debug(RPT_DEBUG, "client_get_message: \"%s\"", str);*/
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
@@ -208,13 +183,13 @@ client_find_screen (Client * c, char *id)
|
||||
if (!id)
|
||||
return NULL;
|
||||
|
||||
debug (RPT_INFO, "client_find_screen(%s)", id);
|
||||
debug (RPT_DEBUG, "%s( c=[%d], id=\"%s\" )", __FUNCTION__, c->sock, id);
|
||||
|
||||
LL_Rewind (c->screenlist);
|
||||
do {
|
||||
s = LL_Get (c->screenlist);
|
||||
if ((s) && (0 == strcmp (s->id, id))) {
|
||||
debug (RPT_DEBUG, "client_find_screen: Found %s", id);
|
||||
debug (RPT_DEBUG, "%s: Found %s", __FUNCTION__, id);
|
||||
return s;
|
||||
}
|
||||
} while (LL_Next (c->screenlist) == 0);
|
||||
@@ -225,7 +200,13 @@ client_find_screen (Client * c, char *id)
|
||||
int
|
||||
client_add_screen (Client * c, Screen * s)
|
||||
{
|
||||
/* TODO: Check for errors here?*/
|
||||
if (!c)
|
||||
return -1;
|
||||
if (!s)
|
||||
return -1;
|
||||
|
||||
debug (RPT_DEBUG, "%s( c=[%d], s=[%s] )", __FUNCTION__, c->sock, s->id);
|
||||
|
||||
LL_Push (c->screenlist, (void *) s);
|
||||
|
||||
/* Now, add it to the screenlist...*/
|
||||
@@ -245,13 +226,15 @@ client_remove_screen (Client * c, Screen * s)
|
||||
if (!s)
|
||||
return -1;
|
||||
|
||||
debug (RPT_DEBUG, "%s( c=[%d], s=[%s] )", __FUNCTION__, c->sock, s->id);
|
||||
|
||||
/* TODO: Check for errors here?*/
|
||||
LL_Remove (c->screenlist, (void *) s);
|
||||
|
||||
/* Now, remove it from the screenlist...*/
|
||||
if (screenlist_remove_all (s) < 0) {
|
||||
/* Not a serious error..*/
|
||||
report (RPT_ERR, "client_remove_screen: Error dequeueing screen");
|
||||
report (RPT_ERR, "%s: Error dequeueing screen", __FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
|
||||
+1
-1
@@ -27,10 +27,10 @@ typedef struct Client {
|
||||
char *name;
|
||||
int ack;
|
||||
int sock;
|
||||
char addr[64];
|
||||
int backlight;
|
||||
int heartbeat;
|
||||
|
||||
/* Messages that the client generated */
|
||||
LinkedList *messages;
|
||||
|
||||
/* The list of screens */
|
||||
|
||||
+11
-11
@@ -31,11 +31,11 @@ LinkedList *clientlist;
|
||||
int
|
||||
clients_init ()
|
||||
{
|
||||
debug(RPT_INFO, "client_init()");
|
||||
debug(RPT_DEBUG, "%s()", __FUNCTION__);
|
||||
|
||||
clientlist = LL_new ();
|
||||
if (!clientlist) {
|
||||
report( RPT_ERR, "client_init: Unable to create client list");
|
||||
report( RPT_ERR, "%s: Unable to create client list", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -47,27 +47,27 @@ clients_shutdown ()
|
||||
{
|
||||
Client *c;
|
||||
|
||||
debug (RPT_INFO, "clients_shutdown()");
|
||||
debug (RPT_DEBUG, "%s()", __FUNCTION__);
|
||||
|
||||
/* Free all client structures... */
|
||||
for (c=LL_GetFirst (clientlist); c; c=LL_GetNext (clientlist) ) {
|
||||
debug (RPT_DEBUG, "clients_shutdown: ...");
|
||||
debug (RPT_DEBUG, "%s: ...", __FUNCTION__);
|
||||
if (c) {
|
||||
debug (RPT_DEBUG, "clients_shutdown: ... %i ...", c->sock);
|
||||
debug (RPT_DEBUG, "%s: ... %i ...", __FUNCTION__, c->sock);
|
||||
if (client_destroy (c) != 0) {
|
||||
report (RPT_ERR, "clients_shutdown: Error freeing client");
|
||||
report (RPT_ERR, "%s: Error freeing client", __FUNCTION__);
|
||||
} else {
|
||||
debug (RPT_DEBUG, "clients_shutdown: Freed client...");
|
||||
debug (RPT_DEBUG, "%s: Freed client...", __FUNCTION__);
|
||||
}
|
||||
} else {
|
||||
debug (RPT_DEBUG, "clients_shutdown: No client!");
|
||||
debug (RPT_DEBUG, "%s: No client!", __FUNCTION__);
|
||||
}
|
||||
}
|
||||
|
||||
/* Then, free the list...*/
|
||||
LL_Destroy (clientlist);
|
||||
|
||||
debug (RPT_DEBUG, "clients_shutdown: done");
|
||||
debug (RPT_DEBUG, "%s: done", __FUNCTION__);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -114,7 +114,7 @@ clients_find_client_by_sock (int sock)
|
||||
{
|
||||
Client *c;
|
||||
|
||||
debug(RPT_INFO, "clients_find_client_by_sock(%i)", sock);
|
||||
debug(RPT_DEBUG, "%s( sock=%i )", __FUNCTION__, sock);
|
||||
|
||||
for( c=LL_GetFirst(clientlist); c; c=LL_GetNext(clientlist) ) {
|
||||
if (c->sock == sock) {
|
||||
@@ -122,7 +122,7 @@ clients_find_client_by_sock (int sock)
|
||||
}
|
||||
}
|
||||
|
||||
debug (RPT_ERR, "client_find_sock: failed");
|
||||
debug (RPT_ERR, "%s: failed", __FUNCTION__);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ test_func_func (Client * c, int argc, char **argv)
|
||||
char str[256];
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
snprintf (str, sizeof(str), "test_func_func: %i -> %s\n", i, argv[i]);
|
||||
snprintf (str, sizeof(str), "%s: %i -> %s\n", __FUNCTION__, i, argv[i]);
|
||||
report (RPT_INFO, str);
|
||||
sock_send_string (c->sock, str);
|
||||
}
|
||||
|
||||
@@ -89,6 +89,7 @@ menu_add_item_func (Client * c, int argc, char **argv)
|
||||
/* Does the client have a menu already ? */
|
||||
if (!c->menu) {
|
||||
/* We need to create it */
|
||||
report( RPT_INFO, "Client [%d] is using the menu", c->sock );
|
||||
c->menu = menu_create ("_client_menu_", menu_commands_handler, c->name, c);
|
||||
menu_add_item (main_menu, c->menu);
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ screen_add_func (Client * c, int argc, char **argv)
|
||||
report(RPT_WARNING, "screen_add_func: Error adding screen");
|
||||
sock_send_string (c->sock, "huh? Failed to add screen\n");
|
||||
}
|
||||
report(RPT_NOTICE, "added a screen (%s) to the display", s->id);
|
||||
report(RPT_INFO, "Client on socket %d added added screen \"%s\"", c->sock, s->id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -125,7 +125,9 @@ screen_del_func (Client * c, int argc, char **argv)
|
||||
} else
|
||||
sock_send_string (c->sock, "huh? Unknown screen id\n");
|
||||
|
||||
report(RPT_NOTICE, "removed a screen (%s) from the display", argv[1]);
|
||||
report(RPT_INFO, "Client on socket %d removed screen \"%s\"", c->sock, s->id);
|
||||
|
||||
screen_destroy(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+13
-9
@@ -90,7 +90,7 @@ driver_load( char * name, char * filename, char * args )
|
||||
Driver * driver = NULL;
|
||||
int res;
|
||||
|
||||
report( RPT_INFO, "driver_load( name=\"%.40s\", filename=\"%.80s\", args=\"%.80s\")", name, filename, args );
|
||||
report( RPT_DEBUG, "%s( name=\"%.40s\", filename=\"%.80s\", args=\"%.80s\")", __FUNCTION__, name, filename, args );
|
||||
|
||||
/* Allocate memory for new driver struct */
|
||||
driver = malloc( sizeof( Driver ));
|
||||
@@ -122,7 +122,7 @@ driver_load( char * name, char * filename, char * args )
|
||||
}
|
||||
|
||||
/* Call the init function */
|
||||
debug( RPT_DEBUG, "Calling driver [%.40s] init function", driver->name );
|
||||
debug( RPT_DEBUG, "%s: Calling driver [%.40s] init function", __FUNCTION__, driver->name );
|
||||
res = driver->init( driver, args );
|
||||
if( res < 0 ) {
|
||||
report( RPT_ERR, "Driver [%.40s] init failed, return code < 0", driver->name );
|
||||
@@ -156,7 +156,7 @@ driver_unload( Driver * driver )
|
||||
free( driver->filename );
|
||||
free( driver->name );
|
||||
free( driver );
|
||||
debug( RPT_DEBUG, "Driver unloaded" );
|
||||
debug( RPT_DEBUG, "%s: Driver unloaded", __FUNCTION__ );
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -168,10 +168,12 @@ driver_bind_module( Driver * driver )
|
||||
int i;
|
||||
int missing_symbols = 0;
|
||||
|
||||
debug( RPT_DEBUG, "%s( driver=[%.40s] )", __FUNCTION__, driver->name );
|
||||
|
||||
/* Load the module */
|
||||
driver->module_handle = dlopen( driver->filename, RTLD_NOW );
|
||||
if( driver->module_handle == NULL ) {
|
||||
report( RPT_ERR, "Could not dlopen driver module %.40s: %s", driver->filename, dlerror() );
|
||||
report( RPT_ERR, "Could not open driver module %.40s: %s", driver->filename, dlerror() );
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -186,23 +188,23 @@ driver_bind_module( Driver * driver )
|
||||
char *s = malloc( strlen( *(driver->symbol_prefix) ) + strlen( driver_symbols[i].name ) + 1 );
|
||||
strcpy( s, *(driver->symbol_prefix) ) ;
|
||||
strcat( s, driver_symbols[i].name );
|
||||
debug( RPT_DEBUG, "finding symbol: %s", s );
|
||||
debug( RPT_DEBUG, "%s: finding symbol: %s", __FUNCTION__, s );
|
||||
*p = dlsym( driver->module_handle, s );
|
||||
free( s );
|
||||
}
|
||||
/* Retrieve the symbol */
|
||||
if( !*p ) {
|
||||
debug( RPT_DEBUG, "finding symbol: %s", driver_symbols[i].name );
|
||||
debug( RPT_DEBUG, "%s: finding symbol: %s", __FUNCTION__, driver_symbols[i].name );
|
||||
*p = dlsym( driver->module_handle, driver_symbols[i].name );
|
||||
}
|
||||
|
||||
if( *p ) {
|
||||
debug( RPT_DEBUG, "found symbol at: %p", *p );
|
||||
debug( RPT_DEBUG, "%s: found symbol at: %p", __FUNCTION__, *p );
|
||||
}
|
||||
|
||||
/* Was the symbol required but not found ? */
|
||||
if( !*p && driver_symbols[i].required ) {
|
||||
report( RPT_ERR, "Module [%.40s] does not have required symbol: %s", driver->name, driver_symbols[i].name );
|
||||
report( RPT_ERR, "Driver [%.40s] does not have required symbol: %s", driver->name, driver_symbols[i].name );
|
||||
missing_symbols = 1;
|
||||
}
|
||||
}
|
||||
@@ -242,6 +244,8 @@ driver_bind_module( Driver * driver )
|
||||
int
|
||||
driver_unbind_module( Driver * driver )
|
||||
{
|
||||
debug( RPT_DEBUG, "%s( driver=[%.40s] )", __FUNCTION__, driver->name );
|
||||
|
||||
dlclose( driver->module_handle );
|
||||
|
||||
return 0;
|
||||
@@ -284,7 +288,7 @@ driver_supports_multiple( Driver * driver )
|
||||
static int
|
||||
driver_store_private_ptr(Driver * driver, void * private_data)
|
||||
{
|
||||
report( RPT_INFO, "driver_store_private_ptr( driver=%p, ptr=%p )", driver, private_data );
|
||||
debug( RPT_DEBUG, "%s( driver=[%.40s], ptr=%p )", __FUNCTION__, driver->name, private_data );
|
||||
|
||||
driver->private_data = private_data;
|
||||
return 0;
|
||||
|
||||
+16
-40
@@ -48,7 +48,7 @@ drivers_load_driver( char * name )
|
||||
char * filename;
|
||||
char * args;
|
||||
|
||||
report( RPT_INFO, "drivers_load_driver( name=\"%.40s\")", name );
|
||||
debug( RPT_DEBUG, "%s( name=\"%.40s\")", __FUNCTION__, name );
|
||||
|
||||
/* First driver ? */
|
||||
if( !loaded_drivers ) {
|
||||
@@ -138,7 +138,7 @@ drivers_unload_all()
|
||||
{
|
||||
Driver * driver;
|
||||
|
||||
report( RPT_INFO, "unload_all_driver()");
|
||||
debug( RPT_DEBUG, "%s()", __FUNCTION__);
|
||||
|
||||
while( (driver = LL_Pop( loaded_drivers )) != NULL ) {
|
||||
driver_unload( driver );
|
||||
@@ -153,7 +153,7 @@ drivers_get_info()
|
||||
{
|
||||
Driver *drv;
|
||||
|
||||
report( RPT_INFO, "drivers_getinfo()" );
|
||||
debug( RPT_DEBUG, "%s()", __FUNCTION__ );
|
||||
|
||||
ForAllDrivers(drv) {
|
||||
if( drv->get_info ) {
|
||||
@@ -169,7 +169,7 @@ drivers_clear()
|
||||
{
|
||||
Driver *drv;
|
||||
|
||||
report( RPT_INFO, "drivers_clear()" );
|
||||
debug( RPT_DEBUG, "%s()", __FUNCTION__ );
|
||||
|
||||
ForAllDrivers(drv) {
|
||||
if( drv->clear )
|
||||
@@ -183,7 +183,7 @@ drivers_flush()
|
||||
{
|
||||
Driver *drv;
|
||||
|
||||
report( RPT_INFO, "drivers_flush()" );
|
||||
debug( RPT_DEBUG, "%s()", __FUNCTION__ );
|
||||
|
||||
ForAllDrivers(drv) {
|
||||
if( drv->flush )
|
||||
@@ -197,7 +197,7 @@ drivers_string( int x, int y, char * string )
|
||||
{
|
||||
Driver *drv;
|
||||
|
||||
report( RPT_INFO, "drivers_string( x=%d, y=%d, string=\"%.40s\" )", x, y, string );
|
||||
debug( RPT_DEBUG, "%s( x=%d, y=%d, string=\"%.40s\" )", __FUNCTION__, x, y, string );
|
||||
|
||||
ForAllDrivers(drv) {
|
||||
if( drv->string )
|
||||
@@ -211,7 +211,7 @@ drivers_chr( int x, int y, char c )
|
||||
{
|
||||
Driver *drv;
|
||||
|
||||
report( RPT_INFO, "drivers_chr( x=%d, y=%d, c='%c' )", x, y, c );
|
||||
debug( RPT_DEBUG, "%s( x=%d, y=%d, c='%c' )", __FUNCTION__, x, y, c );
|
||||
|
||||
ForAllDrivers(drv) {
|
||||
if( drv->chr )
|
||||
@@ -225,7 +225,7 @@ drivers_vbar( int x, int y, int len, int promille, int pattern )
|
||||
{
|
||||
Driver *drv;
|
||||
|
||||
report( RPT_INFO, "drivers_vbar( x=%d, y=%d, len=%d, promille=%d, pattern=%d )", x, y, len, promille, pattern );
|
||||
debug( RPT_DEBUG, "%s( x=%d, y=%d, len=%d, promille=%d, pattern=%d )", __FUNCTION__, x, y, len, promille, pattern );
|
||||
|
||||
/* NEW FUNCTIONS
|
||||
*
|
||||
@@ -247,7 +247,7 @@ drivers_hbar( int x, int y, int len, int promille, int pattern )
|
||||
{
|
||||
Driver *drv;
|
||||
|
||||
report( RPT_INFO, "drivers_hbar( x=%d, y=%d, len=%d, promille=%d, pattern=%d )", x, y, len, promille, pattern );
|
||||
debug( RPT_DEBUG, "%s( x=%d, y=%d, len=%d, promille=%d, pattern=%d )", __FUNCTION__, x, y, len, promille, pattern );
|
||||
|
||||
ForAllDrivers(drv) {
|
||||
if( drv->hbar )
|
||||
@@ -263,7 +263,7 @@ drivers_num( int x, int num )
|
||||
{
|
||||
Driver *drv;
|
||||
|
||||
report( RPT_INFO, "drivers_num( x=%d, num=%d )", x, num );
|
||||
debug( RPT_DEBUG, "%s( x=%d, num=%d )", __FUNCTION__, x, num );
|
||||
|
||||
ForAllDrivers(drv) {
|
||||
if( drv->num )
|
||||
@@ -279,7 +279,7 @@ drivers_heartbeat( int state )
|
||||
{
|
||||
Driver *drv;
|
||||
|
||||
report( RPT_INFO, "drivers_heartbeat( state=%d )", state );
|
||||
debug( RPT_DEBUG, "%s( state=%d )", __FUNCTION__, state );
|
||||
|
||||
ForAllDrivers(drv) {
|
||||
if( drv->heartbeat )
|
||||
@@ -295,7 +295,7 @@ drivers_icon( int x, int y, int icon )
|
||||
{
|
||||
Driver *drv;
|
||||
|
||||
report( RPT_INFO, "drivers_icon( x=%d, y=%d, icon=ICON_%s )", x, y, widget_icon_to_iconname (icon) );
|
||||
debug( RPT_DEBUG, "%s( x=%d, y=%d, icon=ICON_%s )", __FUNCTION__, x, y, widget_icon_to_iconname (icon) );
|
||||
|
||||
ForAllDrivers(drv) {
|
||||
/* Does the driver have the icon function ? */
|
||||
@@ -317,7 +317,7 @@ drivers_cursor( int x, int y, int state )
|
||||
{
|
||||
Driver *drv;
|
||||
|
||||
report( RPT_INFO, "drivers_cursor( x=%d, y=%d, state=%d )", x, y, state );
|
||||
debug( RPT_DEBUG, "%s( x=%d, y=%d, state=%d )", __FUNCTION__, x, y, state );
|
||||
|
||||
ForAllDrivers(drv) {
|
||||
if( drv->cursor )
|
||||
@@ -332,7 +332,7 @@ drivers_backlight( int brightness )
|
||||
{
|
||||
Driver *drv;
|
||||
|
||||
report( RPT_INFO, "drivers_backlight( brightness=%d )", brightness );
|
||||
debug( RPT_DEBUG, "%s( brightness=%d )", __FUNCTION__, brightness );
|
||||
|
||||
ForAllDrivers(drv) {
|
||||
if( drv->backlight )
|
||||
@@ -346,7 +346,7 @@ drivers_output( int state )
|
||||
{
|
||||
Driver *drv;
|
||||
|
||||
report( RPT_INFO, "drivers_output( state=%d )", state );
|
||||
debug( RPT_DEBUG, "%s( state=%d )", __FUNCTION__, state );
|
||||
|
||||
ForAllDrivers(drv) {
|
||||
if( drv->output )
|
||||
@@ -362,7 +362,7 @@ drivers_get_key()
|
||||
Driver *drv;
|
||||
char * keystroke;
|
||||
|
||||
report( RPT_INFO, "drivers_get_key()" );
|
||||
debug( RPT_DEBUG, "%s()", __FUNCTION__ );
|
||||
|
||||
ForAllDrivers(drv) {
|
||||
if( drv->get_key ) {
|
||||
@@ -376,27 +376,3 @@ drivers_get_key()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char
|
||||
drivers_getkey() /* TO BE REMOVED AS SOON AS INPUT ROUTINES ACCEPT STRINGS */
|
||||
{
|
||||
Driver *drv;
|
||||
char * s;
|
||||
char ch;
|
||||
|
||||
report( RPT_INFO, "drivers_getkey()" );
|
||||
|
||||
ForAllDrivers(drv) {
|
||||
if( drv->get_key ) {
|
||||
s = drv->get_key(drv);
|
||||
if( s )
|
||||
return s[0]; /* It returns the first char only ! a hack ! */
|
||||
}
|
||||
else if( drv->getkey ) {
|
||||
ch = drv->getkey(drv);
|
||||
if( ch )
|
||||
return ch;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -101,9 +101,6 @@ drivers_output( int state );
|
||||
char *
|
||||
drivers_get_key();
|
||||
|
||||
char
|
||||
drivers_getkey();
|
||||
|
||||
extern LinkedList * loaded_drivers;
|
||||
/* Please don't read this list except using the following functions */
|
||||
|
||||
|
||||
+32
-32
@@ -30,14 +30,14 @@
|
||||
|
||||
int server_input (int key);
|
||||
void input_send_to_client (Client * c, char * key);
|
||||
void input_internal_key (KeyReservation * kr);
|
||||
void input_internal_key (char * key);
|
||||
|
||||
LinkedList * keylist;
|
||||
|
||||
|
||||
int init_input()
|
||||
{
|
||||
report (RPT_INFO, "%s()", __FUNCTION__ );
|
||||
debug (RPT_DEBUG, "%s()", __FUNCTION__ );
|
||||
|
||||
keylist = LL_new();
|
||||
|
||||
@@ -48,35 +48,35 @@ int
|
||||
handle_input ()
|
||||
{
|
||||
char * key;
|
||||
Client * c;
|
||||
Client * current_client;
|
||||
Client * target;
|
||||
KeyReservation * kr;
|
||||
|
||||
report (RPT_INFO, "%s()", __FUNCTION__ );
|
||||
debug (RPT_DEBUG, "%s()", __FUNCTION__ );
|
||||
|
||||
c = screenlist_current()->client;
|
||||
current_client = screenlist_current()->client;
|
||||
|
||||
/* Handle all keypresses */
|
||||
while ((key = drivers_get_key ()) != NULL ) {
|
||||
|
||||
/* Find what client wants the key */
|
||||
kr = input_find_key (key, c);
|
||||
kr = input_find_key (key, current_client);
|
||||
if (kr) {
|
||||
/* A hit ! */
|
||||
if (kr->client == NULL) {
|
||||
report (RPT_DEBUG, "%s: key for internal client: [%.40s]", __FUNCTION__, key );
|
||||
input_internal_key (kr);
|
||||
}
|
||||
else {
|
||||
/* It's an external client */
|
||||
report (RPT_DEBUG, "%s: key for external client: [%.40s]", __FUNCTION__, key );
|
||||
input_send_to_client (c, key);
|
||||
}
|
||||
report (RPT_DEBUG, "%s: reserved key: \"%.40s\"", __FUNCTION__, key );
|
||||
target = kr->client;
|
||||
} else {
|
||||
report (RPT_DEBUG, "%s: left over key: \"%.40s\"", __FUNCTION__, key );
|
||||
/*target = current_client;*/
|
||||
target = NULL; /* left-over keys are always for internal client */
|
||||
}
|
||||
else {
|
||||
/* What do we do with left-over keys ? */
|
||||
report (RPT_INFO, "%s: left over key: [%.40s]", __FUNCTION__, key );
|
||||
|
||||
/* Well... nothing ! */
|
||||
if (target == NULL) {
|
||||
report (RPT_DEBUG, "%s: key is for internal client", __FUNCTION__ );
|
||||
input_internal_key (key);
|
||||
} else {
|
||||
/* It's an external client */
|
||||
report (RPT_DEBUG, "%s: key is for external client on socket %d", __FUNCTION__, target->sock );
|
||||
input_send_to_client (current_client, key);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -86,7 +86,7 @@ void input_send_to_client (Client * c, char * key)
|
||||
{
|
||||
char * s;
|
||||
|
||||
debug (RPT_DEBUG, "%s( client=%p, key=\"%.40s\" )", __FUNCTION__, c, key);
|
||||
debug (RPT_DEBUG, "%s( client=[%d], key=\"%.40s\" )", __FUNCTION__, c->sock, key);
|
||||
|
||||
/* Allocate just as much as we need */
|
||||
s = malloc (strlen(key) + strlen("key \n") + 1);
|
||||
@@ -96,10 +96,10 @@ void input_send_to_client (Client * c, char * key)
|
||||
}
|
||||
|
||||
void
|
||||
input_internal_key (KeyReservation * kr)
|
||||
input_internal_key (char * key)
|
||||
{
|
||||
if (kr->exclusive || screenlist_current() == menuscreen) {
|
||||
menuscreen_key_handler (kr->key);
|
||||
if (is_menu_key(key) || screenlist_current() == menuscreen) {
|
||||
menuscreen_key_handler (key);
|
||||
}
|
||||
else {
|
||||
/* TODO: give keys to server screen */
|
||||
@@ -111,7 +111,7 @@ input_internal_key (KeyReservation * kr)
|
||||
int
|
||||
server_input (int key)
|
||||
{
|
||||
report(RPT_INFO, "%s( key='%c' )", __FUNCTION__, (char) key);
|
||||
debug(RPT_DEBUG, "%s( key='%c' )", __FUNCTION__, (char) key);
|
||||
|
||||
switch ((char) key) {
|
||||
case INPUT_PAUSE_KEY:
|
||||
@@ -145,7 +145,7 @@ int input_reserve_key (char * key, bool exclusive, Client * client)
|
||||
{
|
||||
KeyReservation * kr;
|
||||
|
||||
debug (RPT_DEBUG, "%s( key=\"%.40s\", exclusive=%d, client=%p )", __FUNCTION__, key, exclusive, client);
|
||||
debug (RPT_DEBUG, "%s( key=\"%.40s\", exclusive=%d, client=[%d] )", __FUNCTION__, key, exclusive, (client?client->sock:-1));
|
||||
|
||||
/* Find out if this key is already reserved in a way that interferes
|
||||
* with the new reservation.
|
||||
@@ -166,7 +166,7 @@ int input_reserve_key (char * key, bool exclusive, Client * client)
|
||||
kr->client = client;
|
||||
LL_Push(keylist, kr);
|
||||
|
||||
report (RPT_INFO, "%s: key [%.40s] is now reserved in %s mode", __FUNCTION__, key, (exclusive?"exclusive":"shared"));
|
||||
report (RPT_INFO, "Key \"%.40s\" is now reserved in %s mode by client [%d]", key, (exclusive?"exclusive":"shared"), (client?client->sock:-1));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -175,15 +175,15 @@ void input_release_key (char * key, Client * client)
|
||||
{
|
||||
KeyReservation * kr;
|
||||
|
||||
debug (RPT_DEBUG, "%s( key=\"%.40s\", client=%p )", __FUNCTION__, key, client);
|
||||
debug (RPT_DEBUG, "%s( key=\"%.40s\", client=[%d] )", __FUNCTION__, key, (client?client->sock:-1));
|
||||
|
||||
for (kr=LL_GetFirst(keylist); kr; kr=LL_GetNext(keylist)) {
|
||||
if (kr->client == client
|
||||
&& strcmp (kr->key, key) == 0) {
|
||||
report (RPT_INFO, "%s: key [%.40s] is being released from %s mode", __FUNCTION__, key, (kr->exclusive?"exclusive":"shared"));
|
||||
free (kr->key);
|
||||
free (kr);
|
||||
LL_DeleteNode (keylist);
|
||||
report (RPT_INFO, "Key \"%.40s\" was reserved in %s mode by client [%d] and is now released", key, (kr->exclusive?"exclusive":"shared"), (client?client->sock:-1));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -193,12 +193,12 @@ void input_release_client_keys (Client * client)
|
||||
{
|
||||
KeyReservation * kr;
|
||||
|
||||
debug (RPT_DEBUG, "%s( client=%p )", __FUNCTION__, client);
|
||||
debug (RPT_DEBUG, "%s( client=[%d] )", __FUNCTION__, (client?client->sock:-1));
|
||||
|
||||
kr=LL_GetFirst(keylist);
|
||||
while (kr) {
|
||||
if (kr->client == client) {
|
||||
report (RPT_INFO, "%s: key [%.40s] is now released from %s mode", __FUNCTION__, kr->key, (kr->exclusive?"exclusive":"shared"));
|
||||
report (RPT_INFO, "Key \"%.40s\" was reserved in %s mode by client [%d] and is now released", kr->key, (kr->exclusive?"exclusive":"shared"), (client?client->sock:-1));
|
||||
free (kr->key);
|
||||
free (kr);
|
||||
LL_DeleteNode (keylist);
|
||||
@@ -213,7 +213,7 @@ KeyReservation * input_find_key (char * key, Client * client)
|
||||
{
|
||||
KeyReservation * kr;
|
||||
|
||||
debug (RPT_DEBUG, "%s( key=\"%.40s\", client=%p )", __FUNCTION__, key, client);
|
||||
debug (RPT_DEBUG, "%s( key=\"%.40s\", client=[%d] )", __FUNCTION__, key, (client?client->sock:-1));
|
||||
|
||||
for (kr=LL_GetFirst(keylist); kr; kr=LL_GetNext(keylist)) {
|
||||
if (strcmp (kr->key, key) == 0) {
|
||||
|
||||
+16
-37
@@ -90,10 +90,6 @@ char *build_date = __DATE__;
|
||||
#define UNSET_INT -1
|
||||
#define UNSET_STR "\01"
|
||||
|
||||
/* int debug_level; for compatibility with MtxOrb and joy drivers.
|
||||
* I was about to remove the comment in front of this.
|
||||
* Now how do we become compatible WITHOUT this debug_level ?*/
|
||||
|
||||
int lcd_port = UNSET_INT;
|
||||
char bind_addr[64]; /* Do not preinit these strings as they will occupy */
|
||||
char configfile[256]; /* a lot of space in the executable. */
|
||||
@@ -188,9 +184,8 @@ main (int argc, char **argv)
|
||||
set_default_settings();
|
||||
|
||||
/* Set reporting values*/
|
||||
/*debug_level = reportLevel; */
|
||||
ESSENTIAL( set_reporting( "LCDd", reportLevel, (reportToSyslog?RPT_DEST_SYSLOG:RPT_DEST_STDERR) ) );
|
||||
report( RPT_NOTICE, "Set report level to %d, output to %s", reportLevel, (reportToSyslog?"syslog":"stderr") );
|
||||
report( RPT_INFO, "Set report level to %d, output to %s", reportLevel, (reportToSyslog?"syslog":"stderr") );
|
||||
|
||||
/* Startup the server*/
|
||||
ESSENTIAL( init_drivers() );
|
||||
@@ -206,11 +201,11 @@ main (int argc, char **argv)
|
||||
#ifndef DEBUG
|
||||
/* Now, go into daemon mode...*/
|
||||
if (daemon_mode) {
|
||||
report(RPT_NOTICE, "Server forking to background");
|
||||
report(RPT_INFO, "Server forking to background");
|
||||
ESSENTIAL( daemonize() );
|
||||
} else {
|
||||
output_GPL_notice();
|
||||
report(RPT_NOTICE, "Server running in foreground");
|
||||
report(RPT_INFO, "Server running in foreground");
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -226,7 +221,7 @@ clear_settings ()
|
||||
{
|
||||
int i;
|
||||
|
||||
/*report( RPT_INFO, "clear_settings()" );*/
|
||||
debug( RPT_DEBUG, "%s()", __FUNCTION__ );
|
||||
|
||||
lcd_port = UNSET_INT;
|
||||
strncpy( bind_addr, UNSET_STR, sizeof(bind_addr) );
|
||||
@@ -254,7 +249,7 @@ process_command_line (int argc, char **argv)
|
||||
{
|
||||
signed char c;
|
||||
|
||||
/*report( RPT_INFO, "process_command_line()" );*/
|
||||
debug( RPT_DEBUG, "%s( argc=%d, argv=...)", __FUNCTION__, argc );
|
||||
|
||||
/* analyze options here..*/
|
||||
while ((c = getopt(argc, argv, "a:p:d:hfib:w:c:u:sr:")) > 0) {
|
||||
@@ -345,7 +340,7 @@ process_configfile ( char *configfile )
|
||||
char * s;
|
||||
/*char buf[64];*/
|
||||
|
||||
/*report( RPT_INFO, "process_configfile()" );*/
|
||||
debug( RPT_DEBUG, "%s()", __FUNCTION__ );
|
||||
|
||||
/* Read server settings*/
|
||||
|
||||
@@ -449,7 +444,7 @@ process_configfile ( char *configfile )
|
||||
void
|
||||
set_default_settings()
|
||||
{
|
||||
/*report( RPT_INFO, "set_default_settings()" );*/
|
||||
debug( RPT_DEBUG, "%s()", __FUNCTION__ );
|
||||
|
||||
/* Set defaults into unfilled variables....*/
|
||||
|
||||
@@ -517,7 +512,7 @@ daemonize()
|
||||
{
|
||||
int child;
|
||||
|
||||
report( RPT_INFO, "daemonize()" );
|
||||
debug( RPT_DEBUG, "%s()", __FUNCTION__ );
|
||||
|
||||
switch ((child = fork ()) ) {
|
||||
case -1:
|
||||
@@ -545,7 +540,7 @@ daemonize()
|
||||
int
|
||||
init_sockets ()
|
||||
{
|
||||
report( RPT_INFO, "init_sockets()" );
|
||||
debug( RPT_DEBUG, "%s()", __FUNCTION__ );
|
||||
|
||||
if (sock_create_server (&bind_addr, lcd_port) <= 0) {
|
||||
report(RPT_ERR, "Error opening socket");
|
||||
@@ -569,7 +564,7 @@ init_drivers()
|
||||
|
||||
int output_loaded = 0;
|
||||
|
||||
report( RPT_INFO, "init_drivers()" );
|
||||
debug( RPT_DEBUG, "%s()", __FUNCTION__ );
|
||||
|
||||
for (i = 0; i < num_drivers; i++) {
|
||||
|
||||
@@ -609,7 +604,7 @@ int drop_privs(char *user)
|
||||
{
|
||||
struct passwd *pwent;
|
||||
|
||||
report( RPT_INFO, "drop_privs()" );
|
||||
debug( RPT_DEBUG, "%s( user=\"%.40s\" )", __FUNCTION__, user );
|
||||
|
||||
if (getuid() == 0 || geteuid() == 0) {
|
||||
if ((pwent = getpwnam(user)) == NULL) {
|
||||
@@ -629,7 +624,7 @@ int drop_privs(char *user)
|
||||
int
|
||||
init_screens ()
|
||||
{
|
||||
report( RPT_INFO, "init_screens()" );
|
||||
debug( RPT_DEBUG, "%s()", __FUNCTION__ );
|
||||
|
||||
if (screenlist_init () < 0) {
|
||||
report(RPT_ERR, "Error initializing screen list");
|
||||
@@ -658,7 +653,7 @@ do_mainloop ()
|
||||
Screen *s = NULL;
|
||||
char *message=NULL;
|
||||
|
||||
report( RPT_INFO, "do_mainloop()" );
|
||||
debug( RPT_DEBUG, "%s()", __FUNCTION__ );
|
||||
|
||||
/*char buf[64];*/
|
||||
|
||||
@@ -675,21 +670,6 @@ do_mainloop ()
|
||||
|
||||
timer++;
|
||||
|
||||
/*if (s == NULL)
|
||||
* s = screenlist_current();
|
||||
|
||||
* this is here because s is getting overwritten...
|
||||
*if (s != screenlist_current()) {
|
||||
* report(RPT_DEBUG, "internal error! s was found overwritten at main.c:637");
|
||||
* s = screenlist_current();
|
||||
*}
|
||||
*/
|
||||
|
||||
/*TODO: THIS MUST BE FIXED..... WHY is s getting overwritten?
|
||||
* s is a local, it is never passed or assigned to anywhere.
|
||||
* So SOMETHING is going haywire and clobbering memory....
|
||||
*/
|
||||
|
||||
if (s && (timer >= s->duration))
|
||||
screenlist_next ();
|
||||
|
||||
@@ -758,7 +738,7 @@ exit_program (int val)
|
||||
{
|
||||
char buf[64];
|
||||
|
||||
report( RPT_INFO, "exit_program()" );
|
||||
debug( RPT_DEBUG, "%s( val=%d )", __FUNCTION__, val );
|
||||
|
||||
/* TODO: These things shouldn't be so interdependent. The order
|
||||
* things are shut down in shouldn't matter...
|
||||
@@ -781,7 +761,7 @@ exit_program (int val)
|
||||
if( reportLevel == UNSET_INT )
|
||||
reportLevel = DEFAULT_REPORTLEVEL;
|
||||
if( reportToSyslog == UNSET_INT )
|
||||
reportLevel = DEFAULT_REPORTLEVEL;
|
||||
reportToSyslog = DEFAULT_REPORTTOSYSLOG;
|
||||
set_reporting( "LCDd", reportLevel, (reportToSyslog?RPT_DEST_SYSLOG:RPT_DEST_STDERR) );
|
||||
|
||||
goodbye_screen (); /* display goodbye screen on LCD display */
|
||||
@@ -791,7 +771,6 @@ exit_program (int val)
|
||||
if( serverStarted ) {
|
||||
clients_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);
|
||||
@@ -804,7 +783,7 @@ HelpScreen ()
|
||||
/* Help screen is printed to stdout on purpose. No reason to have
|
||||
* this in syslog...
|
||||
*/
|
||||
report( RPT_INFO, "HelpScreen()" );
|
||||
debug( RPT_DEBUG, "%s()", __FUNCTION__ );
|
||||
|
||||
fprintf (stdout, "\nLCDd: LCDproc Server Daemon, %s\n", version);
|
||||
fprintf (stdout, "Copyright (c) 1999 Scott Scriven, William Ferrell, and misc contributors\n");
|
||||
|
||||
+35
-9
@@ -53,7 +53,7 @@ menu_create (char *id, MenuEventFunc(*event_func),
|
||||
void
|
||||
menu_destroy (Menu *menu)
|
||||
{
|
||||
debug (RPT_DEBUG, "%s( menu=\"%s\" )", __FUNCTION__, menu->id);
|
||||
debug (RPT_DEBUG, "%s( menu=[%s] )", __FUNCTION__, menu->id);
|
||||
|
||||
menu_destroy_all_items (menu);
|
||||
LL_Destroy (menu->data.menu.contents);
|
||||
@@ -65,7 +65,7 @@ menu_destroy (Menu *menu)
|
||||
void
|
||||
menu_add_item (Menu *menu, MenuItem *item)
|
||||
{
|
||||
debug (RPT_DEBUG, "%s( menu=\"%s\", item=\"%s\" )", __FUNCTION__, menu->id, item->id);
|
||||
debug (RPT_DEBUG, "%s( menu=[%s], item=[%s] )", __FUNCTION__, menu->id, item->id);
|
||||
|
||||
if (!menu) return;
|
||||
|
||||
@@ -77,9 +77,25 @@ menu_add_item (Menu *menu, MenuItem *item)
|
||||
void
|
||||
menu_remove_item (Menu *menu, MenuItem *item)
|
||||
{
|
||||
debug (RPT_DEBUG, "%s( menu=\"%s\", item=\"%s\" )", __FUNCTION__, menu->id, item->id);
|
||||
int i;
|
||||
MenuItem * item2;
|
||||
|
||||
LL_Remove (menu->data.menu.contents, item);
|
||||
debug (RPT_DEBUG, "%s( menu=[%s], item=[%s] )", __FUNCTION__, menu->id, item->id);
|
||||
|
||||
/* Find the item */
|
||||
for (item2=LL_GetFirst(menu->data.menu.contents), i=0;
|
||||
item2;
|
||||
item2=LL_GetNext(menu->data.menu.contents), i++ ) {
|
||||
if (item==item2) {
|
||||
LL_DeleteNode (menu->data.menu.contents);
|
||||
if (menu->data.menu.selector_pos>=i) {
|
||||
menu->data.menu.selector_pos--;
|
||||
if (menu->data.menu.scroll > 0)
|
||||
menu->data.menu.scroll--;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -87,7 +103,7 @@ menu_destroy_all_items (Menu *menu)
|
||||
{
|
||||
MenuItem * item;
|
||||
|
||||
debug (RPT_DEBUG, "%s( menu=\"%s\" )", __FUNCTION__, menu->id);
|
||||
debug (RPT_DEBUG, "%s( menu=[%s] )", __FUNCTION__, menu->id);
|
||||
|
||||
for( item = menu_getfirst_item(menu); item; item = menu_getfirst_item(menu) ) {
|
||||
menuitem_destroy (item);
|
||||
@@ -99,7 +115,7 @@ MenuItem *menu_find_item (Menu *menu, char *id, bool recursive)
|
||||
{
|
||||
MenuItem * item;
|
||||
|
||||
debug (RPT_DEBUG, "%s( menu=\"%s\", id=\"%s\" )", __FUNCTION__, menu->id, id);
|
||||
debug (RPT_DEBUG, "%s( menu=[%s], id=\"%s\", recursive=%d )", __FUNCTION__, menu->id, id, recursive);
|
||||
|
||||
for( item = menu_getfirst_item(menu); item; item = menu_getnext_item(menu) ) {
|
||||
if ( strcmp(item->id, id) == 0 ) {
|
||||
@@ -118,6 +134,8 @@ MenuItem *menu_find_item (Menu *menu, char *id, bool recursive)
|
||||
|
||||
void menu_reset (Menu *menu)
|
||||
{
|
||||
debug (RPT_DEBUG, "%s( menu=[%s] )", __FUNCTION__, menu->id);
|
||||
|
||||
menu->data.menu.selector_pos = 0;
|
||||
menu->data.menu.scroll = 0;
|
||||
}
|
||||
@@ -128,7 +146,7 @@ void menu_build_screen (MenuItem *menu, Screen *s)
|
||||
MenuItem * subitem;
|
||||
int itemnr;
|
||||
|
||||
debug (RPT_DEBUG, "%s( menu=\"%s\", screen=\"%s\" )", __FUNCTION__, menu->id, s->id);
|
||||
debug (RPT_DEBUG, "%s( menu=[%s], screen=[%s] )", __FUNCTION__, menu->id, s->id);
|
||||
|
||||
/* TODO: Put menu in a frame to do easy scrolling */
|
||||
/* Problem: frames are not handled correctly by renderer */
|
||||
@@ -176,6 +194,14 @@ void menu_build_screen (MenuItem *menu, Screen *s)
|
||||
w->text = malloc (display_props->width);
|
||||
break;
|
||||
case MENUITEM_MENU:
|
||||
/* Limit string length */
|
||||
w->text = malloc( strlen(subitem->text) + 4 );
|
||||
strcpy( w->text, subitem->text );
|
||||
strcat( w->text, " >" );
|
||||
if (strlen(subitem->text) >= display_props->width-1) {
|
||||
(w->text)[display_props->width-1] = 0;
|
||||
}
|
||||
break;
|
||||
case MENUITEM_ACTION:
|
||||
case MENUITEM_SLIDER:
|
||||
case MENUITEM_NUMERIC:
|
||||
@@ -217,7 +243,7 @@ void menu_update_screen (MenuItem *menu, Screen *s)
|
||||
MenuItem * subitem;
|
||||
int itemnr;
|
||||
|
||||
debug (RPT_INFO, "%s( menu=\"%s\", screen=\"%s\" )", __FUNCTION__, menu->id, s->id);
|
||||
debug (RPT_DEBUG, "%s( menu=[%s], screen=[%s] )", __FUNCTION__, menu->id, s->id);
|
||||
|
||||
/* Update widgets for the title */
|
||||
w = screen_find_widget (s, "title");
|
||||
@@ -328,7 +354,7 @@ MenuResult menu_process_input (Menu *menu, MenuToken token, char * key)
|
||||
{
|
||||
MenuItem *subitem;
|
||||
|
||||
debug (RPT_DEBUG, "%s( menu=\"%s\", token=%d, key=\"%s\" )", __FUNCTION__, menu->id, token, key);
|
||||
debug (RPT_DEBUG, "%s( menu=[%s], token=%d, key=\"%s\" )", __FUNCTION__, menu->id, token, key);
|
||||
|
||||
switch (token) {
|
||||
case MENUTOKEN_MENU:
|
||||
|
||||
+25
-25
@@ -146,7 +146,7 @@ MenuItem *menuitem_create_action (char *id, MenuEventFunc(*event_func),
|
||||
{
|
||||
MenuItem *new_item;
|
||||
|
||||
debug (RPT_DEBUG, "%s( id=\"%s\", event_func=%p, text=\"%s\", close_menu=%d )",
|
||||
debug (RPT_DEBUG, "%s( id=[%s], event_func=%p, text=\"%s\", close_menu=%d )",
|
||||
__FUNCTION__, id, event_func, text, menu_result);
|
||||
|
||||
new_item = menuitem_create (MENUITEM_ACTION, id, event_func, text);
|
||||
@@ -160,7 +160,7 @@ MenuItem *menuitem_create_checkbox (char *id, MenuEventFunc(*event_func),
|
||||
{
|
||||
MenuItem *new_item;
|
||||
|
||||
debug (RPT_DEBUG, "%s( id=\"%s\", event_func=%p, text=\"%s\", allow_gray=%d, value=%d )",
|
||||
debug (RPT_DEBUG, "%s( id=[%s], event_func=%p, text=\"%s\", allow_gray=%d, value=%d )",
|
||||
__FUNCTION__, id, event_func, text, allow_gray, value);
|
||||
|
||||
new_item = menuitem_create (MENUITEM_CHECKBOX, id, event_func, text);
|
||||
@@ -175,7 +175,7 @@ MenuItem *menuitem_create_ring (char *id, MenuEventFunc(*event_func),
|
||||
{
|
||||
MenuItem *new_item;
|
||||
|
||||
debug (RPT_DEBUG, "%s( id=\"%s\", event_func=%p, text=\"%s\", strings=\"%s\", value=%d )",
|
||||
debug (RPT_DEBUG, "%s( id=[%s], event_func=%p, text=\"%s\", strings=\"%s\", value=%d )",
|
||||
__FUNCTION__, id, event_func, text, strings, value);
|
||||
|
||||
new_item = menuitem_create (MENUITEM_RING, id, event_func, text);
|
||||
@@ -191,7 +191,7 @@ MenuItem *menuitem_create_slider (char *id, MenuEventFunc(*event_func),
|
||||
{
|
||||
MenuItem *new_item;
|
||||
|
||||
debug (RPT_DEBUG, "%s( id=\"%s\", event_func=%p, text=\"%s\", mintext=\"%s\", maxtext=\"%s\", minvalue=%d, maxvalue=%d, stepsize=%d, value=%d )",
|
||||
debug (RPT_DEBUG, "%s( id=[%s], event_func=%p, text=\"%s\", mintext=\"%s\", maxtext=\"%s\", minvalue=%d, maxvalue=%d, stepsize=%d, value=%d )",
|
||||
__FUNCTION__, id, event_func, text, mintext, maxtext, minvalue, maxvalue, stepsize, value);
|
||||
|
||||
new_item = menuitem_create (MENUITEM_SLIDER, id, event_func, text);
|
||||
@@ -210,7 +210,7 @@ MenuItem *menuitem_create_numeric (char *id, MenuEventFunc(*event_func),
|
||||
{
|
||||
MenuItem *new_item;
|
||||
|
||||
debug (RPT_DEBUG, "%s( id=\"%s\", event_func=%p, text=\"%s\", minvalue=%d, maxvalue=%d, value=%d )",
|
||||
debug (RPT_DEBUG, "%s( id=[%s], event_func=%p, text=\"%s\", minvalue=%d, maxvalue=%d, value=%d )",
|
||||
__FUNCTION__, id, event_func, text, minvalue, minvalue, value);
|
||||
|
||||
new_item = menuitem_create (MENUITEM_NUMERIC, id, event_func, text);
|
||||
@@ -256,7 +256,7 @@ void menuitem_destroy (MenuItem *item)
|
||||
{
|
||||
void (*destructor) (MenuItem *);
|
||||
|
||||
debug (RPT_DEBUG, "%s( item=\"%s\" )", __FUNCTION__, item->id);
|
||||
debug (RPT_DEBUG, "%s( item=[%s] )", __FUNCTION__, item->id);
|
||||
|
||||
/* First destroy type specific data */
|
||||
destructor = destructor_table[item->type];
|
||||
@@ -275,7 +275,7 @@ void menuitem_destroy_ring (MenuItem *item)
|
||||
{
|
||||
char * s;
|
||||
|
||||
debug (RPT_DEBUG, "%s( item=\"%s\" )", __FUNCTION__, item->id);
|
||||
debug (RPT_DEBUG, "%s( item=[%s] )", __FUNCTION__, item->id);
|
||||
|
||||
/* deallocate the strings */
|
||||
for (s = LL_GetFirst(item->data.ring.strings); s; s = LL_GetNext(item->data.ring.strings)) {
|
||||
@@ -287,7 +287,7 @@ void menuitem_destroy_ring (MenuItem *item)
|
||||
|
||||
void menuitem_destroy_slider (MenuItem *item)
|
||||
{
|
||||
debug (RPT_DEBUG, "%s( item=\"%s\" )", __FUNCTION__, item->id);
|
||||
debug (RPT_DEBUG, "%s( item=[%s] )", __FUNCTION__, item->id);
|
||||
|
||||
/* These strings should always be allocated */
|
||||
free (item->data.slider.mintext);
|
||||
@@ -296,7 +296,7 @@ void menuitem_destroy_slider (MenuItem *item)
|
||||
|
||||
void menuitem_destroy_numeric (MenuItem *item)
|
||||
{
|
||||
debug (RPT_DEBUG, "%s( item=\"%s\" )", __FUNCTION__, item->id);
|
||||
debug (RPT_DEBUG, "%s( item=[%s] )", __FUNCTION__, item->id);
|
||||
|
||||
/* This string should always be allocated */
|
||||
free (item->data.alpha.edit_str);
|
||||
@@ -304,7 +304,7 @@ void menuitem_destroy_numeric (MenuItem *item)
|
||||
|
||||
void menuitem_destroy_alpha (MenuItem *item)
|
||||
{
|
||||
debug (RPT_DEBUG, "%s( item=\"%s\" )", __FUNCTION__, item->id);
|
||||
debug (RPT_DEBUG, "%s( item=[%s] )", __FUNCTION__, item->id);
|
||||
|
||||
/* These strings should always be allocated */
|
||||
free (item->data.alpha.allowed_extra);
|
||||
@@ -318,7 +318,7 @@ void menuitem_reset (MenuItem *item)
|
||||
{
|
||||
void (*func) (MenuItem *);
|
||||
|
||||
debug (RPT_DEBUG, "%s( item=\"%s\" )", __FUNCTION__, item->id);
|
||||
debug (RPT_DEBUG, "%s( item=[%s] )", __FUNCTION__, item->id);
|
||||
|
||||
/* First destroy type specific data */
|
||||
func = reset_table[item->type];
|
||||
@@ -328,7 +328,7 @@ void menuitem_reset (MenuItem *item)
|
||||
|
||||
void menuitem_reset_numeric (MenuItem *item)
|
||||
{
|
||||
debug (RPT_DEBUG, "%s( item=\"%s\" )", __FUNCTION__, item->id);
|
||||
debug (RPT_DEBUG, "%s( item=[%s] )", __FUNCTION__, item->id);
|
||||
|
||||
item->data.numeric.edit_pos = 0;
|
||||
memset ( item->data.numeric.edit_str, 0, MAX_NUMERIC_LEN);
|
||||
@@ -341,7 +341,7 @@ void menuitem_reset_numeric (MenuItem *item)
|
||||
|
||||
void menuitem_reset_alpha (MenuItem *item)
|
||||
{
|
||||
debug (RPT_DEBUG, "%s( item=\"%s\" )", __FUNCTION__, item->id);
|
||||
debug (RPT_DEBUG, "%s( item=[%s] )", __FUNCTION__, item->id);
|
||||
|
||||
item->data.alpha.edit_pos = 0;
|
||||
memset (item->data.alpha.edit_str, 0, item->data.alpha.maxlength+1);
|
||||
@@ -356,7 +356,7 @@ void menuitem_rebuild_screen (MenuItem *item, Screen *s)
|
||||
Widget * w;
|
||||
void (*build_screen) (MenuItem *item, Screen *s);
|
||||
|
||||
debug (RPT_DEBUG, "%s( item=\"%s\", screen=\"%s\" )", __FUNCTION__, item->id, s->id);
|
||||
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__, item->id, s->id);
|
||||
|
||||
if (!display_props) {
|
||||
/* Nothing to build if no display size is known */
|
||||
@@ -390,7 +390,7 @@ void menuitem_rebuild_screen_slider (MenuItem *item, Screen *s)
|
||||
{
|
||||
Widget * w;
|
||||
|
||||
debug (RPT_DEBUG, "%s( item=\"%s\", screen=\"%s\" )", __FUNCTION__, item->id, s->id);
|
||||
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__, item->id, s->id);
|
||||
|
||||
if (display_props->height >= 2 ) {
|
||||
/* Only add a title if enough space... */
|
||||
@@ -438,7 +438,7 @@ void menuitem_rebuild_screen_numeric (MenuItem *item, Screen *s)
|
||||
{
|
||||
Widget * w;
|
||||
|
||||
debug (RPT_DEBUG, "%s( item=\"%s\", screen=\"%s\" )", __FUNCTION__, item->id, s->id);
|
||||
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__, item->id, s->id);
|
||||
|
||||
if (display_props->height >= 2 ) {
|
||||
/* Only add a title if enough space... */
|
||||
@@ -469,7 +469,7 @@ void menuitem_rebuild_screen_alpha (MenuItem *item, Screen *s)
|
||||
{
|
||||
Widget * w;
|
||||
|
||||
debug (RPT_DEBUG, "%s( item=\"%s\", screen=\"%s\" )", __FUNCTION__, item->id, s->id);
|
||||
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__, item->id, s->id);
|
||||
|
||||
if (display_props->height >= 2 ) {
|
||||
/* Only add a title if enough space... */
|
||||
@@ -502,7 +502,7 @@ void menuitem_update_screen (MenuItem *item, Screen *s)
|
||||
{
|
||||
void (*update_screen) (MenuItem *item, Screen *s);
|
||||
|
||||
debug (RPT_DEBUG, "%s( item=\"%s\", screen=\"%s\" )", __FUNCTION__, item->id, s->id);
|
||||
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__, item->id, s->id);
|
||||
|
||||
/* Disable the cursor by default */
|
||||
s->cursor = CURSOR_OFF;
|
||||
@@ -522,7 +522,7 @@ void menuitem_update_screen_slider (MenuItem *item, Screen *s)
|
||||
Widget * w;
|
||||
int min_len, max_len;
|
||||
|
||||
debug (RPT_DEBUG, "%s( item=\"%s\", screen=\"%s\" )", __FUNCTION__, item->id, s->id);
|
||||
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__, item->id, s->id);
|
||||
|
||||
/* Calculate the bar position and length by filling buffers */
|
||||
min_len = strlen (item->data.slider.mintext);
|
||||
@@ -559,7 +559,7 @@ void menuitem_update_screen_numeric (MenuItem *item, Screen *s)
|
||||
{
|
||||
Widget * w;
|
||||
|
||||
debug (RPT_DEBUG, "%s( item=\"%s\", screen=\"%s\" )", __FUNCTION__, item->id, s->id);
|
||||
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__, item->id, s->id);
|
||||
|
||||
w = screen_find_widget (s, "value");
|
||||
strcpy (w->text, item->data.numeric.edit_str);
|
||||
@@ -580,7 +580,7 @@ void menuitem_update_screen_alpha (MenuItem *item, Screen *s)
|
||||
{
|
||||
Widget * w;
|
||||
|
||||
debug (RPT_DEBUG, "%s( item=\"%s\", screen=\"%s\" )", __FUNCTION__, item->id, s->id);
|
||||
debug (RPT_DEBUG, "%s( item=[%s], screen=[%s] )", __FUNCTION__, item->id, s->id);
|
||||
|
||||
w = screen_find_widget (s, "value");
|
||||
if (item->data.alpha.password_char == 0) {
|
||||
@@ -608,7 +608,7 @@ MenuResult menuitem_process_input (MenuItem *item, MenuToken token, char * key)
|
||||
{
|
||||
MenuResult (*process_input) (MenuItem *item, MenuToken token, char * key);
|
||||
|
||||
debug (RPT_DEBUG, "%s( item=\"%s\", token=%d, key=\"%s\" )", __FUNCTION__, item->id, token, key);
|
||||
debug (RPT_DEBUG, "%s( item=[%s], token=%d, key=\"%s\" )", __FUNCTION__, item->id, token, key);
|
||||
|
||||
/* Call type specific screen building function */
|
||||
process_input = process_input_table [item->type];
|
||||
@@ -622,7 +622,7 @@ MenuResult menuitem_process_input (MenuItem *item, MenuToken token, char * key)
|
||||
|
||||
MenuResult menuitem_process_input_slider (MenuItem *item, MenuToken token, char * key)
|
||||
{
|
||||
debug (RPT_DEBUG, "%s( item=\"%s\", token=%d, key=\"%s\" )", __FUNCTION__, item->id, token, key);
|
||||
debug (RPT_DEBUG, "%s( item=[%s], token=%d, key=\"%s\" )", __FUNCTION__, item->id, token, key);
|
||||
|
||||
switch (token) {
|
||||
case MENUTOKEN_MENU:
|
||||
@@ -659,7 +659,7 @@ MenuResult menuitem_process_input_numeric (MenuItem *item, MenuToken token, char
|
||||
int pos = item->data.numeric.edit_pos;
|
||||
int allow_signed = (item->data.numeric.minvalue < 0);
|
||||
|
||||
debug (RPT_DEBUG, "%s( item=\"%s\", token=%d, key=\"%s\" )", __FUNCTION__, item->id, token, key);
|
||||
debug (RPT_DEBUG, "%s( item=[%s], token=%d, key=\"%s\" )", __FUNCTION__, item->id, token, key);
|
||||
|
||||
if (allow_signed) {
|
||||
format_str = "%+d";
|
||||
@@ -790,7 +790,7 @@ MenuResult menuitem_process_input_alpha (MenuItem *item, MenuToken token, char *
|
||||
char *str = item->data.alpha.edit_str;
|
||||
int pos = item->data.alpha.edit_pos;
|
||||
|
||||
debug (RPT_DEBUG, "%s( item=\"%s\", token=%d, key=\"%s\" )", __FUNCTION__, item->id, token, key);
|
||||
debug (RPT_DEBUG, "%s( item=[%s], token=%d, key=\"%s\" )", __FUNCTION__, item->id, token, key);
|
||||
|
||||
/* Create list of allowed chars */
|
||||
chars = realloc (chars, 26 + 26 + 10 + strlen(item->data.alpha.allowed_extra) + 1);
|
||||
|
||||
+14
-6
@@ -84,6 +84,8 @@ void menuscreen_inform_item_destruction (MenuItem * item)
|
||||
{
|
||||
MenuItem * i;
|
||||
|
||||
debug (RPT_DEBUG, "%s( item=[%s] )", __FUNCTION__, item->id);
|
||||
|
||||
/* Are we currently in (a subitem of) the given item ? */
|
||||
for( i = active_menuitem; i; i = i->parent ) {
|
||||
if( i == item ) {
|
||||
@@ -94,6 +96,10 @@ void menuscreen_inform_item_destruction (MenuItem * item)
|
||||
|
||||
void menuscreen_inform_item_modified (MenuItem * item)
|
||||
{
|
||||
debug (RPT_DEBUG, "%s( item=[%s] )", __FUNCTION__, item->id);
|
||||
|
||||
if( !active_menuitem ) return;
|
||||
|
||||
/* Are we currently in the item or the parent of the item ? */
|
||||
if( active_menuitem == item || active_menuitem == item->parent ) {
|
||||
menuitem_rebuild_screen( active_menuitem, menuscreen );
|
||||
@@ -116,6 +122,8 @@ void menuscreen_switch_item (MenuItem * new_menuitem)
|
||||
{
|
||||
MenuItem * old_menuitem = active_menuitem;
|
||||
|
||||
debug (RPT_DEBUG, "%s( item=[%s] )", __FUNCTION__, new_menuitem?new_menuitem->id:NULL);
|
||||
|
||||
/* First we do the switch */
|
||||
active_menuitem = new_menuitem;
|
||||
|
||||
@@ -295,7 +303,7 @@ void menuscreen_create_menu ()
|
||||
|
||||
MenuEventFunc (heartbeat_handler)
|
||||
{
|
||||
debug (RPT_DEBUG, "%s( item=%s, event=%d )", __FUNCTION__, item->id, event);
|
||||
debug (RPT_DEBUG, "%s( item=[%s], event=%d )", __FUNCTION__, item->id, event);
|
||||
|
||||
if (event == MENUEVENT_UPDATE) {
|
||||
/* Set heartbeat setting */
|
||||
@@ -308,7 +316,7 @@ MenuEventFunc (heartbeat_handler)
|
||||
|
||||
MenuEventFunc (backlight_handler)
|
||||
{
|
||||
debug (RPT_DEBUG, "%s( item=%s, event=%d )", __FUNCTION__, item->id, event);
|
||||
debug (RPT_DEBUG, "%s( item=[%s], event=%d )", __FUNCTION__, item->id, event);
|
||||
|
||||
if (event == MENUEVENT_UPDATE)
|
||||
{
|
||||
@@ -322,7 +330,7 @@ MenuEventFunc (backlight_handler)
|
||||
|
||||
MenuEventFunc (contrast_handler)
|
||||
{
|
||||
debug (RPT_DEBUG, "%s( item=%s, event=%d )", __FUNCTION__, item->id, event);
|
||||
debug (RPT_DEBUG, "%s( item=[%s], event=%d )", __FUNCTION__, item->id, event);
|
||||
|
||||
/* This function can be called by one of several drivers that
|
||||
* support contrast !
|
||||
@@ -342,7 +350,7 @@ MenuEventFunc (contrast_handler)
|
||||
|
||||
MenuEventFunc (brightness_handler)
|
||||
{
|
||||
debug (RPT_DEBUG, "%s( item=%s, event=%d )", __FUNCTION__, item->id, event);
|
||||
debug (RPT_DEBUG, "%s( item=[%s], event=%d )", __FUNCTION__, item->id, event);
|
||||
|
||||
/* This function can be called by one of several drivers that
|
||||
* support contrast !
|
||||
@@ -368,7 +376,7 @@ menuscreen_add_screen (Screen * s)
|
||||
Menu * m;
|
||||
MenuItem * mi;
|
||||
|
||||
debug (RPT_DEBUG, "%s( Screen=\"%s\" )", __FUNCTION__, s->id);
|
||||
debug (RPT_DEBUG, "%s( s=[%s] )", __FUNCTION__, s->id);
|
||||
|
||||
if (!screens_menu)
|
||||
return; /* When screens have not been created ... */
|
||||
@@ -399,7 +407,7 @@ menuscreen_remove_screen (Screen * s)
|
||||
{
|
||||
Menu * m;
|
||||
|
||||
debug (RPT_DEBUG, "%s( Screen=\"%s\" )", __FUNCTION__, s->id);
|
||||
debug (RPT_DEBUG, "%s( s=[%s] )", __FUNCTION__, s->id);
|
||||
|
||||
m = menu_find_item (screens_menu, s->id, false);
|
||||
menu_remove_item (screens_menu, m);
|
||||
|
||||
+6
-1
@@ -191,7 +191,7 @@ parse_all_client_messages ()
|
||||
Client * c;
|
||||
char * str;
|
||||
|
||||
debug( RPT_DEBUG, "parse_all_client_messages()" );
|
||||
debug( RPT_DEBUG, "%s()", __FUNCTION__ );
|
||||
|
||||
for( c=clients_getfirst(); c; c=clients_getnext()) {
|
||||
|
||||
@@ -230,6 +230,8 @@ int parse_message (char * str, Client * c)
|
||||
argpos = 0;
|
||||
}
|
||||
|
||||
debug( RPT_DEBUG, "%s( str=\"%.120s\", client=[%d] )", __FUNCTION__, str, c->sock );
|
||||
|
||||
arg_space = malloc(strlen(str)+1);
|
||||
argv[0] = arg_space;
|
||||
/* We will create a new string that is shorter or equally long as
|
||||
@@ -339,6 +341,7 @@ int parse_message (char * str, Client * c)
|
||||
argv[argc] = NULL;
|
||||
if (error) {
|
||||
snprintf (errmsg, sizeof(errmsg), "huh? Could not parse command\n");
|
||||
report( RPT_WARNING, "Could not parse command from client on socket %d: %s", __FUNCTION__, c->sock, str );
|
||||
sock_send_string (c->sock, errmsg);
|
||||
free( arg_space );
|
||||
return 0;
|
||||
@@ -356,10 +359,12 @@ int parse_message (char * str, Client * c)
|
||||
if (error == 1) {
|
||||
snprintf (errmsg, sizeof(errmsg), "huh? Invalid command \"%.40s\"\n", argv[0]);
|
||||
sock_send_string (c->sock, errmsg);
|
||||
report( RPT_WARNING, "Invalid command from client on socket %d: %s", __FUNCTION__, c->sock, str );
|
||||
}
|
||||
else if (error) {
|
||||
snprintf (errmsg, sizeof(errmsg), "huh? Function returned error \"%.40s\"\n", argv[0]);
|
||||
sock_send_string (c->sock, errmsg);
|
||||
report( RPT_WARNING, "Command function returned an error after command from client on socket %d: %s", __FUNCTION__, c->sock, str );
|
||||
}
|
||||
|
||||
free( arg_space );
|
||||
|
||||
+9
-8
@@ -58,7 +58,7 @@ draw_screen (Screen * s, int timer)
|
||||
static Screen * old_s = NULL;
|
||||
int tmp_state = 0;
|
||||
|
||||
report(RPT_INFO, "draw_screen( screen=\"%.40s\", timer=%d ) ==== START RENDERING ====", s->id, timer );
|
||||
debug(RPT_DEBUG, "%s( screen=[%.40s], timer=%d ) ==== START RENDERING ====", __FUNCTION__, s->id, timer );
|
||||
|
||||
reset = 1;
|
||||
|
||||
@@ -120,7 +120,7 @@ draw_screen (Screen * s, int timer)
|
||||
/* Set the cursor */
|
||||
drivers_cursor (s->cursor_x, s->cursor_y, s->cursor);
|
||||
|
||||
/*debug(RPT_DEBUG, "draw_screen done"); */
|
||||
/*debug(RPT_DEBUG, "%s done", __FUNCTION__); */
|
||||
|
||||
if (heartbeat != HEARTBEAT_OPEN) {
|
||||
tmp_state = heartbeat;
|
||||
@@ -136,9 +136,9 @@ draw_screen (Screen * s, int timer)
|
||||
/* flush display out, frame and all... */
|
||||
drivers_flush ();
|
||||
|
||||
/*debug(RPT_DEBUG, "draw_screen: %8x, %i", s, timer); */
|
||||
/*debug(RPT_DEBUG, "%s: %8x, %i", __FUNCTION__, s, timer); */
|
||||
|
||||
report(RPT_INFO, "==== END RENDERING ====" );
|
||||
debug(RPT_DEBUG, "==== END RENDERING ====" );
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -173,9 +173,10 @@ draw_frame (LinkedList * list,
|
||||
|
||||
int reset = 1;
|
||||
|
||||
report( RPT_INFO, "draw_frame( list=%p, fscroll='%c', left=%d, top=%d, "
|
||||
debug( RPT_DEBUG, "%s( list=%p, fscroll='%c', left=%d, top=%d, "
|
||||
"right=%d, bottom=%d, fwid=%d, fhgt=%d, fspeed=%d, timer=%d )",
|
||||
list, fscroll, left,top, right, bottom, fwid, fhgt, fspeed, timer );
|
||||
__FUNCTION__, list, fscroll, left,top, right, bottom,
|
||||
fwid, fhgt, fspeed, timer );
|
||||
|
||||
vis_width = right - left; /* This is the size of the visible frame area */
|
||||
vis_height = bottom - top;
|
||||
@@ -216,7 +217,7 @@ draw_frame (LinkedList * list,
|
||||
if (!list)
|
||||
return -1;
|
||||
|
||||
/*debug(RPT_DEBUG, "draw_frame: %8x, %i", frame, timer); */
|
||||
/*debug(RPT_DEBUG, "%s: %8x, %i", __FUNCTION__, frame, timer); */
|
||||
|
||||
#define PositiveX(a) ((a)->x > 0)
|
||||
#define PositiveY(a) ((a)->y > 0)
|
||||
@@ -353,7 +354,7 @@ draw_frame (LinkedList * list,
|
||||
break;
|
||||
if (w->right < w->left)
|
||||
break;
|
||||
/*debug(RPT_DEBUG, "rendering: %s %d",w->text,timer);*/
|
||||
/*debug(RPT_DEBUG, "%s: %s %d",__FUNCTION__,w->text,timer);*/
|
||||
screen_width = w->right - w->left + 1;
|
||||
switch (w->length) { /* actually, direction...*/
|
||||
/* FIXED: Horz scrollers don't show the
|
||||
|
||||
+12
-22
@@ -36,20 +36,22 @@ screen_create (char * id, Client * client)
|
||||
{
|
||||
Screen *s;
|
||||
|
||||
debug( RPT_DEBUG, "%s( id=\"%.40s\", client=[%d] )", __FUNCTION__, id, (client?client->sock:-1));
|
||||
|
||||
s = malloc (sizeof (Screen));
|
||||
if (!s) {
|
||||
report(RPT_ERR, "screen_create: Error allocating");
|
||||
report(RPT_ERR, "%s: Error allocating", __FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
if (!id) {
|
||||
report (RPT_ERR, "screen_create: Need id string");
|
||||
report (RPT_ERR, "%s: Need id string", __FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
/* Client can be NULL for serverscreens and other client-less screens */
|
||||
|
||||
s->id = strdup(id);
|
||||
if (!s->id) {
|
||||
report(RPT_ERR, "screen_create: Error allocating");
|
||||
report(RPT_ERR, "%s: Error allocating", __FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -72,7 +74,7 @@ screen_create (char * id, Client * client)
|
||||
|
||||
s->widgetlist = LL_new ();
|
||||
if (!s->widgetlist) {
|
||||
report(RPT_ERR, "screen_create: Error allocating");
|
||||
report(RPT_ERR, "%s: Error allocating", __FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -86,8 +88,7 @@ screen_destroy (Screen * s)
|
||||
{
|
||||
Widget *w;
|
||||
|
||||
if (!s)
|
||||
return -1;
|
||||
debug( RPT_DEBUG, "%s( s=[%.40s] )", __FUNCTION__, s->id );
|
||||
|
||||
menuscreen_remove_screen (s);
|
||||
|
||||
@@ -103,8 +104,6 @@ screen_destroy (Screen * s)
|
||||
free (s->id);
|
||||
if (s->name)
|
||||
free (s->name);
|
||||
if (s->keys)
|
||||
free (s->keys);
|
||||
|
||||
free (s);
|
||||
|
||||
@@ -114,11 +113,7 @@ screen_destroy (Screen * s)
|
||||
int
|
||||
screen_add_widget (Screen * s, Widget * w)
|
||||
{
|
||||
report (RPT_INFO, "screen_add_widget(%s,%s)", s->id, w->id);
|
||||
if (!s)
|
||||
return -1;
|
||||
if (!w)
|
||||
return 1;
|
||||
debug( RPT_DEBUG, "%s( s=[%.40s], widget=[%.40s] )", __FUNCTION__, s->id, w->id );
|
||||
|
||||
LL_Push (s->widgetlist, (void *) w);
|
||||
|
||||
@@ -128,12 +123,7 @@ screen_add_widget (Screen * s, Widget * w)
|
||||
int
|
||||
screen_remove_widget (Screen * s, Widget * w)
|
||||
{
|
||||
report (RPT_INFO, "screen_remove_widget(%s,%s)", s->id, w->id);
|
||||
|
||||
if (!s)
|
||||
return -1;
|
||||
if (!w)
|
||||
return 1;
|
||||
debug( RPT_DEBUG, "%s( s=[%.40s], widget=[%.40s] )", __FUNCTION__, s->id, w->id );
|
||||
|
||||
LL_Remove (s->widgetlist, (void *) w);
|
||||
|
||||
@@ -150,11 +140,11 @@ screen_find_widget (Screen * s, char *id)
|
||||
if (!id)
|
||||
return NULL;
|
||||
|
||||
debug (RPT_DEBUG, "screen_find_widget(%s,%s)", s->id, id);
|
||||
debug( RPT_DEBUG, "%s( s=[%.40s], id=\"%.40s\" )", __FUNCTION__, s->id, id );
|
||||
|
||||
for ( w=LL_GetFirst(s->widgetlist); w; w=LL_GetNext(s->widgetlist) ) {
|
||||
if (0 == strcmp (w->id, id)) {
|
||||
debug (RPT_DEBUG, "screen_find_widget: Found %s", id);
|
||||
debug (RPT_DEBUG, "%s: Found %s", __FUNCTION__, id);
|
||||
return w;
|
||||
}
|
||||
/* Search subscreens recursively */
|
||||
@@ -164,6 +154,6 @@ screen_find_widget (Screen * s, char *id)
|
||||
return w;
|
||||
}
|
||||
}
|
||||
debug (RPT_DEBUG, "screen_find_widget: Not found");
|
||||
debug (RPT_DEBUG, "%s: Not found", __FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
+14
-12
@@ -39,11 +39,11 @@ int compare_addresses (void *one, void *two);
|
||||
int
|
||||
screenlist_init ()
|
||||
{
|
||||
report (RPT_INFO, "screenlist_init()");
|
||||
report (RPT_DEBUG, "%s()", __FUNCTION__);
|
||||
|
||||
screenlist = LL_new ();
|
||||
if (!screenlist) {
|
||||
report(RPT_ERR, "screenlist_init: error allocating list");
|
||||
report(RPT_ERR, "%s: error allocating list", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ screenlist_init ()
|
||||
int
|
||||
screenlist_shutdown ()
|
||||
{
|
||||
report (RPT_INFO, "screenlist_shutdown()");
|
||||
report (RPT_DEBUG, "%s()", __FUNCTION__);
|
||||
|
||||
LL_Destroy (screenlist);
|
||||
|
||||
@@ -66,7 +66,7 @@ screenlist_shutdown ()
|
||||
int
|
||||
screenlist_remove (Screen * s)
|
||||
{
|
||||
report (RPT_INFO, "screenlist_remove()");
|
||||
debug (RPT_DEBUG, "%s( s=[%.40s] )", __FUNCTION__, s->id);
|
||||
|
||||
if (!LL_Remove (screenlist, s))
|
||||
return -1;
|
||||
@@ -79,7 +79,7 @@ screenlist_remove_all (Screen * s)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
report (RPT_INFO, "screenlist_remove_all()");
|
||||
debug (RPT_DEBUG, "%s( s=[%.40s] )", __FUNCTION__, s->id);
|
||||
|
||||
while (LL_Remove (screenlist, s))
|
||||
i++;
|
||||
@@ -92,7 +92,7 @@ screenlist_remove_all (Screen * s)
|
||||
LinkedList *
|
||||
screenlist_getlist ()
|
||||
{
|
||||
report (RPT_INFO, "screenlist_getlist()");
|
||||
report (RPT_DEBUG, "%s()", __FUNCTION__);
|
||||
|
||||
return screenlist;
|
||||
}
|
||||
@@ -105,7 +105,7 @@ screenlist_current ()
|
||||
static Screen * old_s = NULL;
|
||||
Client * c;
|
||||
|
||||
debug( RPT_INFO, "screenlist_current:");
|
||||
debug( RPT_DEBUG, "%s()", __FUNCTION__);
|
||||
|
||||
/*LL_dprint(screenlist);*/
|
||||
|
||||
@@ -169,7 +169,7 @@ screenlist_next ()
|
||||
{
|
||||
Screen *s;
|
||||
|
||||
/*debug(RPT_DEBUG, "Screenlist_next()");*/
|
||||
debug (RPT_DEBUG, "%s()", __FUNCTION__);
|
||||
|
||||
s = screenlist_current ();
|
||||
|
||||
@@ -199,6 +199,8 @@ screenlist_prev ()
|
||||
{
|
||||
Screen *s;
|
||||
|
||||
debug (RPT_DEBUG, "%s()", __FUNCTION__);
|
||||
|
||||
s = screenlist_current ();
|
||||
|
||||
/* If we're on hold, don't advance!*/
|
||||
@@ -221,7 +223,7 @@ screenlist_prev ()
|
||||
int
|
||||
screenlist_add_end (Screen * screen)
|
||||
{
|
||||
debug (RPT_DEBUG, "screenlist_add_end()");
|
||||
debug (RPT_DEBUG, "%s( screen=[%.40s] )", __FUNCTION__, screen->id);
|
||||
|
||||
return LL_Push (screenlist, (void *) screen);
|
||||
}
|
||||
@@ -230,7 +232,7 @@ screenlist_add_end (Screen * screen)
|
||||
Screen *
|
||||
screenlist_next_roll ()
|
||||
{
|
||||
/*debug(RPT_DEBUG, "screenlist_next_roll()");*/
|
||||
debug (RPT_DEBUG, "%s()", __FUNCTION__);
|
||||
|
||||
if (LL_UnRoll (screenlist) != 0)
|
||||
return NULL;
|
||||
@@ -243,7 +245,7 @@ Screen *
|
||||
screenlist_next_priority ()
|
||||
{
|
||||
/*screen *s, *t;*/
|
||||
/*debug(RPT_DEBUG, "screenlist_next_priority");*/
|
||||
debug (RPT_DEBUG, "%s()", __FUNCTION__);
|
||||
|
||||
if (LL_UnRoll (screenlist) != 0)
|
||||
return NULL;
|
||||
@@ -257,7 +259,7 @@ screenlist_next_priority ()
|
||||
Screen *
|
||||
screenlist_prev_roll ()
|
||||
{
|
||||
/*debug(RPT_DEBUG, "screenlist_prev_roll()");*/
|
||||
debug (RPT_DEBUG, "%s()", __FUNCTION__);
|
||||
|
||||
if (LL_Roll (screenlist) != 0)
|
||||
return NULL;
|
||||
|
||||
+23
-69
@@ -58,23 +58,22 @@ sock_create_inet_socket (char * addr, unsigned int port)
|
||||
struct sockaddr_in name;
|
||||
int sock, sockopt=1;
|
||||
|
||||
report (RPT_INFO, "sock_create_inet_socket(%i)", port);
|
||||
debug (RPT_DEBUG, "%s( addr=\"%s\", port=%i )", __FUNCTION__, addr, port);
|
||||
|
||||
/* Create the socket. */
|
||||
/*debug(RPT_DEBUG, "Creating Inet Socket");*/
|
||||
sock = socket (PF_INET, SOCK_STREAM, 0);
|
||||
if (sock < 0) {
|
||||
report(RPT_ERR, "Could not create socket");
|
||||
report(RPT_ERR, "%s: Could not create socket", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
/* Set the socket so we can re-use it*/
|
||||
if(setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&sockopt,sizeof(sockopt)) < 0) {
|
||||
report(RPT_ERR, "Error setting socket option SO_REUSEADDR");
|
||||
report(RPT_ERR, "%s: Error setting socket option SO_REUSEADDR", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Give the socket a name. */
|
||||
/*debug(RPT_DEBUG, "Binding Inet Socket");*/
|
||||
memset (&name, 0, sizeof (name));
|
||||
name.sin_family = AF_INET;
|
||||
name.sin_port = htons (port);
|
||||
@@ -84,7 +83,7 @@ sock_create_inet_socket (char * addr, unsigned int port)
|
||||
report(RPT_ERR, "Could not bind to port %d", port);
|
||||
return -1;
|
||||
} else {
|
||||
report(RPT_NOTICE, "listening for queries on port %d", port);
|
||||
report(RPT_NOTICE, "Listening for queries on %s:%d", addr, port);
|
||||
}
|
||||
|
||||
return sock;
|
||||
@@ -97,17 +96,17 @@ sock_create_server (char *bind_addr, int lcd_port)
|
||||
{
|
||||
int sock;
|
||||
|
||||
report (RPT_INFO, "sock_create_server()");
|
||||
debug (RPT_DEBUG, "%s( bind_addr=\"%s\", port=%d )", __FUNCTION__, bind_addr, lcd_port);
|
||||
|
||||
/* Create the socket and set it up to accept connections. */
|
||||
sock = sock_create_inet_socket (bind_addr, lcd_port);
|
||||
if (sock < 0) {
|
||||
report (RPT_ERR, "sock_create_server: Error creating socket");
|
||||
report (RPT_ERR, "%s: Error creating socket", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (listen (sock, 1) < 0) {
|
||||
report(RPT_ERR, "error in attempting to listen to port");
|
||||
report(RPT_ERR, "%s: error in attempting to listen to port", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -147,7 +146,7 @@ sock_poll_clients ()
|
||||
struct timeval t;
|
||||
Client * c;
|
||||
|
||||
debug(RPT_INFO, "sock_poll_clients()");
|
||||
debug (RPT_DEBUG, "%s()", __FUNCTION__);
|
||||
|
||||
t.tv_sec = 0;
|
||||
t.tv_usec = 0;
|
||||
@@ -156,7 +155,7 @@ sock_poll_clients ()
|
||||
read_fd_set = active_fd_set;
|
||||
|
||||
if (select (FD_SETSIZE, &read_fd_set, NULL, NULL, &t) < 0) {
|
||||
report (RPT_ERR, "sock_poll_clients: Select error");
|
||||
report (RPT_ERR, "%s: Select error", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -169,10 +168,10 @@ sock_poll_clients ()
|
||||
size = sizeof (clientname);
|
||||
new_sock = accept (orig_sock, (struct sockaddr *) &clientname, &size);
|
||||
if (new_sock < 0) {
|
||||
report (RPT_ERR, "sock_poll_clients: Accept error");
|
||||
report (RPT_ERR, "%s: Accept error", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
report (RPT_INFO, "sock_poll_clients: Connect from host %s:%hd on #%d",
|
||||
report (RPT_NOTICE, "Connect from host %s:%hd on socket %i",
|
||||
inet_ntoa (clientname.sin_addr), ntohs (clientname.sin_port), new_sock);
|
||||
FD_SET (new_sock, &active_fd_set);
|
||||
|
||||
@@ -180,32 +179,32 @@ sock_poll_clients ()
|
||||
|
||||
/* Create new client */
|
||||
if ((c = client_create (new_sock)) == NULL) {
|
||||
report( RPT_ERR, "sock_poll_clients: Error creating client %i", i);
|
||||
report( RPT_ERR, "%s: Error creating client on socket %i", __FUNCTION__, i);
|
||||
return -1;
|
||||
}
|
||||
if (clients_add_client (c) != 0) {
|
||||
report( RPT_ERR, "sock_poll_clients: Could not add client %i", i);
|
||||
report( RPT_ERR, "%s: Could not add client on socket %i", __FUNCTION__, i);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
/* Data arriving on an already-connected socket. */
|
||||
err = 0;
|
||||
do {
|
||||
debug (RPT_DEBUG, "sock_poll_clients: reading...");
|
||||
debug (RPT_DEBUG, "%s: reading...", __FUNCTION__);
|
||||
err = read_from_client (i);
|
||||
debug (RPT_DEBUG, "sock_poll_clients: ...done");
|
||||
debug (RPT_DEBUG, "%s: ...done", __FUNCTION__);
|
||||
if (err < 0) {
|
||||
/* TODO: Destroy a "client" here... (done?)*/
|
||||
/* Client disconnected, destroy client data */
|
||||
c = clients_find_client_by_sock (i);
|
||||
if (c) {
|
||||
/*sock_send_string(i, "bye\n");*/
|
||||
report (RPT_NOTICE, "Client on socket %i disconnected", i);
|
||||
client_destroy (c);
|
||||
clients_remove_client (c);
|
||||
close (i);
|
||||
FD_CLR (i, &active_fd_set);
|
||||
report (RPT_INFO, "sock_poll_clients: Closed connection %i", i);
|
||||
} else
|
||||
report (RPT_ERR, "sock_poll_clients: Can't find client %i", i);
|
||||
report (RPT_ERR, "%s: Can't find client of socket %i", __FUNCTION__, i);
|
||||
}
|
||||
} while (err > 0);
|
||||
}
|
||||
@@ -221,24 +220,19 @@ read_from_client (int filedes)
|
||||
int nbytes, i;
|
||||
Client * c;
|
||||
|
||||
report(RPT_DEBUG, "read_from_client()" );
|
||||
|
||||
/*nbytes = read (filedes, buffer, MAXMSG);*/
|
||||
/*debug(RPT_DEBUG, "read_from_client(%i): reading...", filedes);*/
|
||||
/*nbytes = sock_recv (filedes, buffer, MAXMSG);*/
|
||||
/*debug(RPT_DEBUG, "read_from_client(%i): ...done", filedes);*/
|
||||
/*debug (RPT_DEBUG, "read_from_client(%i): %i bytes", filedes, nbytes);*/
|
||||
debug (RPT_DEBUG, "%s()", __FUNCTION__);
|
||||
|
||||
errno = 0;
|
||||
if ((nbytes = sock_recv (filedes, buffer, MAXMSG)) < 0) {
|
||||
if (errno != EAGAIN)
|
||||
report (RPT_DEBUG, "read_from_client: (fd %d) %s", filedes, strerror(errno));
|
||||
report (RPT_DEBUG, "%s: Error on socket %d: %s", __FUNCTION__, filedes, strerror(errno));
|
||||
return 0;
|
||||
} else if (nbytes == 0) /* EOF*/
|
||||
return -1;
|
||||
else if (nbytes > (MAXMSG - (MAXMSG / 8))) /* Very noisy client...*/
|
||||
{
|
||||
sock_send_string (filedes, "huh? Too much data received... quiet down!\n");
|
||||
report (RPT_WARNING, "%s: Too much data received on socket %d", __FUNCTION__, filedes);
|
||||
return -1;
|
||||
} else /* Data Read*/
|
||||
{
|
||||
@@ -252,50 +246,10 @@ read_from_client (int filedes)
|
||||
if (c) {
|
||||
client_add_message (c, buffer);
|
||||
} else
|
||||
report (RPT_DEBUG, "read_from_client: Can't find client %i", filedes);
|
||||
report (RPT_DEBUG, "%s: Can't find client %d", __FUNCTION__, filedes);
|
||||
|
||||
debug (RPT_DEBUG, "read_from_client: got message: `%s'", buffer);
|
||||
report (RPT_DEBUG, "%s: got message from client %d: \"%s\"", __FUNCTION__, filedes, buffer);
|
||||
return nbytes;
|
||||
}
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
/* FIXME: This talks to all open files, including
|
||||
* stdin, stdout, stderr, the LCD, etc...
|
||||
* BUT it should only talk to sockets!
|
||||
*/
|
||||
int
|
||||
sock_close_all ()
|
||||
{
|
||||
int fd;
|
||||
|
||||
return 0;
|
||||
/* Do we need to do this ? Clients_shutdown already closes all
|
||||
client connections ... */
|
||||
|
||||
report (RPT_INFO, "sock_close_all()");
|
||||
|
||||
for (fd = 0; fd < FD_SETSIZE; fd++) {
|
||||
/* TODO: Destroy a "client" here...? Nope.*/
|
||||
|
||||
/* Instead of using STDIN_FILENO, STDOUT_FILENO,
|
||||
* and STDERR_FILENO, one could use "fd = 4" in the
|
||||
* for() call - but this would probably not be good
|
||||
* practice...
|
||||
*/
|
||||
|
||||
if ( fd == STDIN_FILENO ||
|
||||
fd == STDOUT_FILENO ||
|
||||
fd == STDERR_FILENO)
|
||||
continue;
|
||||
else {
|
||||
/*sock_send_string (fd, "bye\n");*/
|
||||
close (fd);
|
||||
FD_CLR (fd, &active_fd_set);
|
||||
debug (RPT_DEBUG, "sock_close_all: Closed connection %i", fd);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ typedef struct sockaddr_in sockaddr_in;
|
||||
int sock_create_server ();
|
||||
int sock_create_inet_socket (unsigned short int port);
|
||||
int sock_poll_clients ();
|
||||
int sock_close_all ();
|
||||
int read_from_client (int filedes);
|
||||
|
||||
#endif
|
||||
|
||||
+4
-4
@@ -72,18 +72,18 @@ widget_create (char *id, WidgetType type, Screen * screen)
|
||||
{
|
||||
Widget * w;
|
||||
|
||||
report (RPT_INFO, "widget_create(%s,%d)", id, type);
|
||||
debug (RPT_DEBUG, "%s( id=\"%s\", type=%d, screen=[%s] )", __FUNCTION__, id, type, screen->id );
|
||||
|
||||
/* Create it */
|
||||
w = malloc (sizeof (Widget));
|
||||
if (!w) {
|
||||
report (RPT_DEBUG, "widget_create: Error allocating");
|
||||
report (RPT_DEBUG, "%s: Error allocating", __FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
w->id = strdup(id);
|
||||
if (!w->id) {
|
||||
report (RPT_DEBUG, "widget_create: Error allocating");
|
||||
report (RPT_DEBUG, "%s: Error allocating", __FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ widget_create (char *id, WidgetType type, Screen * screen)
|
||||
int
|
||||
widget_destroy (Widget * w)
|
||||
{
|
||||
debug (RPT_INFO, "widget_destroy(%s)", w->id);
|
||||
debug (RPT_DEBUG, "%s( w=[%s] )", __FUNCTION__, w->id);
|
||||
|
||||
if (!w)
|
||||
return -1;
|
||||
|
||||
+6
-5
@@ -31,19 +31,20 @@ static int stored_levels[MAX_STORED_MSGS];
|
||||
static int num_stored_msgs = 0;
|
||||
|
||||
|
||||
// local functions
|
||||
/* local functions */
|
||||
static void store_report_message( int level, const char *message );
|
||||
static void flush_messages();
|
||||
|
||||
void report( const int level, const char *format, .../*args*/ )
|
||||
{
|
||||
// Check if we should report it
|
||||
/* Check if we should report it */
|
||||
if( level <= report_level || report_dest == RPT_DEST_STORE ) {
|
||||
|
||||
char buf[1024];
|
||||
|
||||
// Following functions appear to work on RedHat and Debian
|
||||
// Linux, FreeBSD and Solaris
|
||||
/* Following functions appear to work on RedHat and Debian
|
||||
* Linux, FreeBSD and Solaris
|
||||
*/
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, format); /* measure the required size (the number of elements of format) */
|
||||
@@ -58,7 +59,7 @@ void report( const int level, const char *format, .../*args*/ )
|
||||
break;
|
||||
case RPT_DEST_STORE:
|
||||
vsnprintf( buf, sizeof(buf), format, ap );
|
||||
buf[sizeof(buf)-1] = 0; // be sure to have a terminating 0
|
||||
buf[sizeof(buf)-1] = 0; /* be sure to have a terminating 0 */
|
||||
store_report_message( level, buf );
|
||||
break;
|
||||
}
|
||||
|
||||
+25
-24
@@ -31,19 +31,23 @@
|
||||
* The reporting levels have the following meaning:
|
||||
*
|
||||
* 0 RPT_CRIT Critical conditions: the program stops right after
|
||||
* this. Only use this if the program is exited from
|
||||
* the current function.
|
||||
* this. Only use this if the program is actually exited
|
||||
* from the current function.
|
||||
* 1 RPT_ERR Error conditions: serious problem, program continues.
|
||||
* Use just before you return -1 from a function.
|
||||
* 2 RPT_WARNING Warning conditions: request user to fix this problem.
|
||||
* Ex: What a queer port did you select.
|
||||
* 3 RPT_NOTICE Normal but significant condition:
|
||||
* Ex: What options have been set, version number.
|
||||
* 4 RPT_INFO Informational
|
||||
* Ex: What functions have been called.
|
||||
* 5 RPT_DEBUG Debug-level messages: further debug messages
|
||||
* Ex: what are we going to do in the next few lines of
|
||||
* code.
|
||||
* Use this just before you return -1 from a function.
|
||||
* 2 RPT_WARNING Warning conditions: Something that the user should
|
||||
* fix, but the program can continue without a real
|
||||
* problem.
|
||||
* Ex: Protocol errors from a client.
|
||||
* 3 RPT_NOTICE Major event in the program.
|
||||
* Ex: (un)loading of driver, client (dis)connect.
|
||||
* 4 RPT_INFO Minor event in the program: the activation of a
|
||||
* setting, details of a loaded driver, a key
|
||||
* reservation, a keypress, a screen switch.
|
||||
* 5 RPT_DEBUG Insignificant event.
|
||||
* Ex: What function has been called, what subpart of a
|
||||
* function is being executed, what was received and sent
|
||||
* over the socket, etc.
|
||||
*
|
||||
* Levels 4 (maybe) and 5 (certainly) should be reported using the debug
|
||||
* function.
|
||||
@@ -60,35 +64,32 @@
|
||||
#include <syslog.h>
|
||||
|
||||
|
||||
// Reporting levels
|
||||
/* Reporting levels */
|
||||
#define RPT_CRIT 0
|
||||
#define RPT_ERR 1
|
||||
#define RPT_WARNING 2
|
||||
#define RPT_NOTICE 3
|
||||
#define RPT_INFO 4
|
||||
#define RPT_DEBUG 5
|
||||
// Don't just modify these numbers, they're related to syslog.
|
||||
/* Don't just modify these numbers, they're related to syslog. */
|
||||
|
||||
// Reporting destinations
|
||||
/* Reporting destinations */
|
||||
#define RPT_DEST_STDERR 0
|
||||
#define RPT_DEST_SYSLOG 1
|
||||
#define RPT_DEST_STORE 2
|
||||
|
||||
// For compatibility, to be removed ?
|
||||
extern int report_level;
|
||||
extern int report_dest;
|
||||
|
||||
int set_reporting( char *application_name, int new_level, int new_dest );
|
||||
// Sets reporting level and message destination.
|
||||
/* Sets reporting level and message destination. */
|
||||
|
||||
void report( const int level, const char *format, .../*args*/ );
|
||||
// Report the message to the selected destination if important enough
|
||||
/* Report the message to the selected destination if important enough */
|
||||
|
||||
// Consider the debug function to be exactly the same as the report function.
|
||||
// The only difference is that it is only compiled in if DEBUG is defined.
|
||||
/* Consider the debug function to be exactly the same as the report function.
|
||||
* The only difference is that it is only compiled in if DEBUG is defined.
|
||||
*/
|
||||
|
||||
static inline void dont_report( const int level, const char *format, .../*args*/ )
|
||||
{} // The idea is that this gets optimized out
|
||||
{} /* The idea is that this gets optimized out */
|
||||
|
||||
#ifdef DEBUG
|
||||
# define debug report
|
||||
|
||||
+2
-1
@@ -61,7 +61,8 @@ sock_connect (char *host, unsigned short int port)
|
||||
}
|
||||
debug (RPT_DEBUG, "sock_connect: Created socket (%i)", sock);
|
||||
|
||||
sock_init_sockaddr (&servername, host, port);
|
||||
if( sock_init_sockaddr (&servername, host, port) < 0 )
|
||||
return -1;
|
||||
|
||||
err = connect (sock, (struct sockaddr *) &servername, sizeof (servername));
|
||||
if (err < 0) {
|
||||
|
||||
Reference in New Issue
Block a user