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@
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@
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;}
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;}
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;}
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
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
# 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
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;}
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
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
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
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
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
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
# 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)
-/* $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
*
*
*/
+#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();
+ }
}
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
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