aboutsummaryrefslogtreecommitdiff
path: root/lib/python
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python')
-rw-r--r--lib/python/Makefile.am12
-rw-r--r--lib/python/enigma_python.i23
-rw-r--r--lib/python/python.cpp57
-rw-r--r--lib/python/python.h16
4 files changed, 108 insertions, 0 deletions
diff --git a/lib/python/Makefile.am b/lib/python/Makefile.am
new file mode 100644
index 00000000..c3d98c0b
--- /dev/null
+++ b/lib/python/Makefile.am
@@ -0,0 +1,12 @@
+INCLUDES = \
+ -I$(top_srcdir)/include \
+ -I$(top_srcdir)/src \
+ -I/usr/include/python2.3
+
+noinst_LIBRARIES = libenigma_python.a
+
+libenigma_python_a_SOURCES = \
+ python.cpp enigma_python_wrap.cxx
+
+enigma_python_wrap.cxx: enigma_python.i
+ swig -I$(top_srcdir)/ -c++ -python enigma_python.i
diff --git a/lib/python/enigma_python.i b/lib/python/enigma_python.i
new file mode 100644
index 00000000..67244f10
--- /dev/null
+++ b/lib/python/enigma_python.i
@@ -0,0 +1,23 @@
+%module enigma
+%{
+#define SWIG_COMPILE
+#include <lib/base/smartptr.h>
+#include <lib/base/eerror.h>
+#include <lib/base/econfig.h>
+#include <lib/service/iservice.h>
+#include <lib/service/service.h>
+%}
+
+#define DEBUG
+%include "stl.i"
+%include <lib/base/object.h>
+%include <lib/base/eerror.h>
+%include <lib/base/econfig.h>
+%include <lib/base/smartptr.h>
+%include <lib/service/iservice.h>
+%include <lib/service/service.h>
+%template(eServiceCenterPtr) ePtr<eServiceCenter>;
+%template(iPlayableServicePtr) ePtr<iPlayableService>;
+%template(iPauseableServicePtr) ePtr<iPauseableService>;
+%template(iRecordableServicePtr) ePtr<iRecordableService>;
+%template(iListableServicePtr) ePtr<iListableService>;
diff --git a/lib/python/python.cpp b/lib/python/python.cpp
new file mode 100644
index 00000000..a9ad32f6
--- /dev/null
+++ b/lib/python/python.cpp
@@ -0,0 +1,57 @@
+#include <lib/python/python.h>
+#include <Python.h>
+
+extern "C" void init_enigma();
+
+ePython::ePython()
+{
+ Py_Initialize();
+
+ init_enigma();
+}
+
+ePython::~ePython()
+{
+ Py_Finalize();
+}
+
+int ePython::execute(const std::string &pythonfile, const std::string &funcname)
+{
+ PyObject *pName, *pModule, *pDict, *pFunc, *pArgs, *pValue;
+
+ pName = PyString_FromString(pythonfile.c_str());
+
+ pModule = PyImport_Import(pName);
+ Py_DECREF(pName);
+
+ if (pModule != NULL)
+ {
+ pDict = PyModule_GetDict(pModule);
+
+ pFunc = PyDict_GetItemString(pDict, funcname.c_str());
+
+ if (pFunc && PyCallable_Check(pFunc))
+ {
+ pArgs = PyTuple_New(0);
+ // implement arguments..
+ pValue = PyObject_CallObject(pFunc, pArgs);
+ Py_DECREF(pArgs);
+ if (pValue != NULL)
+ {
+ printf("Result of call: %ld\n", PyInt_AsLong(pValue));
+ Py_DECREF(pValue);
+ } else
+ {
+ Py_DECREF(pModule);
+ PyErr_Print();
+ return 1;
+ }
+ }
+ } else
+ {
+ if (PyErr_Occurred())
+ PyErr_Print();
+ return 1;
+ }
+ return 0;
+}
diff --git a/lib/python/python.h b/lib/python/python.h
new file mode 100644
index 00000000..bde18146
--- /dev/null
+++ b/lib/python/python.h
@@ -0,0 +1,16 @@
+#ifndef __lib_python_python_h
+#define __lib_python_python_h
+
+#include <string>
+
+class ePython
+{
+public:
+ ePython();
+ ~ePython();
+ int execute(const std::string &pythonfile, const std::string &funcname);
+private:
+
+};
+
+#endif