2f528d2de452b427aa0bb1ead682bd324bbb13e2
[vuplus_dvbapp] / lib / dvb_ci / dvbci.h
1 #ifndef __dvbci_dvbci_h
2 #define __dvbci_dvbci_h
3
4 #include <lib/base/ebase.h>
5
6 #include <set>
7 #include <queue>
8
9 class eDVBCISession;
10 class eDVBCIApplicationManagerSession;
11 class eDVBCICAManagerSession;
12 class eDVBCIMMISession;
13 class eDVBServicePMTHandler;
14 class eDVBCISlot;
15
16 struct queueData
17 {
18         __u8 prio;
19         unsigned char *data;
20         unsigned int len;
21         queueData( unsigned char *data, unsigned int len, __u8 prio = 0 )
22                 :prio(prio), data(data), len(len)
23         {
24
25         }
26         bool operator < ( const struct queueData &a ) const
27         {
28                 return prio < a.prio;
29         }
30 };
31
32 enum data_source
33 {
34         TUNER_A, TUNER_B, TUNER_C, TUNER_D, CI_A, CI_B, CI_C, CI_D
35 };
36
37 class eDVBCISlot: public iObject, public Object
38 {
39 DECLARE_REF(eDVBCISlot);
40 private:
41         int slotid;
42         int fd;
43         void data(int);
44         eSocketNotifier *notifier;
45
46         int state;
47         std::map<uint16_t, uint8_t> running_services;
48         eDVBCIApplicationManagerSession *application_manager;
49         eDVBCICAManagerSession *ca_manager;
50         eDVBCIMMISession *mmi_session;
51         std::priority_queue<queueData> sendqueue;
52 public:
53         enum {stateRemoved, stateInserted, stateInvalid, stateResetted};
54         int use_count;
55         eDVBCISlot *linked_next; // needed for linked CI handling
56         data_source current_source;
57         int current_tuner;
58
59         eDVBCISlot(eMainloop *context, int nr);
60         ~eDVBCISlot();
61         
62         int send(const unsigned char *data, size_t len);
63
64         void setAppManager( eDVBCIApplicationManagerSession *session );
65         void setMMIManager( eDVBCIMMISession *session );
66         void setCAManager( eDVBCICAManagerSession *session );
67
68         eDVBCIApplicationManagerSession *getAppManager() { return application_manager; }
69         eDVBCIMMISession *getMMIManager() { return mmi_session; }
70         eDVBCICAManagerSession *getCAManager() { return ca_manager; }
71
72         int getState() { return state; }
73         int getSlotID();
74         int reset();
75         int startMMI();
76         int stopMMI();
77         int answerText(int answer);
78         int answerEnq(char *value);
79         int cancelEnq();
80         int getMMIState();
81         int sendCAPMT(eDVBServicePMTHandler *ptr, const std::vector<uint16_t> &caids=std::vector<uint16_t>());
82         void removeService(uint16_t program_number=0xFFFF);
83         int getNumOfServices() { return running_services.size(); }
84         int setSource(data_source source);
85 };
86
87 struct CIPmtHandler
88 {
89         eDVBServicePMTHandler *pmthandler;
90         eDVBCISlot *cislot;
91         CIPmtHandler()
92                 :pmthandler(NULL), cislot(NULL)
93         {}
94         CIPmtHandler( const CIPmtHandler &x )
95                 :pmthandler(x.pmthandler), cislot(x.cislot)
96         {}
97         CIPmtHandler( eDVBServicePMTHandler *ptr )
98                 :pmthandler(ptr), cislot(NULL)
99         {}
100         bool operator==(const CIPmtHandler &x) const { return x.pmthandler == pmthandler; }
101 };
102
103 typedef std::list<CIPmtHandler> PMTHandlerList;
104
105 class eDVBCIInterfaces
106 {
107 DECLARE_REF(eDVBCIInterfaces);
108         static eDVBCIInterfaces *instance;
109 private:
110         eSmartPtrList<eDVBCISlot> m_slots;
111         eDVBCISlot *getSlot(int slotid);
112         PMTHandlerList m_pmt_handlers; 
113 public:
114         eDVBCIInterfaces();
115         ~eDVBCIInterfaces();
116
117         void addPMTHandler(eDVBServicePMTHandler *pmthandler);
118         void removePMTHandler(eDVBServicePMTHandler *pmthandler);
119         void recheckPMTHandlers();
120         void gotPMT(eDVBServicePMTHandler *pmthandler);
121         void ciRemoved(eDVBCISlot *slot);
122         int getSlotState(int slot);
123
124         static eDVBCIInterfaces *getInstance();
125         
126         int reset(int slot);
127         int initialize(int slot);
128         int startMMI(int slot);
129         int stopMMI(int slot);
130         int answerText(int slot, int answer);
131         int answerEnq(int slot, char *value);
132         int cancelEnq(int slot);
133         int getMMIState(int slot);
134         int sendCAPMT(int slot);
135         int setInputSource(int tunerno, data_source source);
136 };
137
138 #endif