openATV enigma2
openATV is an open source SetTopBox Graphical user interface.
connections.h
Go to the documentation of this file.
1 #ifndef __lib_python_connections_h
2 #define __lib_python_connections_h
3 
4 #include <libsig_comp.h>
5 
6 #include <lib/python/python.h>
7 #include <utility>
8 
9 class PSignal
10 {
11 protected:
13 public:
14  PSignal();
15  ~PSignal();
17 #ifndef SWIG
18  PyObject *getSteal(bool clear=false);
19 #endif
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 // Only used by console which might transfer binary data(screenshots). So use Bytes instead of Unicode
34 inline PyObject *PyFrom(std::pair<const char*, int>& p)
35 {
36  return PyBytes_FromStringAndSize(p.first, p.second);
37 }
38 
39 template <class R>
40 class PSignal0: public PSignal, public sigc::signal0<R>
41 {
42 public:
44  {
45  if (m_list)
46  {
47  PyObject *pArgs = PyTuple_New(0);
48  callPython(pArgs);
49  Org_Py_DECREF(pArgs);
50  }
51  return sigc::signal0<R>::operator()();
52  }
53 };
54 
55 template <class R, class V0>
56 class PSignal1: public PSignal, public sigc::signal1<R,V0>
57 {
58 public:
59  R operator()(V0 a0)
60  {
61  if (m_list)
62  {
63  PyObject *pArgs = PyTuple_New(1);
64  PyTuple_SET_ITEM(pArgs, 0, PyFrom(a0));
65  callPython(pArgs);
66  Org_Py_DECREF(pArgs);
67  }
68  return sigc::signal1<R,V0>::operator()(a0);
69  }
70 };
71 
72 template <class R, class V0, class V1>
73 class PSignal2: public PSignal, public sigc::signal2<R,V0,V1>
74 {
75 public:
76  R operator()(V0 a0, V1 a1)
77  {
78  if (m_list)
79  {
80  PyObject *pArgs = PyTuple_New(2);
81  PyTuple_SET_ITEM(pArgs, 0, PyFrom(a0));
82  PyTuple_SET_ITEM(pArgs, 1, PyFrom(a1));
83  callPython(pArgs);
84  Org_Py_DECREF(pArgs);
85  }
86  return sigc::signal2<R,V0,V1>::operator()(a0, a1);
87  }
88 };
89 
90 template <class R, class V0, class V1, class V2>
91 class PSignal3: public PSignal, public sigc::signal3<R,V0,V1,V2>
92 {
93 public:
94  R operator()(V0 a0, V1 a1, V2 a2)
95  {
96  if (m_list)
97  {
98  PyObject *pArgs = PyTuple_New(3);
99  PyTuple_SET_ITEM(pArgs, 0, PyFrom(a0));
100  PyTuple_SET_ITEM(pArgs, 1, PyFrom(a1));
101  PyTuple_SET_ITEM(pArgs, 2, PyFrom(a2));
102  callPython(pArgs);
103  Org_Py_DECREF(pArgs);
104  }
105  return sigc::signal3<R,V0,V1,V2>::operator()(a0, a1, a2);
106  }
107 };
108 
109 #endif
Definition: connections.h:41
R operator()()
Definition: connections.h:43
Definition: connections.h:57
R operator()(V0 a0)
Definition: connections.h:59
Definition: connections.h:74
R operator()(V0 a0, V1 a1)
Definition: connections.h:76
Definition: connections.h:92
R operator()(V0 a0, V1 a1, V2 a2)
Definition: connections.h:94
Definition: connections.h:10
~PSignal()
Definition: connections.cpp:7
PyObject * getSteal(bool clear=false)
Definition: connections.cpp:31
void callPython(SWIG_PYOBJECT(ePyObject) tuple)
Definition: connections.cpp:12
PyObject * get()
Definition: connections.cpp:23
ePyObject m_list
Definition: connections.h:12
PSignal()
Definition: connections.cpp:3
Definition: python.h:31
PyObject * PyFrom(int v)
Definition: connections.h:23
p
Definition: upgrade.py:63
PyString_FromString("#ff000000"))
PyTuple_SET_ITEM(tuple, 0, PyLong_FromLong(x))
ePyObject tuple
Definition: picload.cpp:1516
#define PyTuple_New(args...)
Definition: python.h:452
#define PyInt_FromLong(val)
Definition: python.h:456
#define Org_Py_DECREF(obj)
Definition: python.h:423
#define a2
Definition: rotor_calc.cpp:149
#define a0
Definition: rotor_calc.cpp:147
#define a1
Definition: rotor_calc.cpp:148
#define SWIG_PYOBJECT(x)
Definition: swig.h:23