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 eDVBCISlot::send(const unsigned char *data, size_t len)
132 // printf("%02x ",data[i]);
135 res = ::write(fd, data, len);
137 //printf("write() %d\n",res);
139 notifier->setRequested(eSocketNotifier::Read | eSocketNotifier::Priority | eSocketNotifier::Write);
144 void eDVBCISlot::data(int what)
146 if(what == eSocketNotifier::Priority) {
147 if(state != stateRemoved) {
148 state = stateRemoved;
149 printf("ci removed\n");
150 notifier->setRequested(eSocketNotifier::Read);
152 eDVBCI_UI::getInstance()->setState(0,0);
159 r = ::read(fd, data, 4096);
161 if(state != stateInserted) {
162 state = stateInserted;
163 eDebug("ci inserted");
166 eDVBCI_UI::getInstance()->setState(0,1);
168 /* enable PRI to detect removal or errors */
169 notifier->setRequested(eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Write);
176 // printf("%02x ",data[i]);
178 eDVBCISession::receiveData(this, data, r);
179 notifier->setRequested(eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Write);
183 if(what == eSocketNotifier::Write) {
184 if(eDVBCISession::pollAll() == 0) {
185 notifier->setRequested(eSocketNotifier::Read | eSocketNotifier::Priority);
190 DEFINE_REF(eDVBCISlot);
192 eDVBCISlot::eDVBCISlot(eMainloop *context, int nr)
196 application_manager = 0;
201 sprintf(filename, "/dev/ci%d", nr);
203 fd = ::open(filename, O_RDWR | O_NONBLOCK);
205 eDebug("eDVBCISlot has fd %d", fd);
207 state = stateInserted;
211 notifier = new eSocketNotifier(context, fd, eSocketNotifier::Read | eSocketNotifier::Priority);
212 CONNECT(notifier->activated, eDVBCISlot::data);
219 eDVBCISlot::~eDVBCISlot()
223 int eDVBCISlot::getSlotID()
228 int eDVBCISlot::reset()
230 printf("edvbcislot: reset requested\n");
237 int eDVBCISlot::initialize()
239 printf("edvbcislot: initialize()\n");
243 int eDVBCISlot::startMMI()
245 printf("edvbcislot: startMMI()\n");
247 if(application_manager)
248 application_manager->startMMI();
253 int eDVBCISlot::stopMMI()
255 printf("edvbcislot: stopMMI()\n");
258 mmi_session->stopMMI();
263 int eDVBCISlot::answerText(int answer)
265 printf("edvbcislot: answerText(%d)\n", answer);
268 mmi_session->answerText(answer);
273 int eDVBCISlot::answerEnq(int answer, char *value)
275 printf("edvbcislot: answerMMI(%d,%s)\n", answer, value);
279 eAutoInitP0<eDVBCIInterfaces> init_eDVBCIInterfaces(eAutoInitNumbers::dvb, "CI Slots");