allow dvb state to be queried (last PMT-related event)
[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         ePyObject m_list;
16 public:
17         PSignal();
18         ~PSignal();
19         void callPython(SWIG_PYOBJECT(ePyObject) tuple);
20         PyObject *get();
21 };
22
23 inline PyObject *PyFrom(int v)
24 {
25         return PyInt_FromLong(v);
26 }
27
28 inline PyObject *PyFrom(const char *c)
29 {
30         return PyString_FromString(c);
31 }
32
33 template <class R>
34 class PSignal0: public PSignal, public Signal0<R>
35 {
36 public:
37         R operator()()
38         {
39                 PyObject *pArgs = PyTuple_New(0);
40                 callPython(pArgs);
41                 Org_Py_DECREF(pArgs);
42                 return Signal0<R>::operator()();
43         }
44 };
45
46 template <class R, class V0>
47 class PSignal1: public PSignal, public Signal1<R,V0>
48 {
49 public:
50         R operator()(V0 a0)
51         {
52                 PyObject *pArgs = PyTuple_New(1);
53                 PyTuple_SET_ITEM(pArgs, 0, PyFrom(a0));
54                 callPython(pArgs);
55                 Org_Py_DECREF(pArgs);
56                 return Signal1<R,V0>::operator()(a0);
57         }
58 };
59
60 template <class R, class V0, class V1>
61 class PSignal2: public PSignal, public Signal2<R,V0,V1>
62 {
63 public:
64         R operator()(V0 a0, V1 a1)
65         {
66                 PyObject *pArgs = PyTuple_New(2);
67                 PyTuple_SET_ITEM(pArgs, 0, PyFrom(a0));
68                 PyTuple_SET_ITEM(pArgs, 1, PyFrom(a1));
69                 callPython(pArgs);
70                 Org_Py_DECREF(pArgs);
71                 return Signal2<R,V0,V1>::operator()(a0, a1);
72         }
73 };
74
75 #endif