1 #include <lib/dvb_ci/dvbci_ui.h>
2 #include <lib/dvb_ci/dvbci.h>
10 #include <lib/base/init.h>
11 #include <lib/base/init_num.h>
12 #include <lib/base/eerror.h>
14 eDVBCI_UI *eDVBCI_UI::instance;
16 eDVBCI_UI::eDVBCI_UI()
20 for(int i=0;i<MAX_SLOTS;++i)
22 slotdata[i].mmiScreen=NULL;
23 slotdata[i].mmiScreenReady=0;
24 slotdata[i].mmiTuplePos=0;
29 eDVBCI_UI::~eDVBCI_UI()
31 for(int i=0;i<MAX_SLOTS;++i)
33 if (slotdata[i].mmiScreen)
34 Py_DECREF(slotdata[i].mmiScreen);
38 eDVBCI_UI *eDVBCI_UI::getInstance()
43 int eDVBCI_UI::getState(int slot)
46 return slotdata[slot].state;
50 void eDVBCI_UI::setState(int slot, int newState)
54 slotdata[slot].state = newState;
55 /*emit*/ ciStateChanged(slot);
59 std::string eDVBCI_UI::getAppName(int slot)
62 return slotdata[slot].appName;
66 void eDVBCI_UI::setAppName(int slot, const char *name)
69 slotdata[slot].appName = name;
72 void eDVBCI_UI::setInit(int slot)
74 eDVBCIInterfaces::getInstance()->initialize(slot);
77 void eDVBCI_UI::setReset(int slot)
79 eDVBCIInterfaces::getInstance()->reset(slot);
82 int eDVBCI_UI::startMMI(int slot)
84 eDVBCIInterfaces::getInstance()->startMMI(slot);
88 int eDVBCI_UI::stopMMI(int slot)
90 eDVBCIInterfaces::getInstance()->stopMMI(slot);
94 int eDVBCI_UI::answerMenu(int slot, int answer)
96 eDVBCIInterfaces::getInstance()->answerText(slot, answer);
100 int eDVBCI_UI::answerEnq(int slot, char *value)
102 eDVBCIInterfaces::getInstance()->answerEnq(slot, value);
106 int eDVBCI_UI::cancelEnq(int slot)
108 eDVBCIInterfaces::getInstance()->cancelEnq(slot);
112 int eDVBCI_UI::availableMMI(int slot)
114 if (slot < MAX_SLOTS)
115 return slotdata[slot].mmiScreenReady;
119 int eDVBCI_UI::mmiScreenClose(int slot, int timeout)
121 if (slot >= MAX_SLOTS)
124 slot_ui_data &data = slotdata[slot];
126 data.mmiScreenReady = 0;
129 Py_DECREF(data.mmiScreen);
130 data.mmiScreen = PyList_New(1);
132 PyObject *tuple = PyTuple_New(2);
133 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("CLOSE"));
134 PyTuple_SET_ITEM(tuple, 1, PyLong_FromLong(timeout));
135 PyList_SET_ITEM(data.mmiScreen, 0, tuple);
136 data.mmiScreenReady = 1;
137 /*emit*/ ciStateChanged(slot);
141 int eDVBCI_UI::mmiScreenEnq(int slot, int blind, int answerLen, char *text)
143 if (slot >= MAX_SLOTS)
146 slot_ui_data &data = slotdata[slot];
148 data.mmiScreenReady = 0;
151 Py_DECREF(data.mmiScreen);
152 data.mmiScreen = PyList_New(2);
154 PyObject *tuple = PyTuple_New(1);
155 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("ENQ"));
156 PyList_SET_ITEM(data.mmiScreen, 0, tuple);
158 tuple = PyTuple_New(4);
159 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("PIN"));
160 PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(answerLen));
161 PyTuple_SET_ITEM(tuple, 2, PyString_FromString(text));
162 PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(blind));
164 PyList_SET_ITEM(data.mmiScreen, 1, tuple);
166 data.mmiScreenReady = 1;
168 /*emit*/ ciStateChanged(slot);
173 int eDVBCI_UI::mmiScreenBegin(int slot, int listmenu)
175 if (slot >= MAX_SLOTS)
178 eDebug("eDVBCI_UI::mmiScreenBegin");
180 slot_ui_data &data = slotdata[slot];
182 data.mmiScreenReady = 0;
185 Py_DECREF(data.mmiScreen);
187 data.mmiScreen = PyList_New(1);
189 PyObject *tuple = PyTuple_New(1);
190 if (listmenu == 0) //menu
191 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("MENU"));
193 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("LIST"));
195 PyList_SET_ITEM(data.mmiScreen, 0, tuple);
197 data.mmiTuplePos = 1;
202 int eDVBCI_UI::mmiScreenAddText(int slot, int type, char *value)
204 if (slot >= MAX_SLOTS)
207 eDebug("eDVBCI_UI::mmiScreenAddText(%s)",value ? value : "");
209 slot_ui_data &data = slotdata[slot];
211 PyObject *tuple = PyTuple_New(3);
213 if (type == 0) //title
214 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("TITLE"));
215 else if (type == 1) //subtitle
216 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("SUBTITLE"));
217 else if (type == 2) //bottom
218 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("BOTTOM"));
220 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("TEXT"));
222 eDebug("addText %s with id %d", value, type);
224 PyTuple_SET_ITEM(tuple, 1, PyString_FromString(value));
227 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(type-2));
229 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(-1));
231 PyList_Append(data.mmiScreen, tuple);
237 int eDVBCI_UI::mmiScreenFinish(int slot)
239 if (slot < MAX_SLOTS)
241 eDebug("eDVBCI_UI::mmiScreenFinish");
242 slotdata[slot].mmiScreenReady = 1;
243 /*emit*/ ciStateChanged(slot);
248 void eDVBCI_UI::mmiSessionDestroyed(int slot)
250 /*emit*/ ciStateChanged(slot);
253 int eDVBCI_UI::getMMIState(int slot)
255 return eDVBCIInterfaces::getInstance()->getMMIState(slot);
258 PyObject *eDVBCI_UI::getMMIScreen(int slot)
260 if (slot < MAX_SLOTS)
262 slot_ui_data &data = slotdata[slot];
263 if (data.mmiScreenReady)
265 data.mmiScreenReady = 0;
266 Py_INCREF(data.mmiScreen);
267 return data.mmiScreen;
274 //FIXME: correct "run/startlevel"
275 eAutoInitP0<eDVBCI_UI> init_dvbciui(eAutoInitNumbers::rc, "DVB-CI UI");