+void eDVBCIInterfaces::removePMTHandler(eDVBServicePMTHandler *pmthandler)
+{
+ PMTHandlerSet::iterator it=m_pmt_handlers.find(pmthandler);
+ if (it != m_pmt_handlers.end())
+ {
+ eDVBCISlot *slot = it->usedby;
+ eDVBServicePMTHandler *pmthandler = it->pmthandler;
+ m_pmt_handlers.erase(it);
+ if (slot)
+ {
+ eServiceReferenceDVB removed_service;
+ pmthandler->getService(removed_service);
+ PMTHandlerSet::iterator it=m_pmt_handlers.begin();
+ while (it != m_pmt_handlers.end())
+ {
+ eServiceReferenceDVB ref;
+ it->pmthandler->getService(ref);
+ if (ref == removed_service)
+ break;
+ ++it;
+ }
+ if ( it == m_pmt_handlers.end() && slot->getPrevSentCAPMTVersion() != 0xFF )
+ {
+ std::vector<uint16_t> caids;
+ caids.push_back(0xFFFF);
+ slot->sendCAPMT(pmthandler, caids);
+ }
+ }
+ }
+}
+
+void eDVBCIInterfaces::gotPMT(eDVBServicePMTHandler *pmthandler)
+{
+ eDebug("[eDVBCIInterfaces] gotPMT");
+ PMTHandlerSet::iterator it=m_pmt_handlers.find(pmthandler);
+ eServiceReferenceDVB service;
+ if ( it != m_pmt_handlers.end() )
+ {
+ eDebug("[eDVBCIInterfaces] usedby %p", it->usedby);
+ if (!it->usedby)
+ {
+ // HACK this assigns ALL RUNNING SERVICES to the first free CI !!!
+ for (eSmartPtrList<eDVBCISlot>::iterator ci_it(m_slots.begin()); ci_it != m_slots.end(); ++ci_it)
+ {
+ eDVBCISlot **usedby = &it->usedby;
+ *usedby = ci_it;
+ (*usedby)->resetPrevSentCAPMTVersion();
+ break;
+
+ }
+ }
+ if (it->usedby)
+ it->usedby->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);
+ }
+ }
+}
+
+DEFINE_REF(eDVBCISlot);
+
+eDVBCISlot::eDVBCISlot(eMainloop *context, int nr)