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