allow burning videos (also H.264) to data DVDs
[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
11 #include <lib/python/python.h>
12
13 class PSignal
14 {
15 protected:
16         ePyObject m_list;
17 public:
18         PSignal();
19         ~PSignal();
20         void callPython(SWIG_PYOBJECT(ePyObject) tuple);
21         PyObject *get();
22 };
23
24 inline PyObject *PyFrom(int v)
25 {
26         return PyInt_FromLong(v);
27 }
28
29 inline PyObject *PyFrom(const char *c)
30 {
31         return PyString_FromString(c);
32 }
33
34 template <class R>
35 class PSignal0: public PSignal, public Signal0<R>
36 {
37 public:
38         R operator()()
39         {
40                 if (m_list)
41                 {
42                         PyObject *pArgs = PyTuple_New(0);
43                         callPython(pArgs);
44                         Org_Py_DECREF(pArgs);
45                 }
46                 return Signal0<R>::operator()();
47         }
48 };
49
50 template <class R, class V0>
51 class PSignal1: public PSignal, public Signal1<R,V0>
52 {
53 public:
54         R operator()(V0 a0)
55         {
56                 if (m_list)
57                 {
58                         PyObject *pArgs = PyTuple_New(1);
59                         PyTuple_SET_ITEM(pArgs, 0, PyFrom(a0));
60                         callPython(pArgs);
61                         Org_Py_DECREF(pArgs);
62                 }
63                 return Signal1<R,V0>::operator()(a0);
64         }
65 };
66
67 template <class R, class V0, class V1>
68 class PSignal2: public PSignal, public Signal2<R,V0,V1>
69 {
70 public:
71         R operator()(V0 a0, V1 a1)
72         {
73                 if (m_list)
74                 {
75                         PyObject *pArgs = PyTuple_New(2);
76                         PyTuple_SET_ITEM(pArgs, 0, PyFrom(a0));
77                         PyTuple_SET_ITEM(pArgs, 1, PyFrom(a1));
78                         callPython(pArgs);
79                         Org_Py_DECREF(pArgs);
80                 }
81                 return Signal2<R,V0,V1>::operator()(a0, a1);
82         }
83 };
84
85 #endif