xbmc
PVRTimers.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 "pvr/settings/PVRSettings.h"
12 #include "threads/Thread.h"
13 
14 #include <map>
15 #include <memory>
16 #include <queue>
17 #include <vector>
18 
19 class CDateTime;
20 
21 namespace PVR
22 {
23 enum class TimerOperationResult;
24 enum class PVREvent;
25 
26 class CPVRChannel;
27 class CPVRClient;
28 class CPVREpgInfoTag;
29 class CPVRTimerInfoTag;
30 class CPVRTimersPath;
31 
33 {
34 public:
41  bool UpdateFromClient(const std::shared_ptr<CPVRTimerInfoTag>& timer);
42 
49  std::shared_ptr<CPVRTimerInfoTag> GetByClient(int iClientId, int iClientIndex) const;
50 
51  typedef std::vector<std::shared_ptr<CPVRTimerInfoTag>> VecTimerInfoTag;
52  typedef std::map<CDateTime, VecTimerInfoTag> MapTags;
53 
58  const MapTags& GetTags() const { return m_tags; }
59 
60 protected:
61  void InsertEntry(const std::shared_ptr<CPVRTimerInfoTag>& newTimer);
62 
63  mutable CCriticalSection m_critSection;
64  unsigned int m_iLastId = 0;
65  MapTags m_tags;
66 };
67 
68 class CPVRTimers : public CPVRTimersContainer, private CThread
69 {
70 public:
71  CPVRTimers();
72  ~CPVRTimers() override = default;
73 
77  void Start();
78 
82  void Stop();
83 
89  bool Update(const std::vector<std::shared_ptr<CPVRClient>>& clients);
90 
94  void Unload();
95 
102  bool UpdateFromClients(const std::vector<std::shared_ptr<CPVRClient>>& clients);
103 
108  std::shared_ptr<CPVRTimerInfoTag> GetNextActiveTimer(bool bIgnoreReminders = true) const;
109 
113  std::shared_ptr<CPVRTimerInfoTag> GetNextActiveTVTimer() const;
114 
118  std::shared_ptr<CPVRTimerInfoTag> GetNextActiveRadioTimer() const;
119 
123  std::vector<std::shared_ptr<CPVRTimerInfoTag>> GetActiveTimers() const;
124 
128  std::shared_ptr<CPVRTimerInfoTag> GetNextReminderToAnnnounce();
129 
134  std::vector<std::shared_ptr<CPVRTimerInfoTag>> GetAll() const;
135 
139  int AmountActiveTimers() const;
140 
144  int AmountActiveTVTimers() const;
145 
149  int AmountActiveRadioTimers() const;
150 
154  std::vector<std::shared_ptr<CPVRTimerInfoTag>> GetActiveRecordings() const;
155 
159  std::vector<std::shared_ptr<CPVRTimerInfoTag>> GetActiveTVRecordings() const;
160 
164  std::vector<std::shared_ptr<CPVRTimerInfoTag>> GetActiveRadioRecordings() const;
165 
169  bool IsRecording() const;
170 
176  bool IsRecordingOnChannel(const CPVRChannel& channel) const;
177 
183  std::shared_ptr<CPVRTimerInfoTag> GetActiveTimerForChannel(
184  const std::shared_ptr<CPVRChannel>& channel) const;
185 
189  int AmountActiveRecordings() const;
190 
194  int AmountActiveTVRecordings() const;
195 
199  int AmountActiveRadioRecordings() const;
200 
208  bool DeleteTimersOnChannel(const std::shared_ptr<CPVRChannel>& channel,
209  bool bDeleteTimerRules = true,
210  bool bCurrentlyActiveOnly = false);
211 
215  CDateTime GetNextEventTime() const;
216 
223  bool AddTimer(const std::shared_ptr<CPVRTimerInfoTag>& tag);
224 
235  TimerOperationResult DeleteTimer(const std::shared_ptr<CPVRTimerInfoTag>& tag,
236  bool bForce = false,
237  bool bDeleteRule = false);
238 
245  bool UpdateTimer(const std::shared_ptr<CPVRTimerInfoTag>& tag);
246 
252  std::shared_ptr<CPVRTimerInfoTag> GetTimerForEpgTag(
253  const std::shared_ptr<CPVREpgInfoTag>& epgTag) const;
254 
260  std::shared_ptr<CPVRTimerInfoTag> GetTimerRule(
261  const std::shared_ptr<CPVRTimerInfoTag>& timer) const;
262 
266  void UpdateChannels();
267 
272  void Notify(const PVREvent& event);
273 
279  std::shared_ptr<CPVRTimerInfoTag> GetById(unsigned int iTimerId) const;
280 
281 private:
282  void Process() override;
283 
289  bool LoadFromDatabase(const std::vector<std::shared_ptr<CPVRClient>>& clients);
290 
291  void RemoveEntry(const std::shared_ptr<CPVRTimerInfoTag>& tag);
292  bool UpdateEntries(const CPVRTimersContainer& timers, const std::vector<int>& failedClients);
293  bool UpdateEntries(int iMaxNotificationDelay);
294  std::shared_ptr<CPVRTimerInfoTag> UpdateEntry(const std::shared_ptr<CPVRTimerInfoTag>& timer);
295 
296  bool AddLocalTimer(const std::shared_ptr<CPVRTimerInfoTag>& tag, bool bNotify);
297  bool DeleteLocalTimer(const std::shared_ptr<CPVRTimerInfoTag>& tag, bool bNotify);
298  bool UpdateLocalTimer(const std::shared_ptr<CPVRTimerInfoTag>& tag);
299  std::shared_ptr<CPVRTimerInfoTag> PersistAndUpdateLocalTimer(
300  const std::shared_ptr<CPVRTimerInfoTag>& timer,
301  const std::shared_ptr<CPVRTimerInfoTag>& parentTimer);
302  void NotifyTimersEvent(bool bAddedOrDeleted = true);
303 
304  enum TimerKind
305  {
306  TimerKindAny = 0,
307  TimerKindTV,
308  TimerKindRadio
309  };
310 
311  bool KindMatchesTag(const TimerKind& eKind, const std::shared_ptr<CPVRTimerInfoTag>& tag) const;
312 
313  std::shared_ptr<CPVRTimerInfoTag> GetNextActiveTimer(const TimerKind& eKind,
314  bool bIgnoreReminders) const;
315  int AmountActiveTimers(const TimerKind& eKind) const;
316  std::vector<std::shared_ptr<CPVRTimerInfoTag>> GetActiveRecordings(const TimerKind& eKind) const;
317  int AmountActiveRecordings(const TimerKind& eKind) const;
318 
319  bool CheckAndAppendTimerNotification(std::vector<std::pair<int, std::string>>& timerNotifications,
320  const std::shared_ptr<CPVRTimerInfoTag>& tag,
321  bool bDeleted) const;
322 
323  bool m_bIsUpdating = false;
324  CPVRSettings m_settings;
325  std::queue<std::shared_ptr<CPVRTimerInfoTag>> m_remindersToAnnounce;
326  bool m_bReminderRulesUpdatePending = false;
327 
328  bool m_bFirstUpdate = true;
329  std::vector<int> m_failedClients;
330 };
331 } // namespace PVR
Definition: Thread.h:44
Definition: PVRChannel.h:35
Definition: ContextMenuManager.h:24
const MapTags & GetTags() const
Get the timertags map.
Definition: PVRTimers.h:58
bool UpdateFromClient(const std::shared_ptr< CPVRTimerInfoTag > &timer)
Add a timer tag to this container or update the tag if already present in this container.
Definition: PVRTimers.cpp:44
Definition: PVRTimers.h:68
DateTime class, which uses FileTime as it&#39;s base.
Definition: XBDateTime.h:63
Definition: PVRTimers.h:32
Definition: PVRSettings.h:27
std::shared_ptr< CPVRTimerInfoTag > GetByClient(int iClientId, int iClientIndex) const
Get the timer tag denoted by given client id and timer id.
Definition: PVRTimers.cpp:61