[Lcdproc] Re: g15 updates

Anthony J. Mirabella mirabeaj@gmail.com
Sun Nov 12 02:17:02 2006


This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enigA8AF9A4249D2D8AA911F945F
Content-Type: multipart/mixed;
 boundary="------------060403030808080109030803"

This is a multi-part message in MIME format.
--------------060403030808080109030803
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

I got to thinking about that last patch that I sent and I figured that
there's no reason to read the g15daemon version at every g15_get_key()
call since it's not going to change over the life of the process so I
moved it to the private data structure and fill it in the g15_init()
function.  I'm not sure that there would be much performance hit, but
it's pretty pointless to create and populate a variable that isn't going
to change.  Here's a new patch.

--------------060403030808080109030803
Content-Type: text/x-patch;
 name="g15.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline;
 filename="g15.diff"

Index: g15.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/lcdproc/lcdproc/server/drivers/g15.c,v
retrieving revision 1.1
diff -a -u -r1.1 g15.c
--- g15.c	13 Aug 2006 15:55:47 -0000	1.1
+++ g15.c	12 Nov 2006 02:05:36 -0000
@@ -30,6 +30,7 @@
 #include <errno.h>
 #include <syslog.h>
 #include <sys/socket.h>
+#include <sys/types.h>
 #include <libg15.h>
 #include <g15daemon_client.h>
 #include <libg15render.h>
@@ -70,6 +71,7 @@
    p->cellheight =3D G15_CELL_HEIGHT;
    p->backlight_state =3D BACKLIGHT_ON;
    p->g15screen_fd =3D 0;
+   p->g15d_ver =3D g15daemon_version();
=20
    if((p->g15screen_fd =3D new_g15_screen(G15_G15RBUF)) < 0)
    {
@@ -109,15 +111,8 @@
 =09
 	g15_close_screen(p->g15screen_fd);
 =09
-	if (p !=3D NULL) {
-		if (p->canvas)
-			free(p->canvas);
-	=09
-		if (p->backingstore)
-			free(p->backingstore);
-
-		free(p);
-	}
+	if (p !=3D NULL)
+	  free(p);
 	drvthis->store_private_ptr(drvthis, NULL);
 }
=20
@@ -372,14 +367,35 @@
 MODULE_EXPORT const char * g15_get_key (Driver *drvthis)
 {
 	PrivateData *p =3D drvthis->private_data;
-=09
+	int toread =3D 0;
 	unsigned int key_state =3D 0;
-=09
-	if(send(p->g15screen_fd, "k", 1, MSG_OOB)<1) /* request key status */
-        report(RPT_INFO, "%s: Error in send to g15daemon", drvthis->name=
);   =20
=20
-    	recv(p->g15screen_fd, &key_state , sizeof(key_state),0);
+	if ((strncmp("1.2", p->g15d_ver, 3)))
+	  {	/* other than g15daemon-1.2 (should be >=3D1.9) */
+		fd_set fds;
+		struct timeval tv;
+		memset (&tv, 0, sizeof(struct timeval));
+
+		FD_ZERO(&fds);
+		FD_SET(p->g15screen_fd, &fds);
+=09
+		toread =3D select(FD_SETSIZE, &fds, NULL, NULL, &tv);
+	  }
+	else
+	  {	/* g15daemon-1.2 */
+		if(send(p->g15screen_fd, "k", 1, MSG_OOB)<1) /* request key status */
+		  {
+	 	  	report(RPT_INFO, "%s: Error in send to g15daemon", drvthis->name);=

+			return NULL;
+		  }
+		toread =3D 1;
+	  }
 =09
+	if (toread >=3D 1)
+	  read(p->g15screen_fd, &key_state, sizeof(key_state));
+	else
+	  return NULL;
+
 	if (key_state & G15_KEY_G1)
 		return "Escape";
 	else if (key_state & G15_KEY_L1)
Index: g15.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/lcdproc/lcdproc/server/drivers/g15.h,v
retrieving revision 1.1
diff -a -u -r1.1 g15.h
--- g15.h	13 Aug 2006 15:55:47 -0000	1.1
+++ g15.h	12 Nov 2006 02:05:36 -0000
@@ -32,6 +32,8 @@
 	int cellwidth, cellheight;
 	/* file descriptor for g15daemon socket */
 	int g15screen_fd;
+	/* g15daemon version for compatibility checks */
+	const char *g15d_ver;
 	/* canvas for LCD contents */
 	g15canvas *canvas;
 	g15canvas *backingstore;

--------------060403030808080109030803--

--------------enigA8AF9A4249D2D8AA911F945F
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFVoKBSdAxC41Y09ERAoxVAKCJer5EquyBx5Dav1guahWALm0a/ACg4n+X
On8gy3ck9BKyjMTJbuxQTjo=
=RrKV
-----END PGP SIGNATURE-----

--------------enigA8AF9A4249D2D8AA911F945F--