+ return slot->answerText(answer);
+}
+
+int eDVBCIInterfaces::answerEnq(int slotid, char *value)
+{
+ eDVBCISlot *slot;
+
+ if( (slot = getSlot(slotid)) == 0 )
+ return -1;
+
+ return slot->answerEnq(value);
+}
+
+int eDVBCIInterfaces::cancelEnq(int slotid)
+{
+ eDVBCISlot *slot;
+
+ if( (slot = getSlot(slotid)) == 0 )
+ return -1;
+
+ return slot->cancelEnq();
+}
+
+void eDVBCIInterfaces::addPMTHandler(eDVBServicePMTHandler *pmthandler)
+{
+ CIPmtHandler new_handler(pmthandler);
+
+ eServiceReferenceDVB service;
+ pmthandler->getService(service);
+
+ eDebug("[eDVBCIInterfaces] addPMTHandler %s", service.toString().c_str());
+
+ // HACK the first service get the CI..
+ eSmartPtrList<eDVBCISlot>::iterator ci_it(m_slots.begin());
+ for (; ci_it != m_slots.end(); ++ci_it)
+ {
+ if (ci_it->use_count)
+ continue;
+ ci_it->use_count=1;
+ new_handler.cislot = ci_it;
+ new_handler.cislot->resetPrevSentCAPMTVersion();
+ }
+
+ if (ci_it == m_slots.end())
+ {
+ PMTHandlerList::iterator it = m_pmt_handlers.begin();
+ while (it != m_pmt_handlers.end())
+ {
+ eServiceReferenceDVB ref;
+ it->pmthandler->getService(ref);
+ if ( service == ref && it->cislot )
+ {
+ new_handler.cislot = it->cislot;
+ ++new_handler.cislot->use_count;
+ break;
+ }
+ ++it;
+ }
+ }
+
+ m_pmt_handlers.push_back(new_handler);
+}
+
+void eDVBCIInterfaces::removePMTHandler(eDVBServicePMTHandler *pmthandler)
+{
+ PMTHandlerList::iterator it=std::find(m_pmt_handlers.begin(),m_pmt_handlers.end(),pmthandler);
+ if (it != m_pmt_handlers.end())
+ {
+ eDVBCISlot *slot = it->cislot;
+ eDVBServicePMTHandler *pmthandler = it->pmthandler;
+ m_pmt_handlers.erase(it);
+ if (slot && !--slot->use_count)
+ {
+#if 0
+ eDebug("[eDVBCIInterfaces] remove last pmt handler for service %s send empty capmt");
+ std::vector<uint16_t> caids;
+ caids.push_back(0xFFFF);
+ slot->resetPrevSentCAPMTVersion();
+ slot->sendCAPMT(pmthandler, caids);
+#endif
+ // check if another service is running
+ it = m_pmt_handlers.begin();
+ while (it != m_pmt_handlers.end())
+ {
+ if ( !it->cislot )
+ {
+ it->cislot = slot;
+ ++slot->use_count;
+ slot->resetPrevSentCAPMTVersion();
+ slot->sendCAPMT(it->pmthandler);
+ break;
+ }
+ ++it;
+ }
+ }
+ }
+}
+
+void eDVBCIInterfaces::gotPMT(eDVBServicePMTHandler *pmthandler)
+{
+ eDebug("[eDVBCIInterfaces] gotPMT");
+ PMTHandlerList::iterator it=std::find(m_pmt_handlers.begin(), m_pmt_handlers.end(), pmthandler);
+ eServiceReferenceDVB service;
+ if ( it != m_pmt_handlers.end() && it->cislot)
+ it->cislot->sendCAPMT(pmthandler);
+}
+
+int eDVBCIInterfaces::getMMIState(int slotid)
+{
+ eDVBCISlot *slot;
+
+ if( (slot = getSlot(slotid)) == 0 )
+ return -1;
+
+ return slot->getMMIState();
+}
+
+int eDVBCISlot::send(const unsigned char *data, size_t len)
+{
+ int res;
+ //int i;
+ //printf("< ");
+ //for(i=0;i<len;i++)
+ // printf("%02x ",data[i]);
+ //printf("\n");
+
+ res = ::write(fd, data, len);
+
+ //printf("write() %d\n",res);
+
+ notifier->setRequested(eSocketNotifier::Read | eSocketNotifier::Priority | eSocketNotifier::Write);
+
+ return res;
+}
+
+void eDVBCISlot::data(int what)
+{
+ if(what == eSocketNotifier::Priority) {
+ if(state != stateRemoved) {
+ state = stateRemoved;
+ printf("ci removed\n");
+ notifier->setRequested(eSocketNotifier::Read);
+ //HACK
+ eDVBCI_UI::getInstance()->setState(0,0);
+ }
+ return;
+ }
+
+ __u8 data[4096];
+ int r;
+ r = ::read(fd, data, 4096);
+
+ if(state != stateInserted) {
+ state = stateInserted;
+ eDebug("ci inserted");
+
+ //HACK
+ eDVBCI_UI::getInstance()->setState(0,1);
+
+ /* enable PRI to detect removal or errors */
+ notifier->setRequested(eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Write);
+ }
+
+ if(r > 0) {
+ //int i;
+ //printf("> ");
+ //for(i=0;i<r;i++)
+ // printf("%02x ",data[i]);
+ //printf("\n");
+ eDVBCISession::receiveData(this, data, r);
+ notifier->setRequested(eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Write);
+ return;
+ }
+
+ if(what == eSocketNotifier::Write) {
+ if(eDVBCISession::pollAll() == 0) {
+ notifier->setRequested(eSocketNotifier::Read | eSocketNotifier::Priority);
+ }
+ }