]> git.webhop.me Git - lcd4linux.git/commitdiff
[lcd4linux @ 2005-05-03 11:13:23 by reinelt]
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Tue, 3 May 2005 11:13:24 +0000 (11:13 +0000)
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Tue, 3 May 2005 11:13:24 +0000 (11:13 +0000)
rearranged autoconf a bit,
libX11 will be linked only if really needed (i.e. when the X11 driver has been selected)
plugin_python filled with life

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@537 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

Makefile.am
Makefile.in
configure
drivers.m4
plugin_python.c
plugins.m4

index 7caf41ec8d3bdd21cb6a1e363047e324ba69c958..d98a71f470d6fcbd27457c01725ee5d016fd9053 100644 (file)
@@ -7,9 +7,9 @@ PLUGINS=@PLUGINS@
 
 bin_PROGRAMS = lcd4linux
 
-AM_CFLAGS = $(X_CFLAGS) -D_GNU_SOURCE -Wall -W
+AM_CFLAGS = -D_GNU_SOURCE -Wall -W
 
-lcd4linux_LDFLAGS = $(X_LIBS)
+lcd4linux_LDFLAGS = 
 lcd4linux_LDADD   = @DRIVERS@ @PLUGINS@ @DRVLIBS@ @PLUGINLIBS@
 lcd4linux_DEPENDENCIES = @DRIVERS@ @PLUGINS@
 
index ba776b97d79bc65a33a29e0d76b14b2e51e24172..f63fc60ef25ca1e3ceb0757042aa626c4932996a 100644 (file)
@@ -95,9 +95,9 @@ PLUGINS = @PLUGINS@
 
 bin_PROGRAMS = lcd4linux
 
-AM_CFLAGS = $(X_CFLAGS) -D_GNU_SOURCE -Wall -W
+AM_CFLAGS = -D_GNU_SOURCE -Wall -W
 
-lcd4linux_LDFLAGS = $(X_LIBS)
+lcd4linux_LDFLAGS = 
 lcd4linux_LDADD = @DRIVERS@ @PLUGINS@ @DRVLIBS@ @PLUGINLIBS@
 lcd4linux_DEPENDENCIES = @DRIVERS@ @PLUGINS@
 
index 448ab60c8bab0766eb8d106d1aec9c957363013b..075e9c054fa84d5b010306c4dcc1421cc48c2953 100755 (executable)
--- a/configure
+++ b/configure
@@ -5921,12 +5921,12 @@ if test "$BWCT" = "yes"; then
    if test "$has_usb" = "true"; then
       TEXT="yes"
       DRIVERS="$DRIVERS drv_BWCT.o"
+      DRVLIBS="$DRVLIBS -lusb"
 
 cat >>confdefs.h <<\_ACEOF
 #define WITH_BWCT 1
 _ACEOF
 
-      DRVLIBS="$DRVLIBS -lusb"
    else
       { echo "$as_me:$LINENO: WARNING: usb.h not found: BWCT driver disabled" >&5
 echo "$as_me: WARNING: usb.h not found: BWCT driver disabled" >&2;}
@@ -6047,12 +6047,12 @@ if test "$PNG" = "yes"; then
    if test "$has_gd" = "true"; then
       GRAPHIC="yes"
       IMAGE="yes"
+      DRVLIBS="$DRVLIBS -lgd"
 
 cat >>confdefs.h <<\_ACEOF
 #define WITH_PNG 1
 _ACEOF
 
-      DRVLIBS="$DRVLIBS -lgd"
    else
       { echo "$as_me:$LINENO: WARNING: gd.h not found: PNG driver disabled" >&5
 echo "$as_me: WARNING: gd.h not found: PNG driver disabled" >&2;}
@@ -6109,12 +6109,12 @@ if test "$Trefon" = "yes"; then
    if test "$has_usb" = "true"; then
       TEXT="yes"
       DRIVERS="$DRIVERS drv_Trefon.o"
+      DRVLIBS="$DRVLIBS -lusb"
 
 cat >>confdefs.h <<\_ACEOF
 #define WITH_TREFON 1
 _ACEOF
 
