X-Git-Url: http://code.vuplus.com/gitweb/?a=blobdiff_plain;f=lib%2Fdvb_ci%2Fdvbci.cpp;h=6fa8e2ec8c0d17678030471ad6c8f19dcfea7358;hb=bf057ab3c120bf104f66dbaecd53edffffb0fb38;hp=67b2eafaa163b3dccd22145d5d6217af9a01a63f;hpb=c4bab36eed7b9ce0ba0b16775a9d429c71c5eed7;p=vuplus_dvbapp diff --git a/lib/dvb_ci/dvbci.cpp b/lib/dvb_ci/dvbci.cpp index 67b2eaf..6fa8e2e 100644 --- a/lib/dvb_ci/dvbci.cpp +++ b/lib/dvb_ci/dvbci.cpp @@ -1,14 +1,26 @@ #include +#include + +#include +#include +#include #include #include #include +#include + +eDVBCIInterfaces *eDVBCIInterfaces::instance = 0; + eDVBCIInterfaces::eDVBCIInterfaces() { int num_ci = 0; - + + instance = this; + eDebug("scanning for common interfaces.."); + while (1) { struct stat s; @@ -26,69 +38,193 @@ eDVBCIInterfaces::eDVBCIInterfaces() ++num_ci; } - eDebug("done, found %d common interfaces"); + eDebug("done, found %d common interface slots", num_ci); +} + +eDVBCIInterfaces::~eDVBCIInterfaces() +{ } -int eDVBCISlot::write(const unsigned char *data, size_t len) +eDVBCIInterfaces *eDVBCIInterfaces::getInstance() { - return ::write(fd, data, len); + return instance; +} + +eDVBCISlot *eDVBCIInterfaces::getSlot(int slotid) +{ + for(eSmartPtrList::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; + + return slot->reset(); } -void eDVBCISlot::data(int) +int eDVBCIInterfaces::initialize(int slotid) { - eDebug("ci talks to us"); + eDVBCISlot *slot; + + if( (slot = getSlot(slotid)) == 0 ) + return -1; + + return slot->initialize(); +} + +int eDVBCIInterfaces::startMMI(int slotid) +{ + eDVBCISlot *slot; + + if( (slot = getSlot(slotid)) == 0 ) + return -1; + + return slot->startMMI(); +} + +int eDVBCIInterfaces::answerMMI(int slotid, int answer, char *value) +{ + eDVBCISlot *slot; + + if( (slot = getSlot(slotid)) == 0 ) + return -1; + + return slot->answerMMI(answer, value); +} + +int eDVBCISlot::send(const unsigned char *data, size_t len) +{ + int res; + //int i; + //printf("< "); + //for(i=0;isetRequested(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(r < 0) - eWarning("ERROR reading from CI - %m\n"); if(state != stateInserted) { state = stateInserted; eDebug("ci inserted"); - /* enable HUP to detect removal or errors */ - notifier_event->start(); + //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) + if(r > 0) { + //int i; + //printf("> "); + //for(i=0;isetRequested(eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Write); + return; + } - eDebug("CI removed"); - - /* kill the TransportConnection */ - - /* we know about and disable HUP */ - notifier_event->stop(); + if(what == eSocketNotifier::Write) { + if(eDVBCISession::pollAll() == 0) { + notifier->setRequested(eSocketNotifier::Read | eSocketNotifier::Priority); + } + } } +DEFINE_REF(eDVBCISlot); + eDVBCISlot::eDVBCISlot(eMainloop *context, int nr) { char filename[128]; + slotid = nr; + sprintf(filename, "/dev/ci%d", nr); fd = ::open(filename, O_RDWR | O_NONBLOCK); eDebug("eDVBCISlot has fd %d", fd); + + state = stateInserted; if (fd >= 0) { - //read callback - notifier_data = new eSocketNotifier(context, fd, eSocketNotifier::Read); - CONNECT(notifier_data->activated, eDVBCISlot::data); - //remove callback - notifier_event = new eSocketNotifier(context, fd, eSocketNotifier::Hungup); - CONNECT(notifier_event->activated, eDVBCISlot::event); + notifier = new eSocketNotifier(context, fd, eSocketNotifier::Read | eSocketNotifier::Priority); + CONNECT(notifier->activated, eDVBCISlot::data); } else { perror(filename); } } +eDVBCISlot::~eDVBCISlot() +{ +} + +int eDVBCISlot::getSlotID() +{ + return slotid; +} + +int eDVBCISlot::reset() +{ + printf("edvbcislot: reset requested\n"); + + ioctl(fd, 0); + + return 0; +} + +int eDVBCISlot::initialize() +{ + printf("edvbcislot: initialize()\n"); + return 0; +} + +int eDVBCISlot::startMMI() +{ + printf("edvbcislot: startMMI()\n"); + return 0; +} + +int eDVBCISlot::answerMMI(int answer, char *value) +{ + printf("edvbcislot: answerMMI()\n"); + return 0; +} + +eAutoInitP0 init_eDVBCIInterfaces(eAutoInitNumbers::dvb, "CI Slots");