add stuff
[enigma2.git] / lib / dvb_ci / dvbci.cpp
index 6a748118c0b07fb8a996ced7e21759acedbc2a4b..6fa8e2ec8c0d17678030471ad6c8f19dcfea7358 100644 (file)
@@ -1,16 +1,24 @@
 #include <fcntl.h>
+#include <sys/ioctl.h>
 
 #include <lib/base/init.h>
 #include <lib/base/init_num.h>
+#include <lib/base/ebase.h>
 
 #include <lib/base/eerror.h>
 #include <lib/dvb_ci/dvbci.h>
 #include <lib/dvb_ci/dvbci_session.h>
 
+#include <lib/dvb_ci/dvbci_ui.h>
+
+eDVBCIInterfaces *eDVBCIInterfaces::instance = 0;
+
 eDVBCIInterfaces::eDVBCIInterfaces()
 {
        int num_ci = 0;
-
+       
+       instance = this;
+       
        eDebug("scanning for common interfaces..");
 
        while (1)
@@ -30,28 +38,83 @@ eDVBCIInterfaces::eDVBCIInterfaces()
                ++num_ci;
        }
 
-       eDebug("done, found %d common interfaces");
+       eDebug("done, found %d common interface slots", num_ci);
 }
 
 eDVBCIInterfaces::~eDVBCIInterfaces()
 {
 }
 
+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;
+       
+       return slot->reset();
+}
+
+int eDVBCIInterfaces::initialize(int slotid)
+{
+       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;i<len;i++)
-               printf("%02x ",data[i]);
-       printf("\n");
+       //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);
+       //printf("write() %d\n",res);
 
-       notifier->setRequested(eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Write);
+       notifier->setRequested(eSocketNotifier::Read | eSocketNotifier::Priority | eSocketNotifier::Write);
 
        return res;
 }
@@ -63,45 +126,42 @@ void eDVBCISlot::data(int what)
                        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) {
-               int i;
-               printf("> ");
-               for(i=0;i<r;i++)
-                       printf("%02x ",data[i]);
-               printf("\n");
-               //eDebug("ci talks to us");
+               //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) {
-               printf("pollall\n");
                if(eDVBCISession::pollAll() == 0) {
-                       printf("disable pollout\n");
                        notifier->setRequested(eSocketNotifier::Read | eSocketNotifier::Priority);
                }
-               return;
        }
 }
 
@@ -111,11 +171,15 @@ 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)
        {
@@ -131,4 +195,36 @@ 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<eDVBCIInterfaces> init_eDVBCIInterfaces(eAutoInitNumbers::dvb, "CI Slots");