-      DRVLIBS="$DRVLIBS -lusb"
    else
       { echo "$as_me:$LINENO: WARNING: usb.h not found: Trefon driver disabled" >&5
 echo "$as_me: WARNING: usb.h not found: Trefon driver disabled" >&2;}
@@ -6125,14 +6125,14 @@ if test "$USBLCD" = "yes"; then
    TEXT="yes"
    SERIAL="yes"
    DRIVERS="$DRIVERS drv_USBLCD.o"
+   if test "$has_usb" = "true"; then
+      DRVLIBS="$DRVLIBS -lusb"
+   fi
 
 cat >>confdefs.h <<\_ACEOF
 #define WITH_USBLCD 1
 _ACEOF
 
-   if test "$has_usb" = "true"; then
-      DRVLIBS="$DRVLIBS -lusb"
-   fi
 fi
 
 if test "$X11" = "yes"; then
@@ -6143,6 +6143,7 @@ echo "$as_me: WARNING: X11 headers or libraries not available: X11 driver disabl
       GRAPHIC="yes"
       DRIVERS="$DRIVERS drv_X11.o"
       DRVLIBS="$DRVLIBS -L$ac_x_libraries -lX11"
+      CPP_FLAGS="$CPPFLAGS $X_CFLAGS"
 
 cat >>confdefs.h <<\_ACEOF
 #define WITH_X11 1
@@ -6184,12 +6185,12 @@ fi
 # generic i2c driver
 if test "$I2C" = "yes"; then
    if test "$has_i2c" = true; then
+      DRIVERS="$DRIVERS drv_generic_i2c.o"
 
 cat >>confdefs.h <<\_ACEOF
 #define WITH_I2C 1
 _ACEOF
 
-      DRIVERS="$DRIVERS drv_generic_i2c.o"
    else
       I2C="no"
       { echo "$as_me:$LINENO: WARNING: I2C include files not found: I2C bus driver disabled" >&5
@@ -6953,12 +6954,12 @@ fi
 
       if test "$has_mysql_lib" = "true"; then
         PLUGINS="$PLUGINS plugin_mysql.o"
+        PLUGINLIBS="$PLUGINLIBS -lmysqlclient"
 
 cat >>confdefs.h <<\_ACEOF
 #define PLUGIN_MYSQL 1
 _ACEOF
 
-        PLUGINLIBS="$PLUGINLIBS -lmysqlclient"
       else
         { echo "$as_me:$LINENO: WARNING: mysqlclient lib not found: mysql plugin disabled" >&5
 echo "$as_me: WARNING: mysqlclient lib not found: mysql plugin disabled" >&2;}
@@ -7162,6 +7163,8 @@ if test "$PLUGIN_PYTHON" = "yes"; then
 echo "$as_me: WARNING: python headers not found: python plugin disabled" >&2;}
    else
       PLUGINS="$PLUGINS plugin_python.o"
+      CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
+      PLUGINLIBS="$PLUGINLIBS $PYTHON_LDFLAGS $PYTHON_EXTRA_LIBS"
 
 cat >>confdefs.h <<\_ACEOF
 #define PLUGIN_PYTHON 1
index 5b44db6eb4010cbe52a6d80f6d9b93359f9673d4..ce2a011dc98205b1518939a20936f9ed11874d5d 100644 (file)
@@ -164,8 +164,8 @@ if test "$BWCT" = "yes"; then
    if test "$has_usb" = "true"; then
       TEXT="yes"
       DRIVERS="$DRIVERS drv_BWCT.o"
-      AC_DEFINE(WITH_BWCT,1,[BWCT driver])
       DRVLIBS="$DRVLIBS -lusb"
+      AC_DEFINE(WITH_BWCT,1,[BWCT driver])
    else
       AC_MSG_WARN(usb.h not found: BWCT driver disabled)
    fi
@@ -244,8 +244,8 @@ if test "$PNG" = "yes"; then
    if test "$has_gd" = "true"; then
       GRAPHIC="yes"
       IMAGE="yes"
-      AC_DEFINE(WITH_PNG,1,[ driver])
       DRVLIBS="$DRVLIBS -lgd"
+      AC_DEFINE(WITH_PNG,1,[ driver])
    else
       AC_MSG_WARN(gd.h not found: PNG driver disabled)
    fi
