kodi
EpgTagsContainer.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 
13 #include <map>
14 #include <memory>
15 #include <vector>
16 
17 namespace PVR
18 {
19 class CPVREpgTagsCache;
20 class CPVREpgChannelData;
21 class CPVREpgDatabase;
22 class CPVREpgInfoTag;
23 
25 {
26 public:
27  CPVREpgTagsContainer() = delete;
28  CPVREpgTagsContainer(int iEpgID,
29  const std::shared_ptr<CPVREpgChannelData>& channelData,
30  const std::shared_ptr<CPVREpgDatabase>& database);
31  virtual ~CPVREpgTagsContainer();
32 
37  void SetEpgID(int iEpgID);
38 
43  void SetChannelData(const std::shared_ptr<CPVREpgChannelData>& data);
44 
50  bool UpdateEntry(const std::shared_ptr<CPVREpgInfoTag>& tag);
51 
57  bool DeleteEntry(const std::shared_ptr<CPVREpgInfoTag>& tag);
58 
64  bool UpdateEntries(const CPVREpgTagsContainer& tags);
65 
69  void Clear();
70 
75  void Cleanup(const CDateTime& time);
76 
81  bool IsEmpty() const;
82 
88  std::shared_ptr<CPVREpgInfoTag> GetTag(const CDateTime& startTime) const;
89 
95  std::shared_ptr<CPVREpgInfoTag> GetTag(unsigned int iUniqueBroadcastID) const;
96 
102  std::shared_ptr<CPVREpgInfoTag> GetTagByDatabaseID(int iDatabaseID) const;
103 
110  std::shared_ptr<CPVREpgInfoTag> GetTagBetween(const CDateTime& start, const CDateTime& end) const;
111 
116  bool UpdateActiveTag();
117 
122  std::shared_ptr<CPVREpgInfoTag> GetActiveTag() const;
123 
128  std::shared_ptr<CPVREpgInfoTag> GetNextStartingTag() const;
129 
134  std::shared_ptr<CPVREpgInfoTag> GetLastEndedTag() const;
135 
144  std::vector<std::shared_ptr<CPVREpgInfoTag>> GetTimeline(const CDateTime& timelineStart,
145  const CDateTime& timelineEnd,
146  const CDateTime& minEventEnd,
147  const CDateTime& maxEventStart) const;
148 
153  std::vector<std::shared_ptr<CPVREpgInfoTag>> GetAllTags() const;
154 
159  std::pair<CDateTime, CDateTime> GetFirstAndLastUncommitedEPGDate() const;
160 
165  bool NeedsSave() const;
166 
170  void QueuePersistQuery();
171 
175  void QueueDelete();
176 
177 private:
183  std::vector<std::shared_ptr<CPVREpgInfoTag>> CreateEntries(
184  const std::vector<std::shared_ptr<CPVREpgInfoTag>>& tags) const;
185 
191  std::shared_ptr<CPVREpgInfoTag> CreateEntry(const std::shared_ptr<CPVREpgInfoTag>& tag) const;
192 
199  std::shared_ptr<CPVREpgInfoTag> CreateGapTag(const CDateTime& start, const CDateTime& end) const;
200 
207  void MergeTags(const CDateTime& minEventEnd,
208  const CDateTime& maxEventStart,
209  std::vector<std::shared_ptr<CPVREpgInfoTag>>& tags) const;
210 
215  void FixOverlappingEvents(std::vector<std::shared_ptr<CPVREpgInfoTag>>& tags) const;
216  void FixOverlappingEvents(std::map<CDateTime, std::shared_ptr<CPVREpgInfoTag>>& tags) const;
217 
218  int m_iEpgID = 0;
219  std::shared_ptr<CPVREpgChannelData> m_channelData;
220  const std::shared_ptr<CPVREpgDatabase> m_database;
221  const std::unique_ptr<CPVREpgTagsCache> m_tagsCache;
222 
223  std::map<CDateTime, std::shared_ptr<CPVREpgInfoTag>> m_changedTags;
224  std::map<CDateTime, std::shared_ptr<CPVREpgInfoTag>> m_deletedTags;
225 };
226 
227 } // namespace PVR
std::shared_ptr< CPVREpgInfoTag > GetTagByDatabaseID(int iDatabaseID) const
Get an EPG tag given its database ID.
Definition: EpgTagsContainer.cpp:386
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: EpgTagsContainer.cpp:477
bool NeedsSave() const
Check whether this container has unsaved data.
Definition: EpgTagsContainer.cpp:626
std::shared_ptr< CPVREpgInfoTag > GetActiveTag() const
Get the event that is occurring now.
Definition: EpgTagsContainer.cpp:440
bool UpdateEntry(const std::shared_ptr< CPVREpgInfoTag > &tag)
Update an entry.
Definition: EpgTagsContainer.cpp:278
bool IsEmpty() const
Check whether this container is empty.
Definition: EpgTagsContainer.cpp:344
Definition: ContextMenuManager.h:24
bool UpdateEntries(const CPVREpgTagsContainer &tags)
Update all entries with the provided tags.
Definition: EpgTagsContainer.cpp:134
std::vector< std::shared_ptr< CPVREpgInfoTag > > GetAllTags() const
Get all EPG tags.
Definition: EpgTagsContainer.cpp:584
std::shared_ptr< CPVREpgInfoTag > GetLastEndedTag() const
Get the event that occurred previously.
Definition: EpgTagsContainer.cpp:445
bool DeleteEntry(const std::shared_ptr< CPVREpgInfoTag > &tag)
Delete an entry.
Definition: EpgTagsContainer.cpp:303
std::shared_ptr< CPVREpgInfoTag > GetNextStartingTag() const
Get the event that will occur next.
Definition: EpgTagsContainer.cpp:450
std::shared_ptr< CPVREpgInfoTag > GetTagBetween(const CDateTime &start, const CDateTime &end) const
Get the event that occurs between the given begin and end time.
Definition: EpgTagsContainer.cpp:405
void QueueDelete()
Queue the deletion of this container from its database.
Definition: EpgTagsContainer.cpp:662
std::shared_ptr< CPVREpgInfoTag > GetTag(const CDateTime &startTime) const
Get an EPG tag given its start time.
Definition: EpgTagsContainer.cpp:355
std::pair< CDateTime, CDateTime > GetFirstAndLastUncommitedEPGDate() const
Get the start and end time of the last not yet commited entry in this EPG.
Definition: EpgTagsContainer.cpp:617
void SetChannelData(const std::shared_ptr< CPVREpgChannelData > &data)
Set the channel data for this EPG.
Definition: EpgTagsContainer.cpp:46
DateTime class, which uses FileTime as it&#39;s base.
Definition: XBDateTime.h:63
void QueuePersistQuery()
Write the query to persist data into database&#39;s queue.
Definition: EpgTagsContainer.cpp:631
void Clear()
Release all entries.
Definition: EpgTagsContainer.cpp:338
void Cleanup(const CDateTime &time)
Remove all entries which were finished before the given time.
Definition: EpgTagsContainer.cpp:311
bool UpdateActiveTag()
Update the currently active event.
Definition: EpgTagsContainer.cpp:435
void SetEpgID(int iEpgID)
Set the EPG id for this EPG.
Definition: EpgTagsContainer.cpp:39
Definition: EpgTagsContainer.h:24