Commit 27f8fcd2 authored by Louis-Francis Ratté-Boulianne's avatar Louis-Francis Ratté-Boulianne Committed by Olivier Crête

Added python bindings

parent c491b3b3
SUBDIRS = libgupnp-igd tests doc
PYTHON_SUBDIR = python
SUBDIRS = libgupnp-igd $(PYTHON_SUBDIR) tests doc common-modified m4
ACLOCAL_AMFLAGS = -I m4
pkgconfig_DATA= gupnp-igd-1.0.pc
pkgconfigdir = $(libdir)/pkgconfig
......
......@@ -2,4 +2,5 @@
gtkdocize || exit 1
autoreconf -v --install || exit 1
glib-gettextize --force --copy || exit 1
ACLOCAL_AMFLAGS = -I m4
./configure --enable-gtk-doc "$@"
......@@ -22,9 +22,19 @@ PKG_CHECK_MODULES(GTest, glib-2.0 >= 2.16, [gtest=yes], [gtest=no])
AM_CONDITIONAL(HAVE_GTEST, [test x$gtest = xyes])
AM_CHECK_PYTHON_HEADERS(,[AC_MSG_ERROR(could not find Python headers)])
PKG_CHECK_MODULES(PYGUPNP_IGD, pygobject-2.0 >= 2.12.0)
PKG_CHECK_MODULES(PYCODEGEN, [ pygobject-2.0 >= 2.16.0 ],
PYCODEGEN=pygobject-codegen-2.0,
PKG_CHECK_MODULES(PYCODEGEN, [ pygtk-2.0 >= 2.10 ],
PYCODEGEN=pygtk-codegen-2.0,
AC_MSG_ERROR([You need pygobject 2.16+ or pygtk for the codegen])))
AC_SUBST(PYCODEGEN)
AC_OUTPUT([
Makefile
libgupnp-igd/Makefile
python/Makefile
tests/Makefile
tests/gtest/Makefile
tests/examples/Makefile
......
......@@ -19,11 +19,9 @@ libgupnp_igd_inc_HEADERS = \
libgupnp_igd_1_0_la_SOURCES = \
gupnp-simple-igd.c \
gupnp-simple-igd-thread.c \
gupnp-simple-igd-marshal.c
noinst_HEADERS = gupnp-simple-igd-marshal.h
gupnp-enum-types.c \
gupnp-enum-types.h \
$(BUILT_SOURCES)
BUILT_SOURCES = \
gupnp-simple-igd-marshal.c \
......
#include "gupnp-enum-types.h"
#include "gupnp-simple-igd.h"
/* enumerations from "gupnp-simple-igd.h" */
GType
gupnp_simple_igd_error_get_type (void)
{
static GType etype = 0;
if (etype == 0) {
static const GEnumValue values[] = {
{ GUPNP_SIMPLE_IGD_ERROR_EXTERNAL_ADDRESS, "GUPNP_SIMPLE_IGD_ERROR_EXTERNAL_ADDRESS", "address" },
{ 0, NULL, NULL }
};
etype = g_enum_register_static ("GUPnPSimpleIgdError", values);
}
return etype;
}
#ifndef __GUPNP_ENUM_TYPES_H__
#define __GUPNP_ENUM_TYPES_H__
#include <glib-object.h>
G_BEGIN_DECLS
/* enumerations from "gupnp-simple-igd.h" */
GType gupnp_simple_igd_error_get_type (void);
#define GUPNP_TYPE_SIMPLE_IGD_ERROR (gupnp_simple_igd_error_get_type())
G_END_DECLS
#endif /* __GUPNP_ENUM_TYPES_H__ */
dnl Copy pasted from gst-python's acinclude.m4 file
dnl a macro to check for ability to create python extensions
dnl AM_CHECK_PYTHON_HEADERS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE])
dnl function also defines PYTHON_INCLUDES
AC_DEFUN([AM_CHECK_PYTHON_HEADERS],
[AC_REQUIRE([AM_PATH_PYTHON])
AC_MSG_CHECKING(for headers required to compile python extensions)
dnl deduce PYTHON_INCLUDES
py_prefix=`$PYTHON -c "import sys; print sys.prefix"`
py_exec_prefix=`$PYTHON -c "import sys; print sys.exec_prefix"`
if $PYTHON-config --help 2>/dev/null; then
PYTHON_INCLUDES=`$PYTHON-config --includes 2>/dev/null`
else
PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}"
if test "$py_prefix" != "$py_exec_prefix"; then
PYTHON_INCLUDES="$PYTHON_INCLUDES -I${py_exec_prefix}/include/python${PYTHON_VERSION}"
fi
fi
AC_SUBST(PYTHON_INCLUDES)
dnl check if the headers exist:
save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES"
AC_TRY_CPP([#include <Python.h>],dnl
[AC_MSG_RESULT(found)
$1],dnl
[AC_MSG_RESULT(not found)
$2])
CPPFLAGS="$save_CPPFLAGS"
])
PYDEFS=`pkg-config --variable=defsdir pygobject-2.0`
[ -z "$PYDEFS" && PYDEFS=`pkg-config --variable=defsdir pygtk-2.0`]
AM_CPPFLAGS = \
-I. \
-I$(top_srcdir)/libgupnp-igd/ \
-DDATADIR=\""$(datadir)"\" \
$(PYGUPNP_IGD_CFLAGS) \
$(PYTHON_INCLUDES) \
$(LIBGUPNP_CFLAGS) \
$(WARN_CFLAGS)
BUILT_SOURCES = \
pygupnp-igd.c
pygupnpigddir = $(pyexecdir)/gupnp/
pygupnpigd_LTLIBRARIES = igd.la
igd_la_SOURCES = \
pygupnp-igd-module.c
nodist_igd_la_SOURCES = pygupnp-igd.c
igd_la_LIBADD = \
$(PYGUPNP_IGD_LIBS) \
$(top_builddir)/libgupnp-igd/libgupnp-igd-1.0.la
igd_la_LDFLAGS = \
`python-config --libs` \
-module -avoid-version
pygupnp-igd.c: pygupnp-igd.override pygupnp-igd.defs
$(PYCODEGEN) \
--prefix igd \
--override $(srcdir)/pygupnp-igd.override \
$(srcdir)/pygupnp-igd.defs > $@
EXTRA_DIST = \
pygupnp-igd.defs \
pygupnp-igd-filter.defs \
rebuild-defs.sh
CLEANFILES = $(BUILT_SOURCES)
(define-object Simple
(in-module "GUPnPIgd")
(parent "GObject")
(c-name "GUPnPSimpleIgd")
(gtype-id "GUPNP_TYPE_SIMPLE_IGD")
)
(define-object SimpleThread
(in-module "GUPnPSimpleIgd")
(parent "GUPnPSimpleIgd")
(c-name "GUPnPSimpleIgdThread")
(gtype-id "GUPNP_TYPE_SIMPLE_IGD_THREAD")
)
(define-enum Error
(in-module "GUPnPSimpleIgd")
(c-name "GUPnPSimpleIgdError")
(gtype-id "GUPNP_TYPE_SIMPLE_IGD_ERROR")
(values
'("s" "GUPNP_SIMPLE_IGD_ERROR_EXTERNAL_ADDRESS")
)
)
#include <pygobject.h>
#include <libgupnp-igd/gupnp-simple-igd.h>
#include <libgupnp-igd/gupnp-simple-igd-thread.h>
void igd_register_classes (PyObject *d);
void igd_add_constants(PyObject *module, const gchar *strip_prefix);
DL_EXPORT(void) initigd(void);
extern PyMethodDef igd_functions[];
DL_EXPORT(void)
initigd(void)
{
PyObject *m, *d;
init_pygobject ();
m = Py_InitModule ("igd", igd_functions);
d = PyModule_GetDict (m);
//PyModule_AddIntConstant (m, "CODEC_ID_ANY", FS_CODEC_ID_ANY);
//PyModule_AddIntConstant (m, "CODEC_ID_ANY", FS_CODEC_ID_ANY);
igd_register_classes (d);
igd_add_constants(m, "GUPNP_");
if (PyErr_Occurred ()) {
PyErr_Print();
Py_FatalError ("can't initialise module gupnp.igd");
}
}
(define-object Simple
(in-module "GUPnPIgd")
(parent "GObject")
(c-name "GUPnPSimpleIgd")
(gtype-id "GUPNP_TYPE_SIMPLE_IGD")
)
(define-object SimpleThread
(in-module "GUPnPSimpleIgd")
(parent "GUPnPSimpleIgd")
(c-name "GUPnPSimpleIgdThread")
(gtype-id "GUPNP_TYPE_SIMPLE_IGD_THREAD")
)
(define-enum Error
(in-module "GUPnPSimpleIgd")
(c-name "GUPnPSimpleIgdError")
(gtype-id "GUPNP_TYPE_SIMPLE_IGD_ERROR")
(values
'("s" "GUPNP_SIMPLE_IGD_ERROR_EXTERNAL_ADDRESS")
)
)
;; -*- scheme -*-
; object definitions ...
;; Enumerations and flags ...
;; From gupnp-simple-igd.h
(define-function get_error_domain
(c-name "gupnp_simple_igd_get_error_domain")
(return-type "GQuark")
)
(define-function get_type
(c-name "gupnp_simple_igd_get_type")
(return-type "GType")
)
(define-function new
(c-name "gupnp_simple_igd_new")
(is-constructor-of "GupnpSimpleIgd")
(return-type "GUPnPSimpleIgd*")
(parameters
'("GMainContext*" "main_context")
)
)
(define-method add_port
(of-object "GUPnPSimpleIgd")
(c-name "gupnp_simple_igd_add_port")
(return-type "none")
(parameters
'("const-gchar*" "protocol")
'("guint16" "external_port")
'("const-gchar*" "local_ip")
'("guint16" "local_port")
'("guint32" "lease_duration")
'("const-gchar*" "description")
)
)
(define-method remove_port
(of-object "GUPnPSimpleIgd")
(c-name "gupnp_simple_igd_remove_port")
(return-type "none")
(parameters
'("const-gchar*" "protocol")
'("guint" "external_port")
)
)
(define-method delete_all_mappings
(of-object "GUPnPSimpleIgd")
(c-name "gupnp_simple_igd_delete_all_mappings")
(return-type "gboolean")
)
;; -*- scheme -*-
; object definitions ...
;; Enumerations and flags ...
;; From gupnp-simple-igd-thread.h
(define-function thread_get_type
(c-name "gupnp_simple_igd_thread_get_type")
(return-type "GType")
)
(define-function thread_new
(c-name "gupnp_simple_igd_thread_new")
(is-constructor-of "GupnpSimpleIgdThread")
(return-type "GUPnPSimpleIgdThread*")
)
;; -*- scheme -*-
; object definitions ...
;; Enumerations and flags ...
;; From gupnp-enum-types.h
(define-function error_get_type
(c-name "gupnp_simple_igd_error_get_type")
(return-type "GType")
)
%%
headers
#include <Python.h>
#include <pygobject.h>
#include <libgupnp-igd/gupnp-simple-igd.h>
#include <libgupnp-igd/gupnp-simple-igd-thread.h>
#include <libgupnp-igd/gupnp-enum-types.h>
/* This is new in python 2.5 */
#if PYTHON_API_VERSION < 1013
typedef int Py_ssize_t;
#endif
#
%%
modulename gupnpigd
%%
import gobject.GObject as PyGObject_Type
#!/bin/sh
HEADERS=" \
gupnp-simple-igd.h \
gupnp-simple-igd-thread.h \
gupnp-enum-types.h"
srcdir=../libgupnp-igd/
output=pygupnp-igd.defs
filter=pygupnp-igd-filters.defs
modulename=gupnp_simple_igd
cat $filter>$output
H2DEF="$(pkg-config --variable=codegendir pygobject-2.0)/h2def.py"
[ -z "${H2DEF}" ] && H2DEF="$(pkg-config --variable=codegendir pygtk-2.0)/h2def.py"
[ -z "${H2DEF}" -a -f /usr/share/pygtk/2.0/codegen/h2def.py ] && H2DEF=/usr/share/pygtk/2.0/codegen/h2def.py
for h in $HEADERS; do
python ${H2DEF} --defsfilter=${filter} --modulename=${modulename} ${srcdir}/$h >> $output
done
sed -e "/of-object \"GUPnpSimpleIgd\"/ a \
\ (unblock-threads t)" \
-i ${output}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment