add ServiceInfo.py
[enigma2.git] / lib / dvb_ci / dvbci.cpp
index 67b2eafaa163b3dccd22145d5d6217af9a01a63f..72dfd388920929fb0a135566960bc6b06220bb30 100644 (file)
@@ -1,14 +1,20 @@
 #include <fcntl.h>
 
+#include <lib/base/init.h>
+#include <lib/base/init_num.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()
 {
        int num_ci = 0;
 
        eDebug("scanning for common interfaces..");
+
        while (1)
        {
                struct stat s;
@@ -26,48 +32,80 @@ eDVBCIInterfaces::eDVBCIInterfaces()
                ++num_ci;
        }
 
-       eDebug("done, found %d common interfaces");
+       eDebug("done, found %d common interface slots", num_ci);
 }
 
-int eDVBCISlot::write(const unsigned char *data, size_t len)
+eDVBCIInterfaces::~eDVBCIInterfaces()
 {
-       return ::write(fd, data, len);
 }
 
-void eDVBCISlot::data(int)
+int eDVBCISlot::send(const unsigned char *data, size_t len)
 {
-       eDebug("ci talks to us");
+       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(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;i<r;i++)
+               //      printf("%02x ",data[i]);
+               //printf("\n");
                eDVBCISession::receiveData(this, data, r);
-}
+               notifier->setRequested(eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Write);
+               return;
+       }
 
-void eDVBCISlot::event(int)
-{
-       state = stateRemoved;
-
-       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];
@@ -80,15 +118,16 @@ eDVBCISlot::eDVBCISlot(eMainloop *context, int nr)
 
        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()
+{
+}
+
+eAutoInitP0<eDVBCIInterfaces> init_eDVBCIInterfaces(eAutoInitNumbers::dvb, "CI Slots");