fix restart of playback after EOF (fixes bug #241)
[enigma2.git] / lib / dvb_ci / dvbci_mmi.cpp
index 7165453..f266e5d 100644 (file)
@@ -1,71 +1,48 @@
 /* DVB CI MMI */
 
 #include <lib/dvb_ci/dvbci_mmi.h>
+#include <lib/dvb_ci/dvbci_ui.h>
+
+#include <string>
+
+/*
+PyObject *list = PyList_New(len);
+for (i=0; i<len; ++i) {
+       PyObject *tuple = PyTuple_New(3); // 3 eintrge im tuple
+       PyTuple_SetItem(tuple, 0, PyString_FromString("eintrag 1"))
+       PyTuple_SetItem(tuple, 1, PyInt_FromLong(31337));
+       PyTuple_SetItem(tuple, 2, PyString_FromString("eintrag 3"))
+       PyList_SetItem(list, i, tuple);
+}
+return list;
+*/
 
 eDVBCIMMISession::eDVBCIMMISession(eDVBCISlot *tslot)
 {
        slot = tslot;
-       slot->mmi_session = this;
+       slot->setMMIManager(this);
 }
 
 eDVBCIMMISession::~eDVBCIMMISession()
 {
-       slot->mmi_session = 0;
+       slot->setMMIManager(NULL);
+       eDVBCI_UI::getInstance()->mmiSessionDestroyed(slot->getSlotID());
 }
 
 int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, int len)
 {
-       printf("SESSION(%d)/MMI %02x %02x %02x: ", session_nb, tag[0], tag[1],tag[2]);
+       eDebugNoNewLine("SESSION(%d)/MMI %02x %02x %02x: ", session_nb, tag[0], tag[1],tag[2]);
        for (int i=0; i<len; i++)
-               printf("%02x ", ((const unsigned char*)data)[i]);
-       printf("\n");
+               eDebugNoNewLine("%02x ", ((const unsigned char*)data)[i]);
+       eDebug("");
 
        if ((tag[0]==0x9f) && (tag[1]==0x88))
-       {
-               switch (tag[2])
+               if (eDVBCI_UI::getInstance()->processMMIData(slot->getSlotID(), tag, data, len) == 1)
                {
-                       case 0x01:
-                       printf("MMI display control\n");
-                       if (((unsigned char*)data)[0] != 1)
-                               printf("kann ich nicht. aber das sag ich dem modul nicht.\n");
                        state=stateDisplayReply;
                        return 1;
-               case 0x09:
-               case 0x0c:
-               {
-                       unsigned char *d=(unsigned char*)data;
-                       unsigned char *max=((unsigned char*)d) + len;
-                       printf("Tmenu_last\n");
-                       if (d > max)
-                               break;
-                       int n=*d++;
-                       if (n == 0xFF)
-                               n=0;
-                       else
-                               n++;
-                       printf("%d texts\n", n);
-                       for (int i=0; i < (n+3); ++i)
-                       {
-                               int textlen;
-                               if ((d+3) > max)
-                                       break;
-                               printf("text tag: %02x %02x %02x\n", d[0], d[1], d[2]);
-                               d+=3;
-                               d+=parseLengthField(d, textlen);
-                               printf("%d bytes text\n", textlen);
-                               if ((d+textlen) > max)
-                                       break;
-                               while (textlen--)
-                                       printf("%c", *d++);
-                               printf("\n");
-                       }
-                       break;
-               }
-               default:
-                       printf("unknown APDU tag 9F 88 %02x\n", tag[2]);
-                       break;
                }
-       }
+
        return 0;
 }
 
@@ -81,8 +58,9 @@ int eDVBCIMMISession::doAction()
                unsigned char tag[]={0x9f, 0x88, 0x02};
                unsigned char data[]={0x01, 0x01};
                sendAPDU(tag, data, 2);
-               state=stateFakeOK;
-               return 1;
+               state=stateIdle;
+               //state=stateFakeOK;
+               //return 1;
                break;
        }
        case stateFakeOK:
@@ -103,10 +81,50 @@ int eDVBCIMMISession::doAction()
 
 int eDVBCIMMISession::stopMMI()
 {
-       printf("eDVBCIMMISession::stopMMI()\n");
+       eDebug("eDVBCIMMISession::stopMMI()");
 
        unsigned char tag[]={0x9f, 0x88, 0x00};
        unsigned char data[]={0x00};
        sendAPDU(tag, data, 1);
+       
+       return 0;
+}
+
+int eDVBCIMMISession::answerText(int answer)
+{
+       eDebug("eDVBCIMMISession::answerText(%d)",answer);
+
+       unsigned char tag[]={0x9f, 0x88, 0x0B};
+       unsigned char data[]={0x00};
+       data[0] = answer & 0xff;
+       sendAPDU(tag, data, 1);
+       
+       return 0;
+}
+
+int eDVBCIMMISession::answerEnq(char *answer)
+{
+       unsigned int len = strlen(answer);
+       eDebug("eDVBCIMMISession::answerEnq(%d bytes)", len);
+
+       unsigned char data[len+1];
+       data[0] = 0x01; // answer ok
+       memcpy(data+1, answer, len);
+
+       unsigned char tag[]={0x9f, 0x88, 0x08};
+       sendAPDU(tag, data, len+1);
+
+       return 0;
+}
+
+int eDVBCIMMISession::cancelEnq()
+{
+       eDebug("eDVBCIMMISession::cancelEnq()");
+
+       unsigned char tag[]={0x9f, 0x88, 0x08};
+       unsigned char data[]={0x00}; // canceled
+       sendAPDU(tag, data, 1);
+       
+       return 0;
 }