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)
47 if (eDVBCIInterfaces::getInstance()->getSlotState(slot) == eDVBCISlot::stateInvalid)
48 eDVBCIInterfaces::getInstance()->reset(slot);
49 return slotdata[slot].state;
54 void eDVBCI_UI::setState(int slot, int newState)
58 slotdata[slot].state = newState;
59 /*emit*/ ciStateChanged(slot);
63 std::string eDVBCI_UI::getAppName(int slot)
66 return slotdata[slot].appName;
70 void eDVBCI_UI::setAppName(int slot, const char *name)
73 slotdata[slot].appName = name;
76 void eDVBCI_UI::setInit(int slot)
78 eDVBCIInterfaces::getInstance()->initialize(slot);
81 void eDVBCI_UI::setReset(int slot)
83 eDVBCIInterfaces::getInstance()->reset(slot);
86 int eDVBCI_UI::startMMI(int slot)
88 eDVBCIInterfaces::getInstance()->startMMI(slot);
92 int eDVBCI_UI::stopMMI(int slot)
94 eDVBCIInterfaces::getInstance()->stopMMI(slot);
98 int eDVBCI_UI::answerMenu(int slot, int answer)
100 eDVBCIInterfaces::getInstance()->answerText(slot, answer);
104 int eDVBCI_UI::answerEnq(int slot, char *value)
106 eDVBCIInterfaces::getInstance()->answerEnq(slot, value);
110 int eDVBCI_UI::cancelEnq(int slot)
112 eDVBCIInterfaces::getInstance()->cancelEnq(slot);
116 int eDVBCI_UI::availableMMI(int slot)
118 if (slot < MAX_SLOTS)
119 return slotdata[slot].mmiScreenReady;
123 int eDVBCI_UI::mmiScreenClose(int slot, int timeout)
125 if (slot >= MAX_SLOTS)
128 slot_ui_data &data = slotdata[slot];
130 data.mmiScreenReady = 0;
133 Py_DECREF(data.mmiScreen);
134 data.mmiScreen = PyList_New(1);
136 PyObject *tuple = PyTuple_New(2);
137 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("CLOSE"));
138 PyTuple_SET_ITEM(tuple, 1, PyLong_FromLong(timeout));
139 PyList_SET_ITEM(data.mmiScreen, 0, tuple);
140 data.mmiScreenReady = 1;
141 /*emit*/ ciStateChanged(slot);
145 int eDVBCI_UI::mmiScreenEnq(int slot, int blind, int answerLen, char *text)
147 if (slot >= MAX_SLOTS)
150 slot_ui_data &data = slotdata[slot];
152 data.mmiScreenReady = 0;
155 Py_DECREF(data.mmiScreen);
156 data.mmiScreen = PyList_New(2);
158 PyObject *tuple = PyTuple_New(1);
159 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("ENQ"));
160 PyList_SET_ITEM(data.mmiScreen, 0, tuple);
162 tuple = PyTuple_New(4);
163 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("PIN"));
164 PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(answerLen));
165 PyTuple_SET_ITEM(tuple, 2, PyString_FromString(text));
166 PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(blind));
168 PyList_SET_ITEM(data.mmiScreen, 1, tuple);
170 data.mmiScreenReady = 1;
172 /*emit*/ ciStateChanged(slot);
177 int eDVBCI_UI::mmiScreenBegin(int slot, int listmenu)
179 if (slot >= MAX_SLOTS)
182 printf("eDVBCI_UI::mmiScreenBegin\n");
184 slot_ui_data &data = slotdata[slot];
186 data.mmiScreenReady = 0;
189 Py_DECREF(data.mmiScreen);
191 data.mmiScreen = PyList_New(1);
193 PyObject *tuple = PyTuple_New(1);
194 if (listmenu == 0) //menu
195 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("MENU"));
197 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("LIST"));
199 PyList_SET_ITEM(data.mmiScreen, 0, tuple);
201 data.mmiTuplePos = 1;
206 int eDVBCI_UI::mmiScreenAddText(int slot, int type, char *value)
208 if (slot >= MAX_SLOTS)
211 eDebug("eDVBCI_UI::mmiScreenAddText(%s)",value ? value : "");
213 slot_ui_data &data = slotdata[slot];
215 PyObject *tuple = PyTuple_New(3);
217 if (type == 0) //title
218 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("TITLE"));
219 else if (type == 1) //subtitle
220 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("SUBTITLE"));
221 else if (type == 2) //bottom
222 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("BOTTOM"));
224 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("TEXT"));
226 eDebug("addText %s with id %d", value, type);
228 PyTuple_SET_ITEM(tuple, 1, PyString_FromString(value));
231 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(type-2));
233 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(-1));
235 PyList_Append(data.mmiScreen, tuple);
241 int eDVBCI_UI::mmiScreenFinish(int slot)
243 if (slot < MAX_SLOTS)
245 printf("eDVBCI_UI::mmiScreenFinish\n");
246 slotdata[slot].mmiScreenReady = 1;
247 /*emit*/ ciStateChanged(slot);
252 void eDVBCI_UI::mmiSessionDestroyed(int slot)
254 /*emit*/ ciStateChanged(slot);
257 int eDVBCI_UI::getMMIState(int slot)
259 return eDVBCIInterfaces::getInstance()->getMMIState(slot);
262 PyObject *eDVBCI_UI::getMMIScreen(int slot)
264 if (slot < MAX_SLOTS)
266 slot_ui_data &data = slotdata[slot];
267 if (data.mmiScreenReady)
269 data.mmiScreenReady = 0;
270 Py_INCREF(data.mmiScreen);
271 return data.mmiScreen;
278 //FIXME: correct "run/startlevel"
279 eAutoInitP0<eDVBCI_UI> init_dvbciui(eAutoInitNumbers::rc, "DVB-CI UI");