+eDVBCIInterfaces *eDVBCIInterfaces::getInstance()
+{
+ return instance;
+}
+
+eDVBCISlot *eDVBCIInterfaces::getSlot(int slotid)
+{
+ for(eSmartPtrList<eDVBCISlot>::iterator i(m_slots.begin()); i != m_slots.end(); ++i)
+ if(i->getSlotID() == slotid)
+ return i;
+
+ printf("FIXME: request for unknown slot\n");
+
+ return 0;
+}
+
+int eDVBCIInterfaces::reset(int slotid)
+{
+ eDVBCISlot *slot;
+
+ if( (slot = getSlot(slotid)) == 0 )
+ return -1;
+
+ eDVBCISession::deleteSessions(slot);
+
+ return slot->reset();
+}
+
+int eDVBCIInterfaces::enableTS(int slotid, int enable)
+{
+ eDVBCISlot *slot;
+
+ if( (slot = getSlot(slotid)) == 0 )
+ return -1;
+
+ int tunernum = 0;
+ if (enable)
+ {
+ PMTHandlerList::iterator it = m_pmt_handlers.begin();
+ while (it != m_pmt_handlers.end())
+ {
+ if ( it->cislot == slot )
+ {
+ eDVBServicePMTHandler *pmthandler = it->pmthandler;
+ eUsePtr<iDVBChannel> channel;
+ if (!pmthandler->getChannel(channel))
+ {
+ ePtr<iDVBFrontend> frontend;
+ if (!channel->getFrontend(frontend))
+ {
+ eDVBFrontend *fe = (eDVBFrontend*) &(*frontend);
+ tunernum = fe->getID();
+ }
+ }
+ break;
+ }
+ ++it;
+ }
+ }
+ return slot->enableTS(enable, tunernum);
+}
+
+int eDVBCIInterfaces::initialize(int slotid)
+{
+ eDVBCISlot *slot;
+
+ if( (slot = getSlot(slotid)) == 0 )
+ return -1;
+
+ slot->resetPrevSentCAPMTVersion();
+ PMTHandlerList::iterator it = m_pmt_handlers.begin();
+ while (it != m_pmt_handlers.end())
+ {
+ if ( it->cislot == slot )
+ {
+ slot->sendCAPMT(it->pmthandler); // send capmt
+ break;
+ }
+ ++it;
+ }
+
+ return slot->initialize();
+}
+
+int eDVBCIInterfaces::sendCAPMT(int slotid)
+{
+ eDVBCISlot *slot;
+
+ if( (slot = getSlot(slotid)) == 0 )
+ return -1;
+
+ slot->resetPrevSentCAPMTVersion();
+ PMTHandlerList::iterator it = m_pmt_handlers.begin();
+ while (it != m_pmt_handlers.end())
+ {
+ if ( it->cislot == slot )
+ {
+ slot->sendCAPMT(it->pmthandler); // send capmt
+ return 0;
+ }
+ ++it;
+ }
+
+ return -1;
+}
+
+int eDVBCIInterfaces::startMMI(int slotid)
+{
+ eDVBCISlot *slot;
+
+ if( (slot = getSlot(slotid)) == 0 )
+ return -1;
+
+ return slot->startMMI();
+}
+
+int eDVBCIInterfaces::stopMMI(int slotid)
+{
+ eDVBCISlot *slot;
+
+ if( (slot = getSlot(slotid)) == 0 )
+ return -1;
+
+ return slot->stopMMI();
+}
+
+int eDVBCIInterfaces::answerText(int slotid, int answer)
+{
+ eDVBCISlot *slot;
+
+ if( (slot = getSlot(slotid)) == 0 )
+ return -1;
+
+ 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();
+}
+