[lcdproc] My patchs at last
Glen Gray
glen@antefacto.com
08 Jun 2001 14:36:45 +0100
--=-+Jl4rj/WFfld27zhhG1x
Content-Type: text/plain; charset=ANSI_X3.4-1968
Content-Transfer-Encoding: 7bit
I managed to get some timeout to do up some patchs for my changes. A
pity I didn't get time before to apply them for the 0.4.1 release. Thats
the way it goes sometimes.
Well this is my first ever patch so hurray for me. I hope it works. I
had the following setup...
A dir called cvs-lcdproc. In that dir I had two sub dirs
lcdproc (as from CVS)
new (copy of the lcdproc dir with my changes applied)
I then ran "diff -C3 -r lcdproc new > diff.txt". So hopefully that'll
work for someone to test it out.
Changes that this adds.
1) Two new properties for the screen structure
timeout
backlight
These can be set with
screen_set #id [-]timeout <value in seconds>
screen_set #id [-]backlight <on|off|toggle|flash|blink>
2) In main.c after the timeout we check the timeout value of the screen,
it's it's expired the screen is removed.
3) I added two new startup parameters to allow you to choose the address
and port to listen on. Very important for security, can limit to
localhost etc.
Hope this works and I don't get flamed (:-D
Glen "very nervous" Gray
--=-+Jl4rj/WFfld27zhhG1x
Content-Type: text/x-patch
Content-Disposition: attachment; filename=diff.txt
Content-ID: <992007397.19856.2.camel@cruachann.internal.antefacto.com>
Content-Transfer-Encoding: 7bit
Only in new: Makefile.in
Only in new: aclocal.m4
Only in new/clients: Makefile.in
Only in new/clients/examples: Makefile.in
Only in new/clients/headlines: Makefile.in
Only in new/clients/lcdproc: Makefile.in
Only in new: config.guess
Only in new: config.h.in
Only in new: config.sub
Only in new: configure
Only in new/docs: Makefile.in
Only in new: install-sh
Only in new: missing
Only in new: mkinstalldirs
Only in new/server: Makefile.in
diff -C3 -r lcdproc/server/client_functions.c new/server/client_functions.c
*** lcdproc/server/client_functions.c Tue Jun 5 12:47:46 2001
--- new/server/client_functions.c Fri Jun 8 14:26:39 2001
***************
*** 573,578 ****
--- 573,630 ----
} else {
sock_send_string (c->sock, "huh? -hgt requires a parameter\n");
}
+ }
+ // Handle the "timeout" parameter
+ else if (0 == strcmp (argv[i], "-timeout")
+ || 0 == strcmp (argv[i], "timeout")) {
+ if (argc > i + 1) {
+ i++;
+ debug ("screen_set: timeout=\"%s\"\n", argv[i]);
+
+ // set the duration...
+ number = atoi (argv[i]);
+ if (number > 0) // Add the timeout value in TIME_UNITS to struct
+ s->timeout = number * (TIME_UNIT * 8); // TIME_UNIT is 1/8th of a second
+ sock_send_string(c->sock, "success\n");
+ } else {
+ sock_send_string (c->sock, "huh? -timeout requires a parameter\n");
+ }
+ }
+ // Handle the backlight parameter
+ else if (0 == strcmp (argv[i], "-backlight")
+ || 0 == strcmp (argv[i], "backlight")) {
+ if (argc > i + 1) {
+ i++;
+ debug ("screen_set: backlight=\"%s\"\n", argv[i]);
+
+ // set the backlight status
+ // backlight is an external variable set by default to
+ // BACKLIGHT_OPEN in the render.c file. It is says
+ // whether a backlight is available and can be set from
+ // the command line
+ switch(backlight) {
+ case BACKLIGHT_OPEN:
+ if (0 == strcmp ("on", argv[i]))
+ s->backlight_state = BACKLIGHT_ON;
+ if (0 == strcmp ("off", argv[i]))
+ s->backlight_state = BACKLIGHT_OFF;
+ if (0 == strcmp ("toggle", argv[i])) {
+ if (s->backlight_state == BACKLIGHT_ON)
+ s->backlight_state = BACKLIGHT_OFF;
+ else if (s-backlight_state == BACKLIGHT_OFF)
+ s->backlight_state = BACKLIGHT_ON;
+ }
+
+ if (0 == strcmp ("blink", argv[i]))
+ s->backlight_state |= BACKLIGHT_BLINK;
+
+ if (0 == strcmp ("flash", argv[i]))
+ s->backlight_state |= BACKLIGHT_FLASH;
+ }
+ sock_send_string(c->sock, "success\n");
+ } else {
+ sock_send_string (c->sock, "huh? -backlight requires a parameter\n");
+ }
} else {
sock_send_string (c->sock, "huh? invalid parameter\n");
}
Only in new/server/drivers: Makefile.in
diff -C3 -r lcdproc/server/main.c new/server/main.c
*** lcdproc/server/main.c Tue Jun 5 12:47:46 2001
--- new/server/main.c Fri Jun 8 12:30:24 2001
***************
*** 15,20 ****
--- 15,22 ----
#include <stdlib.h>
#include <stdio.h>
+ #include <ctype.h>
+ #include <limits.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
***************
*** 59,64 ****
--- 61,68 ----
{"-f", "--foreground"},
{"-b", "--backlight"},
{"-i", "--serverinfo"},
+ {"-a", "--address"},
+ {"-p", "--port"},
{NULL, NULL},
};
***************
*** 74,79 ****
--- 78,85 ----
int daemon_mode = 1;
int disable_server_screen = 1;
screen *s = NULL;
+ char *bind_address = NULL;
+ int bind_port = LCDPORT;
char *str, *ing; // strings for commandline handling
// screen_size *size = &sizes[0]; // No longer needed
***************
*** 204,209 ****
--- 210,231 ----
if (0 == strcmp (argv[i], "on"))
disable_server_screen = 0;
}
+ } else if (0 == strcmp(argv[i], "-a") ||
+ 0 == strcmp(argv[i], "--address")) {
+ if (i + 1 >= argc || *argv[i + 1] == '-')
+ HelpScreen();
+ else {
+ bind_address = argv[++i];
+ }
+ } else if (0 == strcmp(argv[i], "-p") ||
+ 0 == strcmp(argv[i], "--port")) {
+ if (i + 1 >= argc || !isdigit(*argv[i + 1]))
+ HelpScreen();
+ else {
+ bind_port = atoi(argv[++i]);
+ if (bind_port < 1 || bind_port > USHRT_MAX)
+ HelpScreen();
+ }
} else {
// otherwise... Get help!
printf ("Invalid parameter: %s\n", argv[i]);
***************
*** 213,219 ****
// Now init a bunch of required stuff...
! if (sock_create_server () <= 0) {
printf ("Error opening socket.\n");
return 1;
}
--- 235,241 ----
// Now init a bunch of required stuff...
! if (sock_create_server (bind_address, (unsigned short)bind_port) <= 0) {
printf ("Error opening socket.\n");
return 1;
}
***************
*** 262,267 ****
--- 284,298 ----
no_screen_screen (timer);
usleep (TIME_UNIT);
+
+ //Check to see if the screen has a timeout value, if it does decrese it
+ //and then check to see if it has excpired. Remove if expired.
+ //Glen Gray <glen.gray@antefacto.com>
+ if (s && s->timeout != -1) {
+ s->timeout -= TIME_UNIT;
+ if (s->timeout <= 0)
+ screen_remove (s->parent, s->id);
+ }
}
// Quit!
***************
*** 308,313 ****
--- 339,349 ----
printf ("\t-f\t--foreground\n\t\t\tRun in the foreground (no daemon)\n");
printf ("\t-b\t--backlight <mode>\n\t\t\tSet backlight mode (on, off, open)\n");
printf ("\t-i\t--serverinfo off\n\t\t\tSet the server screen to low priority\n");
+ printf ("\t-a\t--address <IP address>\n\t\t\tSet the IP address to which the server will be bound\n");
+ printf ("\t\t\tDefaults to * (accepts connections on any address\n");
+ printf ("\t\t\tavailable on the machine)\n");
+ printf ("\t-p\t--port <port>\n\t\t\tSet the TCP port to which the server will be bound\n");
+ printf ("\t\t\tDefaults to %d\n", LCDPORT);
printf ("\n");
printf ("\tUse \"man LCDd\" for more info.\n");
printf ("\tHelp on each driver's parameters are obtained upon request:\n\t\t\"LCDd -d driver --help\"\n");
diff -C3 -r lcdproc/server/render.c new/server/render.c
*** lcdproc/server/render.c Tue Jun 5 12:47:46 2001
--- new/server/render.c Thu Jun 7 18:41:00 2001
***************
*** 61,67 ****
lcd.clear ();
! switch (backlight_state) {
case BACKLIGHT_OFF:
lcd.backlight (backlight_off_brightness);
break;
--- 61,67 ----
lcd.clear ();
! switch (s->backlight_state) {
case BACKLIGHT_OFF:
lcd.backlight (backlight_off_brightness);
break;
***************
*** 69,75 ****
lcd.backlight (backlight_brightness);
break;
default:
! if (backlight_state & BACKLIGHT_FLASH) {
tmp = (!((timer & 7) == 7));
if (backlight_state & 1)
lcd.backlight (tmp ? backlight_brightness : backlight_off_brightness);
--- 69,75 ----
lcd.backlight (backlight_brightness);
break;
default:
! if (s->backlight_state & BACKLIGHT_FLASH) {
tmp = (!((timer & 7) == 7));
if (backlight_state & 1)
lcd.backlight (tmp ? backlight_brightness : backlight_off_brightness);
***************
*** 77,85 ****
else
lcd.backlight (!tmp ? backlight_brightness : backlight_off_brightness);
//lcd.backlight(backlight_brightness * ((timer&7) == 7));
! } else if (backlight_state & BACKLIGHT_BLINK) {
tmp = (!((timer & 14) == 14));
! if (backlight_state & 1)
lcd.backlight (tmp ? backlight_brightness : backlight_off_brightness);
//lcd.backlight(backlight_brightness * (!((timer&14) == 14)));
else
--- 77,85 ----
else
lcd.backlight (!tmp ? backlight_brightness : backlight_off_brightness);
//lcd.backlight(backlight_brightness * ((timer&7) == 7));
! } else if (s->backlight_state & BACKLIGHT_BLINK) {
tmp = (!((timer & 14) == 14));
! if (s->backlight_state & 1)
lcd.backlight (tmp ? backlight_brightness : backlight_off_brightness);
//lcd.backlight(backlight_brightness * (!((timer&14) == 14)));
else
diff -C3 -r lcdproc/server/screen.c new/server/screen.c
*** lcdproc/server/screen.c Tue Jun 5 12:47:46 2001
--- new/server/screen.c Fri Jun 8 14:27:18 2001
***************
*** 11,16 ****
--- 11,17 ----
#include "widget.h"
#include "screenlist.h"
#include "screen.h"
+ #include "render.h" //Sets the default values in screen::backlight_state
screen *
screen_create ()
***************
*** 33,39 ****
s->keys = NULL;
s->parent = NULL;
s->widgets = NULL;
!
s->widgets = LL_new ();
if (!s->widgets) {
fprintf (stderr, "screen_create: Error allocating widget list\n");
--- 34,41 ----
s->keys = NULL;
s->parent = NULL;
s->widgets = NULL;
! s->timeout = -1; //Default value, will be ignored unless set to value > 0
! s->backlight_state = BACKLIGHT_OFF; //Default the backlight to OFF
s->widgets = LL_new ();
if (!s->widgets) {
fprintf (stderr, "screen_create: Error allocating widget list\n");
diff -C3 -r lcdproc/server/screen.h new/server/screen.h
*** lcdproc/server/screen.h Tue Jun 5 12:47:46 2001
--- new/server/screen.h Thu Jun 7 18:42:46 2001
***************
*** 11,16 ****
--- 11,18 ----
int priority;
int duration;
int heartbeat;
+ long timeout;
+ int backlight_state;
char *keys;
LL *widgets;
client *parent;
diff -C3 -r lcdproc/server/sock.c new/server/sock.c
*** lcdproc/server/sock.c Tue Jun 5 12:47:46 2001
--- new/server/sock.c Fri Jun 8 12:19:01 2001
***************
*** 34,41 ****
// Creates a socket in internet space
int
! sock_create_inet_socket (unsigned short int port)
{
struct sockaddr_in name;
int sock;
--- 34,42 ----
// Creates a socket in internet space
int
! sock_create_inet_socket (char *addr, unsigned short int port)
{
+ struct hostent *hostent;
struct sockaddr_in name;
int sock;
***************
*** 50,78 ****
}
/* Give the socket a name. */
! //debug("Binding Inet Socket\n");
! name.sin_family = AF_INET;
name.sin_port = htons (port);
! name.sin_addr.s_addr = htonl (INADDR_ANY);
if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0) {
perror ("Error binding socket");
return -1;
}
return sock;
-
}
//int StartSocketServer()
int
! sock_create_server ()
{
int sock;
debug ("sock_create_server()\n");
/* Create the socket and set it up to accept connections. */
! sock = sock_create_inet_socket (LCDPORT);
if (sock < 0) {
perror ("sock_create_server: Error creating socket");
return -1;
--- 51,90 ----
}
/* Give the socket a name. */
! if (addr) {
! /* Translate hostname into address */
! hostent = gethostbyname(addr);
! if (hostent == NULL) {
! perror("Error finding address");
! return -1;
! }
! memcpy (&name.sin_addr.s_addr, hostent->h_addr_list[0],
! sizeof(struct in_addr));
! } else {
! name.sin_addr.s_addr = htonl (INADDR_ANY);
! name.sin_family = AF_INET;
! }
name.sin_port = htons (port);
!
! //debug("Binding Inet Socket\n");
if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0) {
perror ("Error binding socket");
return -1;
}
return sock;
}
//int StartSocketServer()
int
! sock_create_server (char *addr, unsigned short int port)
{
int sock;
debug ("sock_create_server()\n");
/* Create the socket and set it up to accept connections. */
! sock = sock_create_inet_socket (addr, port);
if (sock < 0) {
perror ("sock_create_server: Error creating socket");
return -1;
diff -C3 -r lcdproc/server/sock.h new/server/sock.h
*** lcdproc/server/sock.h Tue Jun 5 12:47:46 2001
--- new/server/sock.h Thu Jun 7 18:55:21 2001
***************
*** 6,12 ****
typedef struct sockaddr_in sockaddr_in;
// Server functions...
! int sock_create_server ();
int sock_create_inet_socket (unsigned short int port);
int sock_poll_clients ();
int sock_close_all ();
--- 6,12 ----
typedef struct sockaddr_in sockaddr_in;
// Server functions...
! int sock_create_server (char *addr, unsigned short int port);
int sock_create_inet_socket (unsigned short int port);
int sock_poll_clients ();
int sock_close_all ();
Only in new/shared: Makefile.in
Only in new: stamp-h.in
--=-+Jl4rj/WFfld27zhhG1x
Content-Type: text/plain; charset=
-----------------------------------------------------------
To unsubscribe from this list send a blank message to
lcdproc-unsubscribe@lists.omnipotent.net
--=-+Jl4rj/WFfld27zhhG1x--