From c12ec4c53a04bdb0424ea1562be46df1f14f3614 Mon Sep 17 00:00:00 2001 From: mkeil Date: Fri, 16 Jan 2004 10:09:49 +0000 Subject: [lcd4linux @ 2004-01-16 10:09:49 by mkeil] -include caching for values git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@316 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- plugin_xmms.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'plugin_xmms.c') diff --git a/plugin_xmms.c b/plugin_xmms.c index c01081a..700b828 100644 --- a/plugin_xmms.c +++ b/plugin_xmms.c @@ -1,4 +1,4 @@ -/* $Id: plugin_xmms.c,v 1.2 2004/01/06 22:33:14 reinelt Exp $ +/* $Id: plugin_xmms.c,v 1.3 2004/01/16 10:09:49 mkeil Exp $ * * XMMS-Plugin for LCD4Linux * Copyright 2003 Markus Keil @@ -21,6 +21,9 @@ * * * $Log: plugin_xmms.c,v $ + * Revision 1.3 2004/01/16 10:09:49 mkeil + * -include caching for values + * * Revision 1.2 2004/01/06 22:33:14 reinelt * Copyright statements cleaned up * @@ -39,9 +42,6 @@ /* - * - * ATTENTION: This is a convert of my Plugin that i wrote in C++! It might by very buggy! - * * The Argument 'arg1' must be one of these Things (without brackets): * * 'Title' - The title of the current song @@ -63,37 +63,54 @@ #include #include +#include +#include "hash.h" #include "debug.h" #include "plugin.h" static void my_xmms (RESULT *result, RESULT *arg1) { - FILE *xmms; + static HASH xmms = { 0, 0, NULL }; + char *hash_key, *val; + static time_t now=0; + FILE *xmms_stream; char zeile[200]; char *key=R2S(arg1); int len=strlen(key); + // reread every second only + if (time(NULL)!=now) { + //Open Filestream for '/tmp/xmms-info' - xmms = fopen("/tmp/xmms-info","r"); + xmms_stream = fopen("/tmp/xmms-info","r"); //Check for File - if( !xmms ) { + if( !xmms_stream ) { error("Error: Cannot open XMMS-Info Stream! Is XMMS started?"); SetResult(&result, R_STRING, ""); return; } //Read Lines from the Stream - while(fgets(zeile,200,xmms)) { - if (strncmp(key, zeile, len)==0 && zeile[len]==':') { + while(fgets(zeile,200,xmms_stream)) { + hash_key=key; val=zeile; + if (strncmp(key, zeile, len)==0 && zeile[len]==':') { // remove trailing newline zeile[strlen(zeile)-1]='\0'; - SetResult(&result, R_STRING, zeile+len+2); - return; + // add entry to hash table + val=zeile+len+2; + hash_set (&xmms, hash_key, val); + time(&now); + fclose(xmms_stream); } + } } - SetResult(&result, R_STRING, ""); + hash_key=R2S(arg1); + val=hash_get(&xmms, hash_key); + if (val==NULL) val=""; + + SetResult(&result, R_STRING, val); } -- cgit v1.2.3