rewind into timeshift (almost) works now
[enigma2.git] / lib / dvb_ci / dvbci_ui.cpp
1 #include <lib/dvb_ci/dvbci_ui.h>
2 #include <lib/dvb_ci/dvbci.h>
3
4 #include <unistd.h>
5 #include <fcntl.h>
6 #include <sys/ioctl.h>
7
8 #include <string>
9
10 #include <lib/base/init.h>
11 #include <lib/base/init_num.h>
12 #include <lib/base/eerror.h>
13
14 eDVBCI_UI *eDVBCI_UI::instance;
15
16 eDVBCI_UI::eDVBCI_UI()
17 {
18         ASSERT(!instance);
19         instance = this;
20         for(int i=0;i<MAX_SLOTS;++i)
21         {
22                 slotdata[i].mmiScreenReady=0;
23                 slotdata[i].mmiTuplePos=0;
24                 slotdata[i].state=-1;
25         }
26 }
27
28 eDVBCI_UI::~eDVBCI_UI()
29 {
30         for(int i=0;i<MAX_SLOTS;++i)
31         {
32                 if (slotdata[i].mmiScreen)
33                         Py_DECREF(slotdata[i].mmiScreen);
34         }
35 }
36
37 eDVBCI_UI *eDVBCI_UI::getInstance()
38 {
39         return instance;
40 }
41
42 int eDVBCI_UI::getState(int slot)
43 {
44         if (slot < MAX_SLOTS)
45                 return slotdata[slot].state;
46         return 0;
47 }
48
49 void eDVBCI_UI::setState(int slot, int newState)
50 {
51         if (slot < MAX_SLOTS)
52         {
53                 slotdata[slot].state = newState;
54                 /*emit*/ ciStateChanged(slot);
55         }
56 }
57
58 std::string eDVBCI_UI::getAppName(int slot)
59 {
60         if (slot < MAX_SLOTS)
61                 return slotdata[slot].appName;
62         return "";
63 }
64
65 void eDVBCI_UI::setAppName(int slot, const char *name)
66 {
67         if (slot < MAX_SLOTS)
68                 slotdata[slot].appName = name;
69 }
70
71 void eDVBCI_UI::setInit(int slot)
72 {
73         eDVBCIInterfaces::getInstance()->initialize(slot);
74 }
75
76 void eDVBCI_UI::setReset(int slot)
77 {
78         eDVBCIInterfaces::getInstance()->reset(slot);
79 }
80
81 int eDVBCI_UI::startMMI(int slot)
82 {
83         eDVBCIInterfaces::getInstance()->startMMI(slot);
84         return 0;
85 }
86
87 int eDVBCI_UI::stopMMI(int slot)
88 {
89         eDVBCIInterfaces::getInstance()->stopMMI(slot);
90         return 0;
91 }
92
93 int eDVBCI_UI::answerMenu(int slot, int answer)
94 {
95         eDVBCIInterfaces::getInstance()->answerText(slot, answer);
96         return 0;
97 }
98
99 int eDVBCI_UI::answerEnq(int slot, char *value)
100 {
101         eDVBCIInterfaces::getInstance()->answerEnq(slot, value);
102         return 0;
103 }
104
105 int eDVBCI_UI::cancelEnq(int slot)
106 {
107         eDVBCIInterfaces::getInstance()->cancelEnq(slot);
108         return 0;
109 }
110
111 int eDVBCI_UI::availableMMI(int slot)
112 {
113         if (slot < MAX_SLOTS)
114                 return slotdata[slot].mmiScreenReady;
115         return false;
116 }
117
118 int eDVBCI_UI::mmiScreenClose(int slot, int timeout)
119 {
120         if (slot >= MAX_SLOTS)
121                 return 0;
122
123         slot_ui_data &data = slotdata[slot];
124
125         data.mmiScreenReady = 0;
126
127         if (data.mmiScreen)
128                 Py_DECREF(data.mmiScreen);
129         data.mmiScreen = PyList_New(1);
130
131         ePyObject tuple = PyTuple_New(2);
132         PyTuple_SET_ITEM(tuple, 0, PyString_FromString("CLOSE"));
133         PyTuple_SET_ITEM(tuple, 1, PyLong_FromLong(timeout));
134         PyList_SET_ITEM(data.mmiScreen, 0, tuple);
135         data.mmiScreenReady = 1;
136         /*emit*/ ciStateChanged(slot);
137         return 0;
138 }
139
140 int eDVBCI_UI::mmiScreenEnq(int slot, int blind, int answerLen, char *text)
141 {
142         if (slot >= MAX_SLOTS)
143                 return 0;
144
145         slot_ui_data &data = slotdata[slot];
146
147         data.mmiScreenReady = 0;
148
149         if (data.mmiScreen)
150                 Py_DECREF(data.mmiScreen);
151         data.mmiScreen = PyList_New(2);
152
153         ePyObject tuple = PyTuple_New(1);
154         PyTuple_SET_ITEM(tuple, 0, PyString_FromString("ENQ"));
155         PyList_SET_ITEM(data.mmiScreen, 0, tuple);
156
157         tuple = PyTuple_New(4);
158         PyTuple_SET_ITEM(tuple, 0, PyString_FromString("PIN"));
159         PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(answerLen));
160         PyTuple_SET_ITEM(tuple, 2, PyString_FromString(text));
161         PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(blind));
162
163         PyList_SET_ITEM(data.mmiScreen, 1, tuple);
164
165         data.mmiScreenReady = 1;
166
167         /*emit*/ ciStateChanged(slot);
168
169         return 0;
170 }
171
172 int eDVBCI_UI::mmiScreenBegin(int slot, int listmenu)
173 {
174         if (slot >= MAX_SLOTS)
175                 return 0;
176
177         eDebug("eDVBCI_UI::mmiScreenBegin");
178
179         slot_ui_data &data = slotdata[slot];
180
181         data.mmiScreenReady = 0;
182
183         if (data.mmiScreen)
184                 Py_DECREF(data.mmiScreen);
185
186         data.mmiScreen = PyList_New(1);
187
188         ePyObject tuple = PyTuple_New(1);
189         if (listmenu == 0)                              //menu
190                 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("MENU"));
191         else    //list
192                 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("LIST"));
193
194         PyList_SET_ITEM(data.mmiScreen, 0, tuple);
195
196         data.mmiTuplePos = 1;
197
198         return 0;
199 }
200
201 int eDVBCI_UI::mmiScreenAddText(int slot, int type, char *value)
202 {
203         if (slot >= MAX_SLOTS)
204                 return 0;
205
206         eDebug("eDVBCI_UI::mmiScreenAddText(%s)",value ? value : "");
207
208         slot_ui_data &data = slotdata[slot];
209
210         ePyObject tuple = PyTuple_New(3);
211
212         if (type == 0)                                  //title
213                 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("TITLE"));
214         else if (type == 1)                             //subtitle
215                 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("SUBTITLE"));
216         else if (type == 2)                             //bottom
217                 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("BOTTOM"));
218         else
219                 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("TEXT"));
220
221         eDebug("addText %s with id %d", value, type);
222
223         PyTuple_SET_ITEM(tuple, 1, PyString_FromString(value));
224
225         if (type > 2)
226                 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(type-2));
227         else
228                 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(-1));
229
230         PyList_Append(data.mmiScreen, tuple);
231         Py_DECREF(tuple);
232
233         return 0;
234 }
235
236 int eDVBCI_UI::mmiScreenFinish(int slot)
237 {
238         if (slot < MAX_SLOTS)
239         {
240                 eDebug("eDVBCI_UI::mmiScreenFinish");
241                 slotdata[slot].mmiScreenReady = 1;
242                 /*emit*/ ciStateChanged(slot);
243         }
244         return 0;
245 }
246
247 void eDVBCI_UI::mmiSessionDestroyed(int slot)
248 {
249         /*emit*/ ciStateChanged(slot);
250 }
251
252 int eDVBCI_UI::getMMIState(int slot)
253 {
254         return eDVBCIInterfaces::getInstance()->getMMIState(slot);
255 }
256
257 PyObject *eDVBCI_UI::getMMIScreen(int slot)
258 {
259         if (slot < MAX_SLOTS)
260         {
261                 slot_ui_data &data = slotdata[slot];
262                 if (data.mmiScreenReady)
263                 {
264                         data.mmiScreenReady = 0;
265                         Py_INCREF(data.mmiScreen);
266                         return data.mmiScreen;
267                 }
268         }
269         Py_RETURN_NONE;
270 }
271
272 //FIXME: correct "run/startlevel"
273 eAutoInitP0<eDVBCI_UI> init_dvbciui(eAutoInitNumbers::rc, "DVB-CI UI");