4 #include <lib/base/init.h>
5 #include <lib/base/init_num.h>
6 #include <lib/base/ebase.h>
8 #include <lib/base/eerror.h>
9 #include <lib/dvb_ci/dvbci.h>
10 #include <lib/dvb_ci/dvbci_session.h>
12 #include <lib/dvb_ci/dvbci_ui.h>
13 #include <lib/dvb_ci/dvbci_appmgr.h>
14 #include <lib/dvb_ci/dvbci_mmi.h>
16 eDVBCIInterfaces *eDVBCIInterfaces::instance = 0;
18 eDVBCIInterfaces::eDVBCIInterfaces()
24 eDebug("scanning for common interfaces..");
30 sprintf(filename, "/dev/ci%d", num_ci);
32 if (stat(filename, &s))
35 ePtr<eDVBCISlot> cislot;
37 cislot = new eDVBCISlot(eApp, num_ci);
38 m_slots.push_back(cislot);
43 eDebug("done, found %d common interface slots", num_ci);
46 eDVBCIInterfaces::~eDVBCIInterfaces()
50 eDVBCIInterfaces *eDVBCIInterfaces::getInstance()
55 eDVBCISlot *eDVBCIInterfaces::getSlot(int slotid)
57 for(eSmartPtrList<eDVBCISlot>::iterator i(m_slots.begin()); i != m_slots.end(); ++i)
58 if(i->getSlotID() == slotid)
61 printf("FIXME: request for unknown slot\n");
66 int eDVBCIInterfaces::reset(int slotid)
70 if( (slot = getSlot(slotid)) == 0 )
76 int eDVBCIInterfaces::initialize(int slotid)
80 if( (slot = getSlot(slotid)) == 0 )
83 return slot->initialize();
86 int eDVBCIInterfaces::startMMI(int slotid)
90 if( (slot = getSlot(slotid)) == 0 )
93 return slot->startMMI();
96 int eDVBCIInterfaces::stopMMI(int slotid)
100 if( (slot = getSlot(slotid)) == 0 )
103 return slot->stopMMI();
106 int eDVBCIInterfaces::answerText(int slotid, int answer)
110 if( (slot = getSlot(slotid)) == 0 )
113 return slot->answerText(answer);
116 int eDVBCIInterfaces::answerEnq(int slotid, int answer, char *value)
120 if( (slot = getSlot(slotid)) == 0 )
123 return slot->answerEnq(answer, value);
126 int eDVBCIInterfaces::getMMIState(int slotid)
130 if( (slot = getSlot(slotid)) == 0 )
133 return slot->getMMIState();
136 int eDVBCISlot::send(const unsigned char *data, size_t len)
142 // printf("%02x ",data[i]);
145 res = ::write(fd, data, len);
147 //printf("write() %d\n",res);
149 notifier->setRequested(eSocketNotifier::Read | eSocketNotifier::Priority | eSocketNotifier::Write);
154 void eDVBCISlot::data(int what)
156 if(what == eSocketNotifier::Priority) {
157 if(state != stateRemoved) {
158 state = stateRemoved;
159 printf("ci removed\n");
160 notifier->setRequested(eSocketNotifier::Read);
162 eDVBCI_UI::getInstance()->setState(0,0);
169 r = ::read(fd, data, 4096);
171 if(state != stateInserted) {
172 state = stateInserted;
173 eDebug("ci inserted");
176 eDVBCI_UI::getInstance()->setState(0,1);
178 /* enable PRI to detect removal or errors */
179 notifier->setRequested(eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Write);
186 // printf("%02x ",data[i]);
188 eDVBCISession::receiveData(this, data, r);
189 notifier->setRequested(eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Write);
193 if(what == eSocketNotifier::Write) {
194 if(eDVBCISession::pollAll() == 0) {
195 notifier->setRequested(eSocketNotifier::Read | eSocketNotifier::Priority);
200 DEFINE_REF(eDVBCISlot);
202 eDVBCISlot::eDVBCISlot(eMainloop *context, int nr)
206 application_manager = 0;
211 sprintf(filename, "/dev/ci%d", nr);
213 fd = ::open(filename, O_RDWR | O_NONBLOCK);
215 eDebug("eDVBCISlot has fd %d", fd);
217 state = stateInserted;
221 notifier = new eSocketNotifier(context, fd, eSocketNotifier::Read | eSocketNotifier::Priority);
222 CONNECT(notifier->activated, eDVBCISlot::data);
229 eDVBCISlot::~eDVBCISlot()
233 int eDVBCISlot::getSlotID()
238 int eDVBCISlot::reset()
240 printf("edvbcislot: reset requested\n");
247 int eDVBCISlot::initialize()
249 printf("edvbcislot: initialize()\n");
253 int eDVBCISlot::startMMI()
255 printf("edvbcislot: startMMI()\n");
257 if(application_manager)
258 application_manager->startMMI();
263 int eDVBCISlot::stopMMI()
265 printf("edvbcislot: stopMMI()\n");
268 mmi_session->stopMMI();
273 int eDVBCISlot::answerText(int answer)
275 printf("edvbcislot: answerText(%d)\n", answer);
278 mmi_session->answerText(answer);
283 int eDVBCISlot::getMMIState()
291 int eDVBCISlot::answerEnq(int answer, char *value)
293 printf("edvbcislot: answerMMI(%d,%s)\n", answer, value);
297 eAutoInitP0<eDVBCIInterfaces> init_eDVBCIInterfaces(eAutoInitNumbers::dvb, "CI Slots");