1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-05 21:07:52 +00:00

xmms work continued

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@488 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Philip Kovacs 2006-01-08 14:51:47 +00:00
parent 6d24365953
commit 896a5ce701
8 changed files with 90 additions and 264 deletions

View File

@ -85,48 +85,42 @@ dnl XMMS_SUPPORT
dnl dnl
xmms_support=none xmms_support=none
AC_ARG_ENABLE(xmms-support, AC_ARG_ENABLE(xmms,
[ --enable-xmms-support[[=project]] [ --enable-xmms[[=project]] none,xmms,bmp,audacious,infopipe [[default=none]]],
Specify the XMMS-related Project:
none: none [[default]]
xmms: XMMS (version 1) Support
bmp: Beep Media Player (not BMPx) Support
audacious: Audacious (version >= 0.1) Media Player Support
infopipe: XMMS/BMP InfoPipe (version 1.3) Plugin Support ],
[xmms_support="$enableval"]) [xmms_support="$enableval"])
case x$xmms_support in case x$xmms_support in
xnone|xyes|xno) xnone|xyes|xno)
;; ;;
xxmms) xxmms)
AC_DEFINE(XMMS_H, 1, [Define for XMMS support]) AC_DEFINE(XMMS, 1, [Define for XMMS Version 1 support])
echo "Sorry, xmms isn't supported yet" echo "Sorry, xmms isn't supported yet"
exit -1 exit -1
;; ;;
xbmp) xbmp)
PKG_CHECK_MODULES([BMP], [bmp], []) PKG_CHECK_MODULES([XMMS], [bmp], [])
CFLAGS="$CFLAGS $BMP_CFLAGS" CFLAGS="$CFLAGS $XMMS_CFLAGS"
LIBS="$LIBS $BMP_LIBS" LIBS="$LIBS $XMMS_LIBS"
AC_DEFINE(BMP_H, 1, [Define for BMP support]) AC_DEFINE(BMP, 1, [Define for BMP support])
;; ;;
xaudacious) xaudacious)
PKG_CHECK_MODULES([AUDACIOUS], [audacious >= 0.1]) PKG_CHECK_MODULES([XMMS], [audacious >= 0.1])
CFLAGS="$CFLAGS $AUDACIOUS_CFLAGS" CFLAGS="$CFLAGS $XMMS_CFLAGS"
LIBS="$LIBS $AUDACIOUS_LIBS" LIBS="$LIBS $XMMS_LIBS"
AC_DEFINE(AUDACIOUS_H, 1, [Define for Audacious support]) AC_DEFINE(AUDACIOUS, 1, [Define for Audacious support])
;; ;;
xinfopipe) xinfopipe)
AC_DEFINE(INFOPIPE_H, 1, [Define for XMMS/BMP InfoPipe support]) AC_DEFINE(INFOPIPE, 1, [Define for XMMS/BMP InfoPipe support])
;; ;;
*) *)
echo "Error: invalid xmms-status specified: $xmms_support" echo "Error: invalid xmms support specified: $xmms_support"
exit -1 exit -1
;; ;;
esac esac
AM_CONDITIONAL(BUILD_XMMS, test x$xmms_support = xxmms) AM_CONDITIONAL(BUILD_XMMS, test x$xmms_support = xxmms)
AM_CONDITIONAL(BUILD_XMMS_BMP, test x$xmms_support = xbmp) AM_CONDITIONAL(BUILD_BMP, test x$xmms_support = xbmp)
AM_CONDITIONAL(BUILD_XMMS_AUDACIOUS, test x$xmms_support = xaudacious) AM_CONDITIONAL(BUILD_AUDACIOUS, test x$xmms_support = xaudacious)
AM_CONDITIONAL(BUILD_XMMS_INFOPIPE, test x$xmms_support = xinfopipe) AM_CONDITIONAL(BUILD_INFOPIPE, test x$xmms_support = xinfopipe)
dnl dnl
dnl BMPx dnl BMPx

View File

