xbmc
EpgDatabase.h
1 /*
2  * Copyright (C) 2012-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "dbwrappers/Database.h"
12 #include "threads/CriticalSection.h"
13 
14 #include <memory>
15 #include <vector>
16 
17 class CDateTime;
18 
19 namespace PVR
20 {
21  class CPVREpg;
22  class CPVREpgInfoTag;
23  class CPVREpgSearchFilter;
24 
25  struct PVREpgSearchData;
26 
29  static constexpr int EPG_COMMIT_QUERY_COUNT_LIMIT = 10000;
30 
31  class CPVREpgDatabase : public CDatabase, public std::enable_shared_from_this<CPVREpgDatabase>
32  {
33  public:
37  CPVREpgDatabase() = default;
38 
42  ~CPVREpgDatabase() override = default;
43 
48  bool Open() override;
49 
53  void Close() override;
54 
58  void Lock();
59 
63  void Unlock();
64 
69  int GetSchemaVersion() const override { return 16; }
70 
75  const char* GetBaseDBName() const override { return "Epg"; }
76 
79 
84  bool DeleteEpg();
85 
91  bool QueueDeleteEpgQuery(const CPVREpg& table);
92 
98  bool QueueDeleteTagQuery(const CPVREpgInfoTag& tag);
99 
104  std::vector<std::shared_ptr<CPVREpg>> GetAll();
105 
111  std::vector<std::shared_ptr<CPVREpgInfoTag>> GetAllEpgTags(int iEpgID);
112 
118  std::vector<std::string> GetAllIconPaths(int iEpgID);
119 
125  bool HasTags(int iEpgID);
126 
132  CDateTime GetLastEndTime(int iEpgID);
133 
138  std::pair<CDateTime, CDateTime> GetFirstAndLastEPGDate();
139 
146  CDateTime GetMinStartTime(int iEpgID, const CDateTime& minStart);
147 
154  CDateTime GetMaxEndTime(int iEpgID, const CDateTime& maxEnd);
155 
161  std::vector<std::shared_ptr<CPVREpgInfoTag>> GetEpgTags(const PVREpgSearchData& searchData);
162 
169  std::shared_ptr<CPVREpgInfoTag> GetEpgTagByUniqueBroadcastID(int iEpgID,
170  unsigned int iUniqueBroadcastId);
171 
178  std::shared_ptr<CPVREpgInfoTag> GetEpgTagByDatabaseID(int iEpgID, int iDatabaseId);
179 
186  std::shared_ptr<CPVREpgInfoTag> GetEpgTagByStartTime(int iEpgID, const CDateTime& startTime);
187 
194  std::shared_ptr<CPVREpgInfoTag> GetEpgTagByMinStartTime(int iEpgID,
195  const CDateTime& minStartTime);
196 
203  std::shared_ptr<CPVREpgInfoTag> GetEpgTagByMaxEndTime(int iEpgID, const CDateTime& maxEndTime);
204 
212  std::vector<std::shared_ptr<CPVREpgInfoTag>> GetEpgTagsByMinStartMaxEndTime(
213  int iEpgID, const CDateTime& minStartTime, const CDateTime& maxEndTime);
214 
222  std::vector<std::shared_ptr<CPVREpgInfoTag>> GetEpgTagsByMinEndMaxStartTime(
223  int iEpgID, const CDateTime& minEndTime, const CDateTime& maxStartTime);
224 
234  const CDateTime& minEndTime,
235  const CDateTime& maxStartTime);
236 
243  bool GetLastEpgScanTime(int iEpgId, CDateTime* lastScan);
244 
251  bool QueuePersistLastEpgScanTimeQuery(int iEpgId, const CDateTime& lastScanTime);
252 
258  bool QueueDeleteLastEpgScanTimeQuery(const CPVREpg& table);
259 
266  int Persist(const CPVREpg& epg, bool bQueueWrite);
267 
274  bool DeleteEpgTags(int iEpgId, const CDateTime& maxEndTime);
275 
281  bool DeleteEpgTags(int iEpgId);
282 
288  bool QueueDeleteEpgTags(int iEpgId);
289 
295  bool QueuePersistQuery(const CPVREpgInfoTag& tag);
296 
300  int GetLastEPGId();
301 
303 
306 
312  std::vector<std::shared_ptr<CPVREpgSearchFilter>> GetSavedSearches(bool bRadio);
313 
320  std::shared_ptr<CPVREpgSearchFilter> GetSavedSearchById(bool bRadio, int iId);
321 
327  bool Persist(CPVREpgSearchFilter& epgSearch);
328 
334  bool UpdateSavedSearchLastExecuted(const CPVREpgSearchFilter& epgSearch);
335 
341  bool Delete(const CPVREpgSearchFilter& epgSearch);
342 
347  bool DeleteSavedSearches();
348 
350 
351  private:
355  void CreateTables() override;
356 
360  void CreateAnalytics() override;
361 
366  void UpdateTables(int version) override;
367 
368  int GetMinSchemaVersion() const override { return 4; }
369 
370  std::shared_ptr<CPVREpgInfoTag> CreateEpgTag(const std::unique_ptr<dbiplus::Dataset>& pDS);
371 
372  std::shared_ptr<CPVREpgSearchFilter> CreateEpgSearchFilter(
373  bool bRadio, const std::unique_ptr<dbiplus::Dataset>& pDS);
374 
375  CCriticalSection m_critSection;
376  };
377 }
std::shared_ptr< CPVREpgSearchFilter > GetSavedSearchById(bool bRadio, int iId)
Get the saved search matching the given id.
Definition: EpgDatabase.cpp:1357
bool DeleteEpg()
Remove all EPG information from the database.
Definition: EpgDatabase.cpp:329
CPVREpgDatabase()=default
Create a new instance of the EPG database.
std::shared_ptr< CPVREpgInfoTag > GetEpgTagByDatabaseID(int iEpgID, int iDatabaseId)
Get an EPG tag given its EPG id and database ID.
Definition: EpgDatabase.cpp:815
Definition: EpgSearchFilter.h:23
std::shared_ptr< CPVREpgInfoTag > GetEpgTagByMinStartTime(int iEpgID, const CDateTime &minStartTime)
Get the next EPG tag matching the given EPG id and min start time.
Definition: EpgDatabase.cpp:871
~CPVREpgDatabase() override=default
Destroy this instance.
Definition: EpgDatabase.h:31
void Unlock()
Unlock the database.
Definition: EpgDatabase.cpp:47
int Persist(const CPVREpg &epg, bool bQueueWrite)
Persist an EPG table. It&#39;s entries are not persisted.
Definition: EpgDatabase.cpp:1139
Definition: ContextMenuManager.h:24
CDateTime GetLastEndTime(int iEpgID)
Get the end time of the last tag in this EPG.
Definition: EpgDatabase.cpp:472
bool Delete(const CPVREpgSearchFilter &epgSearch)
Delete a saved search.
Definition: EpgDatabase.cpp:1472
std::vector< std::string > GetAllIconPaths(int iEpgID)
Get all icon paths for a given EPG id.
Definition: EpgDatabase.cpp:1063
std::vector< std::shared_ptr< CPVREpgSearchFilter > > GetSavedSearches(bool bRadio)
Get all saved searches from the database.
Definition: EpgDatabase.cpp:1331
CDateTime GetMaxEndTime(int iEpgID, const CDateTime &maxEnd)
Get the end time of the first tag with an end time less than the given max time.
Definition: EpgDatabase.cpp:525
std::vector< std::shared_ptr< CPVREpgInfoTag > > GetAllEpgTags(int iEpgID)
Get all tags for a given EPG id.
Definition: EpgDatabase.cpp:1037
bool QueueDeleteTagQuery(const CPVREpgInfoTag &tag)
Write the query to delete the given EPG tag to db query queue.
Definition: EpgDatabase.cpp:364
bool QueueDeleteEpgTags(int iEpgId)
Queue the erase all EPG tags with the given epg ID.
Definition: EpgDatabase.cpp:1190
bool QueueDeleteEpgQuery(const CPVREpg &table)
Queue deletionof an EPG table.
Definition: EpgDatabase.cpp:343
Definition: EpgInfoTag.h:28
std::vector< std::shared_ptr< CPVREpgInfoTag > > GetEpgTagsByMinStartMaxEndTime(int iEpgID, const CDateTime &minStartTime, const CDateTime &maxEndTime)
Get all EPG tags matching the given EPG id, min start time and max end time.
Definition: EpgDatabase.cpp:933
std::shared_ptr< CPVREpgInfoTag > GetEpgTagByStartTime(int iEpgID, const CDateTime &startTime)
Get an EPG tag given its EPG ID and start time.
Definition: EpgDatabase.cpp:841
bool QueueDeleteLastEpgScanTimeQuery(const CPVREpg &table)
Write the query to delete the last scan time for the given EPG to db query queue. ...
Definition: EpgDatabase.cpp:1119
std::vector< std::shared_ptr< CPVREpg > > GetAll()
Get all EPG tables from the database. Does not get the EPG tables&#39; entries.
Definition: EpgDatabase.cpp:380
bool UpdateSavedSearchLastExecuted(const CPVREpgSearchFilter &epgSearch)
Update time last executed for the given search.
Definition: EpgDatabase.cpp:1459
std::vector< std::shared_ptr< CPVREpgInfoTag > > GetEpgTags(const PVREpgSearchData &searchData)
Get all EPG tags matching the given search criteria.
Definition: EpgDatabase.cpp:667
Definition: Database.h:26
std::pair< CDateTime, CDateTime > GetFirstAndLastEPGDate()
Get the start and end time across all EPGs.
Definition: EpgDatabase.cpp:484
bool QueuePersistQuery(const CPVREpgInfoTag &tag)
Write the query to persist the given EPG tag to db query queue.
Definition: EpgDatabase.cpp:1202
bool QueuePersistLastEpgScanTimeQuery(int iEpgId, const CDateTime &lastScanTime)
Write the query to update the last scan time for the given EPG to db query queue. ...
Definition: EpgDatabase.cpp:1110
std::shared_ptr< CPVREpgInfoTag > GetEpgTagByUniqueBroadcastID(int iEpgID, unsigned int iUniqueBroadcastId)
Get an EPG tag given its EPG id and unique broadcast ID.
Definition: EpgDatabase.cpp:788
const char * GetBaseDBName() const override
Get the default sqlite database filename.
Definition: EpgDatabase.h:75
int GetSchemaVersion() const override
Get the minimal database version that is required to operate correctly.
Definition: EpgDatabase.h:69
DateTime class, which uses FileTime as it&#39;s base.
Definition: XBDateTime.h:63
bool GetLastEpgScanTime(int iEpgId, CDateTime *lastScan)
Get the last stored EPG scan time.
Definition: EpgDatabase.cpp:1089
bool Open() override
Open the database.
Definition: EpgDatabase.cpp:30
Definition: EpgSearchData.h:20
std::vector< std::shared_ptr< CPVREpgInfoTag > > GetEpgTagsByMinEndMaxStartTime(int iEpgID, const CDateTime &minEndTime, const CDateTime &maxStartTime)
Get all EPG tags matching the given EPG id, min end time and max start time.
Definition: EpgDatabase.cpp:973
bool HasTags(int iEpgID)
Check whether this EPG has any tags.
Definition: EpgDatabase.cpp:463
Definition: Epg.h:31
int GetLastEPGId()
Definition: EpgDatabase.cpp:1272
bool DeleteEpgTags(int iEpgId, const CDateTime &maxEndTime)
Erase all EPG tags with the given epg ID and an end time less than the given time.
Definition: EpgDatabase.cpp:1168
bool QueueDeleteEpgTagsByMinEndMaxStartTimeQuery(int iEpgID, const CDateTime &minEndTime, const CDateTime &maxStartTime)
Write the query to delete all EPG tags in range of given EPG id, min end time and max start time to d...
Definition: EpgDatabase.cpp:1013
bool DeleteSavedSearches()
Delete all saved searches.
Definition: EpgDatabase.cpp:1488
CDateTime GetMinStartTime(int iEpgID, const CDateTime &minStart)
Get the start time of the first tag with a start time greater than the given min time.
Definition: EpgDatabase.cpp:508
void Close() override
Close the database.
Definition: EpgDatabase.cpp:36
void Lock()
Lock the database.
Definition: EpgDatabase.cpp:42
std::shared_ptr< CPVREpgInfoTag > GetEpgTagByMaxEndTime(int iEpgID, const CDateTime &maxEndTime)
Get the next EPG tag matching the given EPG id and max end time.
Definition: EpgDatabase.cpp:902