openATV enigma2
openATV is an open source SetTopBox Graphical user interface.
epgcache.h
Go to the documentation of this file.
1 #ifndef __epgcache_h_
2 #define __epgcache_h_
3 
4 #define ENABLE_PRIVATE_EPG 1
5 #define ENABLE_MHW_EPG 1
6 #define ENABLE_FREESAT 1
7 #define ENABLE_NETMED 1
8 #define ENABLE_VIRGIN 1
9 #define ENABLE_ATSC 1
10 #define ENABLE_OPENTV 1
11 
12 #ifndef SWIG
13 
14 #include <vector>
15 #include <tr1/unordered_map>
16 
17 #include <lib/dvb/idvb.h>
18 #include <lib/dvb/dvbtime.h>
19 #include <lib/base/thread.h>
20 #include <lib/base/message.h>
21 #include <lib/service/event.h>
22 #include <lib/python/python.h>
23 
24 struct eventData;
26 class eEPGChannelData;
28 
30 {
31  int sid, onid, tsid;
33  :sid( ref.type != eServiceReference::idInvalid ? ((eServiceReferenceDVB&)ref).getServiceID().get() : -1 )
34  ,onid( ref.type != eServiceReference::idInvalid ? ((eServiceReferenceDVB&)ref).getOriginalNetworkID().get() : -1 )
35  ,tsid( ref.type != eServiceReference::idInvalid ? ((eServiceReferenceDVB&)ref).getTransportStreamID().get() : -1 )
36  {
37  }
39  :sid(-1), onid(-1), tsid(-1)
40  {
41  }
42  uniqueEPGKey( int sid, int onid, int tsid )
43  :sid(sid), onid(onid), tsid(tsid)
44  {
45  }
46  bool operator <(const uniqueEPGKey &a) const
47  {
48  if (sid < a.sid)
49  return true;
50  if (sid != a.sid)
51  return false;
52  if (onid < a.onid)
53  return true;
54  if (onid != a.onid)
55  return false;
56  return (tsid < a.tsid);
57  }
58  operator bool() const
59  {
60  return !(sid == -1 && onid == -1 && tsid == -1);
61  }
62  bool operator==(const uniqueEPGKey &a) const
63  {
64  return (tsid == a.tsid) && (onid == a.onid) && (sid == a.sid);
65  }
66  struct equal
67  {
68  bool operator()(const uniqueEPGKey &a, const uniqueEPGKey &b) const
69  {
70  return (a.tsid == b.tsid) && (a.onid == b.onid) && (a.sid == b.sid);
71  }
72  };
73 };
74 
75 //eventMap is sorted by event_id
76 typedef std::map<uint16_t, eventData*> eventMap;
77 //timeMap is sorted by beginTime
78 typedef std::map<time_t, eventData*> timeMap;
79 
81 {
82  inline size_t operator()( const uniqueEPGKey &x) const
83  {
84  return (x.onid << 16) | x.tsid;
85  }
86 };
87 
91  int sources;
93 };
94 
95 typedef std::tr1::unordered_map<uniqueEPGKey, EventCacheItem, hash_uniqueEPGKey, uniqueEPGKey::equal> eventCache;
96 #ifdef ENABLE_PRIVATE_EPG
97  typedef std::tr1::unordered_map<time_t, std::pair<time_t, uint16_t> > contentTimeMap;
98  typedef std::tr1::unordered_map<int, contentTimeMap > contentMap;
99  typedef std::tr1::unordered_map<uniqueEPGKey, contentMap, hash_uniqueEPGKey, uniqueEPGKey::equal > contentMaps;
100 #endif
101 
102 #endif
103 
104 #ifndef SWIG
105 
107  u_char country_code[3];
108  u_char rating;
109 };
110 #endif
111 
112 class eEPGCache: public eMainloop, private eThread, public sigc::trackable
113 {
114 #ifndef SWIG
116 
117 public:
118  struct Message
119  {
120  enum
121  {
125  };
126  int type;
128  union {
129  int err;
130  };
132  :type(0) {}
134  :type(type) {}
136  :type(type), service(service), err(err) {}
137  };
139 
140 private:
141  friend struct eventData;
142  friend class eEPGChannelData;
144  static eEPGCache *instance;
145 
146  unsigned int historySeconds;
147  unsigned int maxdays;
148 
149  std::vector<int> onid_blacklist;
150  eventCache eventDB;
151  std::string m_filename;
152  bool m_running;
153  unsigned int m_enabledEpgSources;
154  ePtr<eTimer> cleanTimer;
155  bool load_epg;
156  PSignal0<void> epgCacheStarted;
157  bool m_debug;
158 
159 #ifdef ENABLE_PRIVATE_EPG
160  contentMaps content_time_tables;
161 #endif
162 
163  void thread(); // thread function
164 
165 #ifdef ENABLE_PRIVATE_EPG
166  void privateSectionRead(const uniqueEPGKey &, const uint8_t *);
167 #endif
168  void sectionRead(const uint8_t *data, int source, eEPGChannelData *channel);
169 
170  void gotMessage(const Message &message);
171  void cleanLoop();
172  void submitEventData(const std::vector<int>& sids, const std::vector<eDVBChannelID>& chids, long start, long duration, const char* title, const char* short_summary, const char* long_description, char event_type, int source, uint16_t event_id=0);
173  void submitEventData(const std::vector<int>& sids, const std::vector<eDVBChannelID>& chids, long start, long duration, const char* title, const char* short_summary, const char* long_description, std::vector<uint8_t> event_types, std::vector<eit_parental_rating> parental_ratings, int source, uint16_t event_id=0);
174  void clearCompleteEPGCache();
175 
176  eServiceReferenceDVB *m_timeQueryRef;
177  time_t m_timeQueryBegin;
178  int m_timeQueryMinutes;
179  int m_timeQueryCount; // counts the returned events; getNextTimeEntry returns always the m_timeQueryCount'th event
180 #else
181  eEPGCache();
182  ~eEPGCache();
183 #endif // SWIG
184 public:
185  static eEPGCache *getInstance() { return instance; }
186 
187  void crossepgImportEPGv21(std::string dbroot);
188  void clear();
189  void save();
190  void load();
191  void timeUpdated();
192  void flushEPG(int sid, int onid, int tsid);
193  void flushEPG(const uniqueEPGKey & s=uniqueEPGKey(), bool lock = true);
194 #ifndef SWIG
195  eEPGCache();
196  ~eEPGCache();
197 
198 #endif
199  // must be called once!
200  void setCacheFile(const char *filename);
201 
202  // at moment just for one service..
203  RESULT startTimeQuery(const eServiceReference &service, time_t begin=-1, int minutes=-1);
204 
205 #ifndef SWIG
206 private:
207  // For internal use only. Acquire the cache lock before calling.
208  RESULT lookupEventId(const eServiceReference &service, int event_id, const eventData *&);
209  RESULT lookupEventTime(const eServiceReference &service, time_t, const eventData *&, int direction=0);
210 
211 public:
212  /* Used by servicedvbrecord.cpp, time shift, etc. to write the EIT file */
213  RESULT saveEventToFile(const char* filename, const eServiceReference &service, int eit_event_id, time_t begTime, time_t endTime);
214 
215  // Events are parsed epg events.. it's safe to use them after cache unlock
216  // after use the Event pointer must be released using "delete".
217  RESULT lookupEventId(const eServiceReference &service, int event_id, Event* &);
218  RESULT lookupEventTime(const eServiceReference &service, time_t, Event* &, int direction=0);
219  RESULT getNextTimeEntry(Event *&);
220 #endif
221  enum {
229  };
230  enum {
232  CRID_SERIES = 2
233  };
234  enum {
238  };
239  PyObject *lookupEvent(SWIG_PYOBJECT(ePyObject) list, SWIG_PYOBJECT(ePyObject) convertFunc=(PyObject*)0);
240  const char* casetypestr(int value);
241  PyObject *search(SWIG_PYOBJECT(ePyObject));
242 
243  // eServiceEvent are parsed epg events.. it's safe to use them after cache unlock
244  // for use from python ( members: m_start_time, m_duration, m_short_description, m_extended_description )
248 
250 #ifdef ENABLE_MHW_EPG
251  ,MHW=8
252 #endif
253 #ifdef ENABLE_FREESAT
257 #endif
258  ,VIASAT=256
259 #ifdef ENABLE_NETMED
262 #endif
263 #ifdef ENABLE_VIRGIN
266 #endif
267 #ifdef ENABLE_ATSC
268  ,ATSC_EIT=8192
269 #endif
270 #ifdef ENABLE_OPENTV
271  ,OPENTV=16384
272 #endif
273  ,EPG_IMPORT=0x80000000
274  };
275  void setEpgmaxdays(unsigned int epgmaxdays);
276  void setEpgHistorySeconds(time_t seconds);
277  void setEpgSources(unsigned int mask);
278  unsigned int getEpgSources();
279  unsigned int getEpgmaxdays();
280 
281 
282  void submitEventData(const std::vector<eServiceReferenceDVB>& serviceRefs, long start, long duration, const char* title, const char* short_summary, const char* long_description, std::vector<uint8_t> event_types, std::vector<eit_parental_rating> parental_ratings, uint16_t event_id=0);
283 
284  void importEvents(SWIG_PYOBJECT(ePyObject) serviceReferences, SWIG_PYOBJECT(ePyObject) list);
286 };
287 
288 #endif
Definition: epgcache.h:113
PyObject * search(SWIG_PYOBJECT(ePyObject))
Definition: epgcache.cpp:2434
time_t
Definition: epgcache.h:246
void importEvents(SWIG_PYOBJECT(ePyObject) serviceReferences, SWIG_PYOBJECT(ePyObject) list)
Import EPG events from Python into the EPG database. Each event in the list is added to each service ...
Definition: epgcache.cpp:2211
void setCacheFile(const char *filename)
Definition: epgcache.cpp:404
@ PARTIAL_DESCRIPTION_SEARCH
Definition: epgcache.h:227
@ CRID_SEARCH
Definition: epgcache.h:228
@ START_TITLE_SEARCH
Definition: epgcache.h:225
@ SIMILAR_BROADCASTINGS_SEARCH
Definition: epgcache.h:222
@ EXAKT_TITLE_SEARCH
Definition: epgcache.h:223
@ PARTIAL_TITLE_SEARCH
Definition: epgcache.h:224
@ END_TITLE_SEARCH
Definition: epgcache.h:226
@ REGEX_CHECK
Definition: epgcache.h:237
@ NO_CASE_CHECK
Definition: epgcache.h:236
@ CASE_CHECK
Definition: epgcache.h:235
SWIG_VOID(RESULT) lookupEventId(const eServiceReference &service
void setEpgSources(unsigned int mask)
Definition: epgcache.cpp:2158
int event_id
Definition: epgcache.h:245
unsigned int getEpgSources()
Definition: epgcache.cpp:2163
void save()
Definition: epgcache.cpp:1074
@ FREESAT_NOWNEXT
Definition: epgcache.h:254
@ FREESAT_SCHEDULE
Definition: epgcache.h:255
@ FREESAT_SCHEDULE_OTHER
Definition: epgcache.h:256
@ NETMED_SCHEDULE_OTHER
Definition: epgcache.h:261
@ ATSC_EIT
Definition: epgcache.h:268
@ NOWNEXT
Definition: epgcache.h:249
@ VIASAT
Definition: epgcache.h:258
@ NETMED_SCHEDULE
Definition: epgcache.h:260
@ MHW
Definition: epgcache.h:251
@ VIRGIN_SCHEDULE
Definition: epgcache.h:265
@ SCHEDULE
Definition: epgcache.h:249
@ VIRGIN_NOWNEXT
Definition: epgcache.h:264
@ SCHEDULE_OTHER
Definition: epgcache.h:249
@ OPENTV
Definition: epgcache.h:271
@ PRIVATE
Definition: epgcache.h:249
@ EPG_IMPORT
Definition: epgcache.h:273
void load()
Definition: epgcache.cpp:877
eEPGCache()
Definition: epgcache.cpp:377
int ePtr< eServiceEvent > & SWIG_OUTPUT
Definition: epgcache.h:245
void crossepgImportEPGv21(std::string dbroot)
Definition: epgcache.cpp:3198
unsigned int getEpgmaxdays()
Definition: epgcache.cpp:2168
void setEpgHistorySeconds(time_t seconds)
Definition: epgcache.cpp:2153
ePtr< eServiceEvent > int direction
Definition: epgcache.h:246
eFixedMessagePump< Message > messages
Definition: epgcache.h:138
RESULT startTimeQuery(const eServiceReference &service, time_t begin=-1, int minutes=-1)
Definition: epgcache.cpp:1392
static eEPGCache * getInstance()
Definition: epgcache.h:185
PyObject * lookupEvent(SWIG_PYOBJECT(ePyObject) list, SWIG_PYOBJECT(ePyObject) convertFunc=(PyObject *) 0)
Definition: epgcache.cpp:1663
~eEPGCache()
Definition: epgcache.cpp:824
void importEvent(SWIG_PYOBJECT(ePyObject) serviceReference, SWIG_PYOBJECT(ePyObject) list)
Import EPG events from Python into the EPG database. Each event in the list is added to each service ...
Definition: epgcache.cpp:2185
void flushEPG(int sid, int onid, int tsid)
Definition: epgcache.cpp:664
@ CRID_SERIES
Definition: epgcache.h:232
@ CRID_EPISODE
Definition: epgcache.h:231
RESULT saveEventToFile(const char *filename, const eServiceReference &service, int eit_event_id, time_t begTime, time_t endTime)
Definition: epgcache.cpp:1326
SWIG_VOID(RESULT) getNextTimeEntry(ePtr< eServiceEvent > &SWIG_OUTPUT)
void timeUpdated()
Definition: epgcache.cpp:416
const char * casetypestr(int value)
Definition: epgcache.cpp:2418
void clear()
Definition: epgcache.cpp:870
void setEpgmaxdays(unsigned int epgmaxdays)
Definition: epgcache.cpp:2148
RESULT getNextTimeEntry(Event *&)
Definition: epgcache.cpp:1437
Definition: epgchanneldata.h:75
Definition: epgtransponderdatareader.h:52
Definition: ebase.h:187
Definition: python.h:31
Definition: idvb.h:192
Definition: iservice.h:15
Definition: thread.h:27
std::tr1::unordered_map< uniqueEPGKey, EventCacheItem, hash_uniqueEPGKey, uniqueEPGKey::equal > eventCache
Definition: epgcache.h:95
std::tr1::unordered_map< uniqueEPGKey, contentMap, hash_uniqueEPGKey, uniqueEPGKey::equal > contentMaps
Definition: epgcache.h:99
std::map< time_t, eventData * > timeMap
Definition: epgcache.h:78
std::tr1::unordered_map< time_t, std::pair< time_t, uint16_t > > contentTimeMap
Definition: epgcache.h:97
std::tr1::unordered_map< int, contentTimeMap > contentMap
Definition: epgcache.h:98
std::map< uint16_t, eventData * > eventMap
Definition: epgcache.h:76
const char * filename
Definition: epng.h:36
unsigned char data[256]
Definition: hdmi_cec.h:2
dictionary parental_ratings
Definition: SystemPlugins/IceTV/plugin.py:254
lock
Definition: StartEnigma.py:730
value
Definition: Profile.py:29
list ref
Definition: create_picon_e1_to_e2.py:17
source
Definition: enigma_py_patcher.py:9
list list
Definition: main.py:25
#define DECLARE_REF(x)
Definition: object.h:57
int RESULT
Definition: object.h:12
std::string int x
Definition: picload.cpp:1503
Definition: epgcache.h:88
eventMap byEvent
Definition: epgcache.h:89
timeMap byTime
Definition: epgcache.h:90
int sources
Definition: epgcache.h:91
EventCacheItem()
Definition: epgcache.h:92
Definition: epgcache.h:119
int type
Definition: epgcache.h:126
@ timeChanged
Definition: epgcache.h:124
@ flush
Definition: epgcache.h:122
@ quit
Definition: epgcache.h:123
uniqueEPGKey service
Definition: epgcache.h:127
Message(int type)
Definition: epgcache.h:133
int err
Definition: epgcache.h:129
Message()
Definition: epgcache.h:131
Message(int type, const eServiceReference &service, int err=0)
Definition: epgcache.h:135
Definition: epgcache.h:106
u_char rating
Definition: epgcache.h:108
u_char country_code[3]
Definition: epgcache.h:107
Definition: epgcache.cpp:38
Definition: epgcache.h:81
size_t operator()(const uniqueEPGKey &x) const
Definition: epgcache.h:82
Definition: dvb/scan.h:16
Definition: epgcache.h:67
bool operator()(const uniqueEPGKey &a, const uniqueEPGKey &b) const
Definition: epgcache.h:68
Definition: epgcache.h:30
int onid
Definition: epgcache.h:31
uniqueEPGKey()
Definition: epgcache.h:38
int tsid
Definition: epgcache.h:31
uniqueEPGKey(int sid, int onid, int tsid)
Definition: epgcache.h:42
bool operator==(const uniqueEPGKey &a) const
Definition: epgcache.h:62
bool operator<(const uniqueEPGKey &a) const
Definition: epgcache.h:46
int sid
Definition: epgcache.h:31
uniqueEPGKey(const eServiceReference &ref)
Definition: epgcache.h:32
#define SWIG_PYOBJECT(x)
Definition: swig.h:23