fix non working ENQ fields in CI mmi (PIN inputs and other)
[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/econfig.h>
13 #include <lib/base/eerror.h>
14
15 eDVBCI_UI *eDVBCI_UI::instance = 0;
16
17 eDVBCI_UI::eDVBCI_UI()
18         :mmiScreen(NULL)
19         ,mmiTuplePos(0)
20         ,mmiScreenReady(0)
21 {
22         ASSERT(!instance);
23         instance = this;
24         for(int i=0;i<MAX_SLOTS;i++)
25                 state[i] = 0;           //no module
26 }
27
28 eDVBCI_UI::~eDVBCI_UI()
29 {
30         if(mmiScreen)
31                 Py_DECREF(mmiScreen);
32 }
33
34 eDVBCI_UI *eDVBCI_UI::getInstance()
35 {
36         return instance;
37 }
38
39 int eDVBCI_UI::getState(int slot)
40 {
41         return state[slot];     //exploit me ;)
42 }
43
44 void eDVBCI_UI::setState(int slot, int newState)
45 {
46         state[slot] = newState;
47         
48         if(newState == 2)               //enable TS
49                 eDVBCIInterfaces::getInstance()->enableTS(slot, 1);
50 }
51
52 std::string eDVBCI_UI::getAppName(int slot)
53 {
54         return appName;
55 }
56
57 void eDVBCI_UI::setAppName(int slot, const char *name)
58 {
59         //printf("set name to -%c-\n", name);
60         appName = name;
61 }
62
63 void eDVBCI_UI::setInit(int slot)
64 {
65         eDVBCIInterfaces::getInstance()->sendCAPMT(slot);
66 }
67
68 void eDVBCI_UI::setReset(int slot)
69 {
70         eDVBCIInterfaces::getInstance()->reset(slot);
71 }
72
73 int eDVBCI_UI::startMMI(int slot)
74 {
75         eDVBCIInterfaces::getInstance()->startMMI(slot);
76         return 0;
77 }
78
79 int eDVBCI_UI::stopMMI(int slot)
80 {
81         eDVBCIInterfaces::getInstance()->stopMMI(slot);
82         return 0;
83 }
84
85 int eDVBCI_UI::initialize(int slot)
86 {
87         eDVBCIInterfaces::getInstance()->initialize(slot);
88         return 0;
89 }
90
91 int eDVBCI_UI::answerMenu(int slot, int answer)
92 {
93         eDVBCIInterfaces::getInstance()->answerText(slot, answer);
94         return 0;
95 }
96
97 int eDVBCI_UI::answerEnq(int slot, char *value)
98 {
99         eDVBCIInterfaces::getInstance()->answerEnq(slot, value);
100         return 0;
101 }
102
103 int eDVBCI_UI::cancelEnq(int slot)
104 {
105         eDVBCIInterfaces::getInstance()->cancelEnq(slot);
106         return 0;
107 }
108
109 int eDVBCI_UI::availableMMI(int slot)
110 {
111         return mmiScreenReady;
112 }
113
114 int eDVBCI_UI::mmiScreenEnq(int slot, int blind, int answerLen, char *text)
115 {
116         mmiScreenReady = 0;
117
118         if(mmiScreen)
119                 Py_DECREF(mmiScreen);
120         mmiScreen = PyList_New(2);
121
122         PyObject *tuple = PyTuple_New(1);
123         PyTuple_SET_ITEM(tuple, 0, PyString_FromString("ENQ"));
124         PyList_SET_ITEM(mmiScreen, 0, tuple);
125
126         tuple = PyTuple_New(4);
127         PyTuple_SET_ITEM(tuple, 0, PyString_FromString("PIN"));
128         PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(answerLen));
129         PyTuple_SET_ITEM(tuple, 2, PyString_FromString(text));
130         PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(blind));
131
132         PyList_SET_ITEM(mmiScreen, 1, tuple);
133
134         mmiScreenReady = 1;
135
136         return 0;
137 }
138
139 int eDVBCI_UI::mmiScreenBegin(int slot, int listmenu)
140 {
141         printf("eDVBCI_UI::mmiScreenBegin\n");
142
143         mmiScreenReady = 0;
144
145         if(mmiScreen)
146                 Py_DECREF(mmiScreen);
147         mmiScreen = PyList_New(1);
148
149         PyObject *tuple = PyTuple_New(1);
150         if(listmenu == 0)                               //menu
151                 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("MENU"));
152         else    //list
153                 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("LIST"));
154
155         PyList_SET_ITEM(mmiScreen, 0, tuple);
156
157         mmiTuplePos = 1;
158
159         return 0;
160 }
161
162 int eDVBCI_UI::mmiScreenAddText(int slot, int type, char *value)
163 {
164         eDebug("eDVBCI_UI::mmiScreenAddText(%s)",value);
165
166         PyObject *tuple = PyTuple_New(3);
167
168         if(type == 0)                                   //title
169                 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("TITLE"));
170         else if(type == 1)                              //subtitle
171                 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("SUBTITLE"));
172         else if(type == 2)                              //bottom
173                 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("BOTTOM"));
174         else
175                 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("TEXT"));
176
177         eDebug("addText %s with id %d", value, type);
178
179         PyTuple_SET_ITEM(tuple, 1, PyString_FromString(value));
180
181         if(type > 2)
182                 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(type-2));
183         else
184                 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(-1));
185
186         PyList_Append(mmiScreen, tuple);
187         Py_DECREF(tuple);
188
189         return 0;
190 }
191
192 int eDVBCI_UI::mmiScreenFinish(int slot)
193 {
194         printf("eDVBCI_UI::mmiScreenFinish\n");
195
196         mmiScreenReady = 1;
197
198         return 0;
199 }
200
201 int eDVBCI_UI::getMMIState(int slot)
202 {
203         return eDVBCIInterfaces::getInstance()->getMMIState(slot);
204 }
205
206 PyObject *eDVBCI_UI::getMMIScreen(int slot)
207 {
208         if(mmiScreenReady)
209         {
210                 mmiScreenReady = 0;
211                 Py_INCREF(mmiScreen);
212                 return mmiScreen;
213         }
214         Py_INCREF(Py_None);
215         return Py_None;
216 }
217
218 //FIXME: correct "run/startlevel"
219 eAutoInitP0<eDVBCI_UI> init_dvbciui(eAutoInitNumbers::rc, "DVB-CI UI");