add eConsoleAppContainer to execute shell scripts or applications from python without...
[vuplus_dvbapp] / 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 template <class R>
44 class PSignal0: public PSignal, public Signal0<R>
45 {
46 public:
47         R operator()()
48         {
49                 PyObject *pArgs = PyTuple_New(0);
50                 callPython(pArgs);
51                 Py_DECREF(pArgs);
52                 return Signal0<R>::operator()();
53         }
54 };
55
56 template <class R, class V0>
57 class PSignal1: public PSignal, public Signal1<R,V0>
58 {
59 public:
60         R operator()(V0 a0)
61         {
62                 PyObject *pArgs = PyTuple_New(1);
63                 PyTuple_SET_ITEM(pArgs, 0, PyInt_FromLong(a0));
64                 callPython(pArgs);
65                 Py_DECREF(pArgs);
66                 return Signal1<R,V0>::operator()(a0);
67         }
68 };
69
70 template <class R, class V0>
71 class PSignal1Str: public PSignal, public Signal1<R,V0>
72 {
73 public:
74         R operator()(V0 a0)
75         {
76                 PyObject *pArgs = PyTuple_New(1);
77                 PyTuple_SET_ITEM(pArgs, 0, PyString_FromString(a0));
78                 callPython(pArgs);
79                 Py_DECREF(pArgs);
80                 return Signal1<R,V0>::operator()(a0);
81         }
82 };
83
84 template <class R, class V0, class V1>
85 class PSignal2: public PSignal, public Signal2<R,V0,V1>
86 {
87 public:
88         R operator()(V0 a0, V1 a1)
89         {
90                 PyObject *pArgs = PyTuple_New(2);
91                 PyTuple_SET_ITEM(pArgs, 0, PyInt_FromLong(a0));
92                 PyTuple_SET_ITEM(pArgs, 1, PyInt_FromLong(a1));
93                 callPython(pArgs);
94                 Py_DECREF(pArgs);
95                 return Signal2<R,V0,V1>::operator()(a0, a1);
96         }
97 };
98
99 #endif