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].mmiScreenReady=0;
23 slotdata[i].mmiTuplePos=0;
28 eDVBCI_UI::~eDVBCI_UI()
30 for(int i=0;i<MAX_SLOTS;++i)
32 if (slotdata[i].mmiScreen)
33 Py_DECREF(slotdata[i].mmiScreen);
37 eDVBCI_UI *eDVBCI_UI::getInstance()
42 int eDVBCI_UI::getState(int slot)
45 return slotdata[slot].state;
49 void eDVBCI_UI::setState(int slot, int newState)
53 slotdata[slot].state = newState;
54 /*emit*/ ciStateChanged(slot);
58 std::string eDVBCI_UI::getAppName(int slot)
61 return slotdata[slot].appName;
65 void eDVBCI_UI::setAppName(int slot, const char *name)
68 slotdata[slot].appName = name;
71 void eDVBCI_UI::setInit(int slot)
73 eDVBCIInterfaces::getInstance()->initialize(slot);
76 void eDVBCI_UI::setReset(int slot)
78 eDVBCIInterfaces::getInstance()->reset(slot);
81 int eDVBCI_UI::startMMI(int slot)
83 eDVBCIInterfaces::getInstance()->startMMI(slot);
87 int eDVBCI_UI::stopMMI(int slot)
89 eDVBCIInterfaces::getInstance()->stopMMI(slot);
93 int eDVBCI_UI::answerMenu(int slot, int answer)
95 eDVBCIInterfaces::getInstance()->answerText(slot, answer);
99 int eDVBCI_UI::answerEnq(int slot, char *value)
101 eDVBCIInterfaces::getInstance()->answerEnq(slot, value);
105 int eDVBCI_UI::cancelEnq(int slot)
107 eDVBCIInterfaces::getInstance()->cancelEnq(slot);
111 int eDVBCI_UI::availableMMI(int slot)
113 if (slot < MAX_SLOTS)
114 return slotdata[slot].mmiScreenReady;
118 int eDVBCI_UI::mmiScreenClose(int slot, int timeout)
120 if (slot >= MAX_SLOTS)
123 slot_ui_data &data = slotdata[slot];
125 data.mmiScreenReady = 0;
128 Py_DECREF(data.mmiScreen);
129 data.mmiScreen = PyList_New(1);
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);
140 int eDVBCI_UI::mmiScreenEnq(int slot, int blind, int answerLen, char *text)
142 if (slot >= MAX_SLOTS)
145 slot_ui_data &data = slotdata[slot];
147 data.mmiScreenReady = 0;
150 Py_DECREF(data.mmiScreen);
151 data.mmiScreen = PyList_New(2);
153 ePyObject tuple = PyTuple_New(1);
154 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("ENQ"));
155 PyList_SET_ITEM(data.mmiScreen, 0, tuple);
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));
163 PyList_SET_ITEM(data.mmiScreen, 1, tuple);
165 data.mmiScreenReady = 1;
167 /*emit*/ ciStateChanged(slot);
172 int eDVBCI_UI::mmiScreenBegin(int slot, int listmenu)
174 if (slot >= MAX_SLOTS)
177 eDebug("eDVBCI_UI::mmiScreenBegin");
179 slot_ui_data &data = slotdata[slot];
181 data.mmiScreenReady = 0;
184 Py_DECREF(data.mmiScreen);
186 data.mmiScreen = PyList_New(1);
188 ePyObject tuple = PyTuple_New(1);
189 if (listmenu == 0) //menu
190 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("MENU"));
192 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("LIST"));
194 PyList_SET_ITEM(data.mmiScreen, 0, tuple);
196 data.mmiTuplePos = 1;
201 int eDVBCI_UI::mmiScreenAddText(int slot, int type, char *value)
203 if (slot >= MAX_SLOTS)
206 eDebug("eDVBCI_UI::mmiScreenAddText(%s)",value ? value : "");
208 slot_ui_data &data = slotdata[slot];
210 ePyObject tuple = PyTuple_New(3);
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"));
219 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("TEXT"));
221 eDebug("addText %s with id %d", value, type);
223 PyTuple_SET_ITEM(tuple, 1, PyString_FromString(value));
226 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(type-2));
228 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(-1));
230 PyList_Append(data.mmiScreen, tuple);
236 int eDVBCI_UI::mmiScreenFinish(int slot)
238 if (slot < MAX_SLOTS)
240 eDebug("eDVBCI_UI::mmiScreenFinish");
241 slotdata[slot].mmiScreenReady = 1;
242 /*emit*/ ciStateChanged(slot);
247 void eDVBCI_UI::mmiSessionDestroyed(int slot)
249 /*emit*/ ciStateChanged(slot);
252 int eDVBCI_UI::getMMIState(int slot)
254 return eDVBCIInterfaces::getInstance()->getMMIState(slot);
257 PyObject *eDVBCI_UI::getMMIScreen(int slot)
259 if (slot < MAX_SLOTS)
261 slot_ui_data &data = slotdata[slot];
262 if (data.mmiScreenReady)
264 data.mmiScreenReady = 0;
265 Py_INCREF(data.mmiScreen);
266 return data.mmiScreen;
273 //FIXME: correct "run/startlevel"
274 eAutoInitP0<eDVBCI_UI> init_dvbciui(eAutoInitNumbers::rc, "DVB-CI UI");