recursively search for plugins
[enigma2.git] / lib / python / connections.h
1 #ifndef __lib_python_connections_h
2 #define __lib_python_connections_h
3
4 #include <libsig_comp.h>
5
6                 /* avoid warnigs :) */
7 #include <features.h>
8 #undef _POSIX_C_SOURCE
9 #define _POSIX_C_SOURCE 200112L
10 #include <Python.h>
11 #include <lib/python/python.h>
12
13 class PSignal
14 {
15 public:
16         PyObject *m_list;
17 public:
18         PSignal()
19         {
20                 m_list = PyList_New(0);
21                 Py_INCREF(m_list);
22         }
23         ~PSignal()
24         {
25                 Py_DECREF(m_list);
26         }
27         
28         void callPython(PyObject *tuple)
29         {
30                 int size = PyList_Size(m_list);
31                 int i;
32                 for (i=0; i<size; ++i)
33                 {
34                         PyObject *b = PyList_GET_ITEM(m_list, i);
35                         ePython::call(b, tuple);
36                 }
37         }
38         
39         
40         PyObject *get() { Py_INCREF(m_list); return m_list; }
41 };
42
43 inline PyObject *PyFrom(int v)
44 {
45         return PyInt_FromLong(v);
46 }
47
48 inline PyObject *PyFrom(const char *c)
49 {
50         return PyString_FromString(c);
51 }
52
53 template <class R>
54 class PSignal0: public PSignal, public Signal0<R>
55 {
56 public:
57         R operator()()
58         {
59                 PyObject *pArgs = PyTuple_New(0);
60                 callPython(pArgs);
61                 Py_DECREF(pArgs);
62                 return Signal0<R>::operator()();
63         }
64 };
65
66 template <class R, class V0>
67 class PSignal1: public PSignal, public Signal1<R,V0>
68 {
69 public:
70         R operator()(V0 a0)
71         {
72                 PyObject *pArgs = PyTuple_New(1);
73                 PyTuple_SET_ITEM(pArgs, 0, PyFrom(a0));
74                 callPython(pArgs);
75                 Py_DECREF(pArgs);
76                 return Signal1<R,V0>::operator()(a0);
77         }
78 };
79
80 template <class R, class V0, class V1>
81 class PSignal2: public PSignal, public Signal2<R,V0,V1>
82 {
83 public:
84         R operator()(V0 a0, V1 a1)
85         {
86                 PyObject *pArgs = PyTuple_New(2);
87                 PyTuple_SET_ITEM(pArgs, 0, PyFrom(a0));
88                 PyTuple_SET_ITEM(pArgs, 1, PyFrom(a1));
89                 callPython(pArgs);
90                 Py_DECREF(pArgs);
91                 return Signal2<R,V0,V1>::operator()(a0, a1);
92         }
93 };
94
95 #endif