return of void function should not return a value
[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::setReset(int slot)
64 {
65         eDVBCIInterfaces::getInstance()->reset(slot);
66         return;
67 }
68
69 int eDVBCI_UI::startMMI(int slot)
70 {
71         eDVBCIInterfaces::getInstance()->startMMI(slot);
72         return 0;
73 }
74
75 int eDVBCI_UI::stopMMI(int slot)
76 {
77         eDVBCIInterfaces::getInstance()->stopMMI(slot);
78         return 0;
79 }
80
81 int eDVBCI_UI::initialize(int slot)
82 {
83         eDVBCIInterfaces::getInstance()->initialize(slot);
84         return 0;
85 }
86
87 int eDVBCI_UI::answerMenu(int slot, int answer)
88 {
89         eDVBCIInterfaces::getInstance()->answerText(slot, answer);
90         return 0;
91 }
92
93 int eDVBCI_UI::answerEnq(int slot, char *value)
94 {
95         eDVBCIInterfaces::getInstance()->answerEnq(slot, value);
96         return 0;
97 }
98
99 int eDVBCI_UI::cancelEnq(int slot)
100 {
101         eDVBCIInterfaces::getInstance()->cancelEnq(slot);
102         return 0;
103 }
104
105 int eDVBCI_UI::availableMMI(int slot)
106 {
107         return mmiScreenReady;
108 }
109
110 int eDVBCI_UI::mmiScreenEnq(int slot, int blind, int answerLen, char *text)
111 {
112         mmiScreenReady = 0;
113
114         if(mmiScreen)
115                 Py_DECREF(mmiScreen);
116         mmiScreen = PyList_New(2);
117
118         PyObject *tuple = PyTuple_New(1);
119         PyTuple_SET_ITEM(tuple, 0, PyString_FromString("ENQ"));
120         PyList_SET_ITEM(mmiScreen, 0, tuple);
121
122         tuple = PyTuple_New(4);
123         PyTuple_SET_ITEM(tuple, 0, PyString_FromString("PIN"));
124         PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(answerLen));
125         PyTuple_SET_ITEM(tuple, 2, PyString_FromString(text));
126         PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(blind));
127
128         PyList_SET_ITEM(mmiScreen, 1, tuple);
129
130         mmiScreenReady = 1;
131
132         return 0;
133 }
134
135 int eDVBCI_UI::mmiScreenBegin(int slot, int listmenu)
136 {
137         printf("eDVBCI_UI::mmiScreenBegin\n");
138
139         mmiScreenReady = 0;
140
141         if(mmiScreen)
142                 Py_DECREF(mmiScreen);
143         mmiScreen = PyList_New(1);
144
145         PyObject *tuple = PyTuple_New(1);
146         if(listmenu == 0)                               //menu
147                 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("MENU"));
148         else    //list
149                 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("LIST"));
150
151         PyList_SET_ITEM(mmiScreen, 0, tuple);
152
153         mmiTuplePos = 1;
154
155         return 0;
156 }
157
158 int eDVBCI_UI::mmiScreenAddText(int slot, int type, char *value)
159 {
160         eDebug("eDVBCI_UI::mmiScreenAddText(%s)",value);
161
162         PyObject *tuple = PyTuple_New(3);
163
164         if(type == 0)                                   //title
165                 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("TITLE"));
166         else if(type == 1)                              //subtitle
167                 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("SUBTITLE"));
168         else if(type == 2)                              //bottom
169                 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("BOTTOM"));
170         else
171                 PyTuple_SET_ITEM(tuple, 0, PyString_FromString("TEXT"));
172
173         eDebug("addText %s with id %d", value, type);
174
175         PyTuple_SET_ITEM(tuple, 1, PyString_FromString(value));
176
177         if(type > 2)
178                 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(type-2));
179         else
180                 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(-1));
181
182         PyList_Append(mmiScreen, tuple);
183         Py_DECREF(tuple);
184
185         return 0;
186 }
187
188 int eDVBCI_UI::mmiScreenFinish(int slot)
189 {
190         printf("eDVBCI_UI::mmiScreenFinish\n");
191
192         mmiScreenReady = 1;
193
194         return 0;
195 }
196
197 int eDVBCI_UI::getMMIState(int slot)
198 {
199         return eDVBCIInterfaces::getInstance()->getMMIState(slot);
200 }
201
202 PyObject *eDVBCI_UI::getMMIScreen(int slot)
203 {
204         if(mmiScreenReady)
205         {
206                 mmiScreenReady = 0;
207                 Py_INCREF(mmiScreen);
208                 return mmiScreen;
209         }
210         Py_INCREF(Py_None);
211         return Py_None;
212 }
213
214 //FIXME: correct "run/startlevel"
215 eAutoInitP0<eDVBCI_UI> init_dvbciui(eAutoInitNumbers::rc, "DVB-CI UI");