1 #include <lib/mmi/mmi_ui.h>
2 #include <lib/dvb_ci/dvbci_session.h> // for parseLengthField
8 #include <lib/base/init.h>
9 #include <lib/base/init_num.h>
10 #include <lib/base/eerror.h>
11 #include <lib/base/estring.h>
13 eMMI_UI::eMMI_UI(int max_slots)
14 :m_max_slots(max_slots)
16 slotdata = new slot_ui_data[m_max_slots];
17 for(int i=0;i<m_max_slots;++i)
19 slotdata[i].mmiScreenReady=0;
20 slotdata[i].mmiTuplePos=0;
27 for(int i=0;i<m_max_slots;++i)
29 if (slotdata[i].mmiScreen)
30 Py_DECREF(slotdata[i].mmiScreen);
35 int eMMI_UI::processMMIData(int slot_id, const unsigned char *tag, const void *data, int len)
39 case 0x00: //Tmmi_close
41 unsigned char *d=(unsigned char*)data;
49 eDebug("mmi close tag incorrect.. no timeout given.. assume 5 seconds");
54 eDebug("mmi close tag incorrect.. byte 4 should be 0 or 1");
55 mmiScreenClose(slot_id, timeout);
59 eDebug("MMI display control");
60 if (((unsigned char*)data)[0] != 1)
61 eDebug("kann ich nicht. aber das sag ich dem modul nicht.");
63 case 0x07: //Tmenu_enq
65 unsigned char *d=(unsigned char*)data;
66 unsigned char *max=((unsigned char*)d) + len;
67 int textlen = len - 2;
73 eDebug("%d bytes text", textlen);
74 if ((d+textlen) > max)
76 char str[textlen + 1];
77 memcpy(str, ((char*)d), textlen);
79 eDebug("enq-text: %s",str);
80 mmiScreenEnq(slot_id, blind, alen, (char*)convertDVBUTF8(str).c_str());
83 case 0x09: //Tmenu_last
84 case 0x0c: //Tlist_last
86 unsigned char *d=(unsigned char*)data;
87 unsigned char *max=((unsigned char*)d) + len;
93 if(tag[2] == 0x09) //menu
94 mmiScreenBegin(slot_id, 0);
96 mmiScreenBegin(slot_id, 1);
101 eDebug("%d texts", n);
102 for (int i=0; i < (n+3); ++i)
107 eDebug("text tag: %02x %02x %02x", d[0], d[1], d[2]);
109 d+=eDVBCISession::parseLengthField(d, textlen);
110 eDebug("%d bytes text", textlen);
111 if ((d+textlen) > max)
113 char str[textlen + 1];
114 memcpy(str, ((char*)d), textlen);
116 mmiScreenAddText(slot_id, pos++, (char*)convertDVBUTF8(str).c_str());
118 eDebugNoNewLine("%c", *d++);
121 mmiScreenFinish(slot_id);
125 eDebug("unknown APDU tag 9F 88 %02x", tag[2]);
131 int eMMI_UI::getState(int slot)
133 if (slot < m_max_slots)
134 return slotdata[slot].state;
138 void eMMI_UI::setState(int slot, int newState)
140 if (slot < m_max_slots)
142 slotdata[slot].state = newState;
147 std::string eMMI_UI::getAppName(int slot)
149 if (slot < m_max_slots)
150 return slotdata[slot].appName;
154 void eMMI_UI::setAppName(int slot, const char *name)
156 if (slot < m_max_slots)
157 slotdata[slot].appName = name;
160 int eMMI_UI::availableMMI(int slot)
162 if (slot < m_max_slots)
163 return slotdata[slot].mmiScreenReady;
167 int eMMI_UI::mmiScreenClose(int slot, int timeout)
169 if (slot >= m_max_slots)
172 slot_ui_data &data = slotdata[slot];
174 data.mmiScreenReady = 0;
177 Py_DECREF(data.mmiScreen);
178 data.mmiScreen = PyList_New(1);
180 ePyObject tuple = PyTuple_New(2);
181 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("CLOSE"));
182 PyTuple_SET_ITEM(tuple, 1, PyLong_FromLong(timeout));
183 PyList_SET_ITEM(data.mmiScreen, 0, tuple);
184 data.mmiScreenReady = 1;
189 int eMMI_UI::mmiScreenEnq(int slot, int blind, int answerLen, char *text)
191 if (slot >= m_max_slots)
194 slot_ui_data &data = slotdata[slot];
196 data.mmiScreenReady = 0;
199 Py_DECREF(data.mmiScreen);
200 data.mmiScreen = PyList_New(2);
202 ePyObject tuple = PyTuple_New(1);
203 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("ENQ"));
204 PyList_SET_ITEM(data.mmiScreen, 0, tuple);
206 tuple = PyTuple_New(4);
207 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("PIN"));
208 PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(answerLen));
209 PyTuple_SET_ITEM(tuple, 2, PyString_FromString(text));
210 PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(blind));
212 PyList_SET_ITEM(data.mmiScreen, 1, tuple);
214 data.mmiScreenReady = 1;
221 int eMMI_UI::mmiScreenBegin(int slot, int listmenu)
223 if (slot >= m_max_slots)
226 eDebug("eMMI_UI::mmiScreenBegin");
228 slot_ui_data &data = slotdata[slot];
230 data.mmiScreenReady = 0;
233 Py_DECREF(data.mmiScreen);
235 data.mmiScreen = PyList_New(1);
237 ePyObject tuple = PyTuple_New(1);
238 if (listmenu == 0) //menu
239 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("MENU"));
241 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("LIST"));
243 PyList_SET_ITEM(data.mmiScreen, 0, tuple);
245 data.mmiTuplePos = 1;
250 int eMMI_UI::mmiScreenAddText(int slot, int type, char *value)
252 if (slot >= m_max_slots)
255 eDebug("eMMI_UI::mmiScreenAddText(%s)",value ? value : "");
257 slot_ui_data &data = slotdata[slot];
259 ePyObject tuple = PyTuple_New(3);
261 if (type == 0) //title
262 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("TITLE"));
263 else if (type == 1) //subtitle
264 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("SUBTITLE"));
265 else if (type == 2) //bottom
266 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("BOTTOM"));
268 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("TEXT"));
270 eDebug("addText %s with id %d", value, type);
272 PyTuple_SET_ITEM(tuple, 1, PyString_FromString(value));
275 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(type-2));
277 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(-1));
279 PyList_Append(data.mmiScreen, tuple);
285 int eMMI_UI::mmiScreenFinish(int slot)
287 if (slot < m_max_slots)
289 eDebug("eMMI_UI::mmiScreenFinish");
290 slotdata[slot].mmiScreenReady = 1;
296 void eMMI_UI::mmiSessionDestroyed(int slot)
298 mmiScreenClose(slot, 0);
301 PyObject *eMMI_UI::getMMIScreen(int slot)
303 if (slot < m_max_slots)
305 slot_ui_data &data = slotdata[slot];
306 if (data.mmiScreenReady)
308 data.mmiScreenReady = 0;
309 Py_INCREF(data.mmiScreen);
310 return data.mmiScreen;