@@ -285,8 +285,8 @@ if test "$Trefon" = "yes"; then
    if test "$has_usb" = "true"; then
       TEXT="yes"
       DRIVERS="$DRIVERS drv_Trefon.o"
-      AC_DEFINE(WITH_TREFON,1,[TREFON driver])
       DRVLIBS="$DRVLIBS -lusb"
+      AC_DEFINE(WITH_TREFON,1,[TREFON driver])
    else
       AC_MSG_WARN(usb.h not found: Trefon driver disabled)
    fi
@@ -296,10 +296,10 @@ if test "$USBLCD" = "yes"; then
    TEXT="yes"
    SERIAL="yes"
    DRIVERS="$DRIVERS drv_USBLCD.o"
-   AC_DEFINE(WITH_USBLCD,1,[USBLCD driver])
    if test "$has_usb" = "true"; then
       DRVLIBS="$DRVLIBS -lusb"
    fi
+   AC_DEFINE(WITH_USBLCD,1,[USBLCD driver])
 fi
 
 if test "$X11" = "yes"; then
@@ -309,6 +309,7 @@ if test "$X11" = "yes"; then
       GRAPHIC="yes"
       DRIVERS="$DRIVERS drv_X11.o"
       DRVLIBS="$DRVLIBS -L$ac_x_libraries -lX11"
+      CPP_FLAGS="$CPPFLAGS $X_CFLAGS" 
       AC_DEFINE(WITH_X11, 1, [X11 driver])
    fi
 fi
@@ -344,8 +345,8 @@ fi
 # generic i2c driver
 if test "$I2C" = "yes"; then
    if test "$has_i2c" = true; then
-      AC_DEFINE(WITH_I2C, 1, [I2C bus driver])
       DRIVERS="$DRIVERS drv_generic_i2c.o"
+      AC_DEFINE(WITH_I2C, 1, [I2C bus driver])
    else
       I2C="no"
       AC_MSG_WARN(I2C include files not found: I2C bus driver disabled)
index 88e60e8209c06d09e5e29f36066939ad9018b6c9..7b61096b59003ff188bdf5fc8b31176ed135f16c 100644 (file)
@@ -1,8 +1,8 @@
-/* $Id: plugin_python.c,v 1.1 2005/05/02 10:29:20 reinelt Exp $
+/* $Id: plugin_python.c,v 1.2 2005/05/03 11:13:24 reinelt Exp $
  *
  * Python plugin
  *
- * Copyright 2005 Fixme!
+ * Copyright 2005 Dan Fritz  
  * Copyright 2005 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
  *
  * This file is part of LCD4Linux.
  *
  *
  * $Log: plugin_python.c,v $
+ * Revision 1.2  2005/05/03 11:13:24  reinelt
+ * rearranged autoconf a bit,
+ * libX11 will be linked only if really needed (i.e. when the X11 driver has been selected)
+ * plugin_python filled with life
+ *
  * Revision 1.1  2005/05/02 10:29:20  reinelt
  * preparations for python bindings and python plugin
  *
@@ -36,6 +41,7 @@
  *
  */
 
+#include <Python.h>
 
 #include "config.h"
 
 #include "plugin.h"
 #include "hash.h"
 
