/
EpgContainer.h
295 lines (245 loc) · 9.08 KB
/
EpgContainer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#pragma once
/*
* Copyright (C) 2012-2013 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include "XBDateTime.h"
#include "settings/ISettingCallback.h"
#include "threads/CriticalSection.h"
#include "threads/Thread.h"
#include "utils/Observer.h"
#include "Epg.h"
#include "EpgDatabase.h"
#include <map>
class CFileItemList;
class CGUIDialogProgressBarHandle;
namespace EPG
{
#define g_EpgContainer CEpgContainer::Get()
class CEpgContainer : public Observer,
public Observable,
public ISettingCallback,
private CThread
{
friend class CEpgDatabase;
public:
/*!
* @brief Create a new EPG table container.
*/
CEpgContainer(void);
/*!
* @brief Destroy this instance.
*/
virtual ~CEpgContainer(void);
/*!
* @return An instance of this singleton.
*/
static CEpgContainer &Get(void);
/*!
* @brief Get a pointer to the database instance.
* @return A pointer to the database instance.
*/
CEpgDatabase *GetDatabase(void) { return &m_database; }
/*!
* @brief Start the EPG update thread.
*/
virtual void Start(void);
/*!
* @brief Stop the EPG update thread.
* @return
*/
virtual bool Stop(void);
/*!
* @brief Clear all EPG entries.
* @param bClearDb Clear the database too if true.
*/
virtual void Clear(bool bClearDb = false);
/*!
* @brief Stop the update thread and unload all data.
*/
virtual void Unload(void);
/*!
* @brief Clear the EPG and all it's database entries.
*/
virtual void Reset(void) { Clear(true); }
/*!
* @brief Check whether the EpgContainer has fully started.
* @return True if started, false otherwise.
*/
bool IsStarted(void) const;
/*!
* @brief Delete an EPG table from this container.
* @param epg The table to delete.
* @param bDeleteFromDatabase Delete this table from the database too if true.
* @return
*/
virtual bool DeleteEpg(const CEpg &epg, bool bDeleteFromDatabase = false);
/*!
* @brief Process a notification from an observable.
* @param obs The observable that sent the update.
* @param msg The update message.
*/
virtual void Notify(const Observable &obs, const ObservableMessage msg);
virtual void OnSettingChanged(const CSetting *setting);
CEpg *CreateChannelEpg(PVR::CPVRChannelPtr channel);
/*!
* @brief Get all EPG tables and apply a filter.
* @param results The fileitem list to store the results in.
* @param filter The filter to apply.
* @return The amount of entries that were added.
*/
virtual int GetEPGSearch(CFileItemList &results, const EpgSearchFilter &filter);
/*!
* @brief Get all EPG tables.
* @param results The fileitem list to store the results in.
* @return The amount of entries that were added.
*/
virtual int GetEPGAll(CFileItemList &results);
/*!
* @brief Get the start time of the first entry.
* @return The start time.
*/
virtual const CDateTime GetFirstEPGDate(void);
/*!
* @brief Get the end time of the last entry.
* @return The end time.
*/
virtual const CDateTime GetLastEPGDate(void);
/*!
* @brief Get an EPG table given it's ID.
* @param iEpgId The database ID of the table.
* @return The table or NULL if it wasn't found.
*/
virtual CEpg *GetById(int iEpgId) const;
/*!
* @brief Get an EPG table given a PVR channel.
* @param channel The channel to get the EPG table for.
* @return The table or NULL if it wasn't found.
*/
virtual CEpg *GetByChannel(const PVR::CPVRChannel &channel) const;
/*!
* @brief Notify EPG table observers when the currently active tag changed.
* @return True if the check was done, false if it was not the right time to check
*/
virtual bool CheckPlayingEvents(void);
/*!
* @brief The next EPG ID to be given to a table when the db isn't being used.
* @return The next ID.
*/
unsigned int NextEpgId(void);
/*!
* @brief Close the progress bar if it's visible.
*/
virtual void CloseProgressDialog(void);
/*!
* @brief Show the progress bar
* @param bUpdating True if updating epg entries, false if just loading them from db
*/
virtual void ShowProgressDialog(bool bUpdating = true);
/*!
* @brief Update the progress bar.
* @param iCurrent The current position.
* @param iMax The maximum position.
* @param strText The text to display.
*/
virtual void UpdateProgressDialog(int iCurrent, int iMax, const CStdString &strText);
/*!
* @return True to not to store EPG entries in the database.
*/
virtual bool IgnoreDB(void) const { return m_bIgnoreDbForClient; }
/*!
* @brief Wait for an EPG update to finish.
* @param bInterrupt True to interrupt a running update.
*/
void WaitForUpdateFinish(bool bInterrupt = true);
/*!
* @brief Set to true to prevent updates.
* @param bSetTo The new value.
*/
void PreventUpdates(bool bSetTo = true) { m_bPreventUpdates = bSetTo; }
/*!
* @brief Notify EPG container that there are pending manual EPG updates
* @param bHasPendingUpdates The new value
*/
void SetHasPendingUpdates(bool bHasPendingUpdates = true);
/*!
* @return True while being initialised.
*/
bool IsInitialising(void) const;
/*!
* @brief Call Persist() on each table
* @return True when they all were persisted, false otherwise.
*/
bool PersistAll(void);
bool PersistTables(void);
protected:
/*!
* @brief Load the EPG settings.
* @return True if the settings were loaded successfully, false otherwise.
*/
virtual bool LoadSettings(void);
/*!
* @brief Remove old EPG entries.
* @return True if the old entries were removed successfully, false otherwise.
*/
virtual bool RemoveOldEntries(void);
/*!
* @brief Load and update the EPG data.
* @param bOnlyPending Only check and update EPG tables with pending manual updates
* @return True if the update has not been interrupted, false otherwise.
*/
virtual bool UpdateEPG(bool bOnlyPending = false);
/*!
* @return True if a running update should be interrupted, false otherwise.
*/
virtual bool InterruptUpdate(void) const;
/*!
* @brief EPG update thread
*/
virtual void Process(void);
/*!
* @brief Load all tables from the database
*/
void LoadFromDB(void);
void InsertFromDatabase(int iEpgID, const CStdString &strName, const CStdString &strScraperName);
CEpgDatabase m_database; /*!< the EPG database */
/** @name Configuration */
//@{
bool m_bIgnoreDbForClient; /*!< don't save the EPG data in the database */
int m_iDisplayTime; /*!< hours of EPG data to fetch */
int m_iUpdateTime; /*!< update the full EPG after this period */
//@}
/** @name Class state properties */
//@{
bool m_bIsUpdating; /*!< true while an update is running */
bool m_bIsInitialising; /*!< true while the epg manager hasn't loaded all tables */
bool m_bStarted; /*!< true if EpgContainer has fully started */
bool m_bLoaded; /*!< true after epg data is initially loaded from the database */
bool m_bPreventUpdates; /*!< true to prevent EPG updates */
bool m_bHasPendingUpdates; /*!< true if there are manual updates pending */
time_t m_iLastEpgCleanup; /*!< the time the EPG was cleaned up */
time_t m_iNextEpgUpdate; /*!< the time the EPG will be updated */
time_t m_iNextEpgActiveTagCheck; /*!< the time the EPG will be checked for active tag updates */
unsigned int m_iNextEpgId; /*!< the next epg ID that will be given to a new table when the db isn't being used */
std::map<unsigned int, CEpg*> m_epgs; /*!< the EPGs in this container */
//@}
CGUIDialogProgressBarHandle * m_progressHandle; /*!< the progress dialog that is visible when updating the first time */
CCriticalSection m_critSection; /*!< a critical section for changes to this container */
CEvent m_updateEvent; /*!< trigger when an update finishes */
};
}