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