xbmc
Epg.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 "XBDateTime.h"
12 #include "addons/kodi-dev-kit/include/kodi/c-api/addon-instance/pvr/pvr_epg.h"
13 #include "pvr/epg/EpgTagsContainer.h"
14 #include "threads/CriticalSection.h"
15 #include "utils/EventStream.h"
16 
17 #include <atomic>
18 #include <map>
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 namespace PVR
24 {
25  enum class PVREvent;
26 
27  class CPVREpgChannelData;
28  class CPVREpgDatabase;
29  class CPVREpgInfoTag;
30 
31  class CPVREpg
32  {
33  friend class CPVREpgDatabase;
34 
35  public:
43  CPVREpg(int iEpgID,
44  const std::string& strName,
45  const std::string& strScraperName,
46  const std::shared_ptr<CPVREpgDatabase>& database);
47 
56  CPVREpg(int iEpgID,
57  const std::string& strName,
58  const std::string& strScraperName,
59  const std::shared_ptr<CPVREpgChannelData>& channelData,
60  const std::shared_ptr<CPVREpgDatabase>& database);
61 
65  virtual ~CPVREpg();
66 
71  std::shared_ptr<CPVREpgChannelData> GetChannelData() const;
72 
77  void SetChannelData(const std::shared_ptr<CPVREpgChannelData>& data);
78 
83  int ChannelID() const;
84 
89  const std::string& ScraperName() const;
90 
95  bool UpdatePending() const;
96 
100  void ForceUpdate();
101 
106  const std::string& Name() const;
107 
112  int EpgID() const;
113 
118  void Cleanup(const CDateTime& time);
119 
123  void Clear();
124 
129  std::shared_ptr<CPVREpgInfoTag> GetTagNow() const;
130 
135  std::shared_ptr<CPVREpgInfoTag> GetTagNext() const;
136 
141  std::shared_ptr<CPVREpgInfoTag> GetTagPrevious() const;
142 
150  std::shared_ptr<CPVREpgInfoTag> GetTagBetween(const CDateTime& beginTime, const CDateTime& endTime, bool bUpdateFromClient = false);
151 
157  std::shared_ptr<CPVREpgInfoTag> GetTagByBroadcastId(unsigned int iUniqueBroadcastId) const;
158 
164  std::shared_ptr<CPVREpgInfoTag> GetTagByDatabaseId(int iDatabaseId) const;
165 
172  bool UpdateEntry(const EPG_TAG* data, int iClientId);
173 
180  bool UpdateEntry(const std::shared_ptr<CPVREpgInfoTag>& tag, EPG_EVENT_STATE newState);
181 
192  bool Update(time_t start, time_t end, int iUpdateTime, int iPastDays, const std::shared_ptr<CPVREpgDatabase>& database, bool bForceUpdate = false);
193 
198  std::vector<std::shared_ptr<CPVREpgInfoTag>> GetTags() const;
199 
208  std::vector<std::shared_ptr<CPVREpgInfoTag>> GetTimeline(const CDateTime& timelineStart,
209  const CDateTime& timelineEnd,
210  const CDateTime& minEventEnd,
211  const CDateTime& maxEventStart) const;
212 
218  bool QueuePersistQuery(const std::shared_ptr<CPVREpgDatabase>& database);
219 
225  bool QueueDeleteQueries(const std::shared_ptr<CPVREpgDatabase>& database);
226 
231  std::pair<CDateTime, CDateTime> GetFirstAndLastUncommitedEPGDate() const;
232 
237  bool CheckPlayingEvent();
238 
245  static const std::string& ConvertGenreIdToString(int iID, int iSubID);
246 
251  bool NeedsSave() const;
252 
257  bool IsValid() const;
258 
262  CEventStream<PVREvent>& Events() { return m_events; }
263 
267  void Lock() { m_critSection.lock(); }
268 
272  void Unlock() { m_critSection.unlock(); }
273 
277  void RemovedFromContainer();
278 
284  int CleanupCachedImages(const std::shared_ptr<CPVREpgDatabase>& database);
285 
286  private:
287  CPVREpg() = delete;
288  CPVREpg(const CPVREpg&) = delete;
289  CPVREpg& operator =(const CPVREpg&) = delete;
290 
299  bool UpdateFromScraper(time_t start, time_t end, bool bForceUpdate);
300 
306  bool UpdateEntries(const CPVREpg& epg);
307 
312  void Cleanup(int iPastDays);
313 
314  bool m_bChanged = false;
315  std::atomic<bool> m_bUpdatePending = {false};
316  int m_iEpgID = 0;
317  std::string m_strName;
318  std::string m_strScraperName;
319  CDateTime m_lastScanTime;
320  mutable CCriticalSection m_critSection;
321  bool m_bUpdateLastScanTime = false;
322  std::shared_ptr<CPVREpgChannelData> m_channelData;
323  CPVREpgTagsContainer m_tags;
324 
325  CEventSource<PVREvent> m_events;
326  };
327 }
std::shared_ptr< CPVREpgInfoTag > GetTagNow() const
Get the event that is occurring now.
Definition: Epg.cpp:87
bool NeedsSave() const
Check whether this EPG has unsaved data.
Definition: Epg.cpp:528
std::shared_ptr< CPVREpgInfoTag > GetTagByDatabaseId(int iDatabaseId) const
Get the event matching the given database id.
Definition: Epg.cpp:122
int CleanupCachedImages(const std::shared_ptr< CPVREpgDatabase > &database)
Erase stale texture db entries and image files.
Definition: Epg.cpp:548
Definition: EpgDatabase.h:31
std::shared_ptr< CPVREpgInfoTag > GetTagBetween(const CDateTime &beginTime, const CDateTime &endTime, bool bUpdateFromClient=false)
Get the event that occurs between the given begin and end time.
Definition: Epg.cpp:128
Definition: ContextMenuManager.h:24
bool UpdatePending() const
Returns if there is a manual update pending for this EPG.
Definition: Epg.cpp:523
void Clear()
Remove all entries from this EPG.
Definition: Epg.cpp:69
int ChannelID() const
The id of the channel associated with this EPG.
Definition: Epg.cpp:499
"C" PVR add-on channel group member.
Definition: pvr_epg.h:622
void RemovedFromContainer()
Called to inform the EPG that it has been removed from the EPG container.
Definition: Epg.cpp:543
int EpgID() const
Get the database ID of this table.
Definition: Epg.cpp:517
void Unlock()
Unlock the instance. Other threads may get access to this EPG again.
Definition: Epg.h:272
std::shared_ptr< CPVREpgInfoTag > GetTagNext() const
Get the event that will occur next.
Definition: Epg.cpp:93
void Lock()
Lock the instance. No other thread gets access to this EPG until Unlock was called.
Definition: Epg.h:267
static const std::string & ConvertGenreIdToString(int iID, int iSubID)
Convert a genre id and subid to a human readable name.
Definition: Epg.cpp:438
const std::string & Name() const
Get the name of this table.
Definition: Epg.cpp:511
bool CheckPlayingEvent()
Notify observers when the currently active tag changed.
Definition: Epg.cpp:105
bool QueuePersistQuery(const std::shared_ptr< CPVREpgDatabase > &database)
Write the query to persist data into given database&#39;s queue.
Definition: Epg.cpp:324
bool UpdateEntry(const EPG_TAG *data, int iClientId)
Update an entry in this EPG.
Definition: Epg.cpp:195
void Cleanup(const CDateTime &time)
Remove all entries from this EPG that finished before the given time.
Definition: Epg.cpp:81
CEventStream< PVREvent > & Events()
Query the events available for CEventStream.
Definition: Epg.h:262
const std::string & ScraperName() const
Get the name of the scraper to use for this table.
Definition: Epg.cpp:505
void ForceUpdate()
Clear the current tags and schedule manual update.
Definition: Epg.cpp:63
DateTime class, which uses FileTime as it&#39;s base.
Definition: XBDateTime.h:63
bool Update(time_t start, time_t end, int iUpdateTime, int iPastDays, const std::shared_ptr< CPVREpgDatabase > &database, bool bForceUpdate=false)
Update the EPG from &#39;start&#39; till &#39;end&#39;.
Definition: Epg.cpp:248
bool QueueDeleteQueries(const std::shared_ptr< CPVREpgDatabase > &database)
Write the delete queries into the given database&#39;s queue.
Definition: Epg.cpp:357
std::pair< CDateTime, CDateTime > GetFirstAndLastUncommitedEPGDate() const
Get the start and end time of the last not yet commited entry in this table.
Definition: Epg.cpp:381
Definition: Epg.h:31
std::shared_ptr< CPVREpgInfoTag > GetTagByBroadcastId(unsigned int iUniqueBroadcastId) const
Get the event matching the given unique broadcast id.
Definition: Epg.cpp:116
bool IsValid() const
Check whether this EPG is valid.
Definition: Epg.cpp:534
std::vector< std::shared_ptr< CPVREpgInfoTag > > GetTags() const
Get all EPG tags.
Definition: Epg.cpp:318
std::shared_ptr< CPVREpgChannelData > GetChannelData() const
Get data for the channel associated with this EPG.
Definition: Epg.cpp:486
std::shared_ptr< CPVREpgInfoTag > GetTagPrevious() const
Get the event that occurred previously.
Definition: Epg.cpp:99
EPG_EVENT_STATE
Definition: pvr_epg.h:601
virtual ~CPVREpg()
Destroy this EPG instance.
Definition: Epg.cpp:58
std::vector< std::shared_ptr< CPVREpgInfoTag > > GetTimeline(const CDateTime &timelineStart, const CDateTime &timelineEnd, const CDateTime &minEventEnd, const CDateTime &maxEventStart) const
Get all EPG tags for the given time frame, including "gap" tags.
Definition: Epg.cpp:155
void SetChannelData(const std::shared_ptr< CPVREpgChannelData > &data)
Set data for the channel associated with this EPG.
Definition: Epg.cpp:492
Definition: EpgTagsContainer.h:24