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