@ -4,15 +4,15 @@ if BUILD_XMMS
xmms = xmms.c xmms.h xmms = xmms.c xmms.h
endif endif
if BUILD_XMMS_BMP if BUILD_BMP
xmms = xmms.c xmms.h xmms = xmms.c xmms.h
endif endif
if BUILD_XMMS_AUDACIOUS if BUILD_AUDACIOUS
xmms = xmms.c xmms.h xmms = xmms.c xmms.h
endif endif
if BUILD_XMMS_INFOPIPE if BUILD_INFOPIPE
xmms = xmms.c xmms.h xmms = xmms.c xmms.h
endif endif

View File

@ -226,7 +226,7 @@ void update_stuff()
if (NEED(INFO_MPD)) if (NEED(INFO_MPD))
update_mpd(); update_mpd();
#endif #endif
#if defined(XMMS_H) || defined(BMP_H) || defined(AUDACIOUS_H) || defined(INFOPIPE_H) #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
if (NEED(INFO_XMMS)) if (NEED(INFO_XMMS))
update_xmms(); update_xmms();
#endif #endif

View File

@ -892,7 +892,7 @@ enum text_object_type {
OBJ_mpd_track, OBJ_mpd_track,
OBJ_mpd_percent, OBJ_mpd_percent,
#endif #endif
#if defined(XMMS_H) || defined(BMP_H) || defined(AUDACIOUS_H) || defined(INFOPIPE_H) #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
OBJ_xmms_status, OBJ_xmms_status,
OBJ_xmms_title, OBJ_xmms_title,
OBJ_xmms_length, OBJ_xmms_length,
@ -1809,7 +1809,7 @@ int a = stippled_borders, b = 1;
(void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b); (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
END END
#endif #endif
#if defined(XMMS_H) || defined(BMP_H) || defined(AUDACIOUS_H) || defined(INFOPIPE_H) #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
OBJ(xmms_status, INFO_XMMS) END OBJ(xmms_status, INFO_XMMS) END
OBJ(xmms_title, INFO_XMMS) END OBJ(xmms_title, INFO_XMMS) END
OBJ(xmms_length, INFO_XMMS) END OBJ(xmms_length, INFO_XMMS) END
@ -3101,7 +3101,7 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
255.0f)); 255.0f));
} }
#endif #endif
#if defined(XMMS_H) || defined(BMP_H) || defined(AUDACIOUS_H) || defined(INFOPIPE_H) #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
OBJ(xmms_status) { OBJ(xmms_status) {
snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_STATUS]); snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_STATUS]);
} }
@ -5485,7 +5485,7 @@ int main(int argc, char **argv)
ERR("error setting signal handler: %s", strerror(errno) ); ERR("error setting signal handler: %s", strerror(errno) );
} }
#if defined(XMMS_H) || defined(BMP_H) || defined(AUDACIOUS_H) || defined(INFOPIPE_H) #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
/* joinable thread for xmms activity */ /* joinable thread for xmms activity */
pthread_attr_init(&info.xmms.thread_attr); pthread_attr_init(&info.xmms.thread_attr);
pthread_attr_setdetachstate(&info.xmms.thread_attr, PTHREAD_CREATE_JOINABLE); pthread_attr_setdetachstate(&info.xmms.thread_attr, PTHREAD_CREATE_JOINABLE);
@ -5504,7 +5504,7 @@ int main(int argc, char **argv)
main_loop(); main_loop();
#if defined(XMMS_H) || defined(BMP_H) || defined(AUDACIOUS_H) || defined(INFOPIPE_H) #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
/* signal xmms worker thread to terminate */ /* signal xmms worker thread to terminate */
pthread_mutex_lock(&info.xmms.runnable_mutex); pthread_mutex_lock(&info.xmms.runnable_mutex);
info.xmms.runnable=0; info.xmms.runnable=0;

View File

