fix segfault
[enigma2.git] / lib / dvb / db.h
1 #ifndef __db_h
2 #define __db_h
3
4 #ifndef SWIG
5 #include <lib/dvb/idvb.h>
6 #include <lib/base/eptrlist.h>
7 #include <set>
8 class ServiceDescriptionSection;
9 #endif
10
11 class eDVBDB: public iDVBChannelList
12 {
13         DECLARE_REF(eDVBDB);
14         static eDVBDB *instance;
15         friend class eDVBDBQuery;
16         friend class eDVBDBBouquetQuery;
17         friend class eDVBDBSatellitesQuery;
18         friend class eDVBDBProvidersQuery;
19
20         struct channel
21         {
22                 ePtr<iDVBFrontendParameters> m_frontendParameters;
23         };
24         
25         std::map<eDVBChannelID, channel> m_channels;
26         
27         std::map<eServiceReferenceDVB, ePtr<eDVBService> > m_services;
28         
29         std::map<std::string, eBouquet> m_bouquets;
30 #ifdef SWIG
31         eDVBDB();
32         ~eDVBDB();
33 #endif
34 public:
35 // iDVBChannelList
36         RESULT removeFlags(unsigned int flagmask, int dvb_namespace=-1, int tsid=-1, int onid=-1, unsigned int orb_pos=0xFFFFFFFF);
37         RESULT removeServices(int dvb_namespace=-1, int tsid=-1, int onid=-1, unsigned int orb_pos=0xFFFFFFFF);
38         RESULT removeService(const eServiceReference &service);
39         RESULT addFlag(const eServiceReference &service, unsigned int flagmask);
40         RESULT removeFlag(const eServiceReference &service, unsigned int flagmask);
41         PyObject *readSatellites(SWIG_PYOBJECT(ePyObject) sat_list, SWIG_PYOBJECT(ePyObject) sat_dict, SWIG_PYOBJECT(ePyObject) tp_dict);
42         PyObject *readTerrestrials(SWIG_PYOBJECT(ePyObject) ter_list, SWIG_PYOBJECT(ePyObject) tp_dict);
43         PyObject *readCables(SWIG_PYOBJECT(ePyObject) cab_list, SWIG_PYOBJECT(ePyObject) tp_dict);
44 #ifndef SWIG
45         RESULT removeFlags(unsigned int flagmask, eDVBChannelID chid, unsigned int orb_pos);
46         RESULT removeServices(eDVBChannelID chid, unsigned int orb_pos);
47         RESULT removeServices(iDVBFrontendParameters *feparm);
48
49         RESULT addChannelToList(const eDVBChannelID &id, iDVBFrontendParameters *feparm);
50         RESULT removeChannel(const eDVBChannelID &id);
51
52         RESULT getChannelFrontendData(const eDVBChannelID &id, ePtr<iDVBFrontendParameters> &parm);
53         
54         RESULT addService(const eServiceReferenceDVB &service, eDVBService *service);
55         RESULT getService(const eServiceReferenceDVB &reference, ePtr<eDVBService> &service);
56         RESULT flush();
57
58         RESULT startQuery(ePtr<iDVBChannelListQuery> &query, eDVBChannelQuery *query, const eServiceReference &source);
59
60         RESULT getBouquet(const eServiceReference &ref, eBouquet* &bouquet);
61 //////
62         void loadBouquet(const char *path);
63         eServiceReference searchReference(int tsid, int onid, int sid);
64         eDVBDB();
65         virtual ~eDVBDB();
66 #endif
67         void loadServicelist(const char *filename);
68         static eDVBDB *getInstance() { return instance; }
69         void reloadServicelist();
70         void saveServicelist();
71         void saveServicelist(const char *file);
72         void reloadBouquets();
73 };
74
75 #ifndef SWIG
76         // we have to add a possibility to invalidate here.
77 class eDVBDBQueryBase: public iDVBChannelListQuery
78 {
79         DECLARE_REF(eDVBDBQueryBase);
80 protected:
81         ePtr<eDVBDB> m_db;
82         ePtr<eDVBChannelQuery> m_query;
83         eServiceReference m_source;
84 public:
85         eDVBDBQueryBase(eDVBDB *db, const eServiceReference &source, eDVBChannelQuery *query);
86         virtual int compareLessEqual(const eServiceReferenceDVB &a, const eServiceReferenceDVB &b);
87 };
88
89 class eDVBDBQuery: public eDVBDBQueryBase
90 {
91         std::map<eServiceReferenceDVB, ePtr<eDVBService> >::iterator m_cursor;
92 public:
93         eDVBDBQuery(eDVBDB *db, const eServiceReference &source, eDVBChannelQuery *query);
94         RESULT getNextResult(eServiceReferenceDVB &ref);
95 };
96
97 class eDVBDBBouquetQuery: public eDVBDBQueryBase
98 {
99         std::list<eServiceReference>::iterator m_cursor;
100 public:
101         eDVBDBBouquetQuery(eDVBDB *db, const eServiceReference &source, eDVBChannelQuery *query);
102         RESULT getNextResult(eServiceReferenceDVB &ref);
103 };
104
105 class eDVBDBListQuery: public eDVBDBQueryBase
106 {
107 protected:
108         std::list<eServiceReferenceDVB> m_list;
109         std::list<eServiceReferenceDVB>::iterator m_cursor;
110 public:
111         eDVBDBListQuery(eDVBDB *db, const eServiceReference &source, eDVBChannelQuery *query);
112         RESULT getNextResult(eServiceReferenceDVB &ref);
113         int compareLessEqual(const eServiceReferenceDVB &a, const eServiceReferenceDVB &b);
114 };
115
116 class eDVBDBSatellitesQuery: public eDVBDBListQuery
117 {
118 public:
119         eDVBDBSatellitesQuery(eDVBDB *db, const eServiceReference &source, eDVBChannelQuery *query);
120 };
121
122 class eDVBDBProvidersQuery: public eDVBDBListQuery
123 {
124 public:
125         eDVBDBProvidersQuery(eDVBDB *db, const eServiceReference &source, eDVBChannelQuery *query);
126 };
127 #endif // SWIG
128
129 #endif