/* $Id$
* $URL$
*
* plugin for external processes
*
* Copyright (C) 2004 Michael Reinelt <michael@reinelt.co.at>
* Copyright (C) 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
*
* based on the old 'exec' client which is
* Copyright (C) 2001 Leopold T�tsch <lt@toetsch.at>
*
*
* This file is part of LCD4Linux.
*
* LCD4Linux is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* LCD4Linux 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/*
* exported functions:
*
* int plugin_init_exec (void)
* adds functions to start external pocesses
*
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "debug.h"
#include "plugin.h"
#include "hash.h"
#include "cfg.h"
#include "thread.h"
#include "qprintf.h"
#define NUM_THREADS 16
#define SHM_SIZE 4096
typedef struct {
int delay;
int mutex;
pid_t pid;
int shmid;
char *cmd;
char *key;
char *ret;
} EXEC_THREAD;
static EXEC_THREAD Thread[NUM_THREADS];
static int max_thread = -1;
static HASH EXEC;
/* x^0 + x^5 + x^12 */
#define CRCPOLY 0x8408
static unsigned short CRC(const char *s)
{
int i;
unsigned short crc;
/* seed value */
crc = 0xffff;
while (*s != '\0') {
crc ^= *s++;
for (i = 0; i < 8; i++)
crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY : 0);
}
return crc;
}
static void exec_thread(void *data)
{
EXEC_THREAD *Thread = (EXEC_THREAD *) data;
FILE *pipe;
char buffer[SHM_SIZE];
int len;
/* use a safe path */
putenv("PATH=/usr/local/bin:/usr/bin:/bin");
/* forever... */
while (1) {
pipe = popen(Thread->cmd, "r");
if (pipe == NULL) {
error("exec error: could not run pipe '%s': %s", Thread->cmd, strerror(errno));
len = 0;
} else {
len = fread(buffer, 1, SHM_SIZE - 1, pipe);
if (len <= 0) {
error("exec error: could not read from pipe '%s': %s", Thread->cmd, </* $Id$
* $URL$
*
* generic driver helper for graphic displays
*
* Copyright (C) 1999, 2000 Michael Reinelt <michael@reinelt.co.at>
* Copyright (C) 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
*
* This file is part of LCD4Linux.
*
* LCD4Linux is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* LCD4Linux 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/*
*
* exported functions:
*
* int drv_generic_graphic_init (char *section, char *driver);
* initializes the generic graphic driver
*
* int drv_generic_graphic_draw (WIDGET *W);
* renders Text widget into framebuffer
* calls drv_generic_graphic_real_blit()
*
* int drv_generic_graphic_icon_draw (WIDGET *W);
* renders Icon widget into framebuffer
* calls drv_generic_graphic_real_blit()
*
* int drv_generic_graphic_bar_draw (WIDGET *W);
* renders Bar widget into framebuffer
* calls drv_generic_graphic_real_blit()
*
* int drv_generic_graphic_quit (void);
* closes generic graphic driver
*
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#include "debug.h"
#include "cfg.h"
#include "plugin.h"
#include "layout.h"
#include "widget.h"
#include "property.h"
#include "widget_text.h"
#include "widget_icon.h"
#include "widget_bar.h"
#include "widget_image.h"
#include "rgb.h"
#include "drv.h"
#include "drv_generic.h"
#include "drv_generic_graphic.h"
#include "font_6x8.h"
#include "font_6x8_bold.h"
#ifdef WITH_DMALLOC
#include <dmalloc.h>
#endif
/* pixel colors */
RGBA FG_COL = {.R = 0x00,.G = 0x00,.B = 0x00,.A = 0xff };
RGBA BG_COL = {.R = 0xff,.G = 0xff,.B = 0xff,.A = 0xff };
RGBA BL_COL = {.R = 0xff,.G = 0xff,.B = 0xff,.A = 0x00 };
RGBA NO_COL = {.R = 0x00,.G = 0x00,.B = 0x00,.A = 0x00 };
static char *Section = NULL;
static char *Driver = NULL;
/* framebuffer */
static RGBA *drv_generic_graphic_FB[LAYERS] = { NULL, };
/* inverted colors */
static int INVERTED = 0;
/* must be implemented by the real driver */
void (*drv_generic_graphic_real_blit) () = NULL;
/****************************************/
/*** generic Framebuffer stuff ***/
/****************************************/
static void drv_generic_graphic_resizeFB(int rows, int cols)
{
RGBA *newFB;
int i, l, row, col;
/* Layout FB is large enough */
if (rows <= LROWS && cols <= LCOLS)
return;
/* get maximum values */
if (rows < LROWS)
rows = LROWS;
if (cols < LCOLS)
cols = LCOLS;
for (l = 0; l < LAYERS; l++) {
/* allocate and initialize new Layout FB */
newFB = malloc(cols * rows * sizeof(*newFB));
for (i = 0; i < rows * cols; i++)
newFB[i] = NO_COL;
/* transfer contents */
if (drv_generic_graphic_FB[l] != NULL) {
for (row = 0; row < LROWS; row++) {
for (col = 0; col < LCOLS; col++) {
newFB[row * cols + col] = drv_generic_graphic_FB[l][row * LCOLS + col];
}
}
free(drv_generic_graphic_FB[l]);
}
drv_generic_graphic_FB[l] = newFB;
}
LCOLS = cols;
LROWS = rows;
}
static void drv_generic_graphic_window(int pos, int size, int max, int *wpos, int *wsize)
{
int p1 = pos;
int p2 = pos + size;
*wpos = 0;
*wsize = 0;
if (p1 > max || p2 < 0 || size < 1)
return;
if (p1 < 0)
p1 = 0;
if (p2 > max)
p2 = max;
*wpos = p1;
*wsize = p2 - p1;
}
static void drv_generic_graphic_blit(const int row, const int col