kodi
PVRManager.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 "addons/kodi-dev-kit/include/kodi/c-api/addon-instance/pvr/pvr_general.h"
12 #include "interfaces/IAnnouncer.h"
13 #include "pvr/PVRComponentRegistration.h"
14 #include "pvr/guilib/PVRGUIActionListener.h"
15 #include "pvr/settings/PVRSettings.h"
16 #include "threads/CriticalSection.h"
17 #include "threads/Event.h"
18 #include "threads/Thread.h"
19 #include "utils/EventStream.h"
20 
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 class CFileItem;
26 class CStopWatch;
27 
28 namespace PVR
29 {
30 class CPVRChannel;
31 class CPVRChannelGroup;
32 class CPVRChannelGroupsContainer;
33 class CPVRProviders;
34 class CPVRClient;
35 class CPVRClients;
36 class CPVRDatabase;
37 class CPVRGUIInfo;
38 class CPVRGUIProgressHandler;
39 class CPVRManagerJobQueue;
40 class CPVRPlaybackState;
41 class CPVRRecording;
42 class CPVRRecordings;
43 class CPVRTimers;
44 class CPVREpgContainer;
45 class CPVREpgInfoTag;
46 
47 enum class PVREvent
48 {
49  // PVR Manager states
50  ManagerError = 0,
51  ManagerStopped,
52  ManagerStarting,
53  ManagerStopping,
54  ManagerInterrupted,
55  ManagerStarted,
56 
57  // Channel events
58  ChannelPlaybackStopped,
59 
60  // Channel group events
61  ChannelGroup,
62  ChannelGroupInvalidated,
63  ChannelGroupsInvalidated,
64 
65  // Recording events
66  RecordingsInvalidated,
67 
68  // Timer events
69  AnnounceReminder,
70  Timers,
71  TimersInvalidated,
72 
73  // Client events
74  ClientsPrioritiesInvalidated,
75  ClientsInvalidated,
76 
77  // EPG events
78  Epg,
79  EpgActiveItem,
80  EpgContainer,
81  EpgItemUpdate,
82  EpgUpdatePending,
83  EpgDeleted,
84 
85  // Saved searches events
86  SavedSearchesInvalidated,
87 
88  // Item events
89  CurrentItem,
90 
91  // System events
92  SystemSleep,
93  SystemWake,
94 };
95 
97 {
98 public:
102  CPVRManager();
103 
107  ~CPVRManager() override;
108 
109  void Announce(ANNOUNCEMENT::AnnouncementFlag flag,
110  const std::string& sender,
111  const std::string& message,
112  const CVariant& data) override;
113 
118  template<class T>
119  T& Get()
120  {
121  return *m_components->GetComponent<T>();
122  }
123 
128  std::shared_ptr<CPVRProviders> Providers() const;
129 
134  std::shared_ptr<CPVRChannelGroupsContainer> ChannelGroups() const;
135 
140  std::shared_ptr<CPVRRecordings> Recordings() const;
141 
146  std::shared_ptr<CPVRTimers> Timers() const;
147 
152  std::shared_ptr<CPVRClients> Clients() const;
153 
159  std::shared_ptr<CPVRClient> GetClient(const CFileItem& item) const;
160 
166  std::shared_ptr<CPVRClient> GetClient(int iClientId) const;
167 
172  std::shared_ptr<CPVRPlaybackState> PlaybackState() const;
173 
178  CPVREpgContainer& EpgContainer();
179 
183  void Init();
184 
188  void Start();
189 
193  void Stop(bool bRestart = false);
194 
198  void Unload();
199 
203  void Deinit();
204 
208  void OnSleep();
209 
213  void OnWake();
214 
219  std::shared_ptr<CPVRDatabase> GetTVDatabase() const;
220 
225  bool IsStarted() const { return GetState() == ManagerState::STATE_STARTED; }
226 
231  void OnPlaybackStarted(const CFileItem& item);
232 
237  void OnPlaybackStopped(const CFileItem& item);
238 
243  void OnPlaybackEnded(const CFileItem& item);
244 
249  void TriggerRecordingsUpdate(int clientId);
250  void TriggerRecordingsUpdate();
251 
255  void TriggerRecordingsSizeInProgressUpdate();
256 
261  void TriggerTimersUpdate(int clientId);
262  void TriggerTimersUpdate();
263 
268  void TriggerChannelsUpdate(int clientId);
269  void TriggerChannelsUpdate();
270 
275  void TriggerProvidersUpdate(int clientId);
276  void TriggerProvidersUpdate();
277 
282  void TriggerChannelGroupsUpdate(int clientId);
283  void TriggerChannelGroupsUpdate();
284 
288  void TriggerSearchMissingChannelIcons();
289 
293  void TriggerCleanupCachedImages();
294 
299  void TriggerSearchMissingChannelIcons(const std::shared_ptr<CPVRChannelGroup>& group);
300 
304  void LocalizationChanged();
305 
311  bool IsParentalLocked(const std::shared_ptr<const CPVRChannel>& channel) const;
312 
318  bool IsParentalLocked(const std::shared_ptr<const CPVREpgInfoTag>& epgTag) const;
319 
323  void RestartParentalTimer();
324 
328  void ConnectionStateChange(CPVRClient* client,
329  const std::string& connectString,
330  PVR_CONNECTION_STATE state,
331  const std::string& message);
332 
336  CEventStream<PVREvent>& Events() { return m_events; }
337 
342  void PublishEvent(PVREvent state);
343 
344 protected:
348  void Process() override;
349 
350 private:
354  bool SetWakeupCommand();
355 
356  enum class ManagerState
357  {
358  STATE_ERROR = 0,
359  STATE_STOPPED,
360  STATE_STARTING,
361  STATE_STOPPING,
362  STATE_INTERRUPTED,
363  STATE_STARTED
364  };
365 
369  bool IsInitialising() const { return GetState() == ManagerState::STATE_STARTING; }
370 
375  bool IsStopped() const { return GetState() == ManagerState::STATE_STOPPED; }
376 
381  ManagerState GetState() const;
382 
387  void SetState(ManagerState state);
388 
393  void UpdateComponents(ManagerState stateToCheck);
394 
401  bool UpdateComponents(ManagerState stateToCheck,
402  const std::unique_ptr<CPVRGUIProgressHandler>& progressHandler);
403 
407  void UnloadComponents();
408 
413  bool IsKnownClient(int clientID) const;
414 
418  void ResetProperties();
419 
423  void Clear();
424 
428  void TriggerPlayChannelOnStartup();
429 
430  bool IsCurrentlyParentalLocked(const std::shared_ptr<const CPVRChannel>& channel,
431  bool bGenerallyLocked) const;
432 
433  CEventSource<PVREvent> m_events;
434 
437  std::shared_ptr<CPVRProviders> m_providers;
438  std::shared_ptr<CPVRChannelGroupsContainer>
439  m_channelGroups;
440  std::shared_ptr<CPVRRecordings> m_recordings;
441  std::shared_ptr<CPVRTimers> m_timers;
442  std::shared_ptr<CPVRClients> m_addons;
443  std::unique_ptr<CPVRGUIInfo> m_guiInfo;
444  std::shared_ptr<CPVRComponentRegistration> m_components;
445  std::unique_ptr<CPVREpgContainer> m_epgContainer;
447 
448  std::vector<std::shared_ptr<CPVRClient>> m_knownClients;
449  std::unique_ptr<CPVRManagerJobQueue> m_pendingUpdates;
450  std::shared_ptr<CPVRDatabase> m_database;
451  mutable CCriticalSection
452  m_critSection;
453  bool m_bFirstStart = true;
455  mutable CCriticalSection m_managerStateMutex;
456  ManagerState m_managerState = ManagerState::STATE_STOPPED;
457  std::unique_ptr<CStopWatch> m_parentalTimer;
458 
459  CCriticalSection
460  m_startStopMutex; // mutex for protecting pvr manager's start/restart/stop sequence */
461 
462  const std::shared_ptr<CPVRPlaybackState> m_playbackState;
463  CPVRGUIActionListener m_actionListener;
464  CPVRSettings m_settings;
465 };
466 } // namespace PVR
Definition: Stopwatch.h:14
Definition: Thread.h:44
Definition: EpgContainer.h:42
Definition: ContextMenuManager.h:24
bool IsStarted() const
Check whether the PVRManager has fully started.
Definition: PVRManager.h:225
Definition: IAnnouncer.h:70
Definition: PVRGUIActionListener.h:21
Definition: Variant.h:31
PVR_CONNECTION_STATE
Definition: pvr_general.h:81
T & Get()
Get a PVR component.
Definition: PVRManager.h:119
CEventStream< PVREvent > & Events()
Query the events available for CEventStream.
Definition: PVRManager.h:336
Definition: SmartPlayList.cpp:137
Definition: PVRManager.h:96
Definition: PVRClient.h:52
Definition: PVRSettings.h:27
Represents a file on a share.
Definition: FileItem.h:102