fix: e2 didn't start when no sat-frontend was detected
[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
48 std::string eDVBCI_UI::getAppName(int slot)
49 {
50         return appName;
51 }
52
53 void eDVBCI_UI::setAppName(int slot, const char *name)
54 {
55         //printf("set name to -%c-\n", name);
56         appName = name;
57 }
58
59 void eDVBCI_UI::setReset(int slot)
60 {
61         eDVBCIInterfaces::getInstance()->reset(slot);
62 }
63
64 int eDVBCI_UI::startMMI(int slot)
65 {
66         eDVBCIInterfaces::getInstance()->startMMI(slot);
67 }
68
69 int eDVBCI_UI::stopMMI(int slot)
70 {
71         eDVBCIInterfaces::getInstance()->stopMMI(slot);
72 }
73
74 int eDVBCI_UI::initialize(int slot)
75 {
76         eDVBCIInterfaces::getInstance()->initialize(slot);
77 }
78
79 int eDVBCI_UI::answerMenu(int slot, int answer)
80 {
81         eDVBCIInterfaces::getInstance()->answerText(slot, answer);
82 }
83
84 int eDVBCI_UI::answerEnq(int slot, int answer, char *value)
85 {
86         eDVBCIInterfaces::getInstance()->answerEnq(slot, answer, value);
87 }
88
89 int eDVBCI_UI::availableMMI(int slot)
90 {
91         return mmiScreenReady;
92 }
93
94 int eDVBCI_UI::mmiScreenBegin(int slot, int listmenu)
95 {
96         printf("eDVBCI_UI::mmiScreenBegin\n");
97
98         mmiScreenReady = 0;
99         
100         mmiScreen = PyList_New(1);
101
102   PyObject *tuple = PyTuple_New(1);
103         if(listmenu)
104                 PyTuple_SetItem(tuple, 0, PyString_FromString("LIST"));
105         else    
106                 PyTuple_SetItem(tuple, 0, PyString_FromString("MENU"));
107   PyList_SetItem(mmiScreen, 0, tuple);
108         
109         mmiTuplePos = 1;
110         
111         return 0;
112 }
113
114 int eDVBCI_UI::mmiScreenAddText(int slot, int type, char *value)
115 {
116         printf("eDVBCI_UI::mmiScreenAddText(%s)\n",value);
117
118   PyObject *tuple = PyTuple_New(3);
119         
120         if(type == 0)                                                   //title
121                 PyTuple_SetItem(tuple, 0, PyString_FromString("TITLE"));
122         else if(type == 1)                              //subtitle
123                 PyTuple_SetItem(tuple, 0, PyString_FromString("SUBTITLE"));
124         else if(type == 2)                              //bottom
125                 PyTuple_SetItem(tuple, 0, PyString_FromString("BOTTOM"));
126         else
127                 PyTuple_SetItem(tuple, 0, PyString_FromString("TEXT"));
128
129         printf("addText %s with id %d\n", value, type);
130
131         PyTuple_SetItem(tuple, 1, PyString_FromString(value));
132         
133         if(type > 2)
134           PyTuple_SetItem(tuple, 2, PyInt_FromLong(type-2));
135         else    
136           PyTuple_SetItem(tuple, 2, PyInt_FromLong(-1));
137         
138         PyList_Append(mmiScreen, tuple);
139         
140         return 0;
141 }
142
143 int eDVBCI_UI::mmiScreenFinish(int slot)
144 {
145         printf("eDVBCI_UI::mmiScreenFinish\n");
146
147         mmiScreenReady = 1;
148
149         return 0;
150 }
151
152 PyObject *eDVBCI_UI::getMMIScreen(int slot)
153 {
154         if(mmiScreenReady != 1)
155                 return Py_None;
156                 
157         mmiScreenReady = 0;
158
159         return mmiScreen;
160 }
161
162 //FIXME: correct "run/startlevel"
163 eAutoInitP0<eDVBCI_UI> init_dvbciui(eAutoInitNumbers::rc, "DVB-CI UI");