-// Fixme: #include "lcd4linux_wrap.h"
+/* 
+ * Executes a python function specified by function name and module.
+ *
+ * This method is more or less a copy of an example found in the python 
+ * documentation. Kudos goes to Guido van Rossum and Fred L. Drake.
+ * 
+ * Returns a char* directly from PyString_AsString() !!! DO NOT DEALLOCATE !!!
+ */
+static const char* 
+pyt_exec_str(const char* module, const char* function, int argc, const char* argv[]) {
+
+  PyObject *pName, *pModule, *pDict, *pFunc;
+  PyObject *pArgs, *pValue;
+  const char * rv = NULL;
+  int i;
 
-static void my_exec (RESULT *result, RESULT *arg1)
-{
-#if 0
-  const char* value = pyt_exec_str(R2S(arg1));
-#else
-  const char *value = "Fixme";
-#endif
+  pName = PyString_FromString(module);
+  /* Error checking of pName left out */
+
+  pModule = PyImport_Import(pName);
+  Py_DECREF(pName);
+
+  if (pModule != NULL) {
+    pDict = PyModule_GetDict(pModule);
+    /* pDict is a borrowed reference */
+
+    pFunc = PyDict_GetItemString(pDict, function);
+    /* pFun: Borrowed reference */
+
+    if (pFunc && PyCallable_Check(pFunc)) {
+      pArgs = PyTuple_New(argc);
+      for (i = 0; i < argc; ++i) {
+        pValue = PyString_FromString(argv[i]);
+        if (!pValue) {
+          Py_DECREF(pArgs);
+          Py_DECREF(pModule);
+          fprintf(stderr, "Cannot convert argument %s\n", argv[i]);
+          return NULL;
+        }
+        /* pValue reference stolen here: */
+        PyTuple_SetItem(pArgs, i, pValue);
+      }
+      pValue = PyObject_CallObject(pFunc, pArgs);
+      Py_DECREF(pArgs);
+      if (pValue != NULL) {
+        rv = PyString_AsString(pValue);
+        //printf("Result of call: %s\n", rv);
+        Py_DECREF(pValue);
+        return rv;
+      }
+      else {
+        Py_DECREF(pModule);
+        PyErr_Print();
+        fprintf(stderr,"Call failed\n");
+        return NULL;
+      }
+      /* pDict and pFunc are borrowed and must not be Py_DECREF-ed */
+    }
+    else {
+      if (PyErr_Occurred())
+        PyErr_Print();
+      fprintf(stderr, "Cannot find function \"%s\"\n", argv[2]);
+    }
+    Py_DECREF(pModule);
+  }
+  else {
+    PyErr_Print();
+    fprintf(stderr, "Failed to load \"%s\"\n", argv[1]);
+    return NULL;
+  }
+  return NULL;
+}
+
+static int python_cleanup_responsibility = 0;
+    
+static void my_exec (RESULT *result, RESULT *module, RESULT *function, RESULT *arg )
+{ 
+  const char* args[] = {R2S(arg)};
+  const char* value = pyt_exec_str(R2S(module),R2S(function),1,args);
   SetResult(&result, R_STRING, value); 
 }
 
 int plugin_init_python (void)
 {
-  AddFunction ("python::exec", 1, my_exec);
+  if (!Py_IsInitialized()) {
+    Py_Initialize();
+    python_cleanup_responsibility = 1;
+  }
+  AddFunction ("python::exec", 3, my_exec);
   return 0;
 }
 
 void plugin_exit_python (void) 
 {
-  /* empty */
+  /* Make sure NOT to call Py_Finalize() When (and if) the entire lcd4linux process 
+   * is started from inside python
+   */
+  if (python_cleanup_responsibility) {
+    python_cleanup_responsibility = 0;
+    Py_Finalize();
+  }
 }
index 927029f578045cc102cf83cc3c79f4111a6fe55b..d72daf60f3812ea7c26814e96ffa2f076cdb1c40 100644 (file)
@@ -200,8 +200,8 @@ if test "$PLUGIN_MYSQL" = "yes"; then
       AC_CHECK_LIB(mysqlclient, mysql_init, [has_mysql_lib="true"], [has_mysql_lib="false"])
       if test "$has_mysql_lib" = "true"; then
         PLUGINS="$PLUGINS plugin_mysql.o"
-        AC_DEFINE(PLUGIN_MYSQL,1,[mysql plugin])
         PLUGINLIBS="$PLUGINLIBS -lmysqlclient"
+        AC_DEFINE(PLUGIN_MYSQL,1,[mysql plugin])
       else
         AC_MSG_WARN(mysqlclient lib not found: mysql plugin disabled)
       fi
@@ -235,6 +235,8 @@ if test "$PLUGIN_PYTHON" = "yes"; then
       AC_MSG_WARN(python headers not found: python plugin disabled)
    else
       PLUGINS="$PLUGINS plugin_python.o"
+      CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
+      PLUGINLIBS="$PLUGINLIBS $PYTHON_LDFLAGS $PYTHON_EXTRA_LIBS"
       AC_DEFINE(PLUGIN_PYTHON,1,[python plugin])
    fi 
 fi