From d3f2e69cd453852367281aa4bc42babe15f2cf79 Mon Sep 17 00:00:00 2001 From: reinelt Date: Sat, 20 Mar 2004 11:49:40 +0000 Subject: [lcd4linux @ 2004-03-20 11:49:40 by reinelt] forgot to add plugin_exec.c ... git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@406 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- plugin_exec.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 plugin_exec.c diff --git a/plugin_exec.c b/plugin_exec.c new file mode 100644 index 0000000..59bfb89 --- /dev/null +++ b/plugin_exec.c @@ -0,0 +1,127 @@ +/* $Id: plugin_exec.c,v 1.1 2004/03/20 11:49:40 reinelt Exp $ + * + * plugin for external processes + * + * Copyright 2004 Michael Reinelt + * Copyright 2004 The LCD4Linux Team + * + * based on the old 'exec' client which is + * Copyright 2001 Leopold Tötsch + * + * + * 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. + * + * + * $Log: plugin_exec.c,v $ + * Revision 1.1 2004/03/20 11:49:40 reinelt + * forgot to add plugin_exec.c ... + * + */ + +/* + * exported functions: + * + * int plugin_init_exec (void) + * adds functions to start external pocesses + * + */ + + +#include "config.h" + +#include +#include +#include + +// #include +// #include +// #include + +#include +#include +#include + +#include "debug.h" +#include "plugin.h" +#include "hash.h" +#include "cfg.h" +#include "thread.h" + +static HASH EXEC = { 0, }; +static int fatal = 0; + +static int do_exec (void) +{ + int age; + + // if a fatal error occured, do nothing + if (fatal != 0) return -1; + + // reread every 100 msec only + age=hash_age(&EXEC, NULL, NULL); + if (age>0 && age<=100) return 0; + return 0; +} + +static void my_junk (char *name) +{ + int i; + + debug ("junk thread starting!"); + + for (i=0; i<10; i++) { + debug ("junk look %d", i); + sleep (1); + } + debug ("junk thread done!"); +} + + +static void my_exec (RESULT *result, int argc, RESULT *argv[]) +{ + char *key, *val; + + if (do_exec()<0) { + SetResult(&result, R_STRING, ""); + return; + } + + // key=R2S(arg1); + val=hash_get(&EXEC, key); + if (val==NULL) val=""; + + SetResult(&result, R_STRING, val); +} + + +int plugin_init_exec (void) +{ + int junk; + + AddFunction ("exec", -1, my_exec); + + // junk=thread_create ("Junk", my_junk); + // debug ("junk=%d", junk); + + return 0; +} + + +void plugin_exit_exec(void) +{ + hash_destroy(&EXEC); +} -- cgit v1.2.3