@ -9,7 +9,7 @@
#ifndef _conky_h_ #ifndef _conky_h_
#define _conky_h_ #define _conky_h_
#if defined(XMMS_H) || defined(BMP_H) || defined(AUDACIOUS_H) || defined(INFOPIPE_H) #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
#include <pthread.h> #include <pthread.h>
#endif #endif
#if defined(HAS_MCHECK_H) #if defined(HAS_MCHECK_H)
@ -127,7 +127,7 @@ struct mpd_s {
}; };
#endif #endif
#if defined(XMMS_H) || defined(BMP_H) || defined(AUDACIOUS_H) || defined(INFOPIPE_H) #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
#include "xmms.h" #include "xmms.h"
struct xmms_s { struct xmms_s {
xmms_t items; /* e.g. items[XMMS_STATUS] yields char[] */ xmms_t items; /* e.g. items[XMMS_STATUS] yields char[] */
@ -188,7 +188,7 @@ enum {
#ifdef TCP_PORT_MONITOR #ifdef TCP_PORT_MONITOR
INFO_TCP_PORT_MONITOR = 22, INFO_TCP_PORT_MONITOR = 22,
#endif #endif
#if defined(XMMS_H) || defined(BMP_H) || defined(AUDACIOUS_H) || defined(INFOPIPE_H) #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
INFO_XMMS = 23, INFO_XMMS = 23,
#endif #endif
#ifdef BMPX #ifdef BMPX
@ -237,7 +237,7 @@ struct information {
struct mpd_s mpd; struct mpd_s mpd;
mpd_Connection *conn; mpd_Connection *conn;
#endif #endif
#if defined(XMMS_H) || defined(BMP_H) || defined(AUDACIOUS_H) || defined(INFOPIPE_H) #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
struct xmms_s xmms; struct xmms_s xmms;
#endif #endif
#ifdef BMPX #ifdef BMPX

View File

@ -1,149 +0,0 @@
/* -------------------------------------------------------------------------
* infopipe.c: conky support for XMMS/BMP InfoPipe plugin
*
* http://www.beastwithin.org/users/wwwwolf/code/xmms/infopipe.html
*
* Copyright (C) 2005 Philip Kovacs kovacsp3@comcast.net
*
* Based on original ideas and code graciously presented by:
* Ulrich Jansen - ulrich( dot )jansen( at )rwth-aachen.de
*
* $Id$
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* --------------------------------------------------------------------------- */
#include <pthread.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include "infopipe.h"
#include "conky.h"
/* access to this item array is synchronized with mutexes */
static infopipe_t g_items;
/* ----------------------------------------
* Conky update function for InfoPipe data.
* ---------------------------------------- */
void update_infopipe(void)
{
/*
The worker thread is updating the g_items array asynchronously to the main
conky thread. We merely copy the g_items array into the main thread's info
structure when the main thread's update cycle fires. Note that using the
mutexes here makes it easier since we won't have to do any sync in conky.c.
*/
pthread_mutex_lock(&info.infopipe.item_mutex);
memcpy(&info.infopipe.items,g_items,sizeof(g_items));
pthread_mutex_unlock(&info.infopipe.item_mutex);
}
/* --------------------------------------------------
* Worker thread function for InfoPipe data sampling.
* -------------------------------------------------- */
void *infopipe_thread_func(void *pvoid)
{
int i,rc,fd,runnable;
fd_set readset;
struct timeval tm;
static char buf[2048]; /* should equal or exceed sizeof(infopipe_t) */
static infopipe_t items;
char *pbuf,c;
pvoid=(void*)pvoid; /* useless cast to avoid unused var warning */
/* Grab the runnable signal. Should be non-zero here or we do nothing. */
pthread_mutex_lock(&info.infopipe.runnable_mutex);
runnable=info.infopipe.runnable;
pthread_mutex_unlock(&info.infopipe.runnable_mutex );
/* Loop until the main thread sets the runnable signal to 0. */
while(runnable) {
for (;;) { /* convenience loop so we can break below */
memset(buf,0,sizeof(buf));
if ((fd=open(INFOPIPE_NAMED_PIPE, O_RDONLY | O_NONBLOCK)) < 0) {
/* InfoPipe is not running */
memset(items,0,sizeof(items));
strcpy(items[INFOPIPE_STATUS],"Not running");
break;
}
FD_ZERO(&readset);
FD_SET(fd,&readset);
/* On Linux, select() reduces the timer by the amount of time not slept,
* so we must reset the timer with each loop. */
tm.tv_sec=1;
tm.tv_usec=0;
rc=select(fd+1,&readset,NULL,NULL,&tm);
if (rc == -1) {
/* -- debug --
perror("infopipe select()");
*/
}
else if (rc && FD_ISSET(fd,&readset)) { /* ready to read */
if (read(fd,buf,sizeof(buf)) > 0) { /* buf has data */
pbuf=buf;
for (i=0;i<14;i++) {
/* 14 lines of key: value pairs presented in a known order */
if ( sscanf(pbuf,"%*[^:]: %[^\n]",items[i]) == EOF )
break;
while((c = *pbuf++) && (c != '\n'));
}
/* -- debug --
for(i=0;i<14;i++)
printf("%s\n",items[i]);
*/
}
}
else {
/* -- debug --
printf("no infopipe data\n");
*/
}
close(fd);
break;
}
/* Deliver the refreshed items array to g_items. */
pthread_mutex_lock(&info.infopipe.item_mutex);
memcpy(&g_items,items,sizeof(items));
pthread_mutex_unlock(&info.infopipe.item_mutex);
/* Grab the runnable signal for next loop. */
pthread_mutex_lock(&info.infopipe.runnable_mutex);
runnable=info.infopipe.runnable;
pthread_mutex_unlock(&info.infopipe.runnable_mutex);
sleep(1);
}
pthread_exit(NULL);
}

View File

@ -1,61 +0,0 @@
/* -------------------------------------------------------------------------
* infopipe.h: conky support for XMMS/BMP InfoPipe plugin
*
* InfoPipe: http://www.beastwithin.org/users/wwwwolf/code/xmms/infopipe.html
*
* Copyright (C) 2005 Philip Kovacs kovacsp3@comcast.net
*
* Based on original ideas and code graciously presented by:
* Ulrich Jansen - ulrich( dot )jansen( at )rwth-aachen.de
*
* $Id$
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* --------------------------------------------------------------------------- */
#ifndef INFOPIPE_H
#define INFOPIPE_H
/* The named pipe created by the infopipe plugin (actually a symlink) */
#define INFOPIPE_NAMED_PIPE "/tmp/xmms-info"
/* 14 keys comprise the output of the infopipe plugin. */
enum _infopipe_keys {
INFOPIPE_PROTOCOL,
INFOPIPE_VERSION,
INFOPIPE_STATUS,
INFOPIPE_PLAYLIST_TUNES,
INFOPIPE_PLAYLIST_CURRTUNE,
INFOPIPE_USEC_POSITION,
INFOPIPE_POSITION,
INFOPIPE_USEC_TIME,
INFOPIPE_TIME,
INFOPIPE_BITRATE,
INFOPIPE_FREQUENCY,
INFOPIPE_CHANNELS,
INFOPIPE_TITLE,
INFOPIPE_FILE
};
/* 14 slots for the infopipe values */
typedef char infopipe_t[14][128];
/* Service routine for the conky main thread */
void update_infopipe(void);
/* Thread function */
void *infopipe_thread_func(void *);
#endif

View File

@ -25,22 +25,45 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#if defined(XMMS_H) #include "config.h"
#include "conky.h"
#include "xmms.h"
#if defined(XMMS)
#include <xmms/xmmsctrl.h> #include <xmms/xmmsctrl.h>
#elif defined(BMP_H)
#elif defined(BMP)
#include <bmp/beepctrl.h> #include <bmp/beepctrl.h>
#elif defined(AUDACIOUS_H)
#elif defined(AUDACIOUS)
#include <audacious/beepctrl.h> #include <audacious/beepctrl.h>
#elif defined(INFOPIPE_H)
#elif defined(INFOPIPE)
#include <sys/select.h> #include <sys/select.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include <fcntl.h> #include <fcntl.h>
#define INFOPIPE_NAMED_PIPE "/tmp/xmms-info"
#endif
#include "xmms.h" #define INFOPIPE_NAMED_PIPE "/tmp/xmms-info"
#include "conky.h"
/* 14 keys comprise the output of the infopipe plugin. */
enum _infopipe_keys {
INFOPIPE_PROTOCOL=0,
INFOPIPE_VERSION,
INFOPIPE_STATUS,
INFOPIPE_PLAYLIST_TUNES,
INFOPIPE_PLAYLIST_CURRTUNE,
INFOPIPE_USEC_POSITION,
INFOPIPE_POSITION,
INFOPIPE_USEC_TIME,
INFOPIPE_TIME,
INFOPIPE_BITRATE,
INFOPIPE_FREQUENCY,
INFOPIPE_CHANNELS,
INFOPIPE_TITLE,
INFOPIPE_FILE
};
#endif
/* access to this item array is synchronized with mutexes */ /* access to this item array is synchronized with mutexes */
@ -63,7 +86,7 @@ void update_xmms(void)
} }
#if defined(XMMS_H) || defined(BMP_H) || defined(AUDACIOUS_H) #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS)
/* ------------------------------------------------------------ /* ------------------------------------------------------------
* Worker thread function for XMMS/BMP/Audacious data sampling. * Worker thread function for XMMS/BMP/Audacious data sampling.
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
@ -168,7 +191,7 @@ void *xmms_thread_func(void *pvoid)
pthread_exit(NULL); pthread_exit(NULL);
} }
#elif defined(INFOPIPE_H) #elif defined(INFOPIPE)
/* -------------------------------------------------- /* --------------------------------------------------
* Worker thread function for InfoPipe data sampling. * Worker thread function for InfoPipe data sampling.
* -------------------------------------------------- */ * -------------------------------------------------- */
@ -177,16 +200,16 @@ void *xmms_thread_func(void *pvoid)
int i,rc,fd,runnable; int i,rc,fd,runnable;
fd_set readset; fd_set readset;
struct timeval tm; struct timeval tm;
static char buf[2048]; /* should equal or exceed sizeof(infopipe_t) */ static char buf[2048],line[128];
static xmms_t items; static xmms_t items;
char *pbuf,c; char *pbuf,c;
pvoid=(void*)pvoid; /* useless cast to avoid unused var warning */ pvoid=(void*)pvoid; /* useless cast to avoid unused var warning */
/* Grab the runnable signal. Should be non-zero here or we do nothing. */ /* Grab the runnable signal. Should be non-zero here or we do nothing. */
pthread_mutex_lock(&info.infopipe.runnable_mutex); pthread_mutex_lock(&info.xmms.runnable_mutex);
runnable=info.infopipe.runnable; runnable=info.xmms.runnable;
pthread_mutex_unlock(&info.infopipe.runnable_mutex ); pthread_mutex_unlock(&info.xmms.runnable_mutex );
/* Loop until the main thread sets the runnable signal to 0. */ /* Loop until the main thread sets the runnable signal to 0. */
while(runnable) { while(runnable) {
@ -226,6 +249,25 @@ void *xmms_thread_func(void *pvoid)
if ( sscanf(pbuf,"%*[^:]: %[^\n]",items[i]) == EOF ) if ( sscanf(pbuf,"%*[^:]: %[^\n]",items[i]) == EOF )
break; break;
while((c = *pbuf++) && (c != '\n')); while((c = *pbuf++) && (c != '\n'));
switch(i) {
case INFOPIPE_PROTOCOL:
case INFOPIPE_VERSION:
case INFOPIPE_STATUS:
case INFOPIPE_PLAYLIST_TUNES:
case INFOPIPE_PLAYLIST_CURRTUNE:
case INFOPIPE_USEC_POSITION:
case INFOPIPE_POSITION:
case INFOPIPE_USEC_TIME:
case INFOPIPE_TIME:
case INFOPIPE_BITRATE:
case INFOPIPE_FREQUENCY:
case INFOPIPE_CHANNELS:
case INFOPIPE_TITLE:
case INFOPIPE_FILE:
default:
break;
}
} }
/* -- debug -- /* -- debug --
@ -246,14 +288,14 @@ void *xmms_thread_func(void *pvoid)
} }
/* Deliver the refreshed items array to g_items. */ /* Deliver the refreshed items array to g_items. */
pthread_mutex_lock(&info.infopipe.item_mutex); pthread_mutex_lock(&info.xmms.item_mutex);
memcpy(&g_items,items,sizeof(items)); memcpy(&g_items,items,sizeof(items));
pthread_mutex_unlock(&info.infopipe.item_mutex); pthread_mutex_unlock(&info.xmms.item_mutex);
/* Grab the runnable signal for next loop. */ /* Grab the runnable signal for next loop. */
pthread_mutex_lock(&info.infopipe.runnable_mutex); pthread_mutex_lock(&info.xmms.runnable_mutex);
runnable=info.infopipe.runnable; runnable=info.xmms.runnable;
pthread_mutex_unlock(&info.infopipe.runnable_mutex); pthread_mutex_unlock(&info.xmms.runnable_mutex);
sleep(1); sleep(1);
} }