fix high systemload with plugged CI on e2 start
[enigma2.git] / lib / dvb_ci / dvbci_session.h
1 #ifndef __dvbci_dvbci_tc_h
2 #define __dvbci_dvbci_tc_h
3
4 #include <lib/base/ebase.h>
5 #include <lib/base/object.h>
6 #include <lib/dvb_ci/dvbci.h>
7
8 #define SLMS    256
9
10 class eDVBCISession
11 {
12         DECLARE_REF(eDVBCISession);
13         static ePtr<eDVBCISession> sessions[SLMS];
14         static void deleteSessions(const eDVBCISlot *slot);
15         static void createSession(eDVBCISlot *slot, const unsigned char *resource_identifier, unsigned char &status, ePtr<eDVBCISession> &ptr);
16         static void sendSPDU(eDVBCISlot *slot, unsigned char tag,const void *data, int len, unsigned short session_nb, const void *apdu=0,int alen=0);
17         static void sendOpenSessionResponse(eDVBCISlot *slot,unsigned char session_status, const unsigned char *resource_identifier,unsigned short session_nb);
18         void recvCreateSessionResponse(const unsigned char *data);
19         void recvCloseSessionRequest(const unsigned char *data);
20 protected:
21         int state;
22         int status;
23         int action;
24         eDVBCISlot *slot;               //base only
25         unsigned short session_nb;
26         virtual int receivedAPDU(const unsigned char *tag, const void *data, int len) = 0;
27         void sendAPDU(const unsigned char *tag, const void *data=0,int len=0);
28         void sendSPDU(unsigned char tag, const void *data, int len,const void *apdu=0, int alen=0);
29         virtual int doAction()=0;
30         void handleClose();
31 public:
32         virtual ~eDVBCISession();
33
34
35         int poll() { if (action) { action=doAction(); return 1; } return 0; }
36         enum { stateInCreation, stateBusy, stateInDeletion, stateStarted, statePrivate};
37         
38         static int parseLengthField(const unsigned char *pkt, int &len);
39         static int buildLengthField(unsigned char *pkt, int len);
40
41         static void receiveData(eDVBCISlot *slot, const unsigned char *ptr, size_t len);
42         
43         int getState() { return state; }
44         int getStatus() { return status; }
45         
46         static int pollAll();
47         
48 };
49
